]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/subr.el (activate-change-group): Refine fix for bug#33341
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 27 Nov 2020 15:19:21 +0000 (10:19 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 27 Nov 2020 15:19:21 +0000 (10:19 -0500)
lisp/subr.el
test/lisp/subr-tests.el

index 1cf3a49fe4fbf2b80888f84ce3dcfc7fbe0b0b15..0b92a4f9b554c64deab4d0e23c3f0fea019dd983 100644 (file)
@@ -3038,8 +3038,19 @@ to `accept-change-group' or `cancel-change-group'."
       (if (eq buffer-undo-list t)
          (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)))))
+       ;; merged/combined with any previous changes (bug#33341).
+       ;; We're not supposed to introduce a real (visible)
+        ;; `undo-boundary', tho, so we have to push something else
+        ;; that acts like a boundary w.r.t preventing merges while
+       ;; being harmless.
+        ;; We use for that an "empty insertion", but in order to be harmless,
+        ;; it has to be at a harmless position.  Currently only
+        ;; insertions are ever merged/combined, so we use such a "boundary"
+        ;; only when the last change was an insertion and we use the position
+        ;; of the last insertion.
+        (when (numberp (caar buffer-undo-list))
+          (push (cons (caar buffer-undo-list) (caar buffer-undo-list))
+                buffer-undo-list))))))
 
 (defun accept-change-group (handle)
   "Finish a change group made with `prepare-change-group' (which see).
index e3f798d11cf7ea83f78e4a9bb0de8fe394ee3f1f..019441d9a3938b25114020d5d77119e784e0a92d 100644 (file)
@@ -555,13 +555,24 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
   (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"))))
+    (should (equal (buffer-string) "0\n"))
+    (erase-buffer)
+    (setq buffer-undo-list nil)
+    (insert "0\n")
+    (let ((g (prepare-change-group)))
+      (activate-change-group g)
+      (insert "b\n")
+      (insert "c\n")
+      (accept-change-group g))
+    (should (equal (buffer-string) "0\nb\nc\n"))
+    (undo-boundary)
+    (undo)
+    (should (equal (buffer-string) ""))))
 
 (provide 'subr-tests)
 ;;; subr-tests.el ends here