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

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

[elpa] externals/undo-tree f3fc5cd 037/195: Modified undo-tree-undo/redo


From: Stefan Monnier
Subject: [elpa] externals/undo-tree f3fc5cd 037/195: Modified undo-tree-undo/redo to always replace redo/undo entries
Date: Sat, 28 Nov 2020 13:41:16 -0500 (EST)

branch: externals/undo-tree
commit f3fc5cd6ec3d689d81b59f12d0b8a958f53db569
Author: tsc25 <tsc25@cantab.net>
Commit: tsc25 <tsc25@cantab.net>

    Modified undo-tree-undo/redo to always replace redo/undo entries
    with new ones generated by primitive-undo, as the new changesets will 
restore
    the point more reliably.
---
 undo-tree.el | 52 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/undo-tree.el b/undo-tree.el
index cdc8eb8..3f4753f 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -5,7 +5,7 @@
 ;; Copyright (C) 2009 Toby Cubitt
 
 ;; Author: Toby Cubitt <toby-undo-tree@dr-qubit.org>
-;; Version: 0.1.3
+;; Version: 0.1.4
 ;; Keywords: undo, redo, history, tree
 ;; URL: http://www.dr-qubit.org/emacs.php
 
@@ -458,6 +458,11 @@
 
 ;;; Change Log:
 ;;
+;; Version 0.1.4
+;; * modified `undo-tree-undo' and `undo-tree-redo' to always replace
+;;   redo/undo entries with new ones generated by `primitive-undo', as the new
+;;   changesets will restore the point more reliably
+;;
 ;; Version 0.1.3
 ;; * fixed `undo-tree-visualizer-quit' to remove `after-change-functions'
 ;;   hook there, rather than in `undo-tree-kill-visualizer'
@@ -1054,8 +1059,9 @@ which is defined in the `warnings' library.\n")
           (setq node (undo-tree-grow-backwards node nil))
           (setf (undo-tree-root buffer-undo-tree) node)
           (setq buffer-undo-list '(nil undo-tree-canary))
-          (setf (undo-tree-size buffer-undo-tree) size))
-        ))))
+          (setf (undo-tree-size buffer-undo-tree) size)))
+      ;; discard undo history if necessary
+      (undo-tree-discard-history))))
 
 
 (defun undo-list-byte-size (undo-list)
@@ -1133,15 +1139,17 @@ Within the undo-tree visualizer, the following keys are 
available:
                            (undo-tree-node-undo
                             (undo-tree-current buffer-undo-tree))))
         ;; pop redo entries that `primitive-undo' has added to
-        ;; `buffer-undo-list' and record them in current node's redo record if
-        ;; they're not already there
-        (if (undo-tree-node-redo (undo-tree-current buffer-undo-tree))
-            (undo-list-pop-changeset)
-          (setf (undo-tree-node-redo (undo-tree-current buffer-undo-tree))
-                (undo-list-pop-changeset))
-          (incf (undo-tree-size buffer-undo-tree)
-                (undo-list-byte-size
-                 (undo-tree-node-redo (undo-tree-current buffer-undo-tree)))))
+        ;; `buffer-undo-list' and record them in current node's redo record,
+       ;; replacing existing entry if one already exists
+        (when (undo-tree-node-redo (undo-tree-current buffer-undo-tree))
+         (decf (undo-tree-size buffer-undo-tree)
+               (undo-list-byte-size
+                (undo-tree-node-redo (undo-tree-current buffer-undo-tree)))))
+       (setf (undo-tree-node-redo (undo-tree-current buffer-undo-tree))
+             (undo-list-pop-changeset))
+       (incf (undo-tree-size buffer-undo-tree)
+             (undo-list-byte-size
+              (undo-tree-node-redo (undo-tree-current buffer-undo-tree))))
         ;; rewind current node
         (setf (undo-tree-current buffer-undo-tree)
               (undo-tree-node-previous (undo-tree-current buffer-undo-tree)))
@@ -1149,8 +1157,6 @@ Within the undo-tree visualizer, the following keys are 
available:
         (setf (undo-tree-node-timestamp (undo-tree-current buffer-undo-tree))
               (current-time))))
 
-    ;; discard undo history if necessary
-    (undo-tree-discard-history)
     ;; inform user if at branch point
     (when (> (undo-tree-num-branches) 1) (message "Undo branch point!"))))
 
@@ -1184,14 +1190,16 @@ Within the undo-tree visualizer, the following keys are 
available:
           (setf (undo-tree-node-timestamp current) (current-time))
           ;; redo one record from undo tree
           (primitive-undo 1 (undo-copy-list (undo-tree-node-redo current)))
-          ;; discard undo entries that `primitive-undo' has added to
-          ;; `buffer-undo-list' since we already know how to undo from here
-          ;; (NOTE: should we instead overwrite old undo entry for safety's
-          ;;        sake?)
-          (setq buffer-undo-list '(nil undo-tree-canary)))))
-
-    ;; discard undo history if necessary
-    (undo-tree-discard-history)
+         ;; pop undo entries that `primitive-undo' has added to
+         ;; `buffer-undo-list' and record them in current node's undo record,
+         ;; replacing existing entry if one already exists
+        (when (undo-tree-node-undo current)
+         (decf (undo-tree-size buffer-undo-tree)
+               (undo-list-byte-size (undo-tree-node-undo current))))
+       (setf (undo-tree-node-undo current) (undo-list-pop-changeset))
+       (incf (undo-tree-size buffer-undo-tree)
+             (undo-list-byte-size (undo-tree-node-undo current))))))
+
     ;; inform user if at branch point
     (when (> (undo-tree-num-branches) 1) (message "Undo branch point!"))))
 



reply via email to

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