[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 1561d8f 099/195: Preserve timestamps when gen
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 1561d8f 099/195: Preserve timestamps when generating diff for visualizer diff view. |
Date: |
Sat, 28 Nov 2020 13:41:30 -0500 (EST) |
branch: externals/undo-tree
commit 1561d8f021f3ba054be4403a5549a95621cf9ad2
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Preserve timestamps when generating diff for visualizer diff view.
Also split out core of undo-tree-undo|redo into internal
undo-tree-undo|redo-1
functions, which now accept an additional preserve-timestamps argument.
---
undo-tree.el | 97 ++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 59 insertions(+), 38 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 39a78c2..ad2a1a6 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -633,6 +633,10 @@
;; * added `called-interactively-p', `registerv-make', `registerv-data',
;; `diff-no-select' and `diff-file-local-copy' compatibility hacks for
;; older Emacsen
+;; * split out core of `undo-tree-undo' and `undo-tree-redo' into internal
+;; `undo-tree-undo-1' and `undo-tree-redo-1' functions, which now take an
+;; additional optional argument to preserve timestamps
+;; * preserve timestamps when generating diff for visualizer diff view
;;
;; Version 0.4
;; * implemented persistent history storage: `undo-tree-save-history' and
@@ -2037,7 +2041,7 @@ which is defined in the `warnings' library.\n")
;; (recognizable as first node with more than one branch)
(let ((mark-active nil))
(while (= (length (undo-tree-node-next node)) 1)
- (undo-tree-undo)
+ (undo-tree-undo-1)
(setq fragment node
node (undo-tree-current buffer-undo-tree))))
(when (eq splice node) (setq splice nil))
@@ -2154,7 +2158,7 @@ which is defined in the `warnings' library.\n")
(let ((mark-active nil))
(while (not (eq (undo-tree-current buffer-undo-tree)
original-current))
- (undo-tree-redo)))
+ (undo-tree-redo-1)))
nil) ; return nil to indicate failure
;; otherwise...
@@ -2164,9 +2168,9 @@ which is defined in the `warnings' library.\n")
(let ((mark-active nil)
(current (undo-tree-current buffer-undo-tree)))
(while (not (eq (undo-tree-current buffer-undo-tree) node))
- (undo-tree-undo))
+ (undo-tree-undo-1))
(while (not (eq (undo-tree-current buffer-undo-tree) current))
- (undo-tree-redo)))
+ (undo-tree-redo-1)))
(cond
;; if there's no remaining fragment, just create undo-in-region node
@@ -2205,7 +2209,7 @@ which is defined in the `warnings' library.\n")
(undo-tree-node-previous original-fragment))
(let ((mark-active nil))
(while (not (eq (undo-tree-current buffer-undo-tree) splice))
- (undo-tree-redo nil 'preserve-undo))))
+ (undo-tree-redo-1 nil 'preserve-undo))))
;; splice new undo-in-region node into fragment
(setq node (undo-tree-make-node nil region-changeset))
(undo-tree-splice-node node splice)
@@ -2576,7 +2580,7 @@ key bindings do not count.)"
-(defun undo-tree-undo (&optional arg preserve-redo)
+(defun undo-tree-undo (&optional arg)
"Undo changes.
Repeat this command to undo more changes.
A numeric ARG serves as a repeat count.
@@ -2584,15 +2588,24 @@ A numeric ARG serves as a repeat count.
In Transient Mark mode when the mark is active, only undo changes
within the current region. Similarly, when not in Transient Mark
mode, just \\[universal-argument] as an argument limits undo to
-changes within the current region.
-
-A non-nil PRESERVE-REDO causes the existing redo record to be
-preserved, rather than replacing it with the new one generated by
-undoing."
+changes within the current region."
(interactive "*P")
;; throw error if undo is disabled in buffer
(when (eq buffer-undo-list t) (error "No undo information in this buffer"))
-
+ (undo-tree-undo-1 arg)
+ ;; inform user if at branch point
+ (when (> (undo-tree-num-branches) 1) (message "Undo branch point!")))
+
+
+(defun undo-tree-undo-1 (&optional arg preserve-redo preserve-timestamps)
+ ;; Internal undo function. An active mark in `transient-mark-mode', or
+ ;; non-nil ARG otherwise, enables undo-in-region. Non-nil PRESERVE-REDO
+ ;; causes the existing redo record to be preserved, rather than replacing it
+ ;; with the new one generated by undoing. Non-nil PRESERVE-TIMESTAMPS
+ ;; disables updating of timestamps in visited undo-tree nodes. (This latter
+ ;; should *only* be used when temporarily visiting another undo state and
+ ;; immediately returning to the original state afterwards. Otherwise, it
+ ;; could cause history-discarding errors.)
(let ((undo-in-progress t)
(undo-in-region (and undo-tree-enable-undo-in-region
(or (region-active-p)
@@ -2654,9 +2667,10 @@ undoing."
;; rewind current node and update timestamp
(setf (undo-tree-current buffer-undo-tree)
- (undo-tree-node-previous (undo-tree-current buffer-undo-tree))
- (undo-tree-node-timestamp (undo-tree-current buffer-undo-tree))
- (current-time))
+ (undo-tree-node-previous (undo-tree-current buffer-undo-tree)))
+ (unless preserve-timestamps
+ (setf (undo-tree-node-timestamp (undo-tree-current buffer-undo-tree))
+ (current-time)))
;; if undoing-in-region, record current node, region and direction so we
;; can tell if undo-in-region is repeated, and re-activate mark if in
@@ -2671,29 +2685,34 @@ undoing."
(set-marker pos nil)))
;; undo deactivates mark unless undoing-in-region
- (setq deactivate-mark (not undo-in-region))
- ;; inform user if at branch point
- (when (and (called-interactively-p 'interactive)
- (> (undo-tree-num-branches) 1))
- (message "Undo branch point!"))))
+ (setq deactivate-mark (not undo-in-region))))
-(defun undo-tree-redo (&optional arg preserve-undo)
+(defun undo-tree-redo (&optional arg)
"Redo changes. A numeric ARG serves as a repeat count.
In Transient Mark mode when the mark is active, only redo changes
within the current region. Similarly, when not in Transient Mark
mode, just \\[universal-argument] as an argument limits redo to
-changes within the current region.
-
-A non-nil PRESERVE-UNDO causes the existing undo record to be
-preserved, rather than replacing it with the new one generated by
-redoing."
+changes within the current region."
(interactive "*P")
;; throw error if undo is disabled in buffer
(when (eq buffer-undo-list t) (error "No undo information in this buffer"))
-
+ (undo-tree-redo-1 arg)
+ ;; inform user if at branch point
+ (when (> (undo-tree-num-branches) 1) (message "Undo branch point!")))
+
+
+(defun undo-tree-redo-1 (&optional arg preserve-undo preserve-timestamps)
+ ;; Internal redo function. An active mark in `transient-mark-mode', or
+ ;; non-nil ARG otherwise, enables undo-in-region. Non-nil PRESERVE-UNDO
+ ;; causes the existing redo record to be preserved, rather than replacing it
+ ;; with the new one generated by undoing. Non-nil PRESERVE-TIMESTAMPS
+ ;; disables updating of timestamps in visited undo-tree nodes. (This latter
+ ;; should *only* be used when temporarily visiting another undo state and
+ ;; immediately returning to the original state afterwards. Otherwise, it
+ ;; could cause history-discarding errors.)
(let ((undo-in-progress t)
(redo-in-region (and undo-tree-enable-undo-in-region
(or (region-active-p)
@@ -2758,7 +2777,8 @@ redoing."
(undo-list-byte-size (undo-tree-node-undo current))))
;; update timestamp
- (setf (undo-tree-node-timestamp current) (current-time))
+ (unless preserve-timestamps
+ (setf (undo-tree-node-timestamp current) (current-time)))
;; if redoing-in-region, record current node, region and direction so we
;; can tell if redo-in-region is repeated, and re-activate mark if in
@@ -2771,11 +2791,7 @@ redoing."
(set-marker pos nil)))
;; redo deactivates the mark unless redoing-in-region
- (setq deactivate-mark (not redo-in-region))
- ;; inform user if at branch point
- (when (and (called-interactively-p 'interactive)
- (> (undo-tree-num-branches) 1))
- (message "Undo branch point!"))))
+ (setq deactivate-mark (not redo-in-region))))
@@ -2812,9 +2828,13 @@ using `undo-tree-redo'."
(message "Switched to branch %d" branch))
-(defun undo-tree-set (node)
+(defun undo-tree-set (node &optional preserve-timestamps)
;; Set buffer to state corresponding to NODE. Returns intersection point
;; between path back from current node and path back from selected NODE.
+ ;; Non-nil PRESERVE-TIMESTAMPS disables updating of timestamps in visited
+ ;; undo-tree nodes. (This should *only* be used when temporarily visiting
+ ;; another undo state and immediately returning to the original state
+ ;; afterwards. Otherwise, it could cause history-discarding errors.)
(let ((path (make-hash-table :test 'eq))
(n node))
(puthash (undo-tree-root buffer-undo-tree) t path)
@@ -2834,10 +2854,10 @@ using `undo-tree-redo'."
(setq n (undo-tree-node-previous n)))
;; ascend tree until intersection node
(while (not (eq (undo-tree-current buffer-undo-tree) n))
- (undo-tree-undo))
+ (undo-tree-undo-1))
;; descend tree until selected node
(while (not (eq (undo-tree-current buffer-undo-tree) node))
- (undo-tree-redo))
+ (undo-tree-redo-1))
n)) ; return intersection node
@@ -3613,9 +3633,10 @@ at mouse event POS."
;; generate diff
(let ((undo-tree-inhibit-kill-visualizer t)
(current (undo-tree-current buffer-undo-tree)))
- (undo-tree-set (or node (undo-tree-node-previous current) current))
+ (undo-tree-set (or node (undo-tree-node-previous current) current)
+ 'preserve-timestamps)
(setq tmpfile (diff-file-local-copy (current-buffer)))
- (undo-tree-set current))
+ (undo-tree-set current 'preserve-timestamps))
(setq buff (diff-no-select
(current-buffer) tmpfile nil 'noasync
(get-buffer-create undo-tree-diff-buffer-name)))
- [elpa] externals/undo-tree 2b0395a 096/195: Added called-interactively-p compatibility hack for Emacs <= 23.1, (continued)
- [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, 2020/11/28
- [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 <=
- [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
- [elpa] externals/undo-tree d5a6148 120/195: Don't try to auto-save undo history if undo is disabled in buffer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree cfc036a 133/195: Fix undo-tree-redo to avoid corrupting undo-tree state if redoing fails., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bdfd73f 132/195: Ignore bogus buffer modification entries in undo changesets., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 6e0775d 139/195: Use define-derived-mode and define-minor-mode for undo-tree visualizer., Stefan Monnier, 2020/11/28