From: Stefan Monnier Date: Thu, 12 Mar 2020 14:01:54 +0000 (-0400) Subject: * lisp/subr.el (cancel-change-group): Fix bug#39680 X-Git-Tag: emacs-27.0.91~86 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c1ce9fa7f2;p=emacs.git * 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. --- 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"))