summaryrefslogtreecommitdiff
path: root/lisp/term
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2014-10-01 18:13:11 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2014-10-01 18:13:11 -0400
commita8b36b953e3dc4d50dbfe430d5c579f7b1fd71e7 (patch)
treecfbea5b3f0c9514911375ef68a290c193730bf22 /lisp/term
parentc59ef5ef53f8e33a693f1107c1d61535bbd3a187 (diff)
downloademacs-a8b36b953e3dc4d50dbfe430d5c579f7b1fd71e7.tar.gz
Consolidate x-select-text.
* lisp/frame.el (gui-method, gui-method-define, gui-method-declare) (gui-call): New macros. (gui-method--name): New function. (frame-creation-function-alist): Use gui-method-declare. (make-frame): Use gui-method. * lisp/select.el (gui-select-enable-clipboard): Rename from x-select-enable-clipboard and move here. (x-select-enable-clipboard): Define as obsolete alias. (gui-last-selected-text): New var, to replace x-last-selected-text. (gui-select-text): New GUI method. (gui-select-text): New function. (x-select-text): Define as obsolete alias. * lisp/term/common-win.el (x-select-enable-clipboard, x-select-text): Move to select.el. * lisp/simple.el (interprogram-cut-function): Change default to x-select-text. (interprogram-paste-function): Change default to `ignore'. * lisp/w32-common-fns.el (interprogram-cut-function): Don't modify. * lisp/term/x-win.el (interprogram-cut-function): Don't modify. (gui-select-text): Add method for x. * lisp/term/w32-win.el (gui-select-text): Add method for w32. * lisp/term/pc-win.el (x-last-selected-text): Remove, use gui-last-selected-text instead. (msdos-initialize-window-system): Don't set interprogram-cut-function. (gui-select-text): Add method for pc. * lisp/term/ns-win.el (ns-last-selected-text): Remove, use gui-last-selected-text instead. (gui-select-text): Add method for ns. (x-setup-function-keys): Don't change interprogram-cut-function. * lisp/loadup.el ("startup"): Load after "frame". * lisp/subr.el (package--builtin-versions, package--description-file): Move from startup.el. * lisp/startup.el (package--builtin-versions, package--description-file): Move to subr.el. (handle-args-function-alist, window-system-initialization-alist): Use gui-method-declare. (command-line): Use gui-method. * src/xselect.c (selection-converter-alist): Fix docstring.
Diffstat (limited to 'lisp/term')
-rw-r--r--lisp/term/common-win.el64
-rw-r--r--lisp/term/ns-win.el25
-rw-r--r--lisp/term/pc-win.el69
-rw-r--r--lisp/term/w32-win.el15
-rw-r--r--lisp/term/x-win.el24
5 files changed, 68 insertions, 129 deletions
diff --git a/lisp/term/common-win.el b/lisp/term/common-win.el
index ba59c75c4ec..fcb9fd55bb1 100644
--- a/lisp/term/common-win.el
+++ b/lisp/term/common-win.el
@@ -24,67 +24,6 @@
;;; Code:
-(defcustom x-select-enable-clipboard t
- "Non-nil means cutting and pasting uses the clipboard.
-This is in addition to, but in preference to, the primary selection.
-
-Note that MS-Windows does not support selection types other than the
-clipboard. (The primary selection that is set by Emacs is not
-accessible to other programs on MS-Windows.)
-
-This variable is not used by the Nextstep port."
- :type 'boolean
- :group 'killing
- ;; The GNU/Linux version changed in 24.1, the MS-Windows version did not.
- :version "24.1")
-
-(defvar x-last-selected-text) ; w32-fns.el
-(declare-function w32-set-clipboard-data "w32select.c"
- (string &optional ignored))
-(defvar ns-last-selected-text) ; ns-win.el
-(declare-function ns-set-pasteboard "ns-win" (string))
-
-(defvar x-select-enable-primary) ; x-win.el
-(defvar x-last-selected-text-primary)
-(defvar x-last-selected-text-clipboard)
-(defvar saved-region-selection) ; simple.el
-
-(defun x-select-text (text)
- "Select TEXT, a string, according to the window system.
-
-On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the
-clipboard. If `x-select-enable-primary' is non-nil, put TEXT in
-the primary selection.
-
-On MS-Windows, make TEXT the current selection. If
-`x-select-enable-clipboard' is non-nil, copy the text to the
-clipboard as well.
-
-On Nextstep, put TEXT in the pasteboard (`x-select-enable-clipboard'
-is not used)."
- (cond ((eq (framep (selected-frame)) 'w32)
- (if x-select-enable-clipboard
- (w32-set-clipboard-data text))
- (setq x-last-selected-text text))
- ((featurep 'ns)
- ;; Don't send the pasteboard too much text.
- ;; It becomes slow, and if really big it causes errors.
- (ns-set-pasteboard text)
- (setq ns-last-selected-text text))
- (t
- ;; With multi-tty, this function may be called from a tty frame.
- (when (eq (framep (selected-frame)) 'x)
- (when x-select-enable-primary
- (x-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)
- (setq x-last-selected-text-clipboard text))))))
-
;;;; Function keys
(defvar x-alternatives-map
@@ -117,8 +56,7 @@ is not used)."
(set-keymap-parent map (keymap-parent local-function-key-map))
(set-keymap-parent local-function-key-map map))
(when (featurep 'ns)
- (setq interprogram-cut-function 'x-select-text
- interprogram-paste-function 'x-selection-value
+ (setq interprogram-paste-function 'x-selection-value
system-key-alist
(list
;; These are special "keys" used to pass events from C to lisp.
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 47d953aebfb..fc13a2c5ddf 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
@@ -739,7 +739,6 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
;; 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 ns-last-selected-text nil)
;; Return the value of the current Nextstep selection. For
;; compatibility with older Nextstep applications, this checks cut
@@ -751,13 +750,13 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
(if (string= text "") (setq text nil))
(cond
((not text) nil)
- ((eq text ns-last-selected-text) nil)
- ((string= text ns-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 ns-last-selected-text text)
+ (setq gui-last-selected-text text)
nil)
(t
- (setq ns-last-selected-text text)))))
+ (setq gui-last-selected-text text)))))
(defun ns-copy-including-secondary ()
(interactive)
@@ -959,10 +958,18 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
;; Any display name is OK.
(add-to-list 'display-format-alist '(".*" . ns))
-(add-to-list 'handle-args-function-alist '(ns . x-handle-args))
-(add-to-list 'frame-creation-function-alist '(ns . x-create-frame-with-faces))
-(add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system))
-
+(gui-method-define handle-args-function ns #'x-handle-args)
+(gui-method-define frame-creation-function ns #'x-create-frame-with-faces)
+(gui-method-define window-system-initialization ns
+ #'ns-initialize-window-system)
+
+(declare-function ns-set-pasteboard "ns-win" (string))
+(gui-method-define gui-select-text ns
+ (lambda (text)
+ ;; Don't send the pasteboard too much text.
+ ;; It becomes slow, and if really big it causes errors.
+ (when gui-select-enable-clipboard
+ (ns-set-pasteboard text))))
(provide 'ns-win)
diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el
index f24a54fbe28..264d881bc15 100644
--- a/lisp/term/pc-win.el
+++ b/lisp/term/pc-win.el
@@ -219,44 +219,10 @@ the operating system.")
;
;;;; 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.
-(defvar x-last-selected-text nil)
-
-(defcustom x-select-enable-clipboard t
- "Non-nil means cutting and pasting uses the clipboard.
-This is in addition to, but in preference to, the primary selection.
-
-Note that MS-Windows does not support selection types other than the
-clipboard. (The primary selection that is set by Emacs is not
-accessible to other programs on MS-Windows.)
-
-This variable is not used by the Nextstep port."
- :type 'boolean
- :group 'killing)
-
-(defun x-select-text (text)
- "Select TEXT, a string, according to the window system.
-
-On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the
-clipboard. If `x-select-enable-primary' is non-nil, put TEXT in
-the primary selection.
-
-On MS-Windows, make TEXT the current selection. If
-`x-select-enable-clipboard' is non-nil, copy the text to the
-clipboard as well.
-
-On Nextstep, put TEXT in the pasteboard (`x-select-enable-clipboard'
-is not used)."
- (if x-select-enable-clipboard
- (w16-set-clipboard-data text))
- (setq x-last-selected-text text))
-
(defun x-get-selection-value ()
"Return the value of the current selection.
Consult the selection. Treat empty strings as if they were unset."
- (if x-select-enable-clipboard
+ (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"
@@ -264,13 +230,13 @@ Consult the selection. Treat empty strings as if they were unset."
(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))))))
;; x-selection-owner-p is used in simple.el.
(defun x-selection-owner-p (&optional _selection _terminal)
@@ -288,7 +254,7 @@ frame's display, or the first available X display.
On Nextstep, TERMINAL is unused.
\(fn &optional SELECTION TERMINAL)"
- (if x-select-enable-clipboard
+ (if gui-select-enable-clipboard
(let (text)
;; Don't die if w16-get-clipboard-data signals an error.
(ignore-errors
@@ -298,8 +264,8 @@ On Nextstep, TERMINAL is unused.
;; we've put into the Windows clipboard.
(cond
((not text) t)
- ((or (eq text x-last-selected-text)
- (string= text x-last-selected-text))
+ ((or (eq text gui-last-selected-text)
+ (string= text gui-last-selected-text))
text)
(t nil)))))
@@ -463,20 +429,27 @@ 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-cut-function 'x-select-text)
(setq interprogram-paste-function 'x-get-selection-value)
(menu-bar-enable-clipboard)
(run-hooks 'terminal-init-msdos-hook))
;; frame-creation-function-alist is examined by frame.el:make-frame.
-(add-to-list 'frame-creation-function-alist
- '(pc . msdos-create-frame-with-faces))
+(gui-method-define frame-creation-function
+ pc #'msdos-create-frame-with-faces)
;; window-system-initialization-alist is examined by startup.el:command-line.
-(add-to-list 'window-system-initialization-alist
- '(pc . msdos-initialize-window-system))
+(gui-method-define window-system-initialization
+ pc #'msdos-initialize-window-system)
;; We don't need anything beyond tty-handle-args for handling
;; command-line argument; see startup.el.
-(add-to-list 'handle-args-function-alist '(pc . tty-handle-args))
+(gui-method-define handle-args-function pc #'tty-handle-args)
+
+
+(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))))
;; ---------------------------------------------------------------------------
diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el
index e103562ba7a..3eb8e69c28d 100644
--- a/lisp/term/w32-win.el
+++ b/lisp/term/w32-win.el
@@ -371,9 +371,18 @@ This returns an error if any Emacs frames are X frames, or always under W32."
(setq w32-initialized t))
(add-to-list 'display-format-alist '("\\`w32\\'" . w32))
-(add-to-list 'handle-args-function-alist '(w32 . x-handle-args))
-(add-to-list 'frame-creation-function-alist '(w32 . x-create-frame-with-faces))
-(add-to-list 'window-system-initialization-alist '(w32 . w32-initialize-window-system))
+(gui-method-define handle-args-function w32 #'x-handle-args)
+(gui-method-define frame-creation-function w32
+ #'x-create-frame-with-faces)
+(gui-method-define window-system-initialization w32
+ #'w32-initialize-window-system)
+
+(declare-function w32-set-clipboard-data "w32select.c"
+ (string &optional ignored))
+(gui-method-define gui-select-text w32
+ (lambda (text)
+ (if gui-select-enable-clipboard
+ (w32-set-clipboard-data text))))
(provide 'w32-win)
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index 964b9112553..daaef61e494 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -1217,8 +1217,6 @@ The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)."
(remove-text-properties 0 (length text) '(foreign-selection nil) text))
text))
-(defvar x-select-enable-clipboard) ; common-win
-
;; 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,
@@ -1290,7 +1288,6 @@ The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)."
'x-selection-value "24.1")
;; Arrange for the kill and yank functions to set and check the clipboard.
-(setq interprogram-cut-function 'x-select-text)
(setq interprogram-paste-function 'x-selection-value)
;; Make paste from other applications use the decoding in x-select-request-type
@@ -1301,6 +1298,7 @@ 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."
(interactive "*")
(let ((clipboard-text (x-selection-value-internal 'CLIPBOARD))
@@ -1463,9 +1461,23 @@ This returns an error if any Emacs frames are X frames, or always under W32."
(setq x-initialized t))
(add-to-list 'display-format-alist '("\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" . x))
-(add-to-list 'handle-args-function-alist '(x . x-handle-args))
-(add-to-list 'frame-creation-function-alist '(x . x-create-frame-with-faces))
-(add-to-list 'window-system-initialization-alist '(x . x-initialize-window-system))
+(gui-method-define handle-args-function x #'x-handle-args)
+(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
+ (x-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)
+ (setq x-last-selected-text-clipboard text))))
;; Initiate drag and drop
(add-hook 'after-make-frame-functions 'x-dnd-init-frame)