all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Braun Gábor" <braungb88@gmail.com>
To: 34405@debbugs.gnu.org
Subject: bug#34405: 26.1; patch for cancel-change-group to work after undo
Date: Tue, 12 Nov 2019 18:05:48 +0100	[thread overview]
Message-ID: <3538177.LDI8N28pS7@gabor> (raw)
In-Reply-To: <1631063.cd5q6Ms6ql@gabor>

Hi,

Please consider the following fix to the problem, patching function 
cancel-change-group.

In the original implementation, the only form depending on whether the 
last command was an undo is the line

(unless (eq last-command 'undo) (undo-start))

which sets pending-undo-list to buffer-undo-list, when the last command 
was not an undo.  When it was, then pending-undo-list probably contains 
the pending undo entries from a buffer state before the start of the 
change group, which are obviously irrelevant for cancelling the change 
group.

The fix below is to use buffer-undo-list instead of pending-undo-list,
essentially inlining the call to undo-more for this change.  
As a side effect, the value of pending-undo-list will no longer be 
changed by cancel-change-group (unless something in the undo log changes 
it), but as far as I see, it doesn't matter, as its value is useful only 
directly after an undo command.

--- lisp/subr.el
+++ lisp/subr.el
@@ -2669,14 +2669,17 @@
               (progn
                 ;; Temporarily truncate the undo log at ELT.
                 (when (consp elt)
-                  (setcar elt nil) (setcdr elt nil))
-                (unless (eq last-command 'undo) (undo-start))
-                ;; Make sure there's no confusion.
-                (when (and (consp elt) (not (eq elt (last pending-undo-
list))))
-                  (error "Undoing to some unrelated state"))
+                  (setcar elt nil) (setcdr elt nil)
+                  ;; Make sure there's no confusion.
+                  (unless (eq elt (last buffer-undo-list))
+                    (error "Undoing to some unrelated state")))
                 ;; Undo it all.
                 (save-excursion
-                  (while (listp pending-undo-list) (undo-more 1)))
+                  (let ((undo-in-progress t))
+                    (while buffer-undo-list
+                      ;; Undo one step, removing it from undo log.
+                      (setq buffer-undo-list
+                            (primitive-undo 1 buffer-undo-list)))))
                 ;; Revert the undo info to what it was when we grabbed
                 ;; the state.
                 (setq buffer-undo-list elt))

Best wishes,

	Gábor







  reply	other threads:[~2019-11-12 17:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-09 15:49 bug#34405: 26.1; atomic change group after undo fails to cancel Braun Gábor
2019-11-12 17:05 ` Braun Gábor [this message]
2019-11-14 12:10   ` bug#34405: 26.1; patch for cancel-change-group to work after undo Eli Zaretskii
2019-11-14 23:00     ` Braun Gábor
2019-12-20  8:11 ` bug#34405: 26.1; 2-line patch Braun Gábor
2021-08-14 13:58 ` bug#34405: bug#26061: 26.0.50; cancel-change-group fails with "unrelated state" error if used after an undo Lars Ingebrigtsen
2021-08-16 12:01   ` Braun Gábor

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=3538177.LDI8N28pS7@gabor \
    --to=braungb88@gmail.com \
    --cc=34405@debbugs.gnu.org \
    /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.