GNU bug report logs - #56530
29.0.50; mouse-2 cut selected text when cua-mode is enabled

Previous Next

Package: emacs;

Reported by: David Ponce <da_vid <at> orange.fr>

Date: Wed, 13 Jul 2022 09:23:02 UTC

Severity: normal

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #61 received at 56530 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: David Ponce <da_vid <at> orange.fr>, 56530 <at> debbugs.gnu.org,
 Visuwesh <visuweshm <at> gmail.com>
Subject: Re: bug#56530: 29.0.50; mouse-2 cut selected text when cua-mode is
 enabled
Date: Fri, 15 Jul 2022 21:53:33 +0300
[Message part 1 (text/plain, inline)]
>> There is already the minor mode: delete-selection-mode
>> that is configured by symbol properties.
>> Supporting a descriptive symbol name would allow to easily
>> configure the desired behavior with just:
>>
>>   (put 'mouse-yank-at-click 'delete-selection 'yank-on-region)
>
> The problem is that you have to `put' on three symbols, which isn't
> optimal.  (My proposed mode does just that.)

The default settings should be suitable for all users,
but modes for groups of settings could be added too.

This patch works well but only like Visuwesh pointed out
when mouse-yank-at-point is set to t.  This is because
mouse-yank-primary has such line:

  (or mouse-yank-at-point (mouse-set-point event))

When delete-selection deletes the region where the mouse is clicked,
mouse-set-point loses track and sets point to a random position,
because the event contains fixed positions, not markers.
I wonder why?

[yank-on-region.patch (text/x-diff, inline)]
diff --git a/lisp/delsel.el b/lisp/delsel.el
index 5310328e5f..d9e0141d90 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -39,6 +39,8 @@
 ;;      For commands which do a yank; ensures the region about to be
 ;;      deleted isn't immediately yanked back, which would make the
 ;;      command a no-op.
+;;  `yank-on-region'
+;;      Like `yank' but applied only when clicked on the region.
 ;;  `supersede'
 ;;      Delete the active region and ignore the current command,
 ;;      i.e. the command will just delete the region.  This is for
@@ -176,6 +178,8 @@ delete-selection-helper
      For commands which do a yank; ensures the region about to be
      deleted isn't immediately yanked back, which would make the
      command a no-op.
+ `yank-on-region'
+     Like `yank' but applied only when clicked on the region.
  `supersede'
      Delete the active region and ignore the current command,
      i.e. the command will just delete the region.  This is for
@@ -220,6 +224,11 @@ delete-selection-helper
                ;; If the region was, say, rectangular, make sure we yank
                ;; from the top, to "replace".
                (goto-char pos)))
+            ((eq type 'yank-on-region)
+             (let ((pos (posn-point (event-end last-nonmenu-event))))
+               (when (and (>= pos (region-beginning))
+                          (<= pos (region-end)))
+                 (delete-selection-helper 'yank))))
 	    ((eq type 'supersede)
 	     (let ((empty-region (= (point) (mark))))
 	       (delete-active-region)
@@ -300,6 +309,12 @@ delete-selection-uses-region-p
 (put 'yank-pop 'delete-selection 'yank)
 (put 'yank-from-kill-ring 'delete-selection 'yank)
 (put 'clipboard-yank 'delete-selection 'yank)
+
+(put 'mouse-yank-primary 'delete-selection 'yank-on-region)
+(put 'mouse-yank-secondary 'delete-selection 'yank-on-region)
+(put 'mouse-yank-at-click 'delete-selection 'yank-on-region)
+(put 'menu-bar-select-yank 'delete-selection 'yank-on-region)
+
 (put 'insert-register 'delete-selection t)
 ;; delete-backward-char and delete-forward-char already delete the selection by
 ;; default, but not delete-char.

This bug report was last modified 2 years and 356 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.