(scan_lists): Follow coding convention.
[bpt/emacs.git] / src / xselect.c
index cd49e05..0f4d628 100644 (file)
@@ -1,12 +1,12 @@
 /* X Selection processing for Emacs.
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -123,13 +123,6 @@ Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3,
 
 static Lisp_Object Vx_lost_selection_functions;
 static Lisp_Object Vx_sent_selection_functions;
-/* Coding system for communicating with other X clients via cutbuffer,
-   selection, and clipboard.  */
-static Lisp_Object Vselection_coding_system;
-
-/* Coding system for the next communicating with other X clients.  */
-static Lisp_Object Vnext_selection_coding_system;
-
 static Lisp_Object Qforeign_selection;
 
 /* If this is a smaller number than the max-request-size of the display,
@@ -140,11 +133,7 @@ static Lisp_Object Qforeign_selection;
    incremental transfer stuff, but it might improve server performance.  */
 #define MAX_SELECTION_QUANTUM 0xFFFFFF
 
-#ifdef HAVE_X11R4
 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
-#else
-#define SELECTION_QUANTUM(dpy) (((dpy)->max_request_size << 2) - 100)
-#endif
 
 /* The timestamp of the last input event Emacs received from the X server.  */
 /* Defined in keyboard.c.  */
@@ -442,7 +431,7 @@ x_own_selection (selection_name, selection_value)
     if (!NILP (prev_value))
       {
        Lisp_Object rest;       /* we know it's not the CAR, so it's easy.  */
-       for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+       for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
          if (EQ (prev_value, Fcar (XCDR (rest))))
            {
              XSETCDR (rest, Fcdr (XCDR (rest)));
@@ -691,6 +680,10 @@ some_frame_on_display (dpyinfo)
    DATA and SIZE describe the data to send, already converted.
    FORMAT is the unit-size (in bits) of the data to be transmitted.  */
 
+#ifdef TRACE_SELECTION
+static int x_reply_selection_request_cnt;
+#endif  /* TRACE_SELECTION */
+
 static void
 x_reply_selection_request (event, format, data, size, type)
      struct input_event *event;
@@ -729,10 +722,9 @@ x_reply_selection_request (event, format, data, size, type)
 
 #ifdef TRACE_SELECTION
   {
-    static int cnt;
     char *sel = XGetAtomName (display, reply.selection);
     char *tgt = XGetAtomName (display, reply.target);
-    TRACE3 ("%s, target %s (%d)", sel, tgt, ++cnt);
+    TRACE3 ("%s, target %s (%d)", sel, tgt, ++x_reply_selection_request_cnt);
     if (sel) XFree (sel);
     if (tgt) XFree (tgt);
   }
@@ -843,7 +835,7 @@ x_reply_selection_request (event, format, data, size, type)
            break;
 
          /* Now wait for the requester to ack this chunk by deleting the
-            property.   This can run random lisp code or signal.  */
+            property.  This can run random lisp code or signal.  */
          TRACE1 ("Waiting for increment ACK (deletion of %s)",
                  XGetAtomName (display, reply.property));
          wait_for_property_change (wait_object);
@@ -964,6 +956,12 @@ x_handle_selection_request (event)
       Atom type;
       int nofree;
 
+      if (CONSP (converted_selection) && NILP (XCDR (converted_selection)))
+        {
+          x_decline_selection_request (event);
+          goto DONE2;
+        }
+
       lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event),
                                   converted_selection,
                                   &data, &type, &size, &format, &nofree);
@@ -979,6 +977,8 @@ x_handle_selection_request (event)
       if (!nofree)
        xfree (data);
     }
+
+ DONE2:
   unbind_to (count, Qnil);
 
  DONE:
@@ -1014,6 +1014,7 @@ x_handle_selection_clear (event)
 
   TRACE0 ("x_handle_selection_clear");
 
+#ifdef MULTI_KBOARD  
   /* If the new selection owner is also Emacs,
      don't clear the new selection.  */
   BLOCK_INPUT;
@@ -1032,7 +1033,8 @@ x_handle_selection_clear (event)
          }
       }
   UNBLOCK_INPUT;
-
+#endif
+  
   selection_symbol = x_atom_to_symbol (display, selection);
 
   local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
