Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.899 diff -U 8 -r1.899 simple.el --- lisp/simple.el 1 Feb 2008 16:01:05 -0000 1.899 +++ lisp/simple.el 1 Feb 2008 19:09:20 -0000 @@ -2562,16 +2562,34 @@ programs. The function takes one or two arguments. The first argument, TEXT, is a string containing the text which should be made available. The second, optional, argument PUSH, has the same meaning as the similar argument to `x-set-cut-buffer', which see.") +(defvar interprogram-highlight-function nil + "Function to call to make an active region available to other progams. + +In addition to clibpoard cutting and pasting (see `interprogram-cut-function' +and `interprogram-paste-function'), some window systems (okay, one +window system, X11) provide a mechanism whereby text merely highlighted +in one application may be immediately inserted into another. +This variable holds a function that Emacs calls whenever +text is notionally highlighted in emacs - i.e. there is an active +region (see `transient-mark-mode'). The function will only be +called when `select-active-regions' is also set. + +The function takes one or two arguments, +The first argument, TEXT, is a string containing +the text that should be made available. +The second, optional, argument PUSH, has the same meaning as the +similar argument to `x-set-cut-buffer', which see.") + (defvar interprogram-paste-function nil "Function to call to get text cut from other programs. Most window systems provide some sort of facility for cutting and pasting text between the windows of different programs. This variable holds a function that Emacs calls to obtain text that other programs have provided for pasting. @@ -3346,18 +3364,19 @@ (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) + interprogram-highlight-function + (funcall interprogram-highlight-function + (buffer-substring (region-beginning) (region-end)))) (set-marker (mark-marker) pos (current-buffer))) ;; Normally we never clear mark-active except in Transient Mark mode. ;; But when we actually clear out the mark value too, ;; we must clear mark-active in any mode. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) Index: lisp/w32-vars.el =================================================================== RCS file: /sources/emacs/emacs/lisp/w32-vars.el,v retrieving revision 1.19 diff -U 8 -r1.19 w32-vars.el --- lisp/w32-vars.el 8 Jan 2008 20:44:48 -0000 1.19 +++ lisp/w32-vars.el 1 Feb 2008 19:09:21 -0000 @@ -144,18 +144,21 @@ (repeat :inline t (choice :tag "" (const :tag "Separator" ("")) (list :tag "Font Entry" (string :tag "Menu text") (string :tag "Font"))))))) :group 'w32) -(defcustom x-select-enable-clipboard t - "*Non-nil means cutting and pasting uses the clipboard. -This is in addition to the primary selection." - :type 'boolean - :group 'killing) +;; Uh. Does this belong here? It's also in +;; term/x-win.el and now has an extended definition there +;; +;; (defcustom x-select-enable-clipboard t +;; "*Non-nil means cutting and pasting uses the clipboard. +;; This is in addition to the primary selection." +;; :type 'boolean +;; :group 'killing) (provide 'w32-vars) ;;; arch-tag: ee2394fb-9db7-4c15-a8f0-66b47f4a2bb1 ;;; w32-vars.el ends here Index: lisp/term/x-win.el =================================================================== RCS file: /sources/emacs/emacs/lisp/term/x-win.el,v retrieving revision 1.222 diff -U 8 -r1.222 x-win.el --- lisp/term/x-win.el 1 Feb 2008 16:01:25 -0000 1.222 +++ lisp/term/x-win.el 1 Feb 2008 19:09:24 -0000 @@ -2140,55 +2140,179 @@ This is the actual text stored in the X cut buffer.") (defvar x-last-cut-buffer-coding 'iso-latin-1 "The coding we last used to encode/decode the text from the X cut buffer") (defvar x-cut-buffer-max 20000 ; Note this value is overridden below. "Max number of characters to put in the cut buffer. It is said that overlarge strings are slow to put into the cut buffer.") -(defcustom x-select-enable-clipboard nil - "Non-nil means cutting and pasting uses the clipboard. -This is in addition to, but in preference to, the primary selection." - :type 'boolean - :group 'killing) - -(defcustom x-select-enable-primary t - "Non-nil means cutting and pasting uses the primary selection." - :type 'boolean - :group 'killing) +(defcustom x-select-enable-clipboard '(:cut :paste) +"What cut/copy/paste/highlight ops should involve CLIPBOARD. + +In X11, CLIPBOARD is normally associated with 'clipboard cut/copy/paste' +style data interchange. + +Cut/Copy: Set if Killing (e.g. C-w/M-w) in Emacs should place text in the +CLIPBOARD X11 selection, i.e. if you want to paste killed text into other +programs on your desktop with the other programs' clipboard paste +function (typically something like C-v in those programs) + +Paste: Set if Yanking (e.g. C-y) in Emacs should check the clipboard +for text placed there with other programs' clipboard cut or copy +functions (typically something like C-x or C-c in those programs) + +Highlight: Set if merely highlighting text (setting the active region) +in Emacs should immediately put it in the clipboard, if +`select-active-regions' is also set. This is unusual for recent X11 +applications, typically highlighted text is placed in the PRIMARY X11 +selection, for 'highlight/middlebutton' style X11 transfer. +See `x-select-enable-primary'. + +It is recommended to unset `mouse-drag-copy-region' and +set `transient-mark-mode' if Highlight is set here." + +:type '(choice (const :tag "None" nil) + (const :tag "All" t) + (set :tag "Choose" (const :tag "Cut/Copy" :cut) + (const :tag "Paste" :paste) + (const :tag "Highlight" :highlight))) +:group 'killing) + +(defcustom x-select-enable-primary '(:highlight) +"What cut/copy/paste/highlight ops should involve PRIMARY. + +In X11, PRIMARY is associated with 'highlight/middlebutton-insert' style +data interchange. + +Cut/Copy: Set if Killing (e.g. C-w/M-w) in emacs should place text in the +PRIMARY X11 selection. i.e. if you want to paste killed text into other +programs on your desktop with the other programs' primary insertion +function (typically a middle-button-click). This is not usual for X11 +applications, typically Cut/Copied text is placed in the CLIPBOARD X11 +selection, for clipboard-style X11 transfer. +See `x-select-enable-clipboard' + +Paste: Set if Yanking (e.g. C-y) in emacs should check the primary selection +for text placed there with other programs' primary selection +functions (typically highlighting the text in other X11 programs makes it +available as the primary selection). It is not usual in X11 to do so, however +it may be convenient to do so in emacs, as it reduces mousing, allowing easy +keyboard insertion of the primary selection. Note that if both +`x-select-enable-clipboard' and this have Paste set, the clipboard +currently takes precendence when yanking. + +Highlight: Set if merely highlighting text (an active region) in emacs should +immediately put it in the primary selection, if `select-active-regions' is +set. This is usual for recent X11 programs, and allows you to insert the text +into the other program with their primary insertion function (typically +middle-button-click). + +It is recommended to unset `mouse-drag-copy-region' and +set `transient-mark-mode' if Highlight is set here." + +:type '(choice (const :tag "None" nil) + (const :tag "All" t) + (set :tag "Choose" (const :tag "Cut/Copy" :cut) + (const :tag "Paste" :paste) + (const :tag "Highlight" :highlight))) +:group 'killing) + + +(defcustom x-select-enable-cutbuffer nil + "What cut/copy/paste/highlight ops shold involve legacy Cut Buffer 0. + +In X, cut buffers have long been superseded by clipboard and primary +selections. However, some old X programs use them. If you +need to exchange data between emacs and such programs via +X cut buffers, you may want to set this to a non-nil value. + +Cut/Copy: Set if Killing (e.g. C-w/M-w) in emacs should +place text into X Cut Buffer 0 + +Paste: Set if Yanking (e.g. C-y) in Emacs should check +X Cut Buffer 0 for text. + +Highlight: Set if merely highlighting text (an active region) +in emacs should immediately put it in X Cut Buffer 0, if +`select-active-regions' is also set. + +It is recommended to unset `mouse-drag-copy-region' and +set `transient-mark-mode' if Highlight is set here." + +:type '(choice (const :tag "None" nil) + (const :tag "All" t) + (set :tag "Choose" (const :tag "Cut/Copy" :cut) + (const :tag "Paste" :paste) + (const :tag "Highlight" :highlight))) +:group 'killing) + + +(defun x-select-text-for-op (op text &optional push) + "Make TEXT, a string, the primary and/or clipboard X selection. + +This function matches OP against `x-select-enable-primary' +and `x-select-enable-clipboard'. OP must be one of :cut +or :highlight, corresponding to use as an `interprogram-cut-function' +or `interprogram-highlight-function' + +Also may set the value of X cut buffer 0, for backward compatibility +with older X applications, matching OP against `x-select-enable-cutbuffer' -(defun x-select-text (text &optional push) - "Make TEXT, a string, the primary X selection. -Also, set the value of X cut buffer 0, for backward compatibility -with older X applications. address@hidden says it's not desirable to put kills in the clipboard." ;; With multi-tty, this function may be called from a tty frame. (when (eq (framep (selected-frame)) 'x) - ;; Don't send the cut buffer too much text. - ;; It becomes slow, and if really big it causes errors. - (cond ((>= (length text) x-cut-buffer-max) - (x-set-cut-buffer "" push) - (setq x-last-selected-text-cut "" - x-last-selected-text-cut-encoded "")) - (t - (setq x-last-selected-text-cut text - x-last-cut-buffer-coding 'iso-latin-1 - x-last-selected-text-cut-encoded - ;; ICCCM says cut buffer always contain ISO-Latin-1 - (encode-coding-string text 'iso-latin-1)) - (x-set-cut-buffer x-last-selected-text-cut-encoded push))) - (when x-select-enable-primary + (when (or (eq x-select-enable-cutbuffer t) + (member op x-select-enable-cutbuffer)) + ;; Don't send the cut buffer too much text. + ;; It becomes slow, and if really big it causes errors. + (cond ((>= (length text) x-cut-buffer-max) + (x-set-cut-buffer "" push) + (setq x-last-selected-text-cut "" + x-last-selected-text-cut-encoded "")) + (t + (setq x-last-selected-text-cut text + x-last-cut-buffer-coding 'iso-latin-1 + x-last-selected-text-cut-encoded + ;; ICCCM says cut buffer always contain ISO-Latin-1 + (encode-coding-string text 'iso-latin-1)) + (x-set-cut-buffer x-last-selected-text-cut-encoded push)))) + (when (or (eq x-select-enable-primary t) + (member op x-select-enable-primary)) (x-set-selection 'PRIMARY text) (setq x-last-selected-text-primary text)) - (when x-select-enable-clipboard + (when (or (eq x-select-enable-clipboard t) + (member op x-select-enable-clipboard)) (x-set-selection 'CLIPBOARD text) (setq x-last-selected-text-clipboard text)))) + +(defun x-select-text (text &optional push) + "Make TEXT, a string, the primary and/or clipboard X selection (for cut). + +Also may set the value of X cut buffer 0, for backward compatibility +with older X applications. + +This function is suitable as an `interprogram-cut-function'. +This function just calls `x-select-text-for-op' with OP :cut" + (x-select-text-for-op :cut text push)) + + +(defun x-select-text-for-highlight (text &optional push) + "Make TEXT, a string, the primary and/or clipboard X selection (for highlight). + +Also may set the value of X cut buffer 0, for backward compatibility +with older X applications. + +This function is suitable as an `interprogram-highlight-function'. +This function is calls `x-select-text-for-op' with OP `:highlight'" + (x-select-text-for-op :highlight text push)) + + (defvar 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. @@ -2226,17 +2350,18 @@ ;; 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. (defun x-cut-buffer-or-selection-value () ;; With multi-tty, this function may be called from a tty frame. (when (eq (framep (selected-frame)) 'x) (let (clip-text primary-text cut-text) - (when x-select-enable-clipboard + (when (or (eq x-select-enable-clipboard t) + (member :paste x-select-enable-clipboard)) (setq clip-text (x-selection-value 'CLIPBOARD)) (if (string= clip-text "") (setq clip-text nil)) ;; Check the CLIPBOARD selection for 'newness', is it different ;; from what we remebered them to be last time we did a ;; cut/paste operation. (setq clip-text (cond ;; check clipboard @@ -2245,17 +2370,18 @@ ((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 + (when (or (eq x-select-enable-primary t) + (member :paste x-select-enable-primary)) (setq primary-text (x-selection-value 'PRIMARY)) ;; Check the PRIMARY selection for 'newness', is it different ;; from what we remebered 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)) @@ -2263,47 +2389,49 @@ ((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))))) - (setq cut-text (x-get-cut-buffer 0)) - - ;; Check the x cut buffer for 'newness', is it different - ;; from what we remebered them to be last time we did a - ;; cut/paste operation. - (setq cut-text - (let ((next-coding (or next-selection-coding-system 'iso-latin-1))) - (cond ;; check cut buffer - ((or (not cut-text) (string= cut-text "")) - (setq x-last-selected-text-cut nil)) - ;; This short cut doesn't work because x-get-cut-buffer - ;; always returns a newly created string. - ;; ((eq cut-text x-last-selected-text-cut) nil) - ((and (string= cut-text x-last-selected-text-cut-encoded) - (eq x-last-cut-buffer-coding next-coding)) - ;; See the comment above. No need of this recording. - ;; Record the newer string, - ;; so subsequent calls can use the `eq' test. - ;; (setq x-last-selected-text-cut cut-text) - nil) - (t - (setq x-last-selected-text-cut-encoded cut-text - x-last-cut-buffer-coding next-coding - x-last-selected-text-cut - ;; ICCCM says cut buffer always contain ISO-Latin-1, but - ;; use next-selection-coding-system if not nil. - (decode-coding-string - cut-text next-coding)))))) + (when (or (eq x-select-enable-cutbuffer t) + (member :paste x-select-enable-cutbuffer)) + (setq cut-text (x-get-cut-buffer 0)) + + ;; Check the x cut buffer for 'newness', is it different + ;; from what we remebered them to be last time we did a + ;; cut/paste operation. + (setq cut-text + (let ((next-coding (or next-selection-coding-system 'iso-latin-1))) + (cond ;; check cut buffer + ((or (not cut-text) (string= cut-text "")) + (setq x-last-selected-text-cut nil)) + ;; This short cut doesn't work because x-get-cut-buffer + ;; always returns a newly created string. + ;; ((eq cut-text x-last-selected-text-cut) nil) + ((and (string= cut-text x-last-selected-text-cut-encoded) + (eq x-last-cut-buffer-coding next-coding)) + ;; See the comment above. No need of this recording. + ;; Record the newer string, + ;; so subsequent calls can use the `eq' test. + ;; (setq x-last-selected-text-cut cut-text) + nil) + (t + (setq x-last-selected-text-cut-encoded cut-text + x-last-cut-buffer-coding next-coding + x-last-selected-text-cut + ;; ICCCM says cut buffer always contain ISO-Latin-1, but + ;; use next-selection-coding-system if not nil. + (decode-coding-string + cut-text next-coding)))))) - ;; As we have done one selection, clear this now. - (setq next-selection-coding-system nil) + ;; 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) primary, ;; and cut buffer. 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 @@ -2321,16 +2449,17 @@ ;; primary had been set the cut buffer would essentially never be ;; checked again). (or clip-text primary-text cut-text) ))) ;; 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-cut-buffer-or-selection-value) +(setq interprogram-highlight-function 'x-select-text-for-highlight) (defun x-clipboard-yank () "Insert the clipboard contents, or the last stretch of killed text." (interactive "*") (let ((clipboard-text (x-selection-value 'CLIPBOARD)) (x-select-enable-clipboard t)) (if (and clipboard-text (> (length clipboard-text) 0)) (kill-new clipboard-text))