[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree f6f557c 178/195: Fix various bugs in undo his
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree f6f557c 178/195: Fix various bugs in undo history loading/saving. |
Date: |
Sat, 28 Nov 2020 13:41:48 -0500 (EST) |
branch: externals/undo-tree
commit f6f557c65905e3d22df0729358f7d33d7247ad27
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Fix various bugs in undo history loading/saving.
- Add undo-tree-canary to buffer-undo-list after loading history, otherwise
loaded history immediately gets discarded if any new edits are made before
using undo-tree.
- Recreate undo-tree object pool after loading (discarded when saving).
- Don't auto-save undo history for buffers not associated with any file.
---
undo-tree.el | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 81eb435..0ee30b8 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -1108,8 +1108,9 @@ in visualizer."
(defconst undo-tree-diff-buffer-name "*undo-tree Diff*")
;; install history-auto-save hooks
-(add-hook 'write-file-functions 'undo-tree-save-history-hook)
-(add-hook 'find-file-hook 'undo-tree-load-history-hook)
+(add-hook 'write-file-functions 'undo-tree-save-history-from-hook)
+(add-hook 'kill-buffer-hook 'undo-tree-save-history-from-hook)
+(add-hook 'find-file-hook 'undo-tree-load-history-from-hook)
@@ -3122,7 +3123,7 @@ without asking for confirmation."
(undo-list-transfer-to-tree)
(when (and buffer-undo-tree (not (eq buffer-undo-tree t)))
(undo-tree-kill-visualizer)
- ;; should be cleared already by killing the visualize, but writes
+ ;; should be cleared already by killing the visualizer, but writes
;; unreasable data if not for some reason, so just in case...
(undo-tree-clear-visualizer-data buffer-undo-tree)
(let ((buff (current-buffer))
@@ -3136,8 +3137,7 @@ without asking for confirmation."
(when (or (not (file-exists-p filename))
overwrite
(yes-or-no-p (format "Overwrite \"%s\"? " filename)))
- ;; transform undo-tree into non-circular structure, and make temporary
- ;; copy
+ ;; transform undo-tree into non-circular structure, and make tmp copy
(setq tree (copy-undo-tree buffer-undo-tree))
(undo-tree-decircle tree)
;; discard undo-tree object pool before saving
@@ -3175,14 +3175,16 @@ without asking for confirmation."
(defun undo-tree-load-history (&optional filename noerror)
- "Load undo-tree history from file.
+ "Load undo-tree history from file, for the current buffer.
If optional argument FILENAME is null, default load file is
\".<buffer-file-name>.~undo-tree\" if buffer is visiting a file.
Otherwise, prompt for one.
If optional argument NOERROR is non-nil, return nil instead of
-signaling an error if file is not found."
+signaling an error if file is not found.
+
+Note this will overwrite any existing undo history."
(interactive)
(unless undo-tree-mode
(user-error "Undo-tree mode not enabled in buffer"))
@@ -3210,7 +3212,7 @@ signaling an error if file is not found."
(setq hash (read (current-buffer)))
(error
(kill-buffer nil)
- (funcall (if noerror 'message 'user-error)
+ (funcall (if noerror #'message #'user-error)
"Error reading undo-tree history from \"%s\"" filename)
(throw 'load-error nil)))
(unless (string= (sha1 buff) hash)
@@ -3222,7 +3224,7 @@ signaling an error if file is not found."
(setq tree (read (current-buffer)))
(error
(kill-buffer nil)
- (funcall (if noerror 'message 'error)
+ (funcall (if noerror #'message #'error)
"Error reading undo-tree history from \"%s\"" filename)
(throw 'load-error nil)))
(kill-buffer nil)))
@@ -3247,26 +3249,32 @@ signaling an error if file is not found."
(make-hash-table :test 'eq :weakness 'value))
;; restore circular undo-tree data structure
(undo-tree-recircle tree)
- (setq buffer-undo-tree tree))))
+ ;; create undo-tree object pool
+ (setf (undo-tree-object-pool tree)
+ (make-hash-table :test 'eq :weakness 'value))
+ (setq buffer-undo-tree tree
+ buffer-undo-list '(nil undo-tree-canary)))))
;; Versions of save/load functions for use in hooks
(defun undo-tree-save-history-from-hook ()
(when (and undo-tree-mode undo-tree-auto-save-history
- (not (eq buffer-undo-list t)))
- (undo-tree-save-history nil t) nil))
+ (not (eq buffer-undo-list t))
+ buffer-file-name)
+ (undo-tree-save-history nil 'overwrite) nil))
(define-obsolete-function-alias
'undo-tree-save-history-hook 'undo-tree-save-history-from-hook
"`undo-tree-save-history-hook' is obsolete since undo-tree
version 0.6.6. Use `undo-tree-save-history-from-hook' instead.")
+
(defun undo-tree-load-history-from-hook ()
(when (and undo-tree-mode undo-tree-auto-save-history
(not (eq buffer-undo-list t))
(not revert-buffer-in-progress-p))
- (undo-tree-load-history nil t)))
+ (undo-tree-load-history nil 'noerror)))
(define-obsolete-function-alias
'undo-tree-load-history-hook 'undo-tree-load-history-from-hook
- [elpa] externals/undo-tree 133b439 148/195: Set protected-local property on various visualizer variables., (continued)
- [elpa] externals/undo-tree 133b439 148/195: Set protected-local property on various visualizer variables., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bc9d095 156/195: Clear undo-tree-visualizer-needs-extending-[up|down] before drawing tree., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b35a6af 160/195: Bump copyright year and version number., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree a3e81b6 161/195: Fix bug that caused undo-tree to hang when undoing in region (bug#16377)., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2947d7c 169/195: Add hooks to transform/discard undo elements on saving/loading., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree c3d04ea 165/195: Change obsolete subtract-time -> time-subtract., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree af99ee3 166/195: Uncoditionally clear visualizer data before writing to file., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f6471ef 173/195: Simplify undo-list-byte-size., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ea165ed 174/195: Refactor undo-list-transfer-to-tree to not act directly on buffer-undo-list., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8842bb5 176/195: More undo-tree GC corruption mitigations., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f6f557c 178/195: Fix various bugs in undo history loading/saving.,
Stefan Monnier <=
- [elpa] externals/undo-tree b8652b4 180/195: Null undo-tree-limit attemps to preserve all undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f0a6192 184/195: Proper fix to copy-undo-tree by writing bespoke copier., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 3090c4f 185/195: Temporarily increase max-lisp-eval-depth and max-specpdl-size when copying undo-trees., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8cf384f 187/195: Redraw visualizer when history-discarding invalidates it., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree d79fab9 193/195: Switch from cl to cl-lib., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bd65bb0 192/195: Fix hook function issue in Emacs 27., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e01a3e7 191/195: Fix some byte-compilation warnings., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 17454bd 084/195: Improved undo-tree-switch-branch behaviour., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f16ab5f 067/195: Trivial fix in Commentary., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e8215a7 078/195: Minor typo fixes in comments., Stefan Monnier, 2020/11/28