@@ -1059,7 +1061,7 @@ x_handle_selection_clear (event)
   else
     {
       Lisp_Object rest;
-      for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+      for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
        if (EQ (local_selection_data, Fcar (XCDR (rest))))
          {
            XSETCDR (rest, Fcdr (XCDR (rest)));
@@ -1140,7 +1142,7 @@ x_clear_frame_selections (f)
     }
 
   /* Delete elements after the beginning of Vselection_alist.  */
-  for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+  for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
     if (EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest))))))))
       {
        /* Let random Lisp code notice that the selection has been stolen.  */
@@ -1863,9 +1865,9 @@ selection_data_to_lisp_data (display, data, size, type, format)
        }
     }
 
-  /* Convert a single 16 or small 32 bit number to a Lisp_Int.
-     If the number is > 16 bits, convert it to a cons of integers,
-     16 bits in each half.
+  /* Convert a single 16-bit number or a small 32-bit number to a Lisp_Int.
+     If the number is 32 bits and won't fit in a Lisp_Int,
+     convert it to a cons of integers, 16 bits in each half.
    */
   else if (format == 32 && size == sizeof (int))
     return long_to_cons (((unsigned int *) data) [0]);
@@ -2702,7 +2704,7 @@ If the value is 0 or the atom is not known, return the empty string.  */)
     ret = make_string (name, strlen (name));
 
   if (atom && name) XFree (name);
-  if (NILP (ret)) ret = make_string ("", 0);
+  if (NILP (ret)) ret = empty_unibyte_string;
 
   UNBLOCK_INPUT;
 
@@ -2734,11 +2736,11 @@ FRAME is on.  If FRAME is nil, the selected frame is used.  */)
   else
     error ("ATOM must be a symbol or a string");
 
-  for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) 
+  for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
     if (dpyinfo->x_dnd_atoms[i] == x_atom)
       return Qnil;
 
-  if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size) 
+  if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size)
     {
       dpyinfo->x_dnd_atoms_size *= 2;
       dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms,
@@ -2768,7 +2770,7 @@ x_handle_dnd_message (f, event, dpyinfo, bufp)
   int idata[5];
   size_t i;
 
-  for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) 
+  for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
     if (dpyinfo->x_dnd_atoms[i] == event->message_type) break;
 
   if (i == dpyinfo->x_dnd_atoms_length) return 0;
@@ -2789,15 +2791,15 @@ x_handle_dnd_message (f, event, dpyinfo, bufp)
     }
 
   vec = Fmake_vector (make_number (4), Qnil);
-  AREF (vec, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
-                                                 event->message_type));
-  AREF (vec, 1) = frame;
-  AREF (vec, 2) = make_number (event->format);
-  AREF (vec, 3) = x_property_data_to_lisp (f,
-                                           data,
-                                           event->message_type,
-                                           event->format,
-                                           size);
+  ASET (vec, 0, SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
+                                              event->message_type)));
+  ASET (vec, 1, frame);
+  ASET (vec, 2, make_number (event->format));
+  ASET (vec, 3, x_property_data_to_lisp (f,
+                                        data,
+                                        event->message_type,
+                                        event->format,
+                                        size));
 
   mouse_position_for_drop (f, &x, &y);
   bufp->kind = DRAG_N_DROP_EVENT;
@@ -2997,21 +2999,6 @@ This hook doesn't let you change the behavior of Emacs's selection replies,
 it merely informs you that they have happened.  */);
   Vx_sent_selection_functions = Qnil;
 
-  DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
-              doc: /* Coding system for communicating with other X clients.
-When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system.
-The default value is `compound-text-with-extensions'.  */);
-  Vselection_coding_system = intern ("compound-text-with-extensions");
-
-  DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
-              doc: /* Coding system for the next communication with other X clients.
-Usually, `selection-coding-system' is used for communicating with
-other X clients.  But, if this variable is set, it is used for the
-next communication only.  After the communication, this variable is
-set to nil.  */);
-  Vnext_selection_coding_system = Qnil;
-
   DEFVAR_INT ("x-selection-timeout", &x_selection_timeout,
              doc: /* Number of milliseconds to wait for a selection reply.
 If the selection owner doesn't reply in this time, we give up.