diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-10-02 21:39:49 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-10-02 21:39:49 -0400 |
commit | d6f8fef3fc17187687fafce50b428f88a278aee9 (patch) | |
tree | 042705e9c52b2799144888fe9a602022f8d84e72 /lisp/term | |
parent | f0da11bd3978faee12cd15b26dbf2fbf837d8a2b (diff) | |
download | emacs-d6f8fef3fc17187687fafce50b428f88a278aee9.tar.gz emacs-d6f8fef3fc17187687fafce50b428f88a278aee9.tar.bz2 emacs-d6f8fef3fc17187687fafce50b428f88a278aee9.zip |
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.
Diffstat (limited to 'lisp/term')
-rw-r--r-- | lisp/term/common-win.el | 3 | ||||
-rw-r--r-- | lisp/term/ns-win.el | 23 | ||||
-rw-r--r-- | lisp/term/pc-win.el | 19 | ||||
-rw-r--r-- | lisp/term/x-win.el | 123 |
4 files changed, 71 insertions, 97 deletions
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." |