unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 32747@debbugs.gnu.org
Subject: bug#32747: Be able to append mouse selections at the head of `kill-ring' (e.g, with C-M-w)
Date: Sun, 22 May 2022 18:07:53 +0200	[thread overview]
Message-ID: <87o7zptusm.fsf@gnus.org> (raw)
In-Reply-To: <87sfq64iwk.fsf_-_@gnus.org> (Lars Ingebrigtsen's message of "Thu, 21 Apr 2022 16:20:59 +0200")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> And this seems to be because `C-M-w' works by setting `last-command' to
> `kill-region' to signal that the next `copy-region-as-kill' should
> append.  However, when dragging a region, `last-command' ends up being
> nil by the time we reach `copy-region-as-kill' -- presumably because we
> clear it somewhere in the mouse handling?
>
> Anybody have any ideas how to fix this, if we want to fix this?

The following patch fixes this, but it's not clear that we want to do
this.

`C-w C-d' (kill-region + kill-word) will make the second kill append
to the first, while similar commands like `M-w C-d' don't.  So the
mouse.el code has:

	 ;; Ignore
	 ;; `last-command' so we don't append to a preceding kill.

Because we don't want `C-w <drag-mouse-1>' to append to that `C-w',
apparently.

But -- if you do something like `C-d M-w', then that `M-w' is morally
equivalent to the <drag-mouse-1> (i.e., we're putting more stuff onto
the kill ring without killing text).

So why is `C-w <drag-mouse-1>' different here?  The patch makes them
behave the same way.

If we don't want that, we have to come up with a whole nother way to
implement `C-M-w', because it just sets last-command to `kill-region'.

Opinions?

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 4b5f6ed223..5913992e44 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1396,7 +1396,8 @@ mouse-set-region
 	 ;; 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.
-	 (let (this-command last-command deactivate-mark)
+	 (let ((last-command last-command)
+               this-command deactivate-mark)
 	   (copy-region-as-kill beg end)))
     (if (numberp beg) (goto-char beg))
     ;; On a text terminal, bounce the cursor.
@@ -1499,6 +1500,7 @@ mouse-drag-region
       (mouse-drag-and-drop-region start-event)
     ;; Give temporary modes such as isearch a chance to turn off.
     (run-hooks 'mouse-leave-buffer-hook)
+    (ignore-preserving-kill-region)
     (mouse-drag-track start-event)))
 
 ;; Inhibit the region-confinement when undoing mouse-drag-region
@@ -1708,7 +1710,8 @@ mouse-drag-track
                                             nil start-point))
                         ((>= mouse-row bottom)
                          (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
-                                            nil start-point))))))))
+                                            nil start-point))))))
+                 (ignore-preserving-kill-region)))
              map)
            t (lambda ()
                (funcall cleanup)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2022-05-22 16:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<<<ea7faa90-5fef-43f8-8aa9-bb3d60d476c4@default>
     [not found] ` <<<<83tvmlew2a.fsf@gnu.org>
     [not found]   ` <<<932a1915-c043-4708-9f16-dc0ee8fafdb3@default>
     [not found]     ` <<<83pnx9een5.fsf@gnu.org>
     [not found]       ` <<01b0f0c4-e3b8-440f-a739-5995ca4ff615@default>
     [not found]         ` <<83o9cte392.fsf@gnu.org>
2018-09-19 19:23           ` bug#32747: 26; `C-M-w M-w' with non-nil `mouse-drag-copy-region', if selected with mouse Drew Adams
2018-09-16 21:29             ` Drew Adams
2018-09-19  8:22               ` Eli Zaretskii
2018-09-20 15:16               ` Drew Adams
2018-09-20 20:17                 ` Eli Zaretskii
2018-09-20 15:09             ` Drew Adams
     [not found]             ` <87h8ikpf4u.fsf_-_@gmail.com>
2022-04-21 14:20               ` bug#32747: Be able to append mouse selections at the head of `kill-ring' (e.g, with C-M-w) Lars Ingebrigtsen
2022-05-22 16:07                 ` Lars Ingebrigtsen [this message]
2022-06-19 22:59                   ` Lars Ingebrigtsen
     [not found] <<<<<<ea7faa90-5fef-43f8-8aa9-bb3d60d476c4@default>
     [not found] ` <<<<<<83tvmlew2a.fsf@gnu.org>
     [not found]   ` <<<<<932a1915-c043-4708-9f16-dc0ee8fafdb3@default>
     [not found]     ` <<<<<83pnx9een5.fsf@gnu.org>
     [not found]       ` <<<<01b0f0c4-e3b8-440f-a739-5995ca4ff615@default>
     [not found]         ` <<<<83o9cte392.fsf@gnu.org>
     [not found]           ` <<<9136cccc-7e97-4a74-89a9-00eccab73c32@default>
     [not found]             ` <<<4394ff48-2444-4a9b-b635-e96e66a30cba@default>
     [not found]               ` <<<83a7obexed.fsf@gnu.org>
     [not found]                 ` <<1254fccb-35ae-4c51-8471-e01844f64517@default>
     [not found]                   ` <<834lejevn7.fsf@gnu.org>
2018-09-20 20:59                     ` bug#32747: 26; `C-M-w M-w' with non-nil `mouse-drag-copy-region', if selected with mouse Drew Adams
2018-09-20 22:16                       ` Noam Postavsky
2018-09-21  4:23                         ` Drew Adams
2018-09-21  6:44                         ` Eli Zaretskii
2018-10-30  3:54                         ` Drew Adams
2018-10-30  7:33                           ` Eli Zaretskii
     [not found]                     ` <<a141e4d1-fc48-44e3-819a-85befed70c26@default>
     [not found]                       ` <<87efdnq0g9.fsf@gmail.com>
     [not found]                         ` <<80dfd942-980e-44f7-9592-d4c2388168d1@default>
     [not found]                           ` <<83d0rrlwhy.fsf@gnu.org>
2018-10-30 13:33                             ` Drew Adams
     [not found] <<<<<ea7faa90-5fef-43f8-8aa9-bb3d60d476c4@default>
     [not found] ` <<<<<83tvmlew2a.fsf@gnu.org>
     [not found]   ` <<<<932a1915-c043-4708-9f16-dc0ee8fafdb3@default>
     [not found]     ` <<<<83pnx9een5.fsf@gnu.org>
     [not found]       ` <<<01b0f0c4-e3b8-440f-a739-5995ca4ff615@default>
     [not found]         ` <<<83o9cte392.fsf@gnu.org>
     [not found]           ` <<9136cccc-7e97-4a74-89a9-00eccab73c32@default>
     [not found]             ` <<4394ff48-2444-4a9b-b635-e96e66a30cba@default>
     [not found]               ` <<83a7obexed.fsf@gnu.org>
2018-09-20 20:44                 ` Drew Adams
2018-09-20 20:55                   ` Eli Zaretskii
     [not found] <<<ea7faa90-5fef-43f8-8aa9-bb3d60d476c4@default>
     [not found] ` <<<83tvmlew2a.fsf@gnu.org>
     [not found]   ` <<932a1915-c043-4708-9f16-dc0ee8fafdb3@default>
     [not found]     ` <<83pnx9een5.fsf@gnu.org>
2018-09-19 18:24       ` Drew Adams
2018-09-19 18:44         ` Eli Zaretskii
     [not found] <<ea7faa90-5fef-43f8-8aa9-bb3d60d476c4@default>
     [not found] ` <<83tvmlew2a.fsf@gnu.org>
2018-09-19 13:51   ` Drew Adams
2018-09-19 14:38     ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87o7zptusm.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=32747@debbugs.gnu.org \
    --cc=npostavs@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 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).