emacs-diffs
[Top][All Lists]
Advanced

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

master f5b172f 2/2: Avoid asking repeatedly about reloading bookmarks fi


From: Stefan Kangas
Subject: master f5b172f 2/2: Avoid asking repeatedly about reloading bookmarks file
Date: Sun, 14 Feb 2021 18:53:12 -0500 (EST)

branch: master
commit f5b172fb6e41e9bf75acd1fd94325a13d75987bf
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Avoid asking repeatedly about reloading bookmarks file
    
    * lisp/bookmark.el (bookmark-maybe-load-default-file): Reload watched
    bookmarks file only if its mtime has changed since the last query.
    This avoids asking repeatedly about reloading the bookmarks file if
    the user has already said "no" to a previous query.
    (bookmark--watch-file-already-queried-p): New function.
    (bookmark--watch-already-asked-mtime): New variable.
---
 lisp/bookmark.el | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 5cdde25..98797a0 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1040,6 +1040,14 @@ it to the name of the bookmark currently being set, 
advancing
        (car dired-directory)))
     (t (error "Buffer not visiting a file or directory")))))
 
+(defvar bookmark--watch-already-asked-mtime nil
+  "Mtime for which we already queried about reloading.")
+
+(defun bookmark--watch-file-already-queried-p (new-mtime)
+  ;; Don't ask repeatedly if user already said "no" to reloading a
+  ;; file with this mtime:
+  (prog1 (equal new-mtime bookmark--watch-already-asked-mtime)
+    (setq bookmark--watch-already-asked-mtime new-mtime)))
 
 (defun bookmark-maybe-load-default-file ()
   "If bookmarks have not been loaded from the default place, load them."
@@ -1048,13 +1056,15 @@ it to the name of the bookmark currently being set, 
advancing
               (file-readable-p bookmark-default-file)
               (bookmark-load bookmark-default-file t t)))
         ((and bookmark-watch-bookmark-file
-              (not (equal (nth 5 (file-attributes
-                                  (car bookmark-bookmarks-timestamp)))
-                          (cdr bookmark-bookmarks-timestamp)))
-              (or (eq 'silent bookmark-watch-bookmark-file)
-                  (yes-or-no-p
-                   (format "Bookmarks %s changed on disk.  Reload? "
-                           (car bookmark-bookmarks-timestamp)))))
+              (let ((new-mtime (nth 5 (file-attributes
+                                       (car bookmark-bookmarks-timestamp))))
+                    (old-mtime (cdr bookmark-bookmarks-timestamp)))
+                (and (not (equal new-mtime old-mtime))
+                     (not (bookmark--watch-file-already-queried-p new-mtime))
+                     (or (eq 'silent bookmark-watch-bookmark-file)
+                         (yes-or-no-p
+                          (format "Bookmarks %s changed on disk.  Reload? "
+                                  (car bookmark-bookmarks-timestamp)))))))
          (bookmark-load (car bookmark-bookmarks-timestamp) t t))))
 
 (defun bookmark-maybe-sort-alist ()



reply via email to

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