From: Stefan Kangas Date: Sun, 14 Feb 2021 23:43:15 +0000 (+0100) Subject: Avoid asking repeatedly about reloading bookmarks file X-Git-Tag: emacs-28.0.90~3727 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f5b172fb6e41e9bf75acd1fd94325a13d75987bf;p=emacs.git 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. --- diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 5cdde258e0b..98797a0de2a 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 ()