aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshipmints2025-01-25 13:12:56 -0500
committerEli Zaretskii2025-02-01 22:08:03 +0200
commitc7889d0545d5e684fc5cec5d50e249ab9c24da44 (patch)
tree891caa4a302e28ae90a5044e426adaeeb85808f2
parent1292b64216f636bacea7fedf578b373f03affdd8 (diff)
downloademacs-c7889d0545d5e684fc5cec5d50e249ab9c24da44.tar.gz
emacs-c7889d0545d5e684fc5cec5d50e249ab9c24da44.zip
Add missing custom :set to 'savehist-autosave-interval'
* lisp/savehist.el (savehist-autosave-interval): Correctly reset 'savehist-timer' when 'savehist-autosave-interval' changes via setopt or a Customize command. (Bug#75834)
-rw-r--r--lisp/savehist.el45
1 files changed, 30 insertions, 15 deletions
diff --git a/lisp/savehist.el b/lisp/savehist.el
index 153e2db8706..7d755bc5047 100644
--- a/lisp/savehist.el
+++ b/lisp/savehist.el
@@ -96,11 +96,37 @@ the user's privacy."
96 :type '(choice (natnum :tag "Specify") 96 :type '(choice (natnum :tag "Specify")
97 (const :tag "Use default" :value nil))) 97 (const :tag "Use default" :value nil)))
98 98
99(defvar savehist-timer nil)
100
101(defun savehist--cancel-timer ()
102 "Cancel `savehist-autosave' timer, if set."
103 (when (timerp savehist-timer)
104 (cancel-timer savehist-timer))
105 (setq savehist-timer nil))
106
107(defun savehist--manage-timer ()
108 "Set or cancel an invocation of `savehist-autosave' on a timer.
109If `savehist-mode' is enabled, set the timer, otherwise cancel the timer.
110This should not cause noticeable delays for users -- `savehist-autosave'
111executes in under 5 ms on my system."
112 (if (and savehist-mode
113 savehist-autosave-interval
114 (null savehist-timer))
115 (setq savehist-timer
116 (run-with-timer savehist-autosave-interval
117 savehist-autosave-interval #'savehist-autosave))
118 (savehist--cancel-timer)))
119
99(defcustom savehist-autosave-interval (* 5 60) 120(defcustom savehist-autosave-interval (* 5 60)
100 "The interval between autosaves of minibuffer history. 121 "The interval between autosaves of minibuffer history.
101If set to nil, disables timer-based autosaving." 122If set to nil, disables timer-based autosaving.
123Use `setopt' or Customize commands to set this option."
102 :type '(choice (const :tag "Disabled" nil) 124 :type '(choice (const :tag "Disabled" nil)
103 (integer :tag "Seconds"))) 125 (integer :tag "Seconds"))
126 :set (lambda (sym val)
127 (set-default sym val)
128 (savehist--cancel-timer)
129 (savehist--manage-timer)))
104 130
105(defcustom savehist-mode-hook nil 131(defcustom savehist-mode-hook nil
106 "Hook called when Savehist mode is turned on." 132 "Hook called when Savehist mode is turned on."
@@ -122,8 +148,6 @@ unwise, unless you know what you are doing.")
122 148
123;; Internal variables. 149;; Internal variables.
124 150
125(defvar savehist-timer nil)
126
127(defvar savehist-last-checksum nil) 151(defvar savehist-last-checksum nil)
128 152
129(defvar savehist-minibuffer-history-variables nil 153(defvar savehist-minibuffer-history-variables nil
@@ -197,23 +221,14 @@ Installs `savehist-autosave' in `kill-emacs-hook' and on a timer.
197To undo this, call `savehist-uninstall'." 221To undo this, call `savehist-uninstall'."
198 (add-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) 222 (add-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook)
199 (add-hook 'kill-emacs-hook #'savehist-autosave) 223 (add-hook 'kill-emacs-hook #'savehist-autosave)
200 ;; Install an invocation of savehist-autosave on a timer. This 224 (savehist--manage-timer))
201 ;; should not cause noticeable delays for users -- savehist-autosave
202 ;; executes in under 5 ms on my system.
203 (when (and savehist-autosave-interval
204 (null savehist-timer))
205 (setq savehist-timer
206 (run-with-timer savehist-autosave-interval
207 savehist-autosave-interval #'savehist-autosave))))
208 225
209(defun savehist-uninstall () 226(defun savehist-uninstall ()
210 "Undo installing savehist. 227 "Undo installing savehist.
211Normally invoked by calling `savehist-mode' to unset the minor mode." 228Normally invoked by calling `savehist-mode' to unset the minor mode."
212 (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) 229 (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook)
213 (remove-hook 'kill-emacs-hook #'savehist-autosave) 230 (remove-hook 'kill-emacs-hook #'savehist-autosave)
214 (when savehist-timer 231 (savehist--manage-timer))
215 (cancel-timer savehist-timer)
216 (setq savehist-timer nil)))
217 232
218(defvar savehist--has-given-file-warning nil) 233(defvar savehist--has-given-file-warning nil)
219(defun savehist-save (&optional auto-save) 234(defun savehist-save (&optional auto-save)