[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 1f63331: * lisp/subr.el (activate-change-group): Refine fix for b
From: |
Stefan Monnier |
Subject: |
master 1f63331: * lisp/subr.el (activate-change-group): Refine fix for bug#33341 |
Date: |
Fri, 27 Nov 2020 10:19:26 -0500 (EST) |
branch: master
commit 1f633311c194edff9976b0672940769e76ac538e
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/subr.el (activate-change-group): Refine fix for bug#33341
---
lisp/subr.el | 15 +++++++++++++--
test/lisp/subr-tests.el | 15 +++++++++++++--
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 1cf3a49..0b92a4f 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -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).
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index e3f798d..019441d 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 1f63331: * lisp/subr.el (activate-change-group): Refine fix for bug#33341,
Stefan Monnier <=