From: Stefan Monnier Date: Fri, 27 Nov 2020 14:43:56 +0000 (-0500) Subject: * lisp/subr.el (activate-change-group): Fix bug#33341 X-Git-Tag: emacs-28.0.90~5008 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=66eeaaa48858572d47ff3b0b177d5b765df93418;p=emacs.git * lisp/subr.el (activate-change-group): Fix bug#33341 --- diff --git a/lisp/subr.el b/lisp/subr.el index e009dcc2b9a..1cf3a49fe4f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3036,7 +3036,10 @@ to `accept-change-group' or `cancel-change-group'." (dolist (elt handle) (with-current-buffer (car elt) (if (eq buffer-undo-list t) - (setq buffer-undo-list nil))))) + (setq buffer-undo-list nil) + ;; Add a boundary to make sure the upcoming changes won't be + ;; merged with any previous changes (bug#33341). + (undo-boundary))))) (defun accept-change-group (handle) "Finish a change group made with `prepare-change-group' (which see). diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 67f7fc97496..e3f798d11cf 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -551,5 +551,17 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350." (should (equal (replace-regexp-in-string "\\`\\|x" "z" "--xx--") "z--zz--"))) +(ert-deftest subr-tests--change-group-33341 () + (with-temp-buffer + (buffer-enable-undo) + (insert "0\n") + ;; (undo-boundary) + (let ((g (prepare-change-group))) + (activate-change-group g) + (insert "b\n") + (insert "c\n") + (cancel-change-group g)) + (should (equal (buffer-string) "0\n")))) + (provide 'subr-tests) ;;; subr-tests.el ends here