Subject: bug#6677: 24.0.50; NS variant cannot copy to pasteboard correctly

From: David De La Harpe Golden <[email-masked]>
Date: Mon, 09 Aug 2010 00:01:25 +0100

On 25/07/10 07:56, David De La Harpe Golden wrote:

> x11 side ns side
> CLIPBOARD General Pasteboard
> PRIMARY "Selection" named pasteboard
> SECONDARY "Secondary" named pasteboard

Updated patch that at least does this.  There are be
remaining issues, but it should work a bit better on macosx as well.

=== modified file 'lisp/term/ns-win.el'
--- lisp/term/ns-win.el	2010-07-13 10:41:49 +0000
+++ lisp/term/ns-win.el	2010-08-08 22:40:49 +0000
@@ -998,25 +998,25 @@

 ;;;; Pasteboard support.
 
 (declare-function ns-get-cut-buffer-internal "nsselect.m" (buffer))
 
 (defun ns-get-pasteboard ()
   "Returns the value of the pasteboard."
-  (ns-get-cut-buffer-internal 'PRIMARY))
+  (ns-get-cut-buffer-internal 'CLIPBOARD))
 
 (declare-function ns-store-cut-buffer-internal "nsselect.m" (buffer string))
 
 (defun ns-set-pasteboard (string)
   "Store STRING into the pasteboard of the Nextstep display server."
   ;; Check the data type of STRING.
   (if (not (stringp string)) (error "Nonstring given to pasteboard"))
-  (ns-store-cut-buffer-internal 'PRIMARY string))
+  (ns-store-cut-buffer-internal 'CLIPBOARD string))
 
 ;; We keep track of the last text selected here, so we can check the
 ;; current selection against it, and avoid passing back our own text
 ;; from x-cut-buffer-or-selection-value.
 (defvar ns-last-selected-text nil)
 
 (defun x-select-text (text &optional push)
   "Select TEXT, a string, according to the window system.

=== modified file 'src/nsselect.m'
--- src/nsselect.m	2010-07-08 21:25:08 +0000
+++ src/nsselect.m	2010-08-08 20:42:05 +0000
@@ -31,51 +31,56 @@
 #include <setjmp.h>
 
 #include "lisp.h"
 #include "nsterm.h"
 #include "termhooks.h"
 
 #define CUT_BUFFER_SUPPORT
 
-Lisp_Object QPRIMARY, QSECONDARY, QTEXT, QFILE_NAME;
+Lisp_Object QCLIPBOARD, QPRIMARY, QSECONDARY, QTEXT, QFILE_NAME;
 
 static Lisp_Object Vns_sent_selection_hooks;
 static Lisp_Object Vns_lost_selection_hooks;
 static Lisp_Object Vselection_alist;
 static Lisp_Object Vselection_converter_alist;
 
 static Lisp_Object Qforeign_selection;
 
-NSString *NXSecondaryPboard;
 
+/* CLIPBOARD mapped to NSGeneralPboard */
+NSString *NXPrimaryPboard;
+NSString *NXSecondaryPboard;

 /* ==========================================================================
 
     Internal utility functions
 
    ========================================================================== */

 static NSString *
 symbol_to_nsstring (Lisp_Object sym)
 {
   CHECK_SYMBOL (sym);
-  if (EQ (sym, QPRIMARY))     return NSGeneralPboard;
+  if (EQ (sym, QCLIPBOARD))   return NSGeneralPboard;
+  if (EQ (sym, QPRIMARY))     return NXPrimaryPboard;
   if (EQ (sym, QSECONDARY))   return NXSecondaryPboard;
   if (EQ (sym, QTEXT))        return NSStringPboardType;
   return [NSString stringWithUTF8String: SDATA (XSYMBOL (sym)->xname)];
 }

 static Lisp_Object
 ns_string_to_symbol (NSString *t)
 {
   if ([t isEqualToString: NSGeneralPboard])
+    return QCLIPBOARD;
+  if ([t isEqualToString: NXPrimaryPboard])
     return QPRIMARY;
   if ([t isEqualToString: NXSecondaryPboard])
     return QSECONDARY;
   if ([t isEqualToString: NSStringPboardType])
     return QTEXT;
   if ([t isEqualToString: NSFilenamesPboardType])
     return QFILE_NAME;
   if ([t isEqualToString: NSTabularTextPboardType])
@@ -531,22 +536,27 @@
   return Qnil;
 }
 #endif

 void
 nxatoms_of_nsselect (void)
 {
-  NXSecondaryPboard = @"Selection";
+  /* These are the names GNUStep's pasteboard daemon uses,
+     using them for interoperability */
+
+  NXPrimaryPboard = @"Selection";
+  NXSecondaryPboard = @"Secondary";
 }
 
 void
 syms_of_nsselect (void)
 {
+  QCLIPBOARD = intern ("CLIPBOARD");	staticpro (&QCLIPBOARD);
   QPRIMARY   = intern ("PRIMARY");	staticpro (&QPRIMARY);
   QSECONDARY = intern ("SECONDARY");	staticpro (&QSECONDARY);
   QTEXT      = intern ("TEXT"); 	staticpro (&QTEXT);
   QFILE_NAME = intern ("FILE_NAME"); 	staticpro (&QFILE_NAME);
 
   defsubr (&Sx_disown_selection_internal);
   defsubr (&Sx_get_selection_internal);
   defsubr (&Sx_own_selection_internal);