Move clipboard-manager functionality out of hooks.
authorChong Yidong <cyd@stupidchicken.com>
Sun, 29 May 2011 00:45:00 +0000 (20:45 -0400)
committerChong Yidong <cyd@stupidchicken.com>
Sun, 29 May 2011 00:45:00 +0000 (20:45 -0400)
* lisp/select.el: Don't perform clipboard-manager saving in hooks;
leave the hooks empty.

* src/emacs.c (Fkill_emacs): Call x_clipboard_manager_save_all.
* src/frame.c (delete_frame): Call x_clipboard_manager_save_frame.

* src/xselect.c (x_clipboard_manager_save_frame)
(x_clipboard_manager_save_all): New functions.
(Fx_clipboard_manager_save): Lisp function deleted.

* src/xterm.h: Update prototype.

etc/NEWS
lisp/ChangeLog
lisp/select.el
src/ChangeLog
src/emacs.c
src/frame.c
src/xselect.c
src/xterm.h

index e49b3d3..dc1f25d 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -177,6 +177,8 @@ with Xft.  To change font, use the X resource font, for example:
 Emacs.pane.menubar.font:  Courier-12
 
 ** On graphical displays, the mode-line no longer ends in dashes.
+Also, the first dash (which does not indicate anything) is just
+displayed as a space.
 
 ** On Nextstep/OSX, the menu bar can be hidden by customizing
 ns-auto-hide-menu-bar.
@@ -386,6 +388,8 @@ between applications.
 
 *** Support for X cut buffers has been removed.
 
+*** Support for X clipboard managers has been added.
+
 ** 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.
index ee03aec..a236441 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-29  Chong Yidong  <cyd@stupidchicken.com>
+
+       * select.el: Don't perform clipboard-manager saving in hooks;
+       leave the hooks empty.
+
 2011-05-28  Leo Liu  <sdl.web@gmail.com>
 
        * replace.el (occur-menu-map, occur-edit-mode-map): New vars.
index 5abbf8f..10c8f0b 100644 (file)
@@ -395,10 +395,6 @@ This function returns the string \"emacs\"."
        (SAVE_TARGETS . xselect-convert-to-save-targets)
        (_EMACS_INTERNAL . xselect-convert-to-identity)))
 
-(when (fboundp 'x-clipboard-manager-save)
-  (add-hook 'delete-frame-functions 'x-clipboard-manager-save)
-  (add-hook 'kill-emacs-hook 'x-clipboard-manager-save))
-
 (provide 'select)
 
 ;;; select.el ends here
index 1546348..6c56b87 100644 (file)
@@ -1,3 +1,14 @@
+2011-05-29  Chong Yidong  <cyd@stupidchicken.com>
+
+       * xselect.c (x_clipboard_manager_save_frame)
+       (x_clipboard_manager_save_all): New functions.
+       (Fx_clipboard_manager_save): Lisp function deleted.
+
+       * emacs.c (Fkill_emacs): Call x_clipboard_manager_save_all.
+       * frame.c (delete_frame): Call x_clipboard_manager_save_frame.
+
+       * xterm.h: Update prototype.
+
 2011-05-28  William Xu  <william.xwl@gmail.com>
 
        * nsterm.m (ns_term_shutdown): Synchronize user defaults before
index 8c4490b..090fdda 100644 (file)
@@ -1959,6 +1959,11 @@ sort_args (int argc, char **argv)
   xfree (priority);
 }
 \f
+#ifdef HAVE_X_WINDOWS
+/* Defined in xselect.c.  */
+extern void x_clipboard_manager_save_all (void);
+#endif
+
 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
        doc: /* Exit the Emacs job and kill it.
 If ARG is an integer, return ARG as the exit program code.
@@ -1985,6 +1990,11 @@ all of which are called before Emacs is actually killed.  */)
 
   UNGCPRO;
 
+#ifdef HAVE_X_WINDOWS
+  /* Transfer any clipboards we own to the clipboard manager.  */
+  x_clipboard_manager_save_all ();
+#endif
+
   shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
 
   /* If we have an auto-save list file,
index ce92a83..74e222f 100644 (file)
@@ -1347,7 +1347,14 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
       = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
               pending_funcalls);
   else
-    safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
+    {
+#ifdef HAVE_X_WINDOWS
+      /* Also, save clipboard to the the clipboard manager.  */
+      x_clipboard_manager_save_frame (frame);
+#endif
+
+      safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
+    }
 
   /* The hook may sometimes (indirectly) cause the frame to be deleted.  */
   if (! FRAME_LIVE_P (f))
index 8741cb8..0f852a7 100644 (file)
@@ -2107,6 +2107,7 @@ frame's display, or the first available X display.  */)
   return (owner ? Qt : Qnil);
 }
 
+\f
 /* Send the clipboard manager a SAVE_TARGETS request with a
    UTF8_STRING property, as described by
    http://www.freedesktop.org/wiki/ClipboardManager */
@@ -2126,54 +2127,53 @@ x_clipboard_manager_save (struct x_display_info *dpyinfo,
                           Qnil, frame);
 }
 
-DEFUN ("x-clipboard-manager-save", Fx_clipboard_manager_save,
-       Sx_clipboard_manager_save, 0, 1, 0,
-       doc: /* Save the clipboard contents to the clipboard manager.
-This function is intended to run from `delete-frame-functions' and
-`kill-emacs-hook', to transfer clipboard data owned by Emacs to a
-clipboard manager prior to deleting a frame or killing Emacs.
-
-FRAME specifies a frame owning a clipboard; do nothing if FRAME does
-not own the clipboard, or if no clipboard manager is present.  If
-FRAME is nil, save all clipboard contents owned by Emacs.  */)
-  (Lisp_Object frame)
+/* Called from delete_frame: save any clipboard owned by FRAME to the
+   clipboard manager.  Do nothing if FRAME does not own the clipboard,
+   or if no clipboard manager is present.  */
+
+void
+x_clipboard_manager_save_frame (Lisp_Object frame)
 {
-  if (FRAMEP (frame))
+  struct frame *f;
+
+  if (FRAMEP (frame)
+      && (f = XFRAME (frame), FRAME_X_P (f))
+      && FRAME_LIVE_P (f))
     {
-      struct frame *f = XFRAME (frame);
-      if (FRAME_LIVE_P (f) && FRAME_X_P (f))
-       {
-         struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
-         Lisp_Object local_selection
-           = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
-
-         if (!NILP (local_selection)
-             && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection)))))
-             && XGetSelectionOwner (dpyinfo->display,
-                                    dpyinfo->Xatom_CLIPBOARD_MANAGER))
-           x_clipboard_manager_save (dpyinfo, frame);
-       }
+      struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+      Lisp_Object local_selection
+       = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
+
+      if (!NILP (local_selection)
+         && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection)))))
+         && XGetSelectionOwner (dpyinfo->display,
+                                dpyinfo->Xatom_CLIPBOARD_MANAGER))
+       x_clipboard_manager_save (dpyinfo, frame);
     }
-  else if (NILP (frame))
+}
+
+/* Called from Fkill_emacs: save any clipboard owned by FRAME to the
+   clipboard manager.  Do nothing if FRAME does not own the clipboard,
+   or if no clipboard manager is present.  */
+
+void
+x_clipboard_manager_save_all (void)
+{
+  /* Loop through all X displays, saving owned clipboards.  */
+  struct x_display_info *dpyinfo;
+  Lisp_Object local_selection, local_frame;
+  for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
     {
-      /* Loop through all X displays, saving owned clipboards.  */
-      struct x_display_info *dpyinfo;
-      Lisp_Object local_selection, local_frame;
-      for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
-       {
-         local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
-         if (NILP (local_selection)
-             || !XGetSelectionOwner (dpyinfo->display,
-                                     dpyinfo->Xatom_CLIPBOARD_MANAGER))
-           continue;
-
-         local_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
-         if (FRAME_LIVE_P (XFRAME (local_frame)))
-           x_clipboard_manager_save (dpyinfo, local_frame);
-       }
-    }
+      local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
+      if (NILP (local_selection)
+         || !XGetSelectionOwner (dpyinfo->display,
+                                 dpyinfo->Xatom_CLIPBOARD_MANAGER))
+       continue;
 
-  return Qnil;
+      local_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
+      if (FRAME_LIVE_P (XFRAME (local_frame)))
+       x_clipboard_manager_save (dpyinfo, local_frame);
+    }
 }
 
 \f
@@ -2586,7 +2586,6 @@ syms_of_xselect (void)
   defsubr (&Sx_disown_selection_internal);
   defsubr (&Sx_selection_owner_p);
   defsubr (&Sx_selection_exists_p);
-  defsubr (&Sx_clipboard_manager_save);
 
   defsubr (&Sx_get_atom_name);
   defsubr (&Sx_send_client_message);
index c44978d..2184794 100644 (file)
@@ -1024,6 +1024,7 @@ extern Lisp_Object x_property_data_to_lisp (struct frame *,
                                             Atom,
                                             int,
                                             unsigned long);
+extern void x_clipboard_manager_save_frame (Lisp_Object);
 
 /* Defined in xfns.c */