From: "Mattias Engdegård" <mattiase@acm.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: tkk@misasa.okayama-u.ac.jp, 37700@debbugs.gnu.org,
homeros.misasa@gmail.com
Subject: bug#37700: 27.0.50; undo mouse-drag-and-drop-region ineffective
Date: Thu, 31 Oct 2019 12:00:08 +0100 [thread overview]
Message-ID: <41286005-259E-4B78-A1FF-746E7A753FB4@acm.org> (raw)
In-Reply-To: <jwvzhhij9qa.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1066 bytes --]
30 okt. 2019 kl. 20.56 skrev Stefan Monnier <monnier@iro.umontreal.ca>:
>
>> Unfortunately, even with the patch, undoing a drag-and-drop does not leave
>> the region active the way it was before the undo, so the user has to
>> reselect the text in order to try again.
>
> If the undo-list is built right, reselecting the text should be just
> `C-x C-x`, which isn't that bad.
Right, second nature to the Emacs user, but it would still be nice not having to go through that step. kill-region and delete-selection-mode are similarly affected.
> But now that I think about it, maybe a better option would be to check
>
> (when (symbolp last-command)
> (get last-command 'undo-inhibit-region))
>
> and then put the `undo-inhibit-region` property on
> `mouse-drag-and-drop-region`.
Thank you, this looks like the best idea so far. A very simple change, yet effective in practice. Not perfect --- last-command is not buffer-local, and even switching to a different frame and back will change it --- but good enough.
Patch attached.
[-- Attachment #2: 0001-Inhibit-undo-in-region-for-mouse-drag-region-bug-377.patch --]
[-- Type: application/octet-stream, Size: 2582 bytes --]
From 7cf5f680ab1d933fe1cecb862afa3b0976045f1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 31 Oct 2019 10:31:27 +0100
Subject: [PATCH] Inhibit undo-in-region for mouse-drag-region (bug#37700)
'mouse-drag-region' leaves the region active around the dragged text,
so a straight undo did not revert the entire operation. To remedy
this, inhibit undo-in-region when the last command was
mouse-drag-region. (Method suggested by Stefan Monnier.)
* lisp/mouse.el (undo-drag-region): Set the undo-inhibit-region property.
* lisp/simple.el (undo): Inhibit undo-in-region if the last command
had the undo-inhibit-region property set.
---
lisp/mouse.el | 6 ++++++
lisp/simple.el | 7 ++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 76fec507e7..4a351f7be2 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1104,6 +1104,12 @@ mouse-drag-region
(run-hooks 'mouse-leave-buffer-hook)
(mouse-drag-track start-event)))
+;; Inhibit the region-confinement when undoing mouse-drag-region
+;; immediately after the command. Otherwise, the selection left
+;; active around the dragged text would prevent an undo of the whole
+;; operation.
+(put 'mouse-drag-region 'undo-inhibit-region t)
+
(defun mouse-posn-property (pos property)
"Look for a property at click position.
POS may be either a buffer position or a click position like
diff --git a/lisp/simple.el b/lisp/simple.el
index 29e195bca6..10aecd651f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2508,6 +2508,10 @@ undo
(base-buffer (or (buffer-base-buffer) (current-buffer)))
(recent-save (with-current-buffer base-buffer
(recent-auto-save-p)))
+ ;; Allow certain commands to inhibit an immediately following
+ ;; undo-in-region.
+ (inhibit-region (and (symbolp last-command)
+ (get last-command 'undo-inhibit-region)))
message)
;; If we get an error in undo-start,
;; the next command should not be a "consecutive undo".
@@ -2525,7 +2529,8 @@ undo
;; it shows nothing else happened in between.
(gethash list undo-equiv-table))))
(setq undo-in-region
- (or (region-active-p) (and arg (not (numberp arg)))))
+ (and (or (region-active-p) (and arg (not (numberp arg))))
+ (not inhibit-region)))
(if undo-in-region
(undo-start (region-beginning) (region-end))
(undo-start))
--
2.21.0 (Apple Git-122)
next prev parent reply other threads:[~2019-10-31 11:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-11 11:51 bug#37700: 27.0.50; undo mouse-drag-and-drop-region ineffective Mattias Engdegård
2019-10-11 12:19 ` martin rudalics
2019-10-11 12:51 ` Mattias Engdegård
2019-10-11 14:43 ` Eli Zaretskii
2019-10-11 17:18 ` Mattias Engdegård
2019-10-11 18:36 ` Eli Zaretskii
2019-10-11 18:51 ` Eli Zaretskii
2019-10-12 8:24 ` martin rudalics
2019-10-11 18:57 ` Eli Zaretskii
2019-10-11 18:26 ` martin rudalics
2019-10-11 19:12 ` Eli Zaretskii
2019-10-12 1:55 ` Tak Kunihiro
2019-10-12 8:24 ` martin rudalics
2019-10-12 16:42 ` Mattias Engdegård
2019-10-12 17:17 ` Eli Zaretskii
2019-10-12 17:53 ` Eli Zaretskii
2019-10-16 15:27 ` Mattias Engdegård
2019-10-26 10:15 ` Eli Zaretskii
2019-10-28 20:01 ` Stefan Monnier
2019-10-30 19:09 ` Mattias Engdegård
2019-10-30 19:56 ` Stefan Monnier
2019-10-31 11:00 ` Mattias Engdegård [this message]
2019-10-31 14:45 ` Eli Zaretskii
2019-10-31 16:04 ` Mattias Engdegård
2019-10-31 16:10 ` Eli Zaretskii
2019-10-31 16:47 ` Mattias Engdegård
2019-10-11 12:26 ` Eli Zaretskii
2019-10-11 12:53 ` Mattias Engdegård
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=41286005-259E-4B78-A1FF-746E7A753FB4@acm.org \
--to=mattiase@acm.org \
--cc=37700@debbugs.gnu.org \
--cc=homeros.misasa@gmail.com \
--cc=monnier@iro.umontreal.ca \
--cc=tkk@misasa.okayama-u.ac.jp \
/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.