branch: externals/vundo
commit e6c150b84213d7b65b0482086da2c96fb8e11f32
Author: Paul Nelson <[email protected]>
Commit: Yuan Fu <[email protected]>

    vundo-goto-last-saved: avoid erroneous message
    
    * vundo.el (vundo-goto-last-saved): Wrap entire function body in
    vundo--check-for-command so that when the buffer needs refreshing, it
    does not print "Node saved ..."
    
    * test/vundo-test.el (vundo-test--goto-last-saved-refresh): New test.
    
    Fixes #122.
---
 test/vundo-test.el | 13 +++++++++++++
 vundo.el           | 22 +++++++++++-----------
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/test/vundo-test.el b/test/vundo-test.el
index afad1cb9c1..cb7961f4d5 100644
--- a/test/vundo-test.el
+++ b/test/vundo-test.el
@@ -259,6 +259,19 @@ Sans ending newline."
                  500000)))
    (garbage-collect)))
 
+(ert-deftest vundo-test--goto-last-saved-refresh ()
+  "On stale vundo buffers, goto-last-saved should just refresh."
+  (vundo-test--setup
+   (insert "A") (undo-boundary)
+   (push (cons t (current-time)) buffer-undo-list) (undo-boundary)
+   (insert "B") (undo-boundary)
+   (with-current-buffer (vundo-1 (current-buffer))
+     (with-current-buffer vundo--orig-buffer
+       (goto-char (point-max))
+       (insert "C")
+       (undo-boundary))
+     (should (equal (vundo-goto-last-saved 1) "Refresh")))))
+
 (provide 'vundo-test)
 
 ;;; vundo-test.el ends here
diff --git a/vundo.el b/vundo.el
index 115045fdc2..8b9519292d 100644
--- a/vundo.el
+++ b/vundo.el
@@ -1399,22 +1399,22 @@ If ARG < 0, move forward."
 With numeric prefix ARG, move that many saved nodes back (ARG<0
 moves forward in history)."
   (interactive "p")
-  (if-let* ((cur (vundo--current-node vundo--prev-mod-list))
-            (dest (vundo--find-last-saved cur arg)))
-      (progn
-        (unless (eq cur dest)
-          (vundo--check-for-command
+  (vundo--check-for-command
+   (if-let* ((cur (vundo--current-node vundo--prev-mod-list))
+             (dest (vundo--find-last-saved cur arg)))
+       (progn
+         (unless (eq cur dest)
            (vundo--move-to-node
             cur dest vundo--orig-buffer vundo--prev-mod-list)
            (vundo--trim-undo-list
             vundo--orig-buffer dest vundo--prev-mod-list)
            (vundo--refresh-buffer
-            vundo--orig-buffer (current-buffer) 'incremental)))
-        (message "Node saved %s"
-                 (format-time-string
-                  "%F %r"
-                  (vundo--node-timestamp vundo--prev-mod-list dest))))
-    (message "No such saved node")))
+            vundo--orig-buffer (current-buffer) 'incremental))
+         (message "Node saved %s"
+                  (format-time-string
+                   "%F %r"
+                   (vundo--node-timestamp vundo--prev-mod-list dest))))
+     (message "No such saved node"))))
 
 (defun vundo-goto-next-saved (arg)
   "Go to the ARGth saved node after the current node (default 1).

Reply via email to