diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-10-21 11:27:18 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-10-21 11:27:18 -0400 |
commit | a046b8dd48b0e26f9354e9a005113088c3bc04f9 (patch) | |
tree | 608344bb89046a967dcae461b2bde45900c28af5 /lisp/term/x-win.el | |
parent | e5b3b7d3f387c992e6507bef3885056c5235e9ee (diff) | |
download | emacs-a046b8dd48b0e26f9354e9a005113088c3bc04f9.tar.gz |
Get rid of backend-dependent selection-handling functions for kill/yank
and make it generic instead by relying on the lower-level selection
management functions.
* select.el (select-enable-clipboard): Rename from
gui-select-enable-clipboard.
(select-enable-primary): Move from x-win.el and rename from
x-select-enable-primary.
(gui-last-selected-text): Remove.
(gui--last-selected-text-clipboard, gui--last-selected-text-primary):
New vars.
(gui-select-text): Rewrite, based on x-win.el's old x-select-text.
(gui-select-text-alist, gui-selection-value-alist): Remove.
(x-select-request-type): Move from x-win.el.
(gui--selection-value-internal): New function, taken from x-win's
x-selection-value-internal.
(gui-selection-value): Rewrite, based on x-win.el's old x-selection-value.
(gui-set-selection-alist): Rename from gui-own-selection-alist and
extend it to handle a nil value as a "disown" request.
(gui-disown-selection-alist): Remove.
(xselect-convert-to-delete): Adjust accordingly.
(gui-set-selection): Simplify accordingly as well. Use dotimes.
* lisp/frame.el (gui-method): Use window-system rather than framep.
(gui-method-declare): The tty case is now nil rather than t.
(make-frame): Adjust accordingly.
* lisp/term/x-win.el (x-last-selected-text-primary)
(x-select-enable-primary): Remove (moved to select.el).
(x-select-request-type): Move to select.el.
(x-selection-value-internal, x--selection-value): Remove functions.
(gui-selection-value, gui-select-text): Remove moethods.
(gui-set-selection): Merge own and disown methods.
* lisp/startup.el (command-line): Adjust now that `gui-method' expects nil
for ttys.
* lisp/term/ns-win.el (ns-get-pasteboard, ns-set-pasteboard)
(ns-selection-value): Remove functions.
(gui-select-text, gui-selection-value): Don't define method any more.
(gui-set-selection): Merge the old own and disown methods.
(gui-selection-exists-p, gui-get-selection): Adjust to new name of
underlying C primitive.
* lisp/term/pc-win.el (w16-get-selection-value): Add dummy argument and drop
test of gui-select-enable-clipboard, to make it usable as
a gui-get-selection method.
(gui-selection-exists-p): Adjust to new name of C primitive.
(gui-set-selection): Merge own and disown methods.
(gui-select-text, gui-selection-value): Delete methods.
(w16--select-text): Delete function.
* lisp/term/w32-win.el (w32--select-text, w32--get-selection-value):
Delete function (move functionality into w32--set-selection and
w32--get-selection).
(gui-select-text, gui-selection-value): Don't define methods.
(w32--set-selection, w32--get-selection, w32--selection-owner-p):
New functions.
(gui-get-selection, gui-selection-owner-p, gui-selection-exists-p):
Use them.
(gui-selection-exists-p): Adjust to new name of C primitive.
* src/nsselect.m (ns_get_local_selection): Signal error rather than `quit'.
(Fns_own_selection_internal): Tighten scoping.
(Fns_selection_exists_p): Rename from Fx_selection_exists_p.
(Fns_get_selection): Rename from Fx_get_selection_internal.
(Fns_get_selection_internal, Fns_store_selection_internal):
Remove functions.
(syms_of_nsselect): Adjust accordingly.
* src/w16select.c (Fw16_selection_exists_p): Rename from
Fx_selection_exists_p.
(syms_of_win16select): Adjust accordingly.
* src/w32select.c (Fw32_selection_exists_p): Rename from
Fx_selection_exists_p.
(syms_of_w32select): Adjust accordingly.
Diffstat (limited to 'lisp/term/x-win.el')
-rw-r--r-- | lisp/term/x-win.el | 149 |
1 files changed, 4 insertions, 145 deletions
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index a7e695da2a0..ebc34d3fdd6 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -1154,136 +1154,6 @@ as returned by `x-server-vendor'." ;;;; 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. 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 - "The value of the CLIPBOARD X selection last time we selected or -pasted text.") -(defvar x-last-selected-text-primary nil - "The value of the PRIMARY X selection last time we selected or -pasted text.") - -(defcustom x-select-enable-primary nil - "Non-nil means cutting and pasting uses the primary selection." - :type 'boolean - :group 'killing - :version "24.1") - -(defcustom x-select-request-type nil - "Data type request for X selection. -The value is one of the following data types, a list of them, or nil: - `COMPOUND_TEXT', `UTF8_STRING', `STRING', `TEXT' - -If the value is one of the above symbols, try only the specified type. - -If the value is a list of them, try each of them in the specified -order until succeed. - -The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)." - :type '(choice (const :tag "Default" nil) - (const COMPOUND_TEXT) - (const UTF8_STRING) - (const STRING) - (const TEXT) - (set :tag "List of values" - (const COMPOUND_TEXT) - (const UTF8_STRING) - (const STRING) - (const TEXT))) - :group 'killing) - -;; Get a selection value of type TYPE by calling x-get-selection with -;; an appropriate DATA-TYPE argument decided by `x-select-request-type'. -;; The return value is already decoded. If x-get-selection causes an -;; error, this function return nil. - -(defun x-selection-value-internal (type) - (let ((request-type (or x-select-request-type - '(UTF8_STRING COMPOUND_TEXT STRING))) - text) - (if (consp request-type) - (while (and request-type (not text)) - (condition-case nil - (setq text (x-get-selection type (car request-type))) - (error nil)) - (setq request-type (cdr request-type))) - (condition-case nil - (setq text (x-get-selection type request-type)) - (error nil))) - (if text - (remove-text-properties 0 (length text) '(foreign-selection nil) text)) - text)) - -;; Return the value of the current X selection. -;; Consult the selection. Treat empty strings as if they were unset. -;; 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. -(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. - (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") @@ -1457,21 +1327,10 @@ This returns an error if any Emacs frames are X frames." (gui-method-define frame-creation-function x #'x-create-frame-with-faces) (gui-method-define window-system-initialization x #'x-initialize-window-system) -(defvar x-select-enable-primary) ; x-win.el -(gui-method-define gui-select-text x - (lambda (text) - (when x-select-enable-primary - (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) - (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-set-selection x + (lambda (selection value) + (if value (x-own-selection-internal selection value) + (x-disown-selection-internal selection)))) (gui-method-define gui-selection-owner-p x #'x-selection-owner-p) (gui-method-define gui-selection-exists-p x #'x-selection-exists-p) (gui-method-define gui-get-selection x #'x-get-selection-internal) |