From ffcf36626d75b1f421fef36a79542ac8cacb5991 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 14 Aug 2020 10:33:54 -0700 Subject: [PATCH] Add new defcustom 'copy-region-quietly' * lisp/simple.el (copy-region-quietly): Add new defcustom. * lisp/simple.el (indicate-copied-region): Don't swap point and mark if copy-region-quietly is no-swap or t. Don't display a message if copy-region-quietly is no-message or t. Document the change. * etc/NEWS: Document the change. --- etc/NEWS | 4 ++++ lisp/simple.el | 47 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 2be9743a45..5bd495fd43 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -145,6 +145,10 @@ setting the variable 'auto-save-visited-mode' buffer-locally to nil. description of the properties. Likewise 'button-describe' does the same for a button. +** Whether and how the copying of an inactive region is indicated +visually can now be controlled by customizing the variable +'copy-region-quietly'. + * Changes in Specialized Modes and Packages in Emacs 28.1 diff --git a/lisp/simple.el b/lisp/simple.el index 6f72c3b81b..cd1c773f43 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -4871,6 +4871,22 @@ kill-read-only-ok :type 'boolean :group 'killing) +(defcustom copy-region-quietly nil + "Whether the copying of an inactive region is indicated visually. +If nil, behave as per the documentation of `indicate-copied-region'. +`no-swap' means inhibit briefly swapping point and mark. +`no-message' means inhibit displaying a message. +Any other value means inhibit both swapping and message-displaying." + :type '(choice :tag "Copy region quietly" + (const :tag "Default behavior" nil) + (const :tag "Don't swap point and mark" no-swap) + (const :tag "Don't display a message" no-message) + (const + :tag + "Don't swap point and mark or display a message" + t)) + :group 'killing) + (defun kill-region (beg end &optional region) "Kill (\"cut\") text between point and mark. This deletes the text from the buffer and saves it in the kill ring. @@ -5005,7 +5021,10 @@ indicate-copied-region If the mark lies outside the selected window, display an informative message containing a sample of the copied text. The optional argument MESSAGE-LEN, if non-nil, specifies the length -of this sample text; it defaults to 40." +of this sample text; it defaults to 40. + +Both these behaviors can be inhibited by setting `copy-region-quietly', +which see." (let ((mark (mark t)) (point (point)) ;; Inhibit quitting so we can make a quit here @@ -5014,8 +5033,9 @@ indicate-copied-region (if (pos-visible-in-window-p mark (selected-window)) ;; Swap point-and-mark quickly so as to show the region that ;; was selected. Don't do it if the region is highlighted. - (unless (and (region-active-p) - (face-background 'region nil t)) + (unless (or (memq copy-region-quietly '(t no-swap)) + (and (region-active-p) + (face-background 'region nil t))) ;; Swap point and mark. (set-marker (mark-marker) (point) (current-buffer)) (goto-char mark) @@ -5027,14 +5047,19 @@ indicate-copied-region ;; as C-g would as a command. (and quit-flag (region-active-p) (deactivate-mark))) - (let ((len (min (abs (- mark point)) - (or message-len 40)))) - (if (< point mark) - ;; Don't say "killed"; that is misleading. - (message "Saved text until \"%s\"" - (buffer-substring-no-properties (- mark len) mark)) - (message "Saved text from \"%s\"" - (buffer-substring-no-properties mark (+ mark len)))))))) + (unless (memq copy-region-quietly '(t no-message)) + (let ((len (min (abs (- mark point)) + (or message-len 40)))) + (if (< point mark) + ;; Don't say "killed"; that is misleading. + (message "Saved text until \"%s\"" + (buffer-substring-no-properties + (- mark len) + mark)) + (message "Saved text from \"%s\"" + (buffer-substring-no-properties + mark + (+ mark len))))))))) (defun append-next-kill (&optional interactive) "Cause following command, if it kills, to add to previous kill. -- 2.27.0