emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104492: Handle errors when saving to


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104492: Handle errors when saving to clipboard manager (Bug#8779).
Date: Sat, 04 Jun 2011 17:02:42 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104492
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sat 2011-06-04 17:02:42 -0400
message:
  Handle errors when saving to clipboard manager (Bug#8779).
  
  * src/xselect.c (x_clipboard_manager_save): Remove redundant arg.
  (x_clipboard_manager_save): Add return value.
  (x_clipboard_manager_error_1, x_clipboard_manager_error_2): New
  error handlers.
  (x_clipboard_manager_save_frame, x_clipboard_manager_save_all):
  Obey Vx_select_enable_clipboard_manager.  Catch errors in
  x_clipboard_manager_save (Bug#8779).
  (Vx_select_enable_clipboard_manager): New variable.
modified:
  etc/NEWS
  src/ChangeLog
  src/xselect.c
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-06-04 12:31:34 +0000
+++ b/etc/NEWS  2011-06-04 21:02:42 +0000
@@ -400,6 +400,9 @@
 
 *** Support for X clipboard managers has been added.
 
+**** To inhibit use of the clipboard manager, set
+`x-select-enable-clipboard-manager' to nil.
+
 ** New command `rectangle-number-lines', bound to `C-x r N', numbers
 the lines in the current rectangle.  With an prefix argument, this
 prompts for a number to count from and for a format string.

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2011-06-04 18:29:18 +0000
+++ b/src/ChangeLog     2011-06-04 21:02:42 +0000
@@ -1,3 +1,14 @@
+2011-06-04  Chong Yidong  <address@hidden>
+
+       * xselect.c (x_clipboard_manager_save): Remove redundant arg.
+       (x_clipboard_manager_save): Add return value.
+       (x_clipboard_manager_error_1, x_clipboard_manager_error_2): New
+       error handlers.
+       (x_clipboard_manager_save_frame, x_clipboard_manager_save_all):
+       Obey Vx_select_enable_clipboard_manager.  Catch errors in
+       x_clipboard_manager_save (Bug#8779).
+       (Vx_select_enable_clipboard_manager): New variable.
+
 2011-06-04  Dan Nicolaescu  <address@hidden>
 
        * emacs.c (main): Warn when starting a GTK emacs in daemon mode.

=== modified file 'src/xselect.c'
--- a/src/xselect.c     2011-05-29 05:23:24 +0000
+++ b/src/xselect.c     2011-06-04 21:02:42 +0000
@@ -2108,15 +2108,14 @@
 }
 
 
-/* Send the clipboard manager a SAVE_TARGETS request with a
-   UTF8_STRING property, as described by
-   http://www.freedesktop.org/wiki/ClipboardManager */
+/* Send clipboard manager a SAVE_TARGETS request with a UTF8_STRING
+   property (http://www.freedesktop.org/wiki/ClipboardManager).  */
 
-static void
-x_clipboard_manager_save (struct x_display_info *dpyinfo,
-                         Lisp_Object frame)
+static Lisp_Object
+x_clipboard_manager_save (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Atom data = dpyinfo->Xatom_UTF8_STRING;
 
   XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -2125,6 +2124,31 @@
                   (unsigned char *) &data, 1);
   x_get_foreign_selection (QCLIPBOARD_MANAGER, QSAVE_TARGETS,
                           Qnil, frame);
+  return Qt;
+}
+
+/* Error handler for x_clipboard_manager_save_frame.  */
+
+static Lisp_Object
+x_clipboard_manager_error_1 (Lisp_Object err)
+{
+  Lisp_Object args[2];
+  args[0] = build_string ("X clipboard manager error: %s\n\
+If the problem persists, set `x-select-enable-clipboard-manager' to nil.");
+  args[1] = CAR (CDR (err));
+  Fmessage (2, args);
+  return Qnil;
+}
+
+/* Error handler for x_clipboard_manager_save_all.  */
+
+static Lisp_Object
+x_clipboard_manager_error_2 (Lisp_Object err)
+{
+  fprintf (stderr, "Error saving to X clipboard manager.\n\
+If the problem persists, set `x-select-enable-clipboard-manager' \
+to nil.\n");
+  return Qnil;
 }
 
 /* Called from delete_frame: save any clipboard owned by FRAME to the
@@ -2136,7 +2160,8 @@
 {
   struct frame *f;
 
-  if (FRAMEP (frame)
+  if (!NILP (Vx_select_enable_clipboard_manager)
+      && FRAMEP (frame)
       && (f = XFRAME (frame), FRAME_X_P (f))
       && FRAME_LIVE_P (f))
     {
@@ -2148,7 +2173,8 @@
          && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection)))))
          && XGetSelectionOwner (dpyinfo->display,
                                 dpyinfo->Xatom_CLIPBOARD_MANAGER))
-       x_clipboard_manager_save (dpyinfo, frame);
+       internal_condition_case_1 (x_clipboard_manager_save, frame, Qt,
+                                  x_clipboard_manager_error_1);
     }
 }
 
@@ -2162,6 +2188,10 @@
   /* Loop through all X displays, saving owned clipboards.  */
   struct x_display_info *dpyinfo;
   Lisp_Object local_selection, local_frame;
+
+  if (NILP (Vx_select_enable_clipboard_manager))
+    return;
+
   for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
     {
       local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
@@ -2172,7 +2202,8 @@
 
       local_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
       if (FRAME_LIVE_P (XFRAME (local_frame)))
-       x_clipboard_manager_save (dpyinfo, local_frame);
+       internal_condition_case_1 (x_clipboard_manager_save, local_frame,
+                                  Qt, x_clipboard_manager_error_2);
     }
 }
 
@@ -2641,6 +2672,14 @@
 it merely informs you that they have happened.  */);
   Vx_sent_selection_functions = Qnil;
 
+  DEFVAR_LISP ("x-select-enable-clipboard-manager",
+              Vx_select_enable_clipboard_manager,
+              doc: /* Whether to enable X clipboard manager support.
+If non-nil, then whenever Emacs is killed or an Emacs frame is deleted
+while owning the X clipboard, the clipboard contents are saved to the
+clipboard manager if one is present.  */);
+  Vx_select_enable_clipboard_manager = Qt;
+
   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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]