unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 37700@debbugs.gnu.org, tkk@misasa.okayama-u.ac.jp,
	homeros.misasa@gmail.com
Subject: bug#37700: 27.0.50; undo mouse-drag-and-drop-region ineffective
Date: Wed, 16 Oct 2019 17:27:05 +0200	[thread overview]
Message-ID: <37DDF48D-FC37-47A8-8CEC-C6EB66AB2BF7@acm.org> (raw)
In-Reply-To: <83ftjxn94q.fsf@gnu.org>

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

12 okt. 2019 kl. 19.53 skrev Eli Zaretskii <eliz@gnu.org>:
> 
> Or maybe have those commands have an 'undo' property which would tell
> 'undo' to treat them specially.  Like we do with delete-selection.

After trying various approaches, the attached patch looks somewhat promising. It adds a new element type to buffer-undo-list, `unconfined', which disables selective undo for one record. Consider it a proof-of-concept.

While it has the advantage of not requiring the user to change any settings, I still prefer the first approach (an option to disable undo confinement), as it's less intrusive and more generally useful. However, this should work as well.


[-- Attachment #2: 0001-Don-t-confine-undo-of-mouse-drag-and-drop-to-the-reg.patch --]
[-- Type: application/octet-stream, Size: 4497 bytes --]

From 307e5c6a19eda9d464e75f73b73f57fc1cf9e42e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Wed, 16 Oct 2019 15:32:22 +0200
Subject: [PATCH] Don't confine undo of mouse-drag-and-drop to the region
 (bug#37700)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since the region is active after a mouse-drag-and-drop, the change
cannot immediately be undone.  To get around this, tell the undo
machinery to ignore the region confinement for this operation.

* lisp/simple.el (primitive-undo, undo-make-selective-list):
* src/buffer.c (buffer-undo-list):
New `buffer-undo-list’ element `unconfined'.
* lisp/mouse.el (mouse-drag-and-drop-region):
Mark the operation as unconfined upon undo.
---
 lisp/mouse.el  | 7 ++++++-
 lisp/simple.el | 9 +++++++--
 src/buffer.c   | 3 +++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 76fec507e7..533ad606fb 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -2657,7 +2657,12 @@ mouse-drag-and-drop-region
                 (let (deactivate-mark)
                   (dolist (overlay mouse-drag-and-drop-overlays)
                     (delete-region (overlay-start overlay)
-                                   (overlay-end overlay)))))
+                                   (overlay-end overlay))))
+                ;; Since we will leave the destination text selected,
+                ;; make sure an undo operation disregards the region
+                ;; or the operation will only be partially undone.
+                (when (consp buffer-undo-list)
+                  (push 'unconfined buffer-undo-list)))
             ;; When source buffer and destination buffer are different,
             ;; keep (set back the original text as region) or remove the
             ;; original text.
diff --git a/lisp/simple.el b/lisp/simple.el
index b733f76ac7..ea580f651d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2748,6 +2748,7 @@ primitive-undo
              (set-marker marker
                          (- marker offset)
                          (marker-buffer marker))))
+          (unconfined)                  ; Ignore this directive here.
           (_ (error "Unrecognized entry in undo list %S" next))))
       (setq arg (1- arg)))
     ;; Make sure an apply entry produces at least one undo entry,
@@ -2850,6 +2851,7 @@ undo-make-selective-list
   (let ((ulist buffer-undo-list)
         ;; A list of position adjusted undo elements in the region.
         (selective-list (list nil))
+        (unconfined nil)   ; Whether to include whole record unconditionally.
         ;; A list of undo-deltas for out of region undo elements.
         undo-deltas
         undo-elt)
@@ -2862,7 +2864,10 @@ undo-make-selective-list
        ((null undo-elt)
         ;; Don't put two nils together in the list
         (when (car selective-list)
-          (push nil selective-list)))
+          (push nil selective-list))
+        (setq unconfined nil))
+       ((eq undo-elt 'unconfined)
+        (setq unconfined t))
        ((and (consp undo-elt) (eq (car undo-elt) t))
         ;; This is a "was unmodified" element.  Keep it
         ;; if we have kept everything thus far.
@@ -2875,7 +2880,7 @@ undo-make-selective-list
        (t
         (let ((adjusted-undo-elt (undo-adjust-elt undo-elt
                                                   undo-deltas)))
-          (if (undo-elt-in-region adjusted-undo-elt start end)
+          (if (or (undo-elt-in-region adjusted-undo-elt start end) unconfined)
               (progn
                 (setq end (+ end (cdr (undo-delta adjusted-undo-elt))))
                 (push adjusted-undo-elt selective-list)
diff --git a/src/buffer.c b/src/buffer.c
index 8cb28d8aa7..978d4576df 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6128,6 +6128,9 @@ from (abs POSITION).  If POSITION is positive, point was at the front
 Entries with value nil mark undo boundaries.  The undo command treats
 the changes between two undo boundaries as a single step to be undone.
 
+An entry with the value `unconfined' disables selective undo until the
+next undo boundary even if the region is active.
+
 If the value of the variable is t, undo information is not recorded.  */);
 
   DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil,
-- 
2.21.0 (Apple Git-122)


  reply	other threads:[~2019-10-16 15:27 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 [this message]
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
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

  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=37DDF48D-FC37-47A8-8CEC-C6EB66AB2BF7@acm.org \
    --to=mattiase@acm.org \
    --cc=37700@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=homeros.misasa@gmail.com \
    --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 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).