all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: David Ponce <da_vid@orange.fr>,
	56530@debbugs.gnu.org, Visuwesh <visuweshm@gmail.com>
Subject: bug#56530: 29.0.50; mouse-2 cut selected text when cua-mode is enabled
Date: Fri, 15 Jul 2022 21:53:33 +0300	[thread overview]
Message-ID: <86edym1a36.fsf@mail.linkov.net> (raw)
In-Reply-To: <87h73j7epu.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 14 Jul 2022 20:04:45 +0200")

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: yank-on-region.patch --]
[-- Type: text/x-diff, Size: 2150 bytes --]

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.

  reply	other threads:[~2022-07-15 18:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-13  9:22 bug#56530: 29.0.50; mouse-2 cut selected text when cua-mode is enabled David Ponce
2022-07-13  9:50 ` Visuwesh
2022-07-13 10:19   ` Lars Ingebrigtsen
2022-07-13 11:03     ` Visuwesh
2022-07-13 11:11       ` Lars Ingebrigtsen
2022-07-13 11:19         ` Visuwesh
2022-07-13 11:40           ` Lars Ingebrigtsen
2022-07-13 11:30       ` Stefan Kangas
2022-07-13 11:35         ` Visuwesh
2022-07-13 19:14         ` Juri Linkov
2022-07-13 19:19       ` Juri Linkov
2022-07-14 17:20         ` Lars Ingebrigtsen
2022-07-14 17:24           ` Juri Linkov
2022-07-14 18:04             ` Lars Ingebrigtsen
2022-07-15 18:53               ` Juri Linkov [this message]
2022-07-16 10:34                 ` Lars Ingebrigtsen
2022-07-17 18:49                   ` Juri Linkov
2022-07-22 15:07                     ` Lars Ingebrigtsen
2022-07-24 16:52                       ` Juri Linkov
2022-07-26 12:08                         ` Lars Ingebrigtsen
2022-07-13 11:10   ` David Ponce
2022-07-13 11:16     ` Visuwesh
2022-07-14  0:56   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-13 10:10 ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86edym1a36.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=56530@debbugs.gnu.org \
    --cc=da_vid@orange.fr \
    --cc=larsi@gnus.org \
    --cc=visuweshm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.