emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/undo-tree cfc036a 133/195: Fix undo-tree-redo to avoid


From: Stefan Monnier
Subject: [elpa] externals/undo-tree cfc036a 133/195: Fix undo-tree-redo to avoid corrupting undo-tree state if redoing fails.
Date: Sat, 28 Nov 2020 13:41:37 -0500 (EST)

branch: externals/undo-tree
commit cfc036af8cb34c901af8b3c29fed71b5bf8e9018
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>

    Fix undo-tree-redo to avoid corrupting undo-tree state if redoing fails.
    
    primitive-undo can fail and throw an error for example if the buffer is
    narrowed and we try to undo changes outside the visible region. Thus we need
    to ensure buffer-undo-tree is not modified until *after* primitive-undo.
---
 undo-tree.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/undo-tree.el b/undo-tree.el
index 0244053..ab8a584 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -2795,11 +2795,11 @@ changes within the current region."
                       (region-beginning) (region-end))))
        (error "No further redo information for region"))
 
-      ;; advance current node
+      ;; get next node (but DON'T advance current node in tree yet, in case
+      ;; redoing fails)
       (setq current (undo-tree-current buffer-undo-tree)
-           current (setf (undo-tree-current buffer-undo-tree)
-                         (nth (undo-tree-node-branch current)
-                              (undo-tree-node-next current))))
+           current (nth (undo-tree-node-branch current)
+                        (undo-tree-node-next current)))
       ;; remove any GC'd elements from node's redo list
       (decf (undo-tree-size buffer-undo-tree)
            (undo-list-byte-size (undo-tree-node-redo current)))
@@ -2813,6 +2813,8 @@ changes within the current region."
        (set-marker-insertion-type pos t))
       (primitive-undo 1 (undo-tree-copy-list (undo-tree-node-redo current)))
       (undo-boundary)
+      ;; advance current node in tree
+      (setf (undo-tree-current buffer-undo-tree) current)
 
       ;; if preserving old undo record, discard new undo entries that
       ;; `primitive-undo' has added to `buffer-undo-list', and remove any GC'd



reply via email to

[Prev in Thread] Current Thread [Next in Thread]