[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 21d3c89 004/195: Implemented redo command.
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 21d3c89 004/195: Implemented redo command. |
Date: |
Sat, 28 Nov 2020 13:41:09 -0500 (EST) |
branch: externals/undo-tree
commit 21d3c89f153fd371b886a904ec523d535cb3e21a
Author: tsc25 <tsc25@cantab.net>
Commit: tsc25 <tsc25@cantab.net>
Implemented redo command.
---
undo-tree.el | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 251a720..54be572 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -86,11 +86,12 @@ to `buffer-undo-tree'."
(setq buffer-undo-tree (make-undo-tree)))
;; transfer entries accumulated in `buffer-undo-list' to `buffer-undo-tree'
(undo-list-to-tree)
+
(dotimes (i arg)
- ;; check if at top of tree
- (if (null (undo-tree-node-undo (undo-tree-current buffer-undo-tree)))
+ ;; check if at top of undo tree
+ (if (null (undo-tree-node-previous (undo-tree-current buffer-undo-tree)))
(error "No further undo information")
- ;; undo one record from tree
+ ;; undo one record from undo tree
(primitive-undo 1 (undo-copy-list
(undo-tree-node-undo
(undo-tree-current buffer-undo-tree))))
@@ -98,7 +99,35 @@ to `buffer-undo-tree'."
;; `buffer-undo-list' and record them in current node's redo record
(setf (undo-tree-node-redo (undo-tree-current buffer-undo-tree))
(undo-list-pop-changeset))
- ;; rewind pointer to current node
+ ;; rewind current node
(setf (undo-tree-current buffer-undo-tree)
(undo-tree-node-previous (undo-tree-current buffer-undo-tree)))
)))
+
+
+(defun undo-tree-redo (&optional arg)
+ "Redo changes. A numeric ARG serves as a repeat count."
+ (interactive "p")
+ ;; if `buffer-undo-tree' is empty, create initial undo-tree
+ (when (null buffer-undo-tree)
+ (setq buffer-undo-tree (make-undo-tree)))
+ ;; transfer entries accumulated in `buffer-undo-list' to `buffer-undo-tree'
+ (undo-list-to-tree)
+
+ (let ((current (undo-tree-current buffer-undo-tree)))
+ (dotimes (i arg)
+ ;; check if at bottom of undo tree
+ (if (null (undo-tree-node-next (undo-tree-current buffer-undo-tree)))
+ (error "No further redo information")
+ ;; advance current node
+ (setq current
+ (setf (undo-tree-current buffer-undo-tree)
+ (nth (undo-tree-node-branch current)
+ (undo-tree-node-next current))))
+ ;; 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: could overwrite old undo entry instead for safety's sake?)
+ (setq buffer-undo-list nil)
+ ))))
- [elpa] externals/undo-tree 9b14800 018/195: Rewrote undo-tree-compute-widths and undo-tree-clear-visualizer-data, (continued)
- [elpa] externals/undo-tree 9b14800 018/195: Rewrote undo-tree-compute-widths and undo-tree-clear-visualizer-data, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree aa550da 025/195: Implemented undo history discarding so as to remain within memory usage limits, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ad38c6a 020/195: Reuse node markers in undo-tree-draw-tree and undo-tree-draw-subtree,, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 486964c 014/195: Centre undo-tree in visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ff2fd6e 011/195: Implemented undo-tree-mode minor mode., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 30dc485 013/195: Clear visualizer data when quitting visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e0b8308 015/195: Implemented commands to set buffer state to any given undo-tree node., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 0368f0f 006/195: Implemented undo-tree visualisation., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 711dd60 003/195: Implemented undo-tree data structure and undo command., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b15904c 023/195: Update timestamps when nodes are visited by undo/redo., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 21d3c89 004/195: Implemented redo command.,
Stefan Monnier <=
- [elpa] externals/undo-tree f87f815 024/195: Added utility functions for use in discarding undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree dcabd4f 002/195: Added .gitignore to ignore byte-compiled elisp files., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f370170 019/195: Rewrote undo-tree-draw-tree and undo-tree-draw-subtree, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 73c1d04 007/195: Lumped visualizer data into single undo-tree node entry,, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 4dd6905 028/195: Discard marker adjustment undo entries., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 09fb370 027/195: Added lighter to undo-tree-mode., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b074b86 029/195: Updated commentary, and switched to GPLv3., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree c00c1fe 031/195: Add new undo-tree-kill-visualizer to before-change-functions hook, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree aaa4c6d 012/195: Don't create new marker each time we draw a node., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 159c9b4 005/195: Implemented undo-tree branch switching., Stefan Monnier, 2020/11/28