]> code.delx.au - gnu-emacs/blobdiff - src/xselect.c
frame-override-unsplittable/inhibit-frame-unsplittable name change.
[gnu-emacs] / src / xselect.c
index 09e1484159930b61e2f99abfccd0f93c6a07f639..20a977b8fa59178cbb19dd9ace6dfe598e7fcea6 100644 (file)
@@ -236,15 +236,16 @@ x_own_selection (selection_name, selection_value)
   Time time = last_event_timestamp;
   Atom selection_atom;
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (selected_frame);
+  int count;
 
   CHECK_SYMBOL (selection_name, 0);
   selection_atom = symbol_to_x_atom (dpyinfo, display, selection_name);
 
   BLOCK_INPUT;
-  x_catch_errors (display);
+  count = x_catch_errors (display);
   XSetSelectionOwner (display, selection_atom, selecting_window, time);
   x_check_errors (display, "Can't set selection: %s");
-  x_uncatch_errors (display);
+  x_uncatch_errors (display, count);
   UNBLOCK_INPUT;
 
   /* Now update the local cache */
@@ -511,6 +512,7 @@ x_reply_selection_request (event, format, data, size, type)
   int format_bytes = format/8;
   int max_bytes = SELECTION_QUANTUM (display);
   struct x_display_info *dpyinfo = x_display_info_for_display (display);
+  int count;
 
   if (max_bytes > MAX_SELECTION_QUANTUM)
     max_bytes = MAX_SELECTION_QUANTUM;
@@ -527,7 +529,7 @@ x_reply_selection_request (event, format, data, size, type)
 
   /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
   BLOCK_INPUT;
-  x_catch_errors (display);
+  count = x_catch_errors (display);
 
   /* Store the data on the requested property.
      If the selection is large, only store the first N bytes of it.
@@ -549,7 +551,6 @@ x_reply_selection_request (event, format, data, size, type)
       /* Send an INCR selection.  */
       struct prop_location *wait_object;
       int had_errors;
-      int count = specpdl_ptr - specpdl;
       Lisp_Object frame;
 
       frame = some_frame_on_display (dpyinfo);
@@ -631,12 +632,10 @@ x_reply_selection_request (event, format, data, size, type)
 
       XChangeProperty (display, window, reply.property, type, format,
                       PropModeReplace, data, 0);
-
-      unbind_to (count, Qnil);
     }
 
   XFlush (display);
-  x_uncatch_errors (display);
+  x_uncatch_errors (display, count);
   UNBLOCK_INPUT;
 }
 \f
@@ -1109,7 +1108,7 @@ x_get_foreign_selection (selection_symbol, target_type)
   Atom selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol);
   Atom type_atom;
   int secs, usecs;
-  int count = specpdl_ptr - specpdl;
+  int count;
   Lisp_Object frame;
 
   if (CONSP (target_type))
@@ -1118,7 +1117,7 @@ x_get_foreign_selection (selection_symbol, target_type)
     type_atom = symbol_to_x_atom (dpyinfo, display, target_type);
 
   BLOCK_INPUT;
-  x_catch_errors (display);
+  count = x_catch_errors (display);
   XConvertSelection (display, selection_atom, type_atom, target_property,
                     requestor_window, requestor_time);
   XFlush (display);
@@ -1149,8 +1148,7 @@ x_get_foreign_selection (selection_symbol, target_type)
 
   BLOCK_INPUT;
   x_check_errors (display, "Cannot get selection: %s");
-  x_uncatch_errors (display);
-  unbind_to (count, Qnil);
+  x_uncatch_errors (display, count);
   UNBLOCK_INPUT;
 
   if (NILP (XCONS (reading_selection_reply)->car))
@@ -1375,20 +1373,19 @@ x_get_window_property_as_lisp_data (display, window, property, target_type,
       there_is_a_selection_owner
        = XGetSelectionOwner (display, selection_atom);
       UNBLOCK_INPUT;
-      while (1) /* Note debugger can no longer return, so this is obsolete */
-       Fsignal (Qerror,
-                there_is_a_selection_owner ?
-                Fcons (build_string ("selection owner couldn't convert"),
+      Fsignal (Qerror,
+              there_is_a_selection_owner
+              ? Fcons (build_string ("selection owner couldn't convert"),
                        actual_type
                        ? Fcons (target_type,
                                 Fcons (x_atom_to_symbol (dpyinfo, display,
                                                          actual_type),
                                        Qnil))
                        : Fcons (target_type, Qnil))
-                : Fcons (build_string ("no selection"),
-                         Fcons (x_atom_to_symbol (dpyinfo, display,
-                                                  selection_atom),
-                                Qnil)));
+              : Fcons (build_string ("no selection"),
+                       Fcons (x_atom_to_symbol (dpyinfo, display,
+                                                selection_atom),
+                              Qnil)));
     }
   
   if (actual_type == dpyinfo->Xatom_INCR)
@@ -1466,14 +1463,31 @@ selection_data_to_lisp_data (display, data, size, type, format)
   else if (format == 8)
     {
       Lisp_Object str;
-
-      if (type != dpyinfo->Xatom_TEXT && type != dpyinfo->Xatom_COMPOUND_TEXT)
+      int require_encoding = 0;
+
+      /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode DATA
+        to Emacs internal format because DATA may be encoded in
+        compound text format.  In addtion, if TYPE is `STRING' and
+        DATA contains any 8-bit Latin-1 code, we should also decode
+        it.  */
+      if (type == dpyinfo->Xatom_TEXT || type == dpyinfo->Xatom_COMPOUND_TEXT)
+       require_encoding = 1;
+      else if (type == XA_STRING)
+       {
+         int i;
+         for (i = 0; i < size; i++)
+           {
+             if (data[i] >= 0x80)
+               {
+                 require_encoding = 1;
+                 break;
+               }
+           }
+       }
+      if (!require_encoding)
        str = make_string ((char *) data, size);
       else
        {
-         /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode
-            DATA to Emacs internal format because DATA may be
-            encoded in compound text format.  */
          int bufsize, dummy;
          unsigned char *buf;
          struct coding_system coding;
@@ -1582,16 +1596,16 @@ lisp_data_to_selection_data (display, obj,
     {
       /* Since we are now handling multilingual text, we must consider
         sending back compound text.  */
-      char charsets[MAX_CHARSET + 1];
+      int charsets[MAX_CHARSET + 1];
       int num;
 
       *format_ret = 8;
       *size_ret = XSTRING (obj)->size;
       *data_ret = XSTRING (obj)->data;
-      bzero (charsets, MAX_CHARSET + 1);
+      bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
       num = ((*size_ret <= 1)  /* Check the possibility of short cut.  */
             ? 0
-            : find_charset_in_str (*data_ret, *size_ret, charsets));
+            : find_charset_in_str (*data_ret, *size_ret, charsets, Qnil));
 
       if (!num || (num == 1 && charsets[CHARSET_ASCII]))
        {