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.
This commit is contained in:
Lars Ingebrigtsen 2022-06-09 15:57:04 +02:00
parent e99f41f03a
commit 8cb7682e88
3 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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)))))