emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/undo-tree 443d74c 111/195: Avoid triggering error when


From: Stefan Monnier
Subject: [elpa] externals/undo-tree 443d74c 111/195: Avoid triggering error when saving undo history when there's nothing to save.
Date: Sat, 28 Nov 2020 13:41:33 -0500 (EST)

branch: externals/undo-tree
commit 443d74c7dee94127ed1e7c623d9839a034d30803
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>

    Avoid triggering error when saving undo history when there's nothing to 
save.
---
 undo-tree.el | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/undo-tree.el b/undo-tree.el
index 26cfacd..a4e9cf2 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -692,6 +692,8 @@
 ;;
 ;; Version 0.5.2
 ;; * added `~' to end of default history save-file name
+;; * avoid error in `undo-tree-save-history' when undo is disabled in buffer
+;;   or buffer has no undo information to save
 ;;
 ;; Version 0.5.1
 ;; * remove now unnecessary compatibility hack for `called-interactively-p'
@@ -2987,28 +2989,29 @@ Otherwise, prompt for one.
 If OVERWRITE is non-nil, any existing file will be overwritten
 without asking for confirmation."
   (interactive)
-  (condition-case nil
-      (undo-tree-kill-visualizer)
-    (error (undo-tree-clear-visualizer-data buffer-undo-tree)))
   (undo-list-transfer-to-tree)
-  (let ((buff (current-buffer))
-       (tree (copy-undo-tree buffer-undo-tree)))
-    ;; get filename
-    (unless filename
-      (setq filename
-           (if buffer-file-name
-               (undo-tree-make-history-save-file-name)
-             (expand-file-name (read-file-name "File to save in: ") nil))))
-    (when (or (not (file-exists-p filename))
-             overwrite
-             (yes-or-no-p (format "Overwrite \"%s\"? " filename)))
-      ;; discard undo-tree object pool before saving
-      (setf (undo-tree-object-pool tree) nil)
-      ;; print undo-tree to file
-      (with-temp-file filename
-       (prin1 (sha1 buff) (current-buffer))
-       (terpri (current-buffer))
-       (let ((print-circle t)) (prin1 tree (current-buffer)))))))
+  (when (and buffer-undo-tree (not (eq buffer-undo-tree t)))
+    (condition-case nil
+       (undo-tree-kill-visualizer)
+      (error (undo-tree-clear-visualizer-data buffer-undo-tree)))
+    (let ((buff (current-buffer))
+         (tree (copy-undo-tree buffer-undo-tree)))
+      ;; get filename
+      (unless filename
+       (setq filename
+             (if buffer-file-name
+                 (undo-tree-make-history-save-file-name)
+               (expand-file-name (read-file-name "File to save in: ") nil))))
+      (when (or (not (file-exists-p filename))
+               overwrite
+               (yes-or-no-p (format "Overwrite \"%s\"? " filename)))
+       ;; discard undo-tree object pool before saving
+       (setf (undo-tree-object-pool tree) nil)
+       ;; print undo-tree to file
+       (with-temp-file filename
+         (prin1 (sha1 buff) (current-buffer))
+         (terpri (current-buffer))
+         (let ((print-circle t)) (prin1 tree (current-buffer))))))))
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]