]> git.eshelyaron.com Git - emacs.git/commitdiff
Consolidate x-select-text.
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 1 Oct 2014 22:13:11 +0000 (18:13 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 1 Oct 2014 22:13:11 +0000 (18:13 -0400)
* 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.

17 files changed:
etc/NEWS
lisp/emacs-lisp/cl-lib.el
lisp/eshell/esh-io.el
lisp/frame.el
lisp/loadup.el
lisp/menu-bar.el
lisp/select.el
lisp/simple.el
lisp/startup.el
lisp/subr.el
lisp/term/common-win.el
lisp/term/ns-win.el
lisp/term/pc-win.el
lisp/term/w32-win.el
lisp/term/x-win.el
lisp/w32-common-fns.el
src/xselect.c

index 8c2b64b14fc2dff715a4db2cfc99780a980b7861..ddcd70cb11a626f6625c4f1e32c8c3268c85f25c 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -49,6 +49,9 @@ Use './configure PKG_CONFIG=/full/name/of/pkg-config' if you need to.
 \f
 * Changes in Emacs 25.1
 
+** x-select-enable-clipboard is renamed gui-select-enable-clipboard.
+Additionally it now also applies to OSX and GNUstep.
+
 ** `insert-register' now leaves point after the inserted text
 when called interactively.  A prefix argument toggles this behavior.
 
@@ -242,7 +245,9 @@ Emacs-21.
 \f
 * Lisp Changes in Emacs 25.1
 
-*** call-process-shell-command and process-file-shell-command
+** x-select-text is renamed gui-select-text.
+
+** call-process-shell-command and process-file-shell-command
 don't take "&rest args" any more.
 
 ** New function `alist-get', which is also a valid place (aka lvalue).
index 09cc3eee985ec61dd99b22d626dda423159bb991..c7d21c76fc186fad0ceedf0b913d693b3e0aa290 100644 (file)
@@ -701,7 +701,6 @@ If ALIST is non-nil, the new pairs are prepended to it."
 (gv-define-setter window-width (store)
   `(progn (enlarge-window (- ,store (window-width)) t) ,store))
 (gv-define-simple-setter x-get-secondary-selection x-own-secondary-selection t)
-(gv-define-simple-setter x-get-selection x-own-selection t)
 
 ;; More complex setf-methods.
 
index b7830db08b502c6d0a84f5d41a7b00d2f68f164d..ebbca58a442c2aaa9d56a7da987b89a7e168a31e 100644 (file)
@@ -118,8 +118,6 @@ from executing while Emacs is redisplaying."
   :type 'integer
   :group 'eshell-io)
 
-(defvar x-select-enable-clipboard)     ; term/common-win
-
 (defcustom eshell-virtual-targets
   '(("/dev/eshell" eshell-interactive-print nil)
     ("/dev/kill" (lambda (mode)
@@ -128,7 +126,7 @@ from executing while Emacs is redisplaying."
                   'eshell-kill-append) t)
     ("/dev/clip" (lambda (mode)
                   (if (eq mode 'overwrite)
-                      (let ((x-select-enable-clipboard t))
+                      (let ((gui-select-enable-clipboard t))
                         (kill-new "")))
                   'eshell-clipboard-append) t))
   "Map virtual devices name to Emacs Lisp functions.
@@ -328,7 +326,7 @@ last execution result should not be changed."
 (defun eshell-clipboard-append (string)
   "Call `kill-append' with STRING, if it is indeed a string."
   (if (stringp string)
-      (let ((x-select-enable-clipboard t))
+      (let ((gui-select-enable-clipboard t))
        (kill-append string nil))))
 
 (defun eshell-get-target (target &optional mode)
index f144cf234054423c0b13d40fdfeff64488aaf960..18aff5b28790cf375ca0aedcbfe6b170c31a7529 100644 (file)
 ;;; Code:
 (eval-when-compile (require 'cl-lib))
 
-(defvar frame-creation-function-alist
-  (list (cons nil
-             (if (fboundp 'tty-create-frame-with-faces)
-                 'tty-create-frame-with-faces
-                (lambda (_parameters)
-                  (error "Can't create multiple frames without a window system")))))
-  "Alist of window-system dependent functions to call to create a new frame.
+;; Dispatch tables for GUI methods.
+
+(defun gui-method--name (base)
+  (intern (format "%s-alist" base)))
+
+(defmacro gui-method (name &optional type)
+  (macroexp-let2 nil type (or type `(framep (selected-frame)))
+    `(alist-get ,type ,(gui-method--name name)
+                (lambda (&rest _args)
+                  (error "No method %S for %S frame" ',name ,type)))))
+
+(defmacro gui-method-define (name type fun)
+  `(setf (gui-method ,name ',type) ,fun))
+
+(defmacro gui-method-declare (name &optional tty-fun doc)
+  (declare (doc-string 3) (indent 2))
+  `(defvar ,(gui-method--name name)
+     ,(if tty-fun `(list (cons t ,tty-fun))) ,doc))
+
+(defmacro gui-call (name &rest args)
+  `(funcall (gui-method ,name) ,@args))
+
+(gui-method-declare frame-creation-function
+    #'tty-create-frame-with-faces
+  "Method for window-system dependent functions to create a new frame.
 The window system startup file should add its frame creation
-function to this list, which should take an alist of parameters
+function to this method, which should take an alist of parameters
 as its argument.")
 
 (defvar window-system-default-frame-alist nil
   "Window-system dependent default frame parameters.
 The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
-where WINDOW-SYSTEM is a window system symbol (see `window-system')
+where WINDOW-SYSTEM is a window system symbol (as returned by `framep')
 and ALIST is a frame parameter alist like `default-frame-alist'.
 Then, for frames on WINDOW-SYSTEM, any parameters specified in
 ALIST supersede the corresponding parameters specified in
@@ -632,9 +650,8 @@ the new frame according to its own rules."
             ((assq 'terminal parameters)
              (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
                (cond
-                ((eq type t) nil)
-                ((eq type nil) (error "Terminal %s does not exist"
-                                       (cdr (assq 'terminal parameters))))
+                ((null type) (error "Terminal %s does not exist"
+                                     (cdr (assq 'terminal parameters))))
                 (t type))))
             ((assq 'window-system parameters)
              (cdr (assq 'window-system parameters)))
@@ -643,15 +660,12 @@ the new frame according to its own rules."
                   (error "Don't know how to interpret display %S"
                          display)))
             (t window-system)))
-        (frame-creation-function (cdr (assq w frame-creation-function-alist)))
         (oldframe (selected-frame))
         (params parameters)
         frame)
-    (unless frame-creation-function
-      (error "Don't know how to create a frame on window system %s" w))
 
     (unless (get w 'window-system-initialized)
-      (funcall (cdr (assq w window-system-initialization-alist)) display)
+      (funcall (gui-method window-system-initialization w) display)
       (setq x-display-name display)
       (put w 'window-system-initialized t))
 
@@ -665,7 +679,8 @@ the new frame according to its own rules."
        (push p params)))
     ;; Now make the frame.
     (run-hooks 'before-make-frame-hook)
-    (setq frame (funcall frame-creation-function params))
+    (setq frame
+          (funcall (gui-method frame-creation-function w) params))
     (normal-erase-is-backspace-setup-frame frame)
     ;; Inherit the original frame's parameters.
     (dolist (param frame-inherited-parameters)
index c1206e243c55079d75eccf4d0c5bc6e8f3fa7935..9c052b284b8cc1fe706e4eed00349d1e394ed6ab 100644 (file)
 (load "faces")  ; after here, `defface' may be used.
 
 (load "button")
-(load "startup")
 
 ;; We don't want to store loaddefs.el in the repository because it is
 ;; a generated file; but it is required in order to compile the lisp files.
 
 (load "indent")
 (load "frame")
+(load "startup")
 (load "term/tty-colors")
 (load "font-core")
 ;; facemenu must be loaded before font-lock, because `facemenu-keymap'
index 9657c5924f90a05a096c4acadf5f07e021d97190..35f996c5750d7c2a1aaa7e255f6e1150ebd82650 100644 (file)
 (defun clipboard-yank ()
   "Insert the clipboard contents, or the last stretch of killed text."
   (interactive "*")
-  (let ((x-select-enable-clipboard t))
+  (let ((gui-select-enable-clipboard t))
     (yank)))
 
 (defun clipboard-kill-ring-save (beg end &optional region)
-  "Copy region to kill ring, and save in the X clipboard."
+  "Copy region to kill ring, and save in the GUI's clipboard."
   (interactive "r\np")
-  (let ((x-select-enable-clipboard t))
+  (let ((gui-select-enable-clipboard t))
     (kill-ring-save beg end region)))
 
 (defun clipboard-kill-region (beg end &optional region)
-  "Kill the region, and save it in the X clipboard."
+  "Kill the region, and save it in the GUI's clipboard."
   (interactive "r\np")
-  (let ((x-select-enable-clipboard t))
+  (let ((gui-select-enable-clipboard t))
     (kill-region beg end region)))
 
 (defun menu-bar-enable-clipboard ()
index c4d020343af89197d6553f2e5024ce5a4ddfd4bd..c32b45f1c85216f850263b8459c9dfbaf3917795 100644 (file)
@@ -77,6 +77,41 @@ After the communication, this variable is set to nil.")
 ;; Only declared obsolete in 23.3.
 (define-obsolete-function-alias 'x-selection 'x-get-selection "at least 19.34")
 
+(defcustom gui-select-enable-clipboard t
+  "Non-nil means cutting and pasting uses the clipboard.
+This can be in addition to, but in preference to, the primary selection,
+if applicable (i.e. under X11)."
+  :type 'boolean
+  :group 'killing
+  ;; The GNU/Linux version changed in 24.1, the MS-Windows version did not.
+  :version "24.1")
+(define-obsolete-variable-alias 'x-select-enable-clipboard
+  'gui-select-enable-clipboard "25.1")
+
+(gui-method-declare gui-select-text #'ignore
+  "Method used to pass the current selection to the system.
+Called with one argument (the text selected).
+Should obey `gui-select-enable-clipboard' where applicable.")
+
+(defvar gui-last-selected-text nil
+  "Last text passed to `gui-select-text'.")
+
+(defun gui-select-text (text)
+  "Select TEXT, a string, according to the window system.
+if `gui-select-enable-clipboard' is non-nil, copy TEXT to the system's clipboard.
+
+On X, if `x-select-enable-primary' is non-nil, put TEXT in
+the primary selection.
+
+On MS-Windows, make TEXT the current selection."
+  ;; FIXME: We should test gui-select-enable-clipboard here!
+  ;; But that would break the independence between x-select-enable-primary
+  ;; and x-select-enable-clipboard!
+  ;;(when gui-select-enable-clipboard
+    (gui-call gui-select-text text) ;;)
+  (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)
   "Return the value of an X Windows selection.
 The argument TYPE (default `PRIMARY') says which selection,
index 8469ff0d892afc07e7662e591b62b80fc9c5316b..8504cf4be19a9719383f756297c2e779114f8142 100644 (file)
@@ -3629,7 +3629,7 @@ No filtering is done unless a hook says to."
 
 ;;;; Window system cut and paste hooks.
 
-(defvar interprogram-cut-function nil
+(defvar interprogram-cut-function #'x-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
@@ -3640,7 +3640,7 @@ put in the kill ring, to make the new kill available to other
 programs.  The function takes one argument, TEXT, which is a
 string containing the text which should be made available.")
 
-(defvar interprogram-paste-function nil
+(defvar interprogram-paste-function #'ignore
   "Function to call to get text cut from other programs.
 Most window systems provide a facility for cutting and pasting
 text between different programs, such as the clipboard on X and
index c46200a050dc8e7495ff96b1159ff8719fa33537..a0bcd1fcaba00403063d307d5529b62053db613f 100644 (file)
@@ -421,21 +421,6 @@ Warning Warning!!!  Pure space overflow    !!!Warning Warning
   :type 'directory
   :initialize 'custom-initialize-delay)
 
-(defvar package--builtin-versions
-  ;; Mostly populated by loaddefs.el via autoload-builtin-package-versions.
-  (purecopy `((emacs . ,(version-to-list emacs-version))))
-  "Alist giving the version of each versioned builtin package.
-I.e. each element of the list is of the form (NAME . VERSION) where
-NAME is the package name as a symbol, and VERSION is its version
-as a list.")
-
-(defun package--description-file (dir)
-  (concat (let ((subdir (file-name-nondirectory
-                         (directory-file-name dir))))
-            (if (string-match "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)" subdir)
-                (match-string 1 subdir) subdir))
-          "-pkg.el"))
-
 (defun normal-top-level-add-subdirs-to-load-path ()
   "Add all subdirectories of `default-directory' to `load-path'.
 More precisely, this uses only the subdirectories whose names
@@ -719,17 +704,17 @@ It is the default value of the variable `top-level'."
 (defconst tool-bar-images-pixel-height 24
   "Height in pixels of images in the tool-bar.")
 
-(defvar handle-args-function-alist '((nil . tty-handle-args))
-  "Functions for processing window-system dependent command-line arguments.
+(gui-method-declare handle-args-function #'tty-handle-args
+  "Method for processing window-system dependent command-line arguments.
 Window system startup files should add their own function to this
-alist, which should parse the command line arguments.  Those
+method, which should parse the command line arguments.  Those
 pertaining to the window system should be processed and removed
 from the returned command line.")
 
-(defvar window-system-initialization-alist '((nil . ignore))
-  "Alist of window-system initialization functions.
-Window-system startup files should add their own initialization
-function to this list.  The function should take no arguments,
+(gui-method-declare window-system-initialization #'ignore
+  "Method for window-system initialization.
+Window-system startup files should add their own implementation
+to this method.  The function should take no arguments,
 and initialize the window system environment to prepare for
 opening the first frame (e.g. open a connection to an X server).")
 
@@ -965,8 +950,7 @@ please check its value")
       ;; Process window-system specific command line parameters.
       (setq command-line-args
            (funcall
-            (or (cdr (assq initial-window-system handle-args-function-alist))
-                (error "Unsupported window system `%s'" initial-window-system))
+             (gui-method handle-args-function (or initial-window-system t))
             command-line-args))
       ;; Initialize the window system. (Open connection, etc.)
       (funcall
@@ -1311,9 +1295,10 @@ the `--debug-init' option to view a complete error backtrace."
                            (format "Your `load-path' seems to contain
 your `.emacs.d' directory: %s\n\
 This is likely to cause problems...\n\
-Consider using a subdirectory instead, e.g.: %s" dir
-(expand-file-name "lisp" user-emacs-directory))
-                            :warning))))
+Consider using a subdirectory instead, e.g.: %s"
+                                    dir (expand-file-name
+                                         "lisp" user-emacs-directory))
+                            :warning))))
 
   ;; If -batch, terminate after processing the command options.
   (if noninteractive (kill-emacs t))
index 581e52e8f9d2a358ab83cc53d450eaedbbebc585..2435285bf0f3a61c4c862eb20bd32ec7fd98f679 100644 (file)
@@ -4800,6 +4800,21 @@ which is higher than \"1alpha\", which is higher than \"1snapshot\".
 Also, \"-GIT\", \"-CVS\" and \"-NNN\" are treated as snapshot versions."
   (version-list-= (version-to-list v1) (version-to-list v2)))
 
+(defvar package--builtin-versions
+  ;; Mostly populated by loaddefs.el via autoload-builtin-package-versions.
+  (purecopy `((emacs . ,(version-to-list emacs-version))))
+  "Alist giving the version of each versioned builtin package.
+I.e. each element of the list is of the form (NAME . VERSION) where
+NAME is the package name as a symbol, and VERSION is its version
+as a list.")
+
+(defun package--description-file (dir)
+  (concat (let ((subdir (file-name-nondirectory
+                         (directory-file-name dir))))
+            (if (string-match "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)" subdir)
+                (match-string 1 subdir) subdir))
+          "-pkg.el"))
+
 \f
 ;;; Misc.
 (defconst menu-bar-separator '("--")
index ba59c75c4ec785d11bf6c4df8159cc2b9e313b51..fcb9fd55bb1805880ac66b592b2894caf15849e5 100644 (file)
 
 ;;; 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.
index 47d953aebfba76c9a1bef21ee0d7b798925148dc..fc13a2c5ddf432661366f446570fb8f9d3551b45 100644 (file)
@@ -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)
 
index f24a54fbe2889baab00a83177242efeb2e85186a..264d881bc1529d7548bc140834b39668ee826f10 100644 (file)
@@ -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))))
 
 ;; ---------------------------------------------------------------------------
 
index e103562ba7acc3586ce1a010f1f04a435d0ef139..3eb8e69c28dbff5602697adb56f171d8ee6845f9 100644 (file)
@@ -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)
 
index 964b91125539d283dca957d2bc9d59a6c03cb89b..daaef61e494b40677946d27db70379365f565723 100644 (file)
@@ -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)
index d149500c3273e7e6b759d787a5dcd22683761fb6..343a4c25895723be523d55818eacb183707319a4 100644 (file)
@@ -104,12 +104,11 @@ ignored on MS-Windows and MS-DOS."
 ;; current selection against it, and avoid passing back our own text
 ;; from x-selection-value.
 (defvar x-last-selected-text nil)
-(defvar x-select-enable-clipboard)
 
 (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 "w32-get-clipboard-data:%s"
@@ -128,7 +127,6 @@ Consult the selection.  Treat empty strings as if they were unset."
 (defalias 'x-selection-value 'x-get-selection-value)
 
 ;; 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)
 
 (provide 'w32-common-fns)
index 0e8a43717e04feb023673b2949a3cea56535fd89..a06243f592439f81959be6a4351fb6091552a13d 100644 (file)
@@ -2638,12 +2638,14 @@ syms_of_xselect (void)
   converted_selections = NULL;
   conversion_fail_tag = None;
 
+  /* FIXME: Duplicate definition in nsselect.c.  */
   DEFVAR_LISP ("selection-converter-alist", Vselection_converter_alist,
               doc: /* An alist associating X Windows selection-types with functions.
 These functions are called to convert the selection, with three args:
 the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
 a desired type to which the selection should be converted;
-and the local selection value (whatever was given to `x-own-selection').
+and the local selection value (whatever was given to
+`x-own-selection-internal').
 
 The function should return the value to send to the X server
 \(typically a string).  A return value of nil