From f9d71b4284fa1009f8c38a9d389e2202ef1e4dd9 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Wed, 14 Jul 2010 14:03:39 -0400 Subject: [PATCH] Change clipboard/primary selection to X application standards. * lisp/menu-bar.el (menu-bar-enable-clipboard): Don't overwrite Cut/Copy/Paste menu bar items. * lisp/mouse.el: Bind mouse-2 to mouse-yank-primary. (mouse-drag-copy-region): Default to nil. * lisp/simple.el (select-active-regions): Default to t. (push-mark-command): Don't overwrite primary with empty string. * lisp/term/x-win.el (x-select-enable-clipboard): Default to t. (x-initialize-window-system): Don't overwrite Paste menu item. --- etc/NEWS | 14 ++++++++++++++ lisp/ChangeLog | 14 ++++++++++++++ lisp/menu-bar.el | 11 ----------- lisp/mouse.el | 4 ++-- lisp/simple.el | 5 ++++- lisp/term/x-win.el | 20 ++++++++------------ 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 8f5da370b2..27865cce51 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -173,6 +173,20 @@ should use delete-char with a negative argument instead. *** The option `mouse-region-delete-keys' has been deleted. +** Selection changes. + +The way Emacs interacts with the clipboard and primary selection, by +default, is now similar to other X applications. In particular, kill +and yank use the clipboard, in addition to the primary selection. + +*** `select-active-regions' now defaults to t. + +*** `x-select-enable-clipboard' now defaults to t. + +*** `mouse-drag-copy-region' now defaults to nil. + +*** `mouse-2' is now bound to `mouse-yank-primary'. + * Changes in Specialized Modes and Packages in Emacs 24.1 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fcd4bc7ff6..70d37987b6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2010-07-14 Chong Yidong + + * term/x-win.el (x-select-enable-clipboard): Default to t. + (x-initialize-window-system): Don't overwrite Paste menu item. + + * simple.el (select-active-regions): Default to t. + (push-mark-command): Don't overwrite primary with empty string. + + * mouse.el: Bind mouse-2 to mouse-yank-primary. + (mouse-drag-copy-region): Default to nil. + + * menu-bar.el (menu-bar-enable-clipboard): Don't overwrite + Cut/Copy/Paste menu bar items. + 2010-07-13 Thierry Volpiatto Allow C-w when setting a bookmark in a Gnus Article buffer (Bug#5975). diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index f94b67a6e8..2c75a8822f 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -526,17 +526,6 @@ "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard. Do the same for the keys of the same name." (interactive) - ;; We can't use constant list structure here because it becomes pure, - ;; and because it gets modified with cache data. - (define-key menu-bar-edit-menu [paste] - (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank))) - (define-key menu-bar-edit-menu [copy] - (cons "Copy" (cons "Copy text in region to the clipboard" - 'clipboard-kill-ring-save))) - (define-key menu-bar-edit-menu [cut] - (cons "Cut" (cons "Delete text in region and copy it to the clipboard" - 'clipboard-kill-region))) - ;; These are Sun server keysyms for the Cut, Copy and Paste keys ;; (also for XFree86 on Sun keyboard): (define-key global-map [f20] 'clipboard-kill-region) diff --git a/lisp/mouse.el b/lisp/mouse.el index 30fd26b51f..b159add0d9 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -41,7 +41,7 @@ :type 'boolean :group 'mouse) -(defcustom mouse-drag-copy-region t +(defcustom mouse-drag-copy-region nil "If non-nil, mouse drag copies region to kill-ring." :type 'boolean :version "22.1" @@ -2443,7 +2443,7 @@ choose a font." (global-set-key [left-fringe mouse-1] 'mouse-set-point) (global-set-key [right-fringe mouse-1] 'mouse-set-point) -(global-set-key [mouse-2] 'mouse-yank-at-click) +(global-set-key [mouse-2] 'mouse-yank-primary) ;; Allow yanking also when the corresponding cursor is "in the fringe". (global-set-key [right-fringe mouse-2] 'mouse-yank-at-click) (global-set-key [left-fringe mouse-2] 'mouse-yank-at-click) diff --git a/lisp/simple.el b/lisp/simple.el index fdd8521eee..20e109aaaf 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3666,7 +3666,7 @@ a mistake; see the documentation of `set-mark'." (marker-position (mark-marker)) (signal 'mark-inactive nil))) -(defcustom select-active-regions nil +(defcustom select-active-regions t "If non-nil, an active region automatically becomes the window selection." :type 'boolean :group 'killing @@ -3687,6 +3687,7 @@ This function also runs `deactivate-mark-hook'." mark-active (display-selections-p) (x-selection-owner-p 'PRIMARY) + (not (eq (region-beginning) (region-end))) (x-set-selection 'PRIMARY (buffer-substring-no-properties (region-beginning) (region-end)))) (if (and (null force) @@ -3819,6 +3820,8 @@ Display `Mark set' unless the optional second arg NOMSG is non-nil." (push-mark nil nomsg t) (setq mark-active t) (run-hooks 'activate-mark-hook) + (and select-active-regions (display-selections-p) + (x-set-selection 'PRIMARY (current-buffer))) (unless nomsg (message "Mark activated"))))) diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index 3208ece9c0..b3ce877be5 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -1219,13 +1219,9 @@ This is the actual text stored in the X cut buffer.") "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 +(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. - -On MS-Windows, this is non-nil by default, since Windows does not -support other types of selections. \(The primary selection that is -set by Emacs is not accessible to other programs on Windows.\)" +This is in addition to, but in preference to, the primary selection." :type 'boolean :group 'killing) @@ -1560,12 +1556,12 @@ The value nil is the same as this list: ;; Enable CLIPBOARD copy/paste through menu bar commands. (menu-bar-enable-clipboard) - ;; Override Paste so it looks at CLIPBOARD first. - (define-key menu-bar-edit-menu [paste] - (append '(menu-item "Paste" x-clipboard-yank - :enable (not buffer-read-only) - :help "Paste (yank) text most recently cut/copied") - nil)) + ;; ;; Override Paste so it looks at CLIPBOARD first. + ;; (define-key menu-bar-edit-menu [paste] + ;; (append '(menu-item "Paste" x-clipboard-yank + ;; :enable (not buffer-read-only) + ;; :help "Paste (yank) text most recently cut/copied") + ;; nil)) (setq x-initialized t)) -- 2.20.1