[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 159c9b4 005/195: Implemented undo-tree branch
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 159c9b4 005/195: Implemented undo-tree branch switching. |
Date: |
Sat, 28 Nov 2020 13:41:09 -0500 (EST) |
branch: externals/undo-tree
commit 159c9b4b7c5d9a899e954a3cc34473074c160e7d
Author: tsc25 <tsc25@cantab.net>
Commit: tsc25 <tsc25@cantab.net>
Implemented undo-tree branch switching.
---
undo-tree.el | 41 +++++++++++++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 54be572..9ed8aff 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -65,7 +65,7 @@ part of `buffer-undo-tree'."
changeset))
-(defun undo-list-to-tree ()
+(defun undo-list-transfer-to-tree ()
"Transfer entries accumulated in `buffer-undo-list'
to `buffer-undo-tree'."
(when buffer-undo-list
@@ -75,7 +75,13 @@ to `buffer-undo-tree'."
(while buffer-undo-list
(setq node (undo-tree-grow-backwards node (undo-list-pop-changeset))))
(setf (undo-tree-node-previous node) splice)
- (push node (undo-tree-node-next splice)))))
+ (push node (undo-tree-node-next splice))
+ (setf (undo-tree-node-branch splice) 0))))
+
+
+(defmacro undo-tree-num-branches ()
+ "Return number of branches at current undo tree node."
+ '(length (undo-tree-node-next (undo-tree-current buffer-undo-tree))))
(defun undo-tree-undo (&optional arg)
@@ -85,7 +91,7 @@ to `buffer-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)
+ (undo-list-transfer-to-tree)
(dotimes (i arg)
;; check if at top of undo tree
@@ -102,7 +108,10 @@ to `buffer-undo-tree'."
;; rewind current node
(setf (undo-tree-current buffer-undo-tree)
(undo-tree-node-previous (undo-tree-current buffer-undo-tree)))
- )))
+ ))
+ ;; inform user if at branch point
+ (when (> (undo-tree-num-branches) 1)
+ (message "Undo branch point!")))
(defun undo-tree-redo (&optional arg)
@@ -112,7 +121,7 @@ to `buffer-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)
+ (undo-list-transfer-to-tree)
(let ((current (undo-tree-current buffer-undo-tree)))
(dotimes (i arg)
@@ -130,4 +139,24 @@ to `buffer-undo-tree'."
;; `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)
- ))))
+ )))
+ ;; inform user if at branch point
+ (when (> (undo-tree-num-branches) 1)
+ (message "Undo branch point!")))
+
+
+(defun undo-tree-switch-branch (branch)
+ "Switch to a different BRANCH of the undo tree.
+This will affect which branch to descend when *redoing* changes
+using `undo-tree-redo'."
+ (interactive (list (or (and prefix-arg (prefix-numeric-value prefix-arg))
+ (read-number
+ (format "Branch (0-%d): "
+ (1- (undo-tree-num-branches))))
+ )))
+ ;; sanity check branch number
+ (if (or (< branch 0) (> branch (1- (undo-tree-num-branches))))
+ (error "Invalid branch number")
+ ;; switch branch
+ (setf (undo-tree-node-branch (undo-tree-current buffer-undo-tree))
+ branch)))
- [elpa] externals/undo-tree 21d3c89 004/195: Implemented redo command., (continued)
- [elpa] externals/undo-tree 21d3c89 004/195: Implemented redo command., Stefan Monnier, 2020/11/28
- [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 <=
- [elpa] externals/undo-tree 0bbfa5c 026/195: Tweaked commentary., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 86fb076 034/195: Fixed keybindings., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 948386b 035/195: Modified undo-tree-visualizer-active-branch-face, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bca52bf 042/195: Added undo-tree-mode-lighter customization option, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 50ccefd 043/195: Fixed bug in undo-tree-discard-node., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree fd3fc5c 046/195: Pass null argument to kill-buffer call in undo-tree-visualizer-quit,, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 45751ef 050/195: Fixed bug in undo-tree-switch-branch., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f454e88 001/195: Started project to add vim-like undo tree handling to emacs., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b2eab5a 016/195: Made visualizer buffer read-only., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 4877b0f 008/195: Added markers to record positions of nodes in visualizer., Stefan Monnier, 2020/11/28