emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8cb7682e88: New setting for mouse-drag-copy-region to not put ""


From: Lars Ingebrigtsen
Subject: master 8cb7682e88: New setting for mouse-drag-copy-region to not put "" onto kill ring
Date: Thu, 9 Jun 2022 09:58:34 -0400 (EDT)

branch: master
commit 8cb7682e885c943228299c4e6b7adb6a398c8aae
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    New setting for mouse-drag-copy-region to not put "" onto kill ring
    
    * doc/emacs/frames.texi (Mouse Commands): Document it.
    * lisp/mouse.el (mouse-drag-copy-region): Add value (bug#17211)
    for not putting "" strings onto the kill ring.
    (mouse-set-region, mouse-save-then-kill): Use the new value.
---
 doc/emacs/frames.texi |  6 ++++++
 etc/NEWS              |  4 ++++
 lisp/mouse.el         | 20 +++++++++++++++++---
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index a853c9a228..fa248c1a58 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -128,6 +128,12 @@ In addition, the text in the region becomes the primary 
selection
 non-@code{nil} value, dragging the mouse over a stretch of text also
 adds the text to the kill ring.  The default is @code{nil}.
 
+  If this variable is @code{non-empty}, only copy to the kill ring if
+the region is non-empty.  For instance, if you mouse drag an area that
+is less than a half a character, you'd normally get the empty string
+in your kill ring, but with @code{non-empty}, this short mouse drag
+won't affect the kill ring.
+
 @vindex mouse-scroll-min-lines
   If you move the mouse off the top or bottom of the window while
 dragging, the window scrolls at a steady rate until you move the mouse
diff --git a/etc/NEWS b/etc/NEWS
index 9fc8a74419..cd4b1b06ec 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -331,6 +331,10 @@ to another program.
 If non-nil, this option allows scrolling a window while dragging text
 around without a scroll wheel.
 
++++
+*** 'mouse-drag-copy-region' can now be 'non-empty'.
+This inhibits putting empty strings onto the kill ring.
+
 +++
 ** New user options 'dnd-indicate-insertion-point' and 'dnd-scroll-margin'.
 These options allow adjusting point and scrolling a window when
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 9cf6635a01..14cb20c234 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -53,9 +53,17 @@ mouse cursor to the echo area."
 This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
 addition to mouse drags.
 
+If this variable is `non-empty', only copy to the kill ring if
+the region is non-empty.  For instance, if you mouse drag an area
+that is less than a half a character, you'd normally get the
+empty string in your kill ring, but with this value, this short
+mouse drag won't affect the kill ring.
+
 This variable applies only to mouse adjustments in Emacs, not
 selecting and adjusting regions in other windows."
-  :type 'boolean
+  :type '(choice (const :tag "No" nil)
+                 (const :tag "Yes" t)
+                 (const :tag "Non-empty" non-empty))
   :version "24.1")
 
 (defcustom mouse-1-click-follows-link 450
@@ -1423,7 +1431,11 @@ command alters the kill ring or not."
         (if (< end beg)
             (setq end (nth 0 range) beg (nth 1 range))
           (setq beg (nth 0 range) end (nth 1 range)))))
-    (and mouse-drag-copy-region (integerp beg) (integerp end)
+    (when (and mouse-drag-copy-region
+               (integerp beg)
+               (integerp end)
+               (or (not (eq mouse-drag-copy-region 'non-empty))
+                   (/= beg end)))
         ;; Don't set this-command to `kill-region', so a following
         ;; C-w won't double the text in the kill ring.  Ignore
         ;; `last-command' so we don't append to a preceding kill.
@@ -2112,7 +2124,9 @@ if `mouse-drag-copy-region' is non-nil)."
        (if before-scroll (goto-char before-scroll)))
       (exchange-point-and-mark)
       (mouse-set-region-1)
-      (when mouse-drag-copy-region
+      (when (and mouse-drag-copy-region
+                 (or (not (eq mouse-drag-copy-region 'non-empty))
+                     (not (/= (mark t) (point)))))
         (kill-new (filter-buffer-substring (mark t) (point))))
       (setq mouse-save-then-kill-posn click-pt)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]