unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom
@ 2020-08-14 17:38 Sean Whitton
  2020-08-18 13:37 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 30+ messages in thread
From: Sean Whitton @ 2020-08-14 17:38 UTC (permalink / raw)
  To: 42865

[-- Attachment #1: Type: text/plain, Size: 214 bytes --]

Tags: patch

Hello,

I want to have a way to suppress swapping point and mark when copying an
inactive region, as I find that distracting.  Here is a patch adding a
new defcustom to achieve that.

-- 
Sean Whitton

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-defcustom-copy-region-quietly.patch --]
[-- Type: text/x-diff, Size: 4464 bytes --]

From ffcf36626d75b1f421fef36a79542ac8cacb5991 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
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'.
+
 \f
 * 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


^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-06-28  2:02 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-14 17:38 bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom Sean Whitton
2020-08-18 13:37 ` Lars Ingebrigtsen
2020-08-19  1:16   ` Juri Linkov
2020-08-19 10:25     ` Lars Ingebrigtsen
2020-08-20  0:52       ` Juri Linkov
2020-08-20 13:01         ` Lars Ingebrigtsen
2020-08-20 23:19           ` Juri Linkov
2020-08-21 11:28             ` Lars Ingebrigtsen
2020-08-23 18:39               ` Juri Linkov
2020-08-24 13:14                 ` Lars Ingebrigtsen
2020-08-24 13:26                   ` Stefan Kangas
2020-08-24 14:00                     ` Lars Ingebrigtsen
2020-08-24 18:38                   ` Juri Linkov
2020-08-24 19:34                     ` Stefan Kangas
2020-08-25 18:40                       ` Juri Linkov
2020-08-26  0:36                         ` Stefan Kangas
2020-08-27 19:08                           ` Juri Linkov
2020-11-15 20:40                           ` Juri Linkov
2020-08-20  0:55       ` Juri Linkov
2020-08-20 13:05         ` Lars Ingebrigtsen
2020-11-15 20:33       ` Juri Linkov
2020-08-19 16:36     ` Sean Whitton
2020-08-19 16:32   ` Sean Whitton
2020-08-19 16:49     ` Lars Ingebrigtsen
2020-09-10 16:05       ` Sean Whitton
2020-09-11 11:57         ` Lars Ingebrigtsen
2020-09-12 21:22           ` Sean Whitton
2020-09-13 13:09             ` Lars Ingebrigtsen
2021-06-06  9:20               ` Lars Ingebrigtsen
2021-06-28  2:02                 ` Sean Whitton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).