From: Stefan Monnier Date: Fri, 3 Oct 2014 01:39:49 +0000 (-0400) Subject: New gui-selection-value consolidating x-selection-value. X-Git-Tag: emacs-25.0.90~2635^2~679^2~152 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d6f8fef3fc17187687fafce50b428f88a278aee9;p=emacs.git New gui-selection-value consolidating x-selection-value. * lisp/select.el (gui-selection-value-alist): New method. (gui-selection-value): New function. (x-selection-value): Make it an obsolete alias. * lisp/simple.el (interprogram-paste-function): Default to gui-selection-value. * lisp/w32-common-fns.el (w32-get-selection-value): Simplify. (x-selection-value): Remove alias. (interprogram-paste-function): Don't set. (gui-selection-value): Define for w32. * lisp/term/x-win.el (gui-selection-value): Define for x. (x--selection-value): Rename from x--selection-value. (interprogram-paste-function): Don't set. * lisp/term/pc-win.el (w16-get-selection-value): Simplify. (msdos-initialize-window-system): Don't set interprogram-paste-function. (gui-selection-value): Define for pc. * lisp/term/ns-win.el (x-selection-value): Remove. (gui-selection-value): Define for ns, instead. * lisp/term/common-win.el (x-setup-function-keys): Don't set interprogram-paste-function. * lisp/obsolete/mouse-sel.el (mouse-sel-get-selection-function): Use gui-selection-value. --- diff --git a/etc/NEWS b/etc/NEWS index 1c45cc0c6c3..aa953971923 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -247,6 +247,7 @@ Emacs-21. ** Some "x-*" were obsoleted: *** x-select-text is renamed gui-select-text. +*** x-selection-value is renamed gui-selection-value. *** x-get-selection is renamed gui-get-selection. *** x-get-clipboard and x-clipboard-yank are marked obsolete. *** x-get-selection-value is renamed to gui-get-primary-selection. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1f9ac164cfa..d7e24c735a6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,29 @@ +2014-10-03 Stefan Monnier + + New gui-selection-value consolidating x-selection-value. + * select.el (gui-selection-value-alist): New method. + (gui-selection-value): New function. + (x-selection-value): Make it an obsolete alias. + * simple.el (interprogram-paste-function): Default to + gui-selection-value. + * w32-common-fns.el (w32-get-selection-value): Simplify. + (x-selection-value): Remove alias. + (interprogram-paste-function): Don't set. + (gui-selection-value): Define for w32. + * term/x-win.el (gui-selection-value): Define for x. + (x--selection-value): Rename from x--selection-value. + (interprogram-paste-function): Don't set. + * term/pc-win.el (w16-get-selection-value): Simplify. + (msdos-initialize-window-system): Don't set + interprogram-paste-function. + (gui-selection-value): Define for pc. + * term/ns-win.el (x-selection-value): Remove. + (gui-selection-value): Define for ns, instead. + * term/common-win.el (x-setup-function-keys): Don't set + interprogram-paste-function. + * obsolete/mouse-sel.el (mouse-sel-get-selection-function): + Use gui-selection-value. + 2014-10-02 David Raynes (tiny change) * term/ns-win.el: Add functions to ns frame, not x frame (bug#18614). diff --git a/lisp/obsolete/mouse-sel.el b/lisp/obsolete/mouse-sel.el index 7d7cd1f137f..837aefb8b7f 100644 --- a/lisp/obsolete/mouse-sel.el +++ b/lisp/obsolete/mouse-sel.el @@ -98,7 +98,7 @@ ;; ;; Selection/kill-ring interaction is retained ;; interprogram-cut-function = gui-select-text -;; interprogram-paste-function = x-selection-value +;; interprogram-paste-function = gui-selection-value ;; ;; What you lose is the ability to select some text in ;; delete-selection-mode and yank over the top of it. @@ -308,13 +308,13 @@ Called with two arguments: This sets the selection, unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.") -(declare-function x-selection-value "term/x-win" ()) (defvar mouse-sel-get-selection-function (lambda (selection) (if (eq selection 'PRIMARY) - (or (x-selection-value) - (bound-and-true-p x-last-selected-text-primary)) + (or (gui-selection-value) + (bound-and-true-p x-last-selected-text-primary) + gui-last-selected-text) (x-get-selection selection))) "Function to call to get the selection. Called with one argument: diff --git a/lisp/select.el b/lisp/select.el index d6be917f291..9e48cc0b432 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -98,6 +98,9 @@ SELECTION-SYMBOL is typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. TARGET-TYPE is the type of data desired, typically `STRING'.") (defvar gui-last-selected-text nil + ;; 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 gui-selection-value. "Last text passed to `gui-select-text'.") (defun gui-select-text (text) @@ -116,6 +119,25 @@ On MS-Windows, make TEXT the current selection." (setq gui-last-selected-text text)) (define-obsolete-function-alias 'x-select-text 'gui-select-text "25.1") +(gui-method-declare gui-selection-value #'ignore + "Method to return the GUI's selection. +Takes no argument, and returns a string. +Should obey `gui-select-enable-clipboard'.") + +(defun gui-selection-value () + (let ((text (gui-call gui-selection-value))) + (if (string= text "") (setq text nil)) + (cond + ((not text) nil) + ((eq text gui-last-selected-text) nil) + ((string= text gui-last-selected-text) + ;; Record the newer string, so subsequent calls can use the `eq' test. + (setq gui-last-selected-text text) + nil) + (t + (setq gui-last-selected-text text))))) +(define-obsolete-function-alias 'x-selection-value 'gui-selection-value "25.1") + (defun gui-get-selection (&optional type data-type) "Return the value of an X Windows selection. The argument TYPE (default `PRIMARY') says which selection, diff --git a/lisp/simple.el b/lisp/simple.el index fc5ecbad10e..9b59b65b851 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3640,7 +3640,7 @@ put in the kill ring, to make the new kill available to other programs. The function takes one argument, TEXT, which is a string containing the text which should be made available.") -(defvar interprogram-paste-function #'ignore +(defvar interprogram-paste-function #'gui-selection-value "Function to call to get text cut from other programs. Most window systems provide a facility for cutting and pasting text between different programs, such as the clipboard on X and diff --git a/lisp/term/common-win.el b/lisp/term/common-win.el index fcb9fd55bb1..d026ee8eabe 100644 --- a/lisp/term/common-win.el +++ b/lisp/term/common-win.el @@ -56,8 +56,7 @@ (set-keymap-parent map (keymap-parent local-function-key-map)) (set-keymap-parent local-function-key-map map)) (when (featurep 'ns) - (setq interprogram-paste-function 'x-selection-value - system-key-alist + (setq system-key-alist (list ;; These are special "keys" used to pass events from C to lisp. (cons (logior (lsh 0 16) 1) 'ns-power-off) diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index b1d3a00df0c..22e99d87968 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -736,27 +736,14 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") (if (not (stringp string)) (error "Nonstring given to pasteboard")) (ns-store-selection-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-selection-value. - ;; Return the value of the current Nextstep selection. For ;; compatibility with older Nextstep applications, this checks cut ;; buffer 0 before retrieving the value of the primary selection. -(defun x-selection-value () - (let (text) - ;; Consult the selection. Treat empty strings as if they were unset. - (or text (setq text (ns-get-pasteboard))) - (if (string= text "") (setq text nil)) - (cond - ((not text) nil) - ((eq text gui-last-selected-text) nil) - ((string= text gui-last-selected-text) - ;; Record the newer string, so subsequent calls can use the `eq' test. - (setq gui-last-selected-text text) - nil) - (t - (setq gui-last-selected-text text))))) +(gui-method-define gui-selection-value ns #'ns-selection-value) +(defun ns-selection-value () + ;; Consult the selection. Treat empty strings as if they were unset. + (if gui-select-enable-clipboard + (ns-get-pasteboard))) (defun ns-copy-including-secondary () (interactive) diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el index 3498937b4d2..a7507377bda 100644 --- a/lisp/term/pc-win.el +++ b/lisp/term/pc-win.el @@ -223,20 +223,9 @@ the operating system.") "Return the value of the current selection. Consult the selection. Treat empty strings as if they were unset." (if gui-select-enable-clipboard - (let (text) - ;; Don't die if x-get-selection signals an error. - (with-demoted-errors "w16-get-clipboard-data:%s" - (setq text (w16-get-clipboard-data))) - (if (string= text "") (setq text nil)) - (cond - ((not text) nil) - ((eq text gui-last-selected-text) nil) - ((string= text gui-last-selected-text) - ;; Record the newer string, so subsequent calls can use the 'eq' test. - (setq gui-last-selected-text text) - nil) - (t - (setq gui-last-selected-text text)))))) + ;; Don't die if x-get-selection signals an error. + (with-demoted-errors "w16-get-clipboard-data:%s" + (w16-get-clipboard-data)))) ;; gui-selection-owner-p is used in simple.el. (gui-method-define gui-selection-owner-p pc #'w16-selection-owner-p) @@ -380,7 +369,6 @@ Errors out because it is not supposed to be called, ever." (setq split-window-keep-point t) ;; Arrange for the kill and yank functions to set and check the ;; clipboard. - (setq interprogram-paste-function #'w16-get-selection-value) (menu-bar-enable-clipboard) (run-hooks 'terminal-init-msdos-hook)) @@ -398,6 +386,7 @@ Errors out because it is not supposed to be called, ever." (declare-function w16-set-clipboard-data "w16select.c" (string &optional ignored)) (gui-method-define gui-select-text pc #'w16--select-text) +(gui-method-define gui-selection-value pc #'w16-get-selection-value) (defun w16--select-text (text) (when gui-select-enable-clipboard (w16-set-clipboard-data text))) diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index a50f886c66a..d6848628bf3 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -1156,7 +1156,7 @@ as returned by `x-server-vendor'." ;; 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-selection-value. We track both +;; from x--selection-value. We track both ;; separately in case another X application only sets one of them ;; we aren't fooled by the PRIMARY or CLIPBOARD selection staying the same. (defvar x-last-selected-text-clipboard nil @@ -1222,73 +1222,72 @@ The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)." ;; If this function is called twice and finds the same text, ;; it returns nil the second time. This is so that a single ;; selection won't be added to the kill ring over and over. -(defun x-selection-value () +(gui-method-define gui-selection-value x #'x--selection-value) +(defun x--selection-value () ;; With multi-tty, this function may be called from a tty frame. - (when (eq (framep (selected-frame)) 'x) - (let (clip-text primary-text) - (when x-select-enable-clipboard - (setq clip-text (x-selection-value-internal 'CLIPBOARD)) - (if (string= clip-text "") (setq clip-text nil)) - - ;; Check the CLIPBOARD selection for 'newness', is it different - ;; from what we remembered them to be last time we did a - ;; cut/paste operation. - (setq clip-text - (cond ;; check clipboard - ((or (not clip-text) (string= clip-text "")) - (setq x-last-selected-text-clipboard nil)) - ((eq clip-text x-last-selected-text-clipboard) nil) - ((string= clip-text x-last-selected-text-clipboard) - ;; Record the newer string, - ;; so subsequent calls can use the `eq' test. - (setq x-last-selected-text-clipboard clip-text) - nil) - (t (setq x-last-selected-text-clipboard clip-text))))) - - (when x-select-enable-primary - (setq primary-text (x-selection-value-internal 'PRIMARY)) - ;; Check the PRIMARY selection for 'newness', is it different - ;; from what we remembered them to be last time we did a - ;; cut/paste operation. - (setq primary-text - (cond ;; check primary selection - ((or (not primary-text) (string= primary-text "")) - (setq x-last-selected-text-primary nil)) - ((eq primary-text x-last-selected-text-primary) nil) - ((string= primary-text x-last-selected-text-primary) - ;; Record the newer string, - ;; so subsequent calls can use the `eq' test. - (setq x-last-selected-text-primary primary-text) - nil) - (t - (setq x-last-selected-text-primary primary-text))))) - - ;; As we have done one selection, clear this now. - (setq next-selection-coding-system nil) - - ;; At this point we have recorded the current values for the - ;; selection from clipboard (if we are supposed to) and primary. - ;; So return the first one that has changed - ;; (which is the first non-null one). - ;; - ;; NOTE: There will be cases where more than one of these has - ;; changed and the new values differ. This indicates that - ;; something like the following has happened since the last time - ;; we looked at the selections: Application X set all the - ;; selections, then Application Y set only one of them. - ;; In this case since we don't have - ;; timestamps there is no way to know what the 'correct' value to - ;; return is. The nice thing to do would be to tell the user we - ;; saw multiple possible selections and ask the user which was the - ;; one they wanted. - (or clip-text primary-text) - ))) + (let (clip-text primary-text) + (when x-select-enable-clipboard + (setq clip-text (x-selection-value-internal 'CLIPBOARD)) + (if (string= clip-text "") (setq clip-text nil)) + + ;; Check the CLIPBOARD selection for 'newness', is it different + ;; from what we remembered them to be last time we did a + ;; cut/paste operation. + (setq clip-text + (cond ;; check clipboard + ((or (not clip-text) (string= clip-text "")) + (setq x-last-selected-text-clipboard nil)) + ((eq clip-text x-last-selected-text-clipboard) nil) + ((string= clip-text x-last-selected-text-clipboard) + ;; Record the newer string, + ;; so subsequent calls can use the `eq' test. + (setq x-last-selected-text-clipboard clip-text) + nil) + (t (setq x-last-selected-text-clipboard clip-text))))) + + (when x-select-enable-primary + (setq primary-text (x-selection-value-internal 'PRIMARY)) + ;; Check the PRIMARY selection for 'newness', is it different + ;; from what we remembered them to be last time we did a + ;; cut/paste operation. + (setq primary-text + (cond ;; check primary selection + ((or (not primary-text) (string= primary-text "")) + (setq x-last-selected-text-primary nil)) + ((eq primary-text x-last-selected-text-primary) nil) + ((string= primary-text x-last-selected-text-primary) + ;; Record the newer string, + ;; so subsequent calls can use the `eq' test. + (setq x-last-selected-text-primary primary-text) + nil) + (t + (setq x-last-selected-text-primary primary-text))))) + + ;; As we have done one selection, clear this now. + (setq next-selection-coding-system nil) + + ;; At this point we have recorded the current values for the + ;; selection from clipboard (if we are supposed to) and primary. + ;; So return the first one that has changed + ;; (which is the first non-null one). + ;; + ;; NOTE: There will be cases where more than one of these has + ;; changed and the new values differ. This indicates that + ;; something like the following has happened since the last time + ;; we looked at the selections: Application X set all the + ;; selections, then Application Y set only one of them. + ;; In this case since we don't have + ;; timestamps there is no way to know what the 'correct' value to + ;; return is. The nice thing to do would be to tell the user we + ;; saw multiple possible selections and ask the user which was the + ;; one they wanted. + (or clip-text primary-text) + )) (define-obsolete-function-alias 'x-cut-buffer-or-selection-value 'x-selection-value "24.1") ;; Arrange for the kill and yank functions to set and check the clipboard. -(setq interprogram-paste-function 'x-selection-value) (defun x-clipboard-yank () "Insert the clipboard contents, or the last stretch of killed text." diff --git a/lisp/w32-common-fns.el b/lisp/w32-common-fns.el index 3f8cbc19dba..04037839b94 100644 --- a/lisp/w32-common-fns.el +++ b/lisp/w32-common-fns.el @@ -70,32 +70,15 @@ That includes all Windows systems except for 9X/Me." ;;;; Selections -;; 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-selection-value. - (defun w32-get-selection-value () "Return the value of the current selection. Consult the selection. Treat empty strings as if they were unset." (if gui-select-enable-clipboard - (let ((text - ;; Don't die if x-get-selection signals an error. - (with-demoted-errors "w32-get-clipboard-data:%S" - (w32-get-clipboard-data)))) - (if (string= text "") (setq text nil)) - (cond - ((not text) nil) - ((eq text gui-last-selected-text) nil) - ((string= text gui-last-selected-text) - ;; Record the newer string, so subsequent calls can use the 'eq' test. - (setq gui-last-selected-text text) - nil) - (t - (setq gui-last-selected-text text)))))) + ;; Don't die if x-get-selection signals an error. + (with-demoted-errors "w32-get-clipboard-data:%S" + (w32-get-clipboard-data)))) -(defalias 'x-selection-value #'w32-get-selection-value) - ;; Arrange for the kill and yank functions to set and check the clipboard. -(setq interprogram-paste-function #'w32-get-selection-value) +(gui-method-define gui-selection-value w32 #'w32-get-selection-value) (provide 'w32-common-fns)