Commit 31300bee authored by Stefan Monnier's avatar Stefan Monnier

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.
parent c7c0acd4
...@@ -245,7 +245,12 @@ Emacs-21. ...@@ -245,7 +245,12 @@ Emacs-21.
* Lisp Changes in Emacs 25.1 * 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 ** call-process-shell-command and process-file-shell-command
don't take "&rest args" any more. don't take "&rest args" any more.
......
2014-10-02 Stefan Monnier <monnier@iro.umontreal.ca>
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 <dieter@duenenhof-wilhelm.de> (tiny change) 2014-10-02 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> (tiny change)
* calc/calc-help.el (calc-describe-thing): Quote strings * calc/calc-help.el (calc-describe-thing): Quote strings
......
...@@ -147,7 +147,7 @@ If you have the bug (or the real fix :-), please let me know." ...@@ -147,7 +147,7 @@ If you have the bug (or the real fix :-), please let me know."
;; Third, set the selection. ;; Third, set the selection.
;; (setq me-beg beg me-end end me-range range) ; for debugging ;; (setq me-beg beg me-end end me-range range) ; for debugging
(set-buffer end-buffer) (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) (defun mouse-drag-secondary-pasting (start-event)
...@@ -203,7 +203,7 @@ by johnh@ficus.cs.ucla.edu." ...@@ -203,7 +203,7 @@ by johnh@ficus.cs.ucla.edu."
(kill-region (overlay-start mouse-secondary-overlay) (kill-region (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))) (overlay-end mouse-secondary-overlay)))
;; (delete-overlay mouse-secondary-overlay) ;; (delete-overlay mouse-secondary-overlay)
;; (x-set-selection 'SECONDARY nil) ;; (gui-set-selection 'SECONDARY nil)
;; (setq mouse-secondary-overlay nil) ;; (setq mouse-secondary-overlay nil)
) )
......
...@@ -1068,24 +1068,7 @@ regardless of where you click." ...@@ -1068,24 +1068,7 @@ regardless of where you click."
(let (select-active-regions) (let (select-active-regions)
(deactivate-mark))) (deactivate-mark)))
(or mouse-yank-at-point (mouse-set-point click)) (or mouse-yank-at-point (mouse-set-point click))
(let ((primary (let ((primary (gui-get-primary-selection)))
(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"))
(push-mark (point)) (push-mark (point))
(insert-for-yank primary))) (insert-for-yank primary)))
...@@ -1272,7 +1255,7 @@ This must be bound to a mouse drag event." ...@@ -1272,7 +1255,7 @@ This must be bound to a mouse drag event."
(if (numberp (posn-point posn)) (if (numberp (posn-point posn))
(setq beg (posn-point posn))) (setq beg (posn-point posn)))
(move-overlay mouse-secondary-overlay beg (posn-point end)) (move-overlay mouse-secondary-overlay beg (posn-point end))
(x-set-selection (gui-set-selection
'SECONDARY 'SECONDARY
(buffer-substring (overlay-start mouse-secondary-overlay) (buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end 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." ...@@ -1347,13 +1330,13 @@ The function returns a non-nil value if it creates a secondary selection."
(if (marker-position mouse-secondary-start) (if (marker-position mouse-secondary-start)
(save-window-excursion (save-window-excursion
(delete-overlay mouse-secondary-overlay) (delete-overlay mouse-secondary-overlay)
(x-set-selection 'SECONDARY nil) (gui-set-selection 'SECONDARY nil)
(select-window start-window) (select-window start-window)
(save-excursion (save-excursion
(goto-char mouse-secondary-start) (goto-char mouse-secondary-start)
(sit-for 1) (sit-for 1)
nil)) nil))
(x-set-selection (gui-set-selection
'SECONDARY 'SECONDARY
(buffer-substring (overlay-start mouse-secondary-overlay) (buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))))))))) (overlay-end mouse-secondary-overlay)))))))))
...@@ -1486,7 +1469,7 @@ CLICK position, kill the secondary selection." ...@@ -1486,7 +1469,7 @@ CLICK position, kill the secondary selection."
(setq str (buffer-substring (overlay-start mouse-secondary-overlay) (setq str (buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))) (overlay-end mouse-secondary-overlay)))
(> (length str) 0) (> (length str) 0)
(x-set-selection 'SECONDARY str)))) (gui-set-selection 'SECONDARY str))))
(defcustom mouse-buffer-menu-maxlen 20 (defcustom mouse-buffer-menu-maxlen 20
......
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
;; In this mode, mouse-insert-selection just calls mouse-yank-at-click. ;; In this mode, mouse-insert-selection just calls mouse-yank-at-click.
;; ;;
;; Selection/kill-ring interaction is retained ;; Selection/kill-ring interaction is retained
;; interprogram-cut-function = x-select-text ;; interprogram-cut-function = gui-select-text
;; interprogram-paste-function = x-selection-value ;; interprogram-paste-function = x-selection-value
;; ;;
;; What you lose is the ability to select some text in ;; What you lose is the ability to select some text in
...@@ -292,15 +292,13 @@ where SELECTION-NAME = name of selection ...@@ -292,15 +292,13 @@ where SELECTION-NAME = name of selection
SELECTION-THING-SYMBOL = name of variable where the current selection SELECTION-THING-SYMBOL = name of variable where the current selection
type for this selection should be stored.") type for this selection should be stored.")
(declare-function x-select-text "term/common-win" (text))
(defvar mouse-sel-set-selection-function (defvar mouse-sel-set-selection-function
(if (eq mouse-sel-default-bindings 'interprogram-cut-paste) (if (eq mouse-sel-default-bindings 'interprogram-cut-paste)
'x-set-selection 'gui-set-selection
(lambda (selection value) (lambda (selection value)
(if (eq selection 'PRIMARY) (if (eq selection 'PRIMARY)
(x-select-text value) (gui-select-text value)
(x-set-selection selection value)))) (gui-set-selection selection value))))
"Function to call to set selection. "Function to call to set selection.
Called with two arguments: Called with two arguments:
...@@ -316,7 +314,6 @@ is `interprogram-cut-paste'.") ...@@ -316,7 +314,6 @@ is `interprogram-cut-paste'.")
(lambda (selection) (lambda (selection)
(if (eq selection 'PRIMARY) (if (eq selection 'PRIMARY)
(or (x-selection-value) (or (x-selection-value)
(bound-and-true-p x-last-selected-text)
(bound-and-true-p x-last-selected-text-primary)) (bound-and-true-p x-last-selected-text-primary))
(x-get-selection selection))) (x-get-selection selection)))
"Function to call to get the selection. "Function to call to get the selection.
......
...@@ -71,9 +71,6 @@ other programs (X Windows clients or MS Windows programs). But, if this ...@@ -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. variable is set, it is used for the next communication only.
After the communication, this variable is set to nil.") 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. ;; Only declared obsolete in 23.3.
(define-obsolete-function-alias 'x-selection 'x-get-selection "at least 19.34") (define-obsolete-function-alias 'x-selection 'x-get-selection "at least 19.34")
...@@ -93,6 +90,13 @@ if applicable (i.e. under X11)." ...@@ -93,6 +90,13 @@ if applicable (i.e. under X11)."
Called with one argument (the text selected). Called with one argument (the text selected).
Should obey `gui-select-enable-clipboard' where applicable.") 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 (defvar gui-last-selected-text nil
"Last text passed to `gui-select-text'.") "Last text passed to `gui-select-text'.")
...@@ -112,7 +116,7 @@ On MS-Windows, make TEXT the current selection." ...@@ -112,7 +116,7 @@ On MS-Windows, make TEXT the current selection."
(setq gui-last-selected-text text)) (setq gui-last-selected-text text))
(define-obsolete-function-alias 'x-select-text 'gui-select-text "25.1") (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. "Return the value of an X Windows selection.
The argument TYPE (default `PRIMARY') says which selection, The argument TYPE (default `PRIMARY') says which selection,
and the argument DATA-TYPE (default `STRING') says and the argument DATA-TYPE (default `STRING') says
...@@ -126,39 +130,69 @@ all upper-case names. The most often used ones, in addition to ...@@ -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 DATA-TYPE is usually `STRING', but can also be one of the symbols
in `selection-converter-alist', which see. This argument is in `selection-converter-alist', which see. This argument is
ignored on MS-Windows and MS-DOS." ignored on MS-Windows and MS-DOS."
(let ((data (x-get-selection-internal (or type 'PRIMARY) (let ((data (gui-call gui-get-selection (or type 'PRIMARY)
(or data-type 'STRING))) (or data-type 'STRING))))
coding)
(when (and (stringp data) (when (and (stringp data)
(setq data-type (get-text-property 0 'foreign-selection data))) (setq data-type (get-text-property 0 'foreign-selection data)))
(setq coding (or next-selection-coding-system (let ((coding (or next-selection-coding-system
selection-coding-system selection-coding-system
(cond ((eq data-type 'UTF8_STRING) (pcase data-type
'utf-8) ('UTF8_STRING 'utf-8)
((eq data-type 'COMPOUND_TEXT) ('COMPOUND_TEXT 'compound-text-with-extensions)
'compound-text-with-extensions) ('C_STRING nil)
((eq data-type 'C_STRING) ('STRING 'iso-8859-1)
nil) (_ (error "Unknown selection data type: %S"
((eq data-type 'STRING) type))))))
'iso-8859-1) (setq data (if coding (decode-coding-string data coding)
(t (string-to-multibyte data))))
(error "Unknown selection data type: %S" type))))
data (if coding (decode-coding-string data coding)
(string-to-multibyte data)))
(setq next-selection-coding-system nil) (setq next-selection-coding-system nil)
(put-text-property 0 (length data) 'foreign-selection data-type data)) (put-text-property 0 (length data) 'foreign-selection data-type data))
data)) data))
(define-obsolete-function-alias 'x-get-selection 'gui-get-selection "25.1")
(defun x-get-clipboard () (defun x-get-clipboard ()
"Return text pasted to the clipboard." "Return text pasted to the clipboard."
(x-get-selection-internal 'CLIPBOARD 'STRING)) (declare (obsolete gui-get-selection "25.1"))
(gui-call gui-get-selection 'CLIPBOARD 'STRING))
(declare-function x-own-selection-internal "xselect.c"
(selection-name selection-value &optional frame)) (defun gui-get-primary-selection ()
(declare-function x-disown-selection-internal "xselect.c" "Return the PRIMARY selection, or the best emulation thereof."
(selection &optional time terminal)) (or (gui-get-selection 'PRIMARY)
(and (fboundp 'w32-get-selection-value)
(defun x-set-selection (type data) (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. "Make an X selection of type TYPE and value DATA.
The argument TYPE (nil means `PRIMARY') says which selection, and The argument TYPE (nil means `PRIMARY') says which selection, and
DATA specifies the contents. TYPE must be a symbol. \(It can also DATA specifies the contents. TYPE must be a symbol. \(It can also
...@@ -186,23 +220,24 @@ are not available to other programs." ...@@ -186,23 +220,24 @@ are not available to other programs."
(list 'PRIMARY (read-string "Set text for pasting: ")) (list 'PRIMARY (read-string "Set text for pasting: "))
(list 'PRIMARY (buffer-substring (region-beginning) (region-end))))) (list 'PRIMARY (buffer-substring (region-beginning) (region-end)))))
(if (stringp type) (setq type (intern type))) (if (stringp type) (setq type (intern type)))
(or (x-valid-simple-selection-p data) (or (gui--valid-simple-selection-p data)
(and (vectorp data) (and (vectorp data)
(let ((valid t) (let ((valid t)
(i (1- (length data)))) (i (1- (length data))))
(while (>= i 0) (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 valid nil))
(setq i (1- i))) (setq i (1- i)))
valid)) valid))
(signal 'error (list "invalid selection" data))) (signal 'error (list "invalid selection" data)))
(or type (setq type 'PRIMARY)) (or type (setq type 'PRIMARY))
(if data (if data
(x-own-selection-internal type data) (gui-call gui-own-selection type data)
(x-disown-selection-internal type)) (gui-call gui-disown-selection type))
data) 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) (or (bufferp data)
(and (consp data) (and (consp data)
(markerp (car data)) (markerp (car data))
...@@ -358,7 +393,7 @@ two markers or an overlay. Otherwise, it is nil." ...@@ -358,7 +393,7 @@ two markers or an overlay. Otherwise, it is nil."
(apply 'vector all))) (apply 'vector all)))
(defun xselect-convert-to-delete (selection _type _value) (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, ;; 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 ;; 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. ;; done the conversion (and any side-effects) but have no value to return.
......
...@@ -3629,7 +3629,7 @@ No filtering is done unless a hook says to." ...@@ -3629,7 +3629,7 @@ No filtering is done unless a hook says to."
;;;; Window system cut and paste hooks. ;;;; 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. "Function to call to make a killed region available to other programs.
Most window systems provide a facility for cutting and pasting Most window systems provide a facility for cutting and pasting
text between different programs, such as the clipboard on X and text between different programs, such as the clipboard on X and
...@@ -4497,8 +4497,6 @@ a mistake; see the documentation of `set-mark'." ...@@ -4497,8 +4497,6 @@ a mistake; see the documentation of `set-mark'."
(signal 'mark-inactive nil))) (signal 'mark-inactive nil)))
;; Behind display-selections-p. ;; Behind display-selections-p.
(declare-function x-selection-owner-p "xselect.c"
(&optional selection terminal))
(declare-function x-selection-exists-p "xselect.c" (declare-function x-selection-exists-p "xselect.c"
(&optional selection terminal)) (&optional selection terminal))
...@@ -4525,15 +4523,15 @@ run `deactivate-mark-hook'." ...@@ -4525,15 +4523,15 @@ run `deactivate-mark-hook'."
;; the region prior to the last command modifying the buffer. ;; the region prior to the last command modifying the buffer.
;; Set the selection to that, or to the current region. ;; Set the selection to that, or to the current region.
(cond (saved-region-selection (cond (saved-region-selection
(x-set-selection 'PRIMARY saved-region-selection) (gui-set-selection 'PRIMARY saved-region-selection)
(setq saved-region-selection nil)) (setq saved-region-selection nil))
;; If another program has acquired the selection, region ;; If another program has acquired the selection, region
;; deactivation should not clobber it (Bug#11772). ;; deactivation should not clobber it (Bug#11772).
((and (/= (region-beginning) (region-end)) ((and (/= (region-beginning) (region-end))
(or (x-selection-owner-p 'PRIMARY) (or (call-gui gui-selection-owner-p 'PRIMARY)
(null (x-selection-exists-p 'PRIMARY)))) (null (gui-selection-exists-p 'PRIMARY))))
(x-set-selection 'PRIMARY (gui-set-selection 'PRIMARY
(funcall region-extract-function nil))))) (funcall region-extract-function nil)))))
(when mark-active (force-mode-line-update)) ;Refresh toolbar (bug#16382). (when mark-active (force-mode-line-update)) ;Refresh toolbar (bug#16382).
(cond (cond
((eq (car-safe transient-mark-mode) 'only) ((eq (car-safe transient-mark-mode) 'only)
......
...@@ -1249,16 +1249,7 @@ without any interpretation." ...@@ -1249,16 +1249,7 @@ without any interpretation."
(run-hooks 'mouse-leave-buffer-hook) (run-hooks 'mouse-leave-buffer-hook)
(setq this-command 'yank) (setq this-command 'yank)
(mouse-set-point click) (mouse-set-point click)
(term-send-raw-string (term-send-raw-string (gui-get-primary-selection))))
;; 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")))))
(defun term-paste () (defun term-paste ()
"Insert the last stretch of killed text at point." "Insert the last stretch of killed text at point."
......
...@@ -971,6 +971,11 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") ...@@ -971,6 +971,11 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
(when gui-select-enable-clipboard (when gui-select-enable-clipboard
(ns-set-pasteboard text)))) (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) (provide 'ns-win)
;;; ns-win.el ends here ;;; ns-win.el ends here
...@@ -219,7 +219,7 @@ the operating system.") ...@@ -219,7 +219,7 @@ the operating system.")
; ;
;;;; Selections ;;;; Selections
; ;
(defun x-get-selection-value () (defun w16-get-selection-value ()
"Return the value of the current selection. "Return the value of the current selection.
Consult the selection. Treat empty strings as if they were unset." Consult the selection. Treat empty strings as if they were unset."
(if gui-select-enable-clipboard (if gui-select-enable-clipboard
...@@ -238,93 +238,44 @@ Consult the selection. Treat empty strings as if they were unset." ...@@ -238,93 +238,44 @@ Consult the selection. Treat empty strings as if they were unset."
(t (t
(setq gui-last-selected-text text)))))) (setq gui-last-selected-text text))))))
;; x-selection-owner-p is used in simple.el. ;; gui-selection-owner-p is used in simple.el.
(defun x-selection-owner-p (&optional _selection _terminal) (gui-method-define gui-selection-owner-p pc #'w16-selection-owner-p)
"Whether the current Emacs process owns the given X Selection. (defun w16-selection-owner-p (_selection)
The arg should be the name of the selection in question, typically one of ;; FIXME: Other systems don't obey gui-select-enable-clipboard here.
the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. (if gui-select-enable-clipboard
\(Those are literal upper-case symbol names, since that's what X expects.) (let ((text
For convenience, the symbol nil is the same as `PRIMARY', ;; Don't die if w16-get-clipboard-data signals an error.
and t is the same as `SECONDARY'. (ignore-errors
(w16-get-clipboard-data))))
TERMINAL should be a terminal object or a frame specifying the X ;; We consider ourselves the owner of the selection
server to query. If omitted or nil, that stands for the selected ;; if it does not exist, or exists and compares
frame's display, or the first available X display. ;; equal with the last text we've put into the
;; Windows clipboard.
On Nextstep, TERMINAL is unused. (cond
((not text) t)
\(fn &optional SELECTION TERMINAL)" ((or (eq text gui-last-selected-text)
(if gui-select-enable-clipboard (string= text gui-last-selected-text))
(let (text) text)
;; Don't die if w16-get-clipboard-data signals an error. (t nil)))))
(ignore-errors
(setq text (w16-get-clipboard-data))) ;; gui-own-selection and gui-disown-selection are used in gui-set-selection.
;; We consider ourselves the owner of the selection if it does (gui-method-define gui-own-selection pc
;; not exist, or exists and compares equal with the last text (lambda (_selection value)
;; we've put into the Windows clipboard. ;; FIXME: Other systems don't obey
(cond ;; gui-select-enable-clipboard here.
((not text) t) (ignore-errors
((or (eq text gui-last-selected-text) (w16--select-text value))
(string= text gui-last-selected-text)) value))
text)
(t nil))))) (gui-method-define gui-disown-selection pc
(lambda (selection &optional _time-object _terminal)
;; x-own-selection-internal and x-disown-selection-internal are used (if (w16-selection-owner-p selection)
;; in select.el:x-set-selection. t)))
(defun x-own-selection-internal (_selection value &optional _frame)
"Assert an X selection of the type SELECTION with and value VALUE. ;; gui-get-selection is used in select.el
SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. (gui-method-define gui-get-selection pc
\(Those are literal upper-case symbol names, since that's what X expects.) (lambda (selection-symbol target-type)
VALUE is typically a string, or a cons of two markers, but may be (w16-get-selection-value)))
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.