[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 3ab4581 107/195: Avoid error if point was mov
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 3ab4581 107/195: Avoid error if point was moved manually in visualizer selection mode |
Date: |
Sat, 28 Nov 2020 13:41:32 -0500 (EST) |
branch: externals/undo-tree
commit 3ab458134cdb5e52871b91040023db4af51ef215
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Avoid error if point was moved manually in visualizer selection mode
by using undo-tree-visualizer-selected-node to store currently selected
node,
instead of relying on point location.
---
undo-tree.el | 66 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 42 insertions(+), 24 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index cefff36..20b69db 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -652,6 +652,9 @@
;; cause read errors in `undo-tree-load-history'
;; * make `undo-tree-visualizer-timestamps' into defcustom, to allow
;; timestamps to be displayed by default
+;; * use `undo-tree-visualizer-selected-node' to store currently selected node
+;; in visualizer selection mode, instead of relying on point location, to
+;; avoid errors if point was moved manually
;;
;; Version 0.4
;; * implemented persistent history storage: `undo-tree-save-history' and
@@ -1032,6 +1035,10 @@ in visualizer."
(if undo-tree-visualizer-relative-timestamps 9 13)
3))
+;; holds marker located at selected node in visualizer selection mode
+(defvar undo-tree-visualizer-selected-node nil)
+(make-variable-buffer-local 'undo-tree-visualizer-selected)
+
;; dynamically bound to t when undoing from visualizer, to inhibit
;; `undo-tree-kill-visualizer' hook function in parent buffer
(defvar undo-tree-inhibit-kill-visualizer nil)
@@ -3404,6 +3411,7 @@ Within the undo-tree visualizer, the following keys are
available:
(setq truncate-lines t)
(setq cursor-type nil)
(setq buffer-read-only t)
+ (setq undo-tree-visualizer-selected-node nil)
(when undo-tree-visualizer-diff (undo-tree-visualizer-update-diff)))
@@ -3550,6 +3558,8 @@ at mouse event POS."
(setq mode-name "undo-tree-visualizer-selection-mode")
(use-local-map undo-tree-visualizer-selection-map)
(setq cursor-type 'box)
+ (setq undo-tree-visualizer-selected-node
+ (undo-tree-current buffer-undo-tree))
;; erase diff (if any), as initially selected node is identical to current
(when undo-tree-visualizer-diff
(let ((buff (get-buffer undo-tree-diff-buffer-name))
@@ -3560,20 +3570,22 @@ at mouse event POS."
(defun undo-tree-visualizer-select-previous (&optional arg)
"Move to previous node."
(interactive "p")
- (let ((node (get-text-property (point) 'undo-tree-node)))
+ (let ((node undo-tree-visualizer-selected-node))
(catch 'top
(dotimes (i arg)
(unless (undo-tree-node-previous node) (throw 'top t))
(setq node (undo-tree-node-previous node))))
(goto-char (undo-tree-node-marker node))
- (when undo-tree-visualizer-diff
- (undo-tree-visualizer-update-diff node))))
+ (when (and undo-tree-visualizer-diff
+ (not (eq node undo-tree-visualizer-selected-node)))
+ (undo-tree-visualizer-update-diff node))
+ (setq undo-tree-visualizer-selected-node node)))
(defun undo-tree-visualizer-select-next (&optional arg)
"Move to next node."
(interactive "p")
- (let ((node (get-text-property (point) 'undo-tree-node)))
+ (let ((node undo-tree-visualizer-selected-node))
(catch 'bottom
(dotimes (i arg)
(unless (nth (undo-tree-node-branch node) (undo-tree-node-next node))
@@ -3581,46 +3593,52 @@ at mouse event POS."
(setq node
(nth (undo-tree-node-branch node) (undo-tree-node-next node)))))
(goto-char (undo-tree-node-marker node))
- (when undo-tree-visualizer-diff
- (undo-tree-visualizer-update-diff node))))
+ (when (and undo-tree-visualizer-diff
+ (not (eq node undo-tree-visualizer-selected-node)))
+ (undo-tree-visualizer-update-diff node))
+ (setq undo-tree-visualizer-selected-node node)))
(defun undo-tree-visualizer-select-right (&optional arg)
"Move right to a sibling node."
(interactive "p")
- (let ((pos (point))
- (end (line-end-position))
- (current (get-text-property (point) 'undo-tree-node))
- node)
+ (let ((node undo-tree-visualizer-selected-node)
+ end)
+ (goto-char (undo-tree-node-marker undo-tree-visualizer-selected-node))
+ (setq end (line-end-position))
(catch 'end
(dotimes (i arg)
- (while (or (null node) (eq node current))
+ (while (or (null node) (eq node undo-tree-visualizer-selected-node))
(forward-char)
(setq node (get-text-property (point) 'undo-tree-node))
(when (= (point) end) (throw 'end t)))))
- (unless (eq node current)
- (goto-char (if node (undo-tree-node-marker node) pos))
- (when (and undo-tree-visualizer-diff node)
- (undo-tree-visualizer-update-diff node)))))
+ (goto-char (undo-tree-node-marker
+ (or node undo-tree-visualizer-selected-node)))
+ (when (and undo-tree-visualizer-diff node
+ (not (eq node undo-tree-visualizer-selected-node)))
+ (undo-tree-visualizer-update-diff node))
+ (setq undo-tree-visualizer-selected-node node)))
(defun undo-tree-visualizer-select-left (&optional arg)
"Move left to a sibling node."
(interactive "p")
- (let ((pos (point))
- (beg (line-beginning-position))
- (current (get-text-property (point) 'undo-tree-node))
- node)
+ (let ((node (get-text-property (point) 'undo-tree-node))
+ beg)
+ (goto-char (undo-tree-node-marker undo-tree-visualizer-selected-node))
+ (setq beg (line-beginning-position))
(catch 'beg
(dotimes (i arg)
- (while (or (null node) (eq node current))
+ (while (or (null node) (eq node undo-tree-visualizer-selected-node))
(backward-char)
(setq node (get-text-property (point) 'undo-tree-node))
(when (= (point) beg) (throw 'beg t)))))
- (unless (eq node current)
- (goto-char (if node (undo-tree-node-marker node) pos))
- (when (and undo-tree-visualizer-diff node)
- (undo-tree-visualizer-update-diff node)))))
+ (goto-char (undo-tree-node-marker
+ (or node undo-tree-visualizer-selected-node)))
+ (when (and undo-tree-visualizer-diff node
+ (not (eq node undo-tree-visualizer-selected-node)))
+ (undo-tree-visualizer-update-diff node))
+ (setq undo-tree-visualizer-selected-node node)))
- [elpa] externals/undo-tree 6680aab 086/195: Create proper registerv structure when storing undo state in register., (continued)
- [elpa] externals/undo-tree 6680aab 086/195: Create proper registerv structure when storing undo state in register., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree cd06456 073/195: Modified slightly misleading message in turn-on-undo-tree-mode., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 98170c6 075/195: Added additional check to more reliably identify marker undo elements., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 89bf725 081/195: Prevent undo history being discarded on major-mode switch, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2b0395a 096/195: Added called-interactively-p compatibility hack for Emacs <= 23.1, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b42fe10 076/195: Fixed bug in undo-list-transfer-to-tree., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 897f2ff 089/195: Let-bind inhibit-read-only instead of setting and restoring buffer-read-only., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree adca566 094/195: Allow undo-tree-visualizer-diff variable to be customized., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree da54994 117/195: When discarding root, erase previous link of new root., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 4c6280b 101/195: Fixed bug preventing registers being displayed in visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 3ab4581 107/195: Avoid error if point was moved manually in visualizer selection mode,
Stefan Monnier <=
- [elpa] externals/undo-tree 824b904 129/195: Preparatory changes for lazy tree drawing., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 40c7065 108/195: Added undo-tree-visualizer-abort command, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 107d4c8 102/195: Allow visualizer to display relative timestamps., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 1561d8f 099/195: Preserve timestamps when generating diff for visualizer diff view., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 08db836 123/195: Fix bug in undo-tree-visualizer-select-left/right., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 6e5cc0f 104/195: Generate history save filename using a function, to allow customization., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 17568c3 113/195: Allow undo history save directory to be customized., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 965650c 127/195: Highlight node in visualizer corresponding to unmodified buffer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ca9ec7b 105/195: Clear visualizer data / kill visualizer before saving history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 270bc25 110/195: Added `~' to end of default history save-file name., Stefan Monnier, 2020/11/28