From c1ce9fa7f2b1d88637e8d8f03f08d8ddd2ff9e4a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 12 Mar 2020 10:01:54 -0400 Subject: [PATCH] * lisp/subr.el (cancel-change-group): Fix bug#39680 Don't re-use an existing `pending-undo-list` even if (eq last-command 'undo) since there might have been changes to the buffer since that `undo` command and the `pending-undo-list` can hence be invalid for the current buffer contents. --- lisp/subr.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 5b94343e499..a744cfddfd4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2964,13 +2964,18 @@ This finishes the change group by reverting all of its changes." ;; the body of `atomic-change-group' all changes can be undone. (widen) (let ((old-car (car-safe elt)) - (old-cdr (cdr-safe elt))) + (old-cdr (cdr-safe elt)) + ;; Use `pending-undo-list' temporarily since `undo-more' needs + ;; it, but restore it afterwards so as not to mess with an + ;; ongoing sequence of `undo's. + (pending-undo-list + ;; Use `buffer-undo-list' unconditionally (bug#39680). + buffer-undo-list)) (unwind-protect (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")) -- 2.39.2