From 31300bee24ddcfd7dc27e757513d3c176a7fad83 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 1 Oct 2014 23:19:32 -0400 Subject: [PATCH] Consolidate management/ownership of selections. * lisp/select.el (gui-get-selection-alist): New method. (gui-get-selection): Use it. Rename from x-get-selection. (x-get-selection): Define as obsolete alias. (x-get-clipboard): Mark obsolete. (gui-get-primary-selection): New function. (x-get-selection-value): Mark obsolete. (gui-own-selection-alist, gui-disown-selection-alist) (gui-selection-owner-p-alist): New methods. (gui-set-selection): Use them. Rename from x-set-selection. (x-set-selection): Define as obsolete alias. (gui--valid-simple-selection-p): Rename from x-valid-simple-selection-p. * lisp/w32-common-fns.el (gui-own-selection, gui-disown-selection) (gui-selection-owner-p, gui-get-selection): Define for w32. (w32-get-selection-value): Rename from x-get-selection-value. Use the new gui-last-selected-text. * lisp/term/x-win.el (x-get-selection-value): Remove. (x-clipboard-yank): Declare obsolete. (gui-own-selection, gui-disown-selection, gui-get-selection) (gui-selection-owner-p): Define for x. * lisp/term/w32-win.el (w32-win-suspend-error): Rename from x-win-suspend-error. * lisp/term/pc-win.el (w16-get-selection-value): Rename from x-get-selection-value. (w16-selection-owner-p): Rename from x-selection-owner-p. (gui-own-selection, gui-disown-selection, gui-get-selection) (gui-selection-owner-p): Define for pc. (w16--select-text): New function. * lisp/term/ns-win.el (gui-own-selection, gui-disown-selection) (gui-get-selection, gui-selection-owner-p): Define for ns. * lisp/term.el (term-mouse-paste): * lisp/mouse.el (mouse-yank-primary): Use gui-get-primary-selection. * src/nsselect.m (ns-own-selection-internal, ns-disown-selection-internal): Rename from the "x-" prefix. --- etc/NEWS | 7 ++- lisp/ChangeLog | 36 ++++++++++++ lisp/mouse-copy.el | 4 +- lisp/mouse.el | 27 ++------- lisp/obsolete/mouse-sel.el | 11 ++-- lisp/select.el | 105 ++++++++++++++++++++++------------ lisp/simple.el | 14 ++--- lisp/term.el | 11 +--- lisp/term/ns-win.el | 5 ++ lisp/term/pc-win.el | 137 +++++++++++++++------------------------------ lisp/term/w32-win.el | 7 +-- lisp/term/x-win.el | 21 +++---- lisp/w32-common-fns.el | 87 +++++++++------------------- src/ChangeLog | 5 ++ src/nsselect.m | 43 +++++--------- 15 files changed, 238 insertions(+), 282 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ddcd70cb11a..f5720280db4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -245,7 +245,12 @@ Emacs-21. * Lisp Changes in Emacs 25.1 -** x-select-text is renamed gui-select-text. +** Some "x-*" were obsoleted: +*** x-select-text is renamed gui-select-text. +*** 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. +*** x-set-selection is renamed to gui-set-selection ** call-process-shell-command and process-file-shell-command don't take "&rest args" any more. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4e27e66a0b3..58dc8372a7a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,39 @@ +2014-10-02 Stefan Monnier + + Consolidate management/ownership of selections. + * select.el (gui-get-selection-alist): New method. + (gui-get-selection): Use it. Rename from x-get-selection. + (x-get-selection): Define as obsolete alias. + (x-get-clipboard): Mark obsolete. + (gui-get-primary-selection): New function. + (x-get-selection-value): Mark obsolete. + (gui-own-selection-alist, gui-disown-selection-alist) + (gui-selection-owner-p-alist): New methods. + (gui-set-selection): Use them. Rename from x-set-selection. + (x-set-selection): Define as obsolete alias. + (gui--valid-simple-selection-p): Rename from + x-valid-simple-selection-p. + * w32-common-fns.el (gui-own-selection, gui-disown-selection) + (gui-selection-owner-p, gui-get-selection): Define for w32. + (w32-get-selection-value): Rename from x-get-selection-value. + Use the new gui-last-selected-text. + * term/x-win.el (x-get-selection-value): Remove. + (x-clipboard-yank): Declare obsolete. + (gui-own-selection, gui-disown-selection, gui-get-selection) + (gui-selection-owner-p): Define for x. + * term/w32-win.el (w32-win-suspend-error): Rename from + x-win-suspend-error. + * term/pc-win.el (w16-get-selection-value): Rename from + x-get-selection-value. + (w16-selection-owner-p): Rename from x-selection-owner-p. + (gui-own-selection, gui-disown-selection, gui-get-selection) + (gui-selection-owner-p): Define for pc. + (w16--select-text): New function. + * term/ns-win.el (gui-own-selection, gui-disown-selection) + (gui-get-selection, gui-selection-owner-p): Define for ns. + * term.el (term-mouse-paste): + * mouse.el (mouse-yank-primary): Use gui-get-primary-selection. + 2014-10-02 H. Dieter Wilhelm (tiny change) * calc/calc-help.el (calc-describe-thing): Quote strings diff --git a/lisp/mouse-copy.el b/lisp/mouse-copy.el index b8bd339acb3..ddfb879318f 100644 --- a/lisp/mouse-copy.el +++ b/lisp/mouse-copy.el @@ -147,7 +147,7 @@ If you have the bug (or the real fix :-), please let me know." ;; Third, set the selection. ;; (setq me-beg beg me-end end me-range range) ; for debugging (set-buffer end-buffer) - (x-set-selection 'SECONDARY (buffer-substring beg end))))) + (gui-set-selection 'SECONDARY (buffer-substring beg end))))) (defun mouse-drag-secondary-pasting (start-event) @@ -203,7 +203,7 @@ by johnh@ficus.cs.ucla.edu." (kill-region (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))) ;; (delete-overlay mouse-secondary-overlay) - ;; (x-set-selection 'SECONDARY nil) + ;; (gui-set-selection 'SECONDARY nil) ;; (setq mouse-secondary-overlay nil) ) diff --git a/lisp/mouse.el b/lisp/mouse.el index 93bd6283158..f569ec3577d 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -1068,24 +1068,7 @@ regardless of where you click." (let (select-active-regions) (deactivate-mark))) (or mouse-yank-at-point (mouse-set-point click)) - (let ((primary - (if (fboundp 'x-get-selection-value) - (if (eq (framep (selected-frame)) 'w32) - ;; MS-Windows emulates PRIMARY in x-get-selection, but not - ;; in x-get-selection-value (the latter only accesses the - ;; clipboard). So try PRIMARY first, in case they selected - ;; something with the mouse in the current Emacs session. - (or (x-get-selection 'PRIMARY) - (x-get-selection-value)) - ;; Else MS-DOS or X. - ;; On X, x-get-selection-value supports more formats and - ;; encodings, so use it in preference to x-get-selection. - (or (x-get-selection-value) - (x-get-selection 'PRIMARY))) - ;; FIXME: What about xterm-mouse-mode etc.? - (x-get-selection 'PRIMARY)))) - (unless primary - (error "No selection is available")) + (let ((primary (gui-get-primary-selection))) (push-mark (point)) (insert-for-yank primary))) @@ -1272,7 +1255,7 @@ This must be bound to a mouse drag event." (if (numberp (posn-point posn)) (setq beg (posn-point posn))) (move-overlay mouse-secondary-overlay beg (posn-point end)) - (x-set-selection + (gui-set-selection 'SECONDARY (buffer-substring (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay)))))) @@ -1347,13 +1330,13 @@ The function returns a non-nil value if it creates a secondary selection." (if (marker-position mouse-secondary-start) (save-window-excursion (delete-overlay mouse-secondary-overlay) - (x-set-selection 'SECONDARY nil) + (gui-set-selection 'SECONDARY nil) (select-window start-window) (save-excursion (goto-char mouse-secondary-start) (sit-for 1) nil)) - (x-set-selection + (gui-set-selection 'SECONDARY (buffer-substring (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))))))))) @@ -1486,7 +1469,7 @@ CLICK position, kill the secondary selection." (setq str (buffer-substring (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))) (> (length str) 0) - (x-set-selection 'SECONDARY str)))) + (gui-set-selection 'SECONDARY str)))) (defcustom mouse-buffer-menu-maxlen 20 diff --git a/lisp/obsolete/mouse-sel.el b/lisp/obsolete/mouse-sel.el index 21765c3d652..7d7cd1f137f 100644 --- a/lisp/obsolete/mouse-sel.el +++ b/lisp/obsolete/mouse-sel.el @@ -97,7 +97,7 @@ ;; In this mode, mouse-insert-selection just calls mouse-yank-at-click. ;; ;; Selection/kill-ring interaction is retained -;; interprogram-cut-function = x-select-text +;; interprogram-cut-function = gui-select-text ;; interprogram-paste-function = x-selection-value ;; ;; What you lose is the ability to select some text in @@ -292,15 +292,13 @@ where SELECTION-NAME = name of selection SELECTION-THING-SYMBOL = name of variable where the current selection type for this selection should be stored.") -(declare-function x-select-text "term/common-win" (text)) - (defvar mouse-sel-set-selection-function (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) - 'x-set-selection + 'gui-set-selection (lambda (selection value) (if (eq selection 'PRIMARY) - (x-select-text value) - (x-set-selection selection value)))) + (gui-select-text value) + (gui-set-selection selection value)))) "Function to call to set selection. Called with two arguments: @@ -316,7 +314,6 @@ is `interprogram-cut-paste'.") (lambda (selection) (if (eq selection 'PRIMARY) (or (x-selection-value) - (bound-and-true-p x-last-selected-text) (bound-and-true-p x-last-selected-text-primary)) (x-get-selection selection))) "Function to call to get the selection. diff --git a/lisp/select.el b/lisp/select.el index c32b45f1c85..d6be917f291 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -71,9 +71,6 @@ other programs (X Windows clients or MS Windows programs). But, if this variable is set, it is used for the next communication only. After the communication, this variable is set to nil.") -(declare-function x-get-selection-internal "xselect.c" - (selection-symbol target-type &optional time-stamp terminal)) - ;; Only declared obsolete in 23.3. (define-obsolete-function-alias 'x-selection 'x-get-selection "at least 19.34") @@ -93,6 +90,13 @@ if applicable (i.e. under X11)." Called with one argument (the text selected). Should obey `gui-select-enable-clipboard' where applicable.") +(gui-method-declare gui-get-selection #'ignore + "Return selected text. +Called with 2 arguments: (SELECTION-SYMBOL TARGET-TYPE) +SELECTION-SYMBOL is typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. +\(Those are literal upper-case symbol names, since that's what X expects.) +TARGET-TYPE is the type of data desired, typically `STRING'.") + (defvar gui-last-selected-text nil "Last text passed to `gui-select-text'.") @@ -112,7 +116,7 @@ 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") -(defun x-get-selection (&optional type data-type) +(defun gui-get-selection (&optional type data-type) "Return the value of an X Windows selection. The argument TYPE (default `PRIMARY') says which selection, and the argument DATA-TYPE (default `STRING') says @@ -126,39 +130,69 @@ all upper-case names. The most often used ones, in addition to DATA-TYPE is usually `STRING', but can also be one of the symbols in `selection-converter-alist', which see. This argument is ignored on MS-Windows and MS-DOS." - (let ((data (x-get-selection-internal (or type 'PRIMARY) - (or data-type 'STRING))) - coding) + (let ((data (gui-call gui-get-selection (or type 'PRIMARY) + (or data-type 'STRING)))) (when (and (stringp data) (setq data-type (get-text-property 0 'foreign-selection data))) - (setq coding (or next-selection-coding-system - selection-coding-system - (cond ((eq data-type 'UTF8_STRING) - 'utf-8) - ((eq data-type 'COMPOUND_TEXT) - 'compound-text-with-extensions) - ((eq data-type 'C_STRING) - nil) - ((eq data-type 'STRING) - 'iso-8859-1) - (t - (error "Unknown selection data type: %S" type)))) - data (if coding (decode-coding-string data coding) - (string-to-multibyte data))) + (let ((coding (or next-selection-coding-system + selection-coding-system + (pcase data-type + ('UTF8_STRING 'utf-8) + ('COMPOUND_TEXT 'compound-text-with-extensions) + ('C_STRING nil) + ('STRING 'iso-8859-1) + (_ (error "Unknown selection data type: %S" + type)))))) + (setq data (if coding (decode-coding-string data coding) + (string-to-multibyte data)))) (setq next-selection-coding-system nil) (put-text-property 0 (length data) 'foreign-selection data-type data)) data)) +(define-obsolete-function-alias 'x-get-selection 'gui-get-selection "25.1") (defun x-get-clipboard () "Return text pasted to the clipboard." - (x-get-selection-internal 'CLIPBOARD 'STRING)) - -(declare-function x-own-selection-internal "xselect.c" - (selection-name selection-value &optional frame)) -(declare-function x-disown-selection-internal "xselect.c" - (selection &optional time terminal)) - -(defun x-set-selection (type data) + (declare (obsolete gui-get-selection "25.1")) + (gui-call gui-get-selection 'CLIPBOARD 'STRING)) + +(defun gui-get-primary-selection () + "Return the PRIMARY selection, or the best emulation thereof." + (or (gui-get-selection 'PRIMARY) + (and (fboundp 'w32-get-selection-value) + (eq (framep (selected-frame)) 'w32) + ;; MS-Windows emulates PRIMARY in x-get-selection, but only + ;; within the Emacs session, so consult the clipboard if + ;; primary is not found. + (w32-get-selection-value)) + (error "No selection is available"))) +(define-obsolete-function-alias 'x-get-selection-value + 'gui-get-primary-selection "25.1") + +(gui-method-declare gui-own-selection nil + "Method to assert a selection of type SELECTION and value VALUE. +SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. +(Those are literal upper-case symbol names, since that's what X expects.) +VALUE is typically a string, or a cons of two markers, but may be +anything that the functions on `selection-converter-alist' know about. + +Called with 2 args: (SELECTION VALUE).") + +(gui-method-declare gui-disown-selection nil + "If we own the selection SELECTION, disown it. +Disowning it means there is no such selection. + +Called with one argument: (SELECTION)") + +(gui-method-declare gui-selection-owner-p #'ignore + "Whether the current Emacs process owns the given X Selection. +Called with one argument: (SELECTION). +The arg should be the name of the selection in question, typically one of +the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. +(Those are literal upper-case symbol names, since that's what X expects.) +For convenience, the symbol nil is the same as `PRIMARY', +and t is the same as `SECONDARY'.") + +(defun gui-set-selection (type data) "Make an X selection of type TYPE and value DATA. The argument TYPE (nil means `PRIMARY') says which selection, and DATA specifies the contents. TYPE must be a symbol. \(It can also @@ -186,23 +220,24 @@ are not available to other programs." (list 'PRIMARY (read-string "Set text for pasting: ")) (list 'PRIMARY (buffer-substring (region-beginning) (region-end))))) (if (stringp type) (setq type (intern type))) - (or (x-valid-simple-selection-p data) + (or (gui--valid-simple-selection-p data) (and (vectorp data) (let ((valid t) (i (1- (length data)))) (while (>= i 0) - (or (x-valid-simple-selection-p (aref data i)) + (or (gui--valid-simple-selection-p (aref data i)) (setq valid nil)) (setq i (1- i))) valid)) (signal 'error (list "invalid selection" data))) (or type (setq type 'PRIMARY)) (if data - (x-own-selection-internal type data) - (x-disown-selection-internal type)) + (gui-call gui-own-selection type data) + (gui-call gui-disown-selection type)) data) +(define-obsolete-function-alias 'x-set-selection 'gui-set-selection "25.1") -(defun x-valid-simple-selection-p (data) +(defun gui--valid-simple-selection-p (data) (or (bufferp data) (and (consp data) (markerp (car data)) @@ -358,7 +393,7 @@ two markers or an overlay. Otherwise, it is nil." (apply 'vector all))) (defun xselect-convert-to-delete (selection _type _value) - (x-disown-selection-internal selection) + (gui-call gui-disown-selection selection) ;; A return value of nil means that we do not know how to do this conversion, ;; and replies with an "error". A return value of NULL means that we have ;; done the conversion (and any side-effects) but have no value to return. diff --git a/lisp/simple.el b/lisp/simple.el index 8504cf4be19..f96904cc177 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3629,7 +3629,7 @@ No filtering is done unless a hook says to." ;;;; Window system cut and paste hooks. -(defvar interprogram-cut-function #'x-select-text +(defvar interprogram-cut-function #'gui-select-text "Function to call to make a killed region available to other programs. Most window systems provide a facility for cutting and pasting text between different programs, such as the clipboard on X and @@ -4497,8 +4497,6 @@ a mistake; see the documentation of `set-mark'." (signal 'mark-inactive nil))) ;; Behind display-selections-p. -(declare-function x-selection-owner-p "xselect.c" - (&optional selection terminal)) (declare-function x-selection-exists-p "xselect.c" (&optional selection terminal)) @@ -4525,15 +4523,15 @@ run `deactivate-mark-hook'." ;; the region prior to the last command modifying the buffer. ;; Set the selection to that, or to the current region. (cond (saved-region-selection - (x-set-selection 'PRIMARY saved-region-selection) + (gui-set-selection 'PRIMARY saved-region-selection) (setq saved-region-selection nil)) ;; If another program has acquired the selection, region ;; deactivation should not clobber it (Bug#11772). ((and (/= (region-beginning) (region-end)) - (or (x-selection-owner-p 'PRIMARY) - (null (x-selection-exists-p 'PRIMARY)))) - (x-set-selection 'PRIMARY - (funcall region-extract-function nil))))) + (or (call-gui gui-selection-owner-p 'PRIMARY) + (null (gui-selection-exists-p 'PRIMARY)))) + (gui-set-selection 'PRIMARY + (funcall region-extract-function nil))))) (when mark-active (force-mode-line-update)) ;Refresh toolbar (bug#16382). (cond ((eq (car-safe transient-mark-mode) 'only) diff --git a/lisp/term.el b/lisp/term.el index 825a202c046..611a0c660e1 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -1249,16 +1249,7 @@ without any interpretation." (run-hooks 'mouse-leave-buffer-hook) (setq this-command 'yank) (mouse-set-point click) - (term-send-raw-string - ;; From `mouse-yank-primary': - (or (if (fboundp 'x-get-selection-value) - (if (eq system-type 'windows-nt) - (or (x-get-selection 'PRIMARY) - (x-get-selection-value)) - (or (x-get-selection-value) - (x-get-selection 'PRIMARY))) - (x-get-selection 'PRIMARY)) - (error "No selection is available"))))) + (term-send-raw-string (gui-get-primary-selection)))) (defun term-paste () "Insert the last stretch of killed text at point." diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index fc13a2c5ddf..5889baf6946 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -971,6 +971,11 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") (when gui-select-enable-clipboard (ns-set-pasteboard text)))) +(gui-method-define gui-own-selection x #'ns-own-selection-internal) +(gui-method-define gui-disown-selection x #'ns-disown-selection-internal) +(gui-method-define gui-selection-owner-p x #'ns-selection-owner-p) +(gui-method-define gui-get-selection x #'x-get-selection-internal) ;FIXME:name! + (provide 'ns-win) ;;; ns-win.el ends here diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el index 264d881bc15..3498937b4d2 100644 --- a/lisp/term/pc-win.el +++ b/lisp/term/pc-win.el @@ -219,7 +219,7 @@ the operating system.") ; ;;;; Selections ; -(defun x-get-selection-value () +(defun w16-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 @@ -238,93 +238,44 @@ Consult the selection. Treat empty strings as if they were unset." (t (setq gui-last-selected-text text)))))) -;; x-selection-owner-p is used in simple.el. -(defun x-selection-owner-p (&optional _selection _terminal) - "Whether the current Emacs process owns the given X Selection. -The arg should be the name of the selection in question, typically one of -the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. -\(Those are literal upper-case symbol names, since that's what X expects.) -For convenience, the symbol nil is the same as `PRIMARY', -and t is the same as `SECONDARY'. - -TERMINAL should be a terminal object or a frame specifying the X -server to query. If omitted or nil, that stands for the selected -frame's display, or the first available X display. - -On Nextstep, TERMINAL is unused. - -\(fn &optional SELECTION TERMINAL)" - (if gui-select-enable-clipboard - (let (text) - ;; Don't die if w16-get-clipboard-data signals an error. - (ignore-errors - (setq text (w16-get-clipboard-data))) - ;; We consider ourselves the owner of the selection if it does - ;; not exist, or exists and compares equal with the last text - ;; we've put into the Windows clipboard. - (cond - ((not text) t) - ((or (eq text gui-last-selected-text) - (string= text gui-last-selected-text)) - text) - (t nil))))) - -;; x-own-selection-internal and x-disown-selection-internal are used -;; in select.el:x-set-selection. -(defun x-own-selection-internal (_selection value &optional _frame) - "Assert an X selection of the type SELECTION with and value VALUE. -SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. -\(Those are literal upper-case symbol names, since that's what X expects.) -VALUE is typically a string, or a cons of two markers, but may be -anything that the functions on `selection-converter-alist' know about. - -FRAME should be a frame that should own the selection. If omitted or -nil, it defaults to the selected frame. - -On Nextstep, FRAME is unused. - -\(fn SELECTION VALUE &optional FRAME)" - (ignore-errors - (x-select-text value)) - value) - -(defun x-disown-selection-internal (selection &optional _time-object _terminal) - "If we own the selection SELECTION, disown it. -Disowning it means there is no such selection. - -Sets the last-change time for the selection to TIME-OBJECT (by default -the time of the last event). - -TERMINAL should be a terminal object or a frame specifying the X -server to query. If omitted or nil, that stands for the selected -frame's display, or the first available X display. - -On Nextstep, the TIME-OBJECT and TERMINAL arguments are unused. -On MS-DOS, all this does is return non-nil if we own the selection. - -\(fn SELECTION &optional TIME-OBJECT TERMINAL)" - (if (x-selection-owner-p selection) - t)) - -;; x-get-selection-internal is used in select.el -(defun x-get-selection-internal (_selection-symbol _target-type - &optional _time-stamp _terminal) - "Return text selected from some X window. -SELECTION-SYMBOL is typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. -\(Those are literal upper-case symbol names, since that's what X expects.) -TARGET-TYPE is the type of data desired, typically `STRING'. - -TIME-STAMP is the time to use in the XConvertSelection call for foreign -selections. If omitted, defaults to the time for the last event. - -TERMINAL should be a terminal object or a frame specifying the X -server to query. If omitted or nil, that stands for the selected -frame's display, or the first available X display. - -On Nextstep, TIME-STAMP and TERMINAL are unused. - -\(fn SELECTION-SYMBOL TARGET-TYPE &optional TIME-STAMP TERMINAL)" - (x-get-selection-value)) +;; gui-selection-owner-p is used in simple.el. +(gui-method-define gui-selection-owner-p pc #'w16-selection-owner-p) +(defun w16-selection-owner-p (_selection) + ;; FIXME: Other systems don't obey gui-select-enable-clipboard here. + (if gui-select-enable-clipboard + (let ((text + ;; Don't die if w16-get-clipboard-data signals an error. + (ignore-errors + (w16-get-clipboard-data)))) + ;; We consider ourselves the owner of the selection + ;; if it does not exist, or exists and compares + ;; equal with the last text we've put into the + ;; Windows clipboard. + (cond + ((not text) t) + ((or (eq text gui-last-selected-text) + (string= text gui-last-selected-text)) + text) + (t nil))))) + +;; gui-own-selection and gui-disown-selection are used in gui-set-selection. +(gui-method-define gui-own-selection pc + (lambda (_selection value) + ;; FIXME: Other systems don't obey + ;; gui-select-enable-clipboard here. + (ignore-errors + (w16--select-text value)) + value)) + +(gui-method-define gui-disown-selection pc + (lambda (selection &optional _time-object _terminal) + (if (w16-selection-owner-p selection) + t))) + +;; gui-get-selection is used in select.el +(gui-method-define gui-get-selection pc + (lambda (selection-symbol target-type) + (w16-get-selection-value))) ;; From src/fontset.c: (fset 'query-fontset 'ignore) @@ -429,7 +380,7 @@ 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 'x-get-selection-value) + (setq interprogram-paste-function #'w16-get-selection-value) (menu-bar-enable-clipboard) (run-hooks 'terminal-init-msdos-hook)) @@ -446,10 +397,10 @@ 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 - (lambda (text) - (when gui-select-enable-clipboard - (w16-set-clipboard-data text)))) +(gui-method-define gui-select-text pc #'w16--select-text) +(defun w16--select-text (text) + (when gui-select-enable-clipboard + (w16-set-clipboard-data text))) ;; --------------------------------------------------------------------------- diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index 3eb8e69c28d..8ef718ad230 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el @@ -205,9 +205,8 @@ European languages which are distributed with Windows as See the documentation of `create-fontset-from-fontset-spec' for the format.") -(defun x-win-suspend-error () - "Report an error when a suspend is attempted. -This returns an error if any Emacs frames are X frames, or always under W32." +(defun w32-win-suspend-error () + "Report an error when a suspend is attempted." (error "Suspending an Emacs running under W32 makes no sense")) (defvar dynamic-library-alist) @@ -353,7 +352,7 @@ This returns an error if any Emacs frames are X frames, or always under W32." (cons '(reverse . t) default-frame-alist))))) ;; Don't let Emacs suspend under Windows. - (add-hook 'suspend-hook 'x-win-suspend-error) + (add-hook 'suspend-hook #'w32-win-suspend-error) ;; Turn off window-splitting optimization; w32 is usually fast enough ;; that this is only annoying. diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index daaef61e494..a50f886c66a 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -1290,16 +1290,9 @@ The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)." ;; Arrange for the kill and yank functions to set and check the clipboard. (setq interprogram-paste-function 'x-selection-value) -;; Make paste from other applications use the decoding in x-select-request-type -;; and not just STRING. -(defun x-get-selection-value () - "Get the current value of the PRIMARY selection. -Request data types in the order specified by `x-select-request-type'." - (x-selection-value-internal 'PRIMARY)) - (defun x-clipboard-yank () - ;; FIXME: How is that different from `clipboard-yank'? "Insert the clipboard contents, or the last stretch of killed text." + (declare (obsolete clipboard-yank "25.1")) (interactive "*") (let ((clipboard-text (x-selection-value-internal 'CLIPBOARD)) (x-select-enable-clipboard t)) @@ -1325,9 +1318,9 @@ Request data types in the order specified by `x-select-request-type'." (defun x-win-suspend-error () "Report an error when a suspend is attempted. -This returns an error if any Emacs frames are X frames, or always under W32." +This returns an error if any Emacs frames are X frames." ;; Don't allow suspending if any of the frames are X frames. - (if (memq 'x (mapcar 'window-system (frame-list))) + (if (memq 'x (mapcar #'window-system (frame-list))) (error "Cannot suspend Emacs while running under X"))) (defvar x-initialized nil @@ -1469,15 +1462,19 @@ This returns an error if any Emacs frames are X frames, or always under W32." (gui-method-define gui-select-text x (lambda (text) (when x-select-enable-primary - (x-set-selection 'PRIMARY text) + (gui-set-selection 'PRIMARY text) (setq x-last-selected-text-primary text)) (when x-select-enable-clipboard ;; When cutting, the selection is cleared and PRIMARY ;; set to the empty string. Prevent that, PRIMARY ;; should not be reset by cut (Bug#16382). (setq saved-region-selection text) - (x-set-selection 'CLIPBOARD text) + (gui-set-selection 'CLIPBOARD text) (setq x-last-selected-text-clipboard text)))) +(gui-method-define gui-own-selection x #'x-own-selection-internal) +(gui-method-define gui-disown-selection x #'x-disown-selection-internal) +(gui-method-define gui-selection-owner-p x #'x-selection-owner-p) +(gui-method-define gui-get-selection x #'x-get-selection-internal) ;; Initiate drag and drop (add-hook 'after-make-frame-functions 'x-dnd-init-frame) diff --git a/lisp/w32-common-fns.el b/lisp/w32-common-fns.el index 343a4c25895..3f8cbc19dba 100644 --- a/lisp/w32-common-fns.el +++ b/lisp/w32-common-fns.el @@ -41,53 +41,23 @@ That includes all Windows systems except for 9X/Me." (declare-function x-server-version "w32fns.c" (&optional display)) ;;; Fix interface to (X-specific) mouse.el -(defun x-set-selection (type data) - "Make an X selection of type TYPE and value DATA. -The argument TYPE (nil means `PRIMARY') says which selection, and -DATA specifies the contents. TYPE must be a symbol. \(It can also -be a string, which stands for the symbol with that name, but this -is considered obsolete.) DATA may be a string, a symbol, an -integer (or a cons of two integers or list of two integers). - -The selection may also be a cons of two markers pointing to the same buffer, -or an overlay. In these cases, the selection is considered to be the text -between the markers *at whatever time the selection is examined*. -Thus, editing done in the buffer after you specify the selection -can alter the effective value of the selection. - -The data may also be a vector of valid non-vector selection values. - -The return value is DATA. - -Interactively, this command sets the primary selection. Without -prefix argument, it reads the selection in the minibuffer. With -prefix argument, it uses the text of the region as the selection value. - -Note that on MS-Windows, primary and secondary selections set by Emacs -are not available to other programs." - (put 'x-selections (or type 'PRIMARY) data)) - -(defun x-get-selection (&optional type _data-type) - "Return the value of an X Windows selection. -The argument TYPE (default `PRIMARY') says which selection, -and the argument DATA-TYPE (default `STRING') says -how to convert the data. - -TYPE may be any symbol \(but nil stands for `PRIMARY'). However, -only a few symbols are commonly used. They conventionally have -all upper-case names. The most often used ones, in addition to -`PRIMARY', are `SECONDARY' and `CLIPBOARD'. - -DATA-TYPE is usually `STRING', but can also be one of the symbols -in `selection-converter-alist', which see. This argument is -ignored on MS-Windows and MS-DOS." - (get 'x-selections (or type 'PRIMARY))) - -;; x-selection-owner-p is used in simple.el -(defun x-selection-owner-p (&optional selection _terminal) - "" ; placeholder for doc.c - (and (memq selection '(nil PRIMARY SECONDARY)) - (get 'x-selections (or selection 'PRIMARY)))) +(gui-method-define gui-own-selection w32 + (lambda (type value) + (put 'x-selections (or type 'PRIMARY) data))) + +(gui-method-define gui-disown-selection w32 + (lambda (type &optional _time-object _frame) + (put 'x-selections (or type 'PRIMARY) nil))) + +(gui-method-define gui-get-selection w32 + (lambda (&optional type _data-type) + (get 'x-selections (or type 'PRIMARY)))) + +;; gui-selection-owner-p is used in simple.el +(gui-method-define gui-selection-owner-p w32 + (lambda (selection) + (and (memq selection '(nil PRIMARY SECONDARY)) + (get 'x-selections (or selection 'PRIMARY))))) ;; The "Windows" keys on newer keyboards bring up the Start menu ;; whether you want it or not - make Emacs ignore these keystrokes @@ -103,30 +73,29 @@ ignored on MS-Windows and MS-DOS." ;; 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. -(defvar x-last-selected-text nil) -(defun x-get-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" - (setq text (w32-get-clipboard-data))) + (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 x-last-selected-text) nil) - ((string= text x-last-selected-text) + ((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 x-last-selected-text text) + (setq gui-last-selected-text text) nil) (t - (setq x-last-selected-text text)))))) + (setq gui-last-selected-text text)))))) -(defalias 'x-selection-value 'x-get-selection-value) +(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 'x-get-selection-value) +(setq interprogram-paste-function #'w32-get-selection-value) (provide 'w32-common-fns) diff --git a/src/ChangeLog b/src/ChangeLog index 34f19b85389..2c5aa61e417 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2014-10-02 Stefan Monnier + + * nsselect.m (ns-own-selection-internal, ns-disown-selection-internal): + Rename from the "x-" prefix. + 2014-10-01 Stefan Monnier * xselect.c (selection-converter-alist): Fix docstring. diff --git a/src/nsselect.m b/src/nsselect.m index 038849c0aed..3712ba064e7 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -328,19 +328,14 @@ ns_string_to_pasteboard (id pb, Lisp_Object str) ========================================================================== */ -DEFUN ("x-own-selection-internal", Fx_own_selection_internal, - Sx_own_selection_internal, 2, 3, 0, +DEFUN ("ns-own-selection-internal", Fns_own_selection_internal, + Sns_own_selection_internal, 2, 2, 0, doc: /* Assert an X selection of type SELECTION and value VALUE. SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. \(Those are literal upper-case symbol names, since that's what X expects.) VALUE is typically a string, or a cons of two markers, but may be -anything that the functions on `selection-converter-alist' know about. - -FRAME should be a frame that should own the selection. If omitted or -nil, it defaults to the selected frame. - -On Nextstep, FRAME is unused. */) - (Lisp_Object selection, Lisp_Object value, Lisp_Object frame) +anything that the functions on `selection-converter-alist' know about. */) + (Lisp_Object selection, Lisp_Object value) { id pb; Lisp_Object old_value, new_value; @@ -385,21 +380,11 @@ On Nextstep, FRAME is unused. */) } -DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal, - Sx_disown_selection_internal, 1, 3, 0, +DEFUN ("ns-disown-selection-internal", Fns_disown_selection_internal, + Sns_disown_selection_internal, 1, 1, 0, doc: /* If we own the selection SELECTION, disown it. -Disowning it means there is no such selection. - -Sets the last-change time for the selection to TIME-OBJECT (by default -the time of the last event). - -TERMINAL should be a terminal object or a frame specifying the X -server to query. If omitted or nil, that stands for the selected -frame's display, or the first available X display. - -On Nextstep, the TIME-OBJECT and TERMINAL arguments are unused. -On MS-DOS, all this does is return non-nil if we own the selection. */) - (Lisp_Object selection, Lisp_Object time_object, Lisp_Object terminal) +Disowning it means there is no such selection. */) + (Lisp_Object selection) { id pb; check_window_system (NULL); @@ -443,7 +428,7 @@ On Nextstep, TERMINAL is unused. */) } -DEFUN ("x-selection-owner-p", Fx_selection_owner_p, Sx_selection_owner_p, +DEFUN ("ns-selection-owner-p", Fns_selection_owner_p, Sns_selection_owner_p, 0, 2, 0, doc: /* Whether the current Emacs process owns the given X Selection. The arg should be the name of the selection in question, typically one of @@ -507,7 +492,7 @@ On Nextstep, TIME-STAMP and TERMINAL are unused. */) DEFUN ("ns-get-selection-internal", Fns_get_selection_internal, Sns_get_selection_internal, 1, 1, 0, doc: /* Returns the value of SELECTION as a string. -SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */) +SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */) (Lisp_Object selection) { id pb; @@ -520,7 +505,7 @@ SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */) DEFUN ("ns-store-selection-internal", Fns_store_selection_internal, Sns_store_selection_internal, 2, 2, 0, doc: /* Sets the string value of SELECTION. -SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */) +SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */) (Lisp_Object selection, Lisp_Object string) { id pb; @@ -546,11 +531,11 @@ syms_of_nsselect (void) QTEXT = intern_c_string ("TEXT"); staticpro (&QTEXT); QFILE_NAME = intern_c_string ("FILE_NAME"); staticpro (&QFILE_NAME); - defsubr (&Sx_disown_selection_internal); + defsubr (&Sns_disown_selection_internal); defsubr (&Sx_get_selection_internal); - defsubr (&Sx_own_selection_internal); + defsubr (&Sns_own_selection_internal); defsubr (&Sx_selection_exists_p); - defsubr (&Sx_selection_owner_p); + defsubr (&Sns_selection_owner_p); defsubr (&Sns_get_selection_internal); defsubr (&Sns_store_selection_internal); -- 2.11.4.GIT