branch: externals/org
commit 4c575a806dba240706576e062683d01c2acab1cf
Author: Morgan Smith <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    org-preserve-local-variables: Amalgamate undo
    
    * lisp/org-macs.el (org-preserve-local-variables): Amalgamate undo as
    undoing in steps could leave the buffer in a state the user has never
    seen before.
---
 lisp/org-macs.el | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 5abb8da7af..aabaf13d96 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -247,26 +247,25 @@ This function is only useful when called from Agenda 
buffer."
   "Execute BODY while preserving local variables."
   (declare (debug (body)))
   (org-with-gensyms (local-variables tick-counter-before)
-    `(let ((,local-variables
-            (org-with-wide-buffer
-             (goto-char (point-max))
-             (let ((case-fold-search t))
-               (and (re-search-backward "^[ \t]*# +Local Variables:"
-                                        (max (- (point) 3000) 1)
-                                        t)
-                    (let ((buffer-undo-list t))
-                      (delete-and-extract-region (point) (point-max)))))))
-           (,tick-counter-before (buffer-modified-tick)))
-       (unwind-protect (progn ,@body)
-         (when ,local-variables
-           (org-with-wide-buffer
-            (goto-char (point-max))
-            (unless (bolp) (insert "\n"))
-            (let ((modified (< ,tick-counter-before (buffer-modified-tick)))
-                  (buffer-undo-list t))
-              (insert ,local-variables)
-              (unless modified
-                (restore-buffer-modified-p nil)))))))))
+    `(org-with-undo-amalgamate
+       (let ((,local-variables
+              (org-with-wide-buffer
+               (goto-char (point-max))
+               (let ((case-fold-search t))
+                 (and (re-search-backward "^[ \t]*# +Local Variables:"
+                                          (max (- (point) 3000) 1)
+                                          t)
+                      (delete-and-extract-region (point) (point-max))))))
+             (,tick-counter-before (buffer-modified-tick)))
+         (unwind-protect (progn ,@body)
+           (when ,local-variables
+             (org-with-wide-buffer
+              (goto-char (point-max))
+              (unless (bolp) (insert "\n"))
+              (let ((modified (< ,tick-counter-before (buffer-modified-tick))))
+                (insert ,local-variables)
+                (unless modified
+                  (restore-buffer-modified-p nil))))))))))
 
 ;;;###autoload
 (defmacro org-element-with-disabled-cache (&rest body)

Reply via email to