diff options
| author | Stefan Monnier | 2019-05-14 14:00:58 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-05-14 14:00:58 -0400 |
| commit | 624a232a8df44f8ca82a2900f88a4c5ef324bf53 (patch) | |
| tree | 1b71446b308bbfd90a26fb49ed42b9e7ef645783 | |
| parent | d2dea70415ca7ec390a2de11b224ab4cbb2c6b55 (diff) | |
| download | emacs-624a232a8df44f8ca82a2900f88a4c5ef324bf53.tar.gz emacs-624a232a8df44f8ca82a2900f88a4c5ef324bf53.zip | |
* lisp/savehist.el: Use lexical-binding
Remove redundant :group args.
(savehist-no-conversion): Remove constant.
(savehist-save): Use savehist-coding-system instead since it's no slower.
| -rw-r--r-- | lisp/savehist.el | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/lisp/savehist.el b/lisp/savehist.el index 1eab18ef763..fb3b7483397 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; savehist.el --- Save minibuffer history | 1 | ;;; savehist.el --- Save minibuffer history -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1997, 2005-2019 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1997, 2005-2019 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -62,8 +62,7 @@ | |||
| 62 | "If non-nil, save all recorded minibuffer histories. | 62 | "If non-nil, save all recorded minibuffer histories. |
| 63 | If you want to save only specific histories, use `savehist-save-hook' | 63 | If you want to save only specific histories, use `savehist-save-hook' |
| 64 | to modify the value of `savehist-minibuffer-history-variables'." | 64 | to modify the value of `savehist-minibuffer-history-variables'." |
| 65 | :type 'boolean | 65 | :type 'boolean) |
| 66 | :group 'savehist) | ||
| 67 | 66 | ||
| 68 | (defcustom savehist-additional-variables () | 67 | (defcustom savehist-additional-variables () |
| 69 | "List of additional variables to save. | 68 | "List of additional variables to save. |
| @@ -77,13 +76,11 @@ non-nil. | |||
| 77 | User options should be saved with the Customize interface. This | 76 | User options should be saved with the Customize interface. This |
| 78 | list is useful for saving automatically updated variables that are not | 77 | list is useful for saving automatically updated variables that are not |
| 79 | minibuffer histories, such as `compile-command' or `kill-ring'." | 78 | minibuffer histories, such as `compile-command' or `kill-ring'." |
| 80 | :type '(repeat variable) | 79 | :type '(repeat variable)) |
| 81 | :group 'savehist) | ||
| 82 | 80 | ||
| 83 | (defcustom savehist-ignored-variables nil ;; '(command-history) | 81 | (defcustom savehist-ignored-variables nil ;; '(command-history) |
| 84 | "List of additional variables not to save." | 82 | "List of additional variables not to save." |
| 85 | :type '(repeat variable) | 83 | :type '(repeat variable)) |
| 86 | :group 'savehist) | ||
| 87 | 84 | ||
| 88 | (defcustom savehist-file | 85 | (defcustom savehist-file |
| 89 | (locate-user-emacs-file "history" ".emacs-history") | 86 | (locate-user-emacs-file "history" ".emacs-history") |
| @@ -95,8 +92,7 @@ for more details. | |||
| 95 | If you want your minibuffer history shared between Emacs and XEmacs, | 92 | If you want your minibuffer history shared between Emacs and XEmacs, |
| 96 | customize this value and make sure that `savehist-coding-system' is | 93 | customize this value and make sure that `savehist-coding-system' is |
| 97 | set to a coding system that exists in both emacsen." | 94 | set to a coding system that exists in both emacsen." |
| 98 | :type 'file | 95 | :type 'file) |
| 99 | :group 'savehist) | ||
| 100 | 96 | ||
| 101 | (defcustom savehist-file-modes #o600 | 97 | (defcustom savehist-file-modes #o600 |
| 102 | "Default permissions of the history file. | 98 | "Default permissions of the history file. |
| @@ -104,27 +100,23 @@ This is decimal, not octal. The default is 384 (0600 in octal). | |||
| 104 | Set to nil to use the default permissions that Emacs uses, typically | 100 | Set to nil to use the default permissions that Emacs uses, typically |
| 105 | mandated by umask. The default is a bit more restrictive to protect | 101 | mandated by umask. The default is a bit more restrictive to protect |
| 106 | the user's privacy." | 102 | the user's privacy." |
| 107 | :type 'integer | 103 | :type 'integer) |
| 108 | :group 'savehist) | ||
| 109 | 104 | ||
| 110 | (defcustom savehist-autosave-interval (* 5 60) | 105 | (defcustom savehist-autosave-interval (* 5 60) |
| 111 | "The interval between autosaves of minibuffer history. | 106 | "The interval between autosaves of minibuffer history. |
| 112 | If set to nil, disables timer-based autosaving." | 107 | If set to nil, disables timer-based autosaving." |
| 113 | :type '(choice (const :tag "Disabled" nil) | 108 | :type '(choice (const :tag "Disabled" nil) |
| 114 | (integer :tag "Seconds")) | 109 | (integer :tag "Seconds"))) |
| 115 | :group 'savehist) | ||
| 116 | 110 | ||
| 117 | (defcustom savehist-mode-hook nil | 111 | (defcustom savehist-mode-hook nil |
| 118 | "Hook called when Savehist mode is turned on." | 112 | "Hook called when Savehist mode is turned on." |
| 119 | :type 'hook | 113 | :type 'hook) |
| 120 | :group 'savehist) | ||
| 121 | 114 | ||
| 122 | (defcustom savehist-save-hook nil | 115 | (defcustom savehist-save-hook nil |
| 123 | "Hook called by `savehist-save' before saving the variables. | 116 | "Hook called by `savehist-save' before saving the variables. |
| 124 | You can use this hook to influence choice and content of variables | 117 | You can use this hook to influence choice and content of variables |
| 125 | to save." | 118 | to save." |
| 126 | :type 'hook | 119 | :type 'hook) |
| 127 | :group 'savehist) | ||
| 128 | 120 | ||
| 129 | ;; This should be capable of representing characters used by Emacs. | 121 | ;; This should be capable of representing characters used by Emacs. |
| 130 | ;; We prefer UTF-8 over ISO 2022 because it is well-known outside | 122 | ;; We prefer UTF-8 over ISO 2022 because it is well-known outside |
| @@ -150,12 +142,6 @@ The contents of this variable is built while Emacs is running, and saved | |||
| 150 | along with minibuffer history. You can change its value off | 142 | along with minibuffer history. You can change its value off |
| 151 | `savehist-save-hook' to influence which variables are saved.") | 143 | `savehist-save-hook' to influence which variables are saved.") |
| 152 | 144 | ||
| 153 | (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion) | ||
| 154 | "Coding system without any conversion. | ||
| 155 | This is used for calculating an internal checksum. Should be as fast | ||
| 156 | as possible, ideally simply exposing the internal representation of | ||
| 157 | buffer text.") | ||
| 158 | |||
| 159 | (defvar savehist-loaded nil | 145 | (defvar savehist-loaded nil |
| 160 | "Whether the history has already been loaded. | 146 | "Whether the history has already been loaded. |
| 161 | This prevents toggling Savehist mode from destroying existing | 147 | This prevents toggling Savehist mode from destroying existing |
| @@ -223,8 +209,8 @@ histories, which is probably undesirable." | |||
| 223 | Normally invoked by calling `savehist-mode' to set the minor mode. | 209 | Normally invoked by calling `savehist-mode' to set the minor mode. |
| 224 | Installs `savehist-autosave' in `kill-emacs-hook' and on a timer. | 210 | Installs `savehist-autosave' in `kill-emacs-hook' and on a timer. |
| 225 | To undo this, call `savehist-uninstall'." | 211 | To undo this, call `savehist-uninstall'." |
| 226 | (add-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) | 212 | (add-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) |
| 227 | (add-hook 'kill-emacs-hook 'savehist-autosave) | 213 | (add-hook 'kill-emacs-hook #'savehist-autosave) |
| 228 | ;; Install an invocation of savehist-autosave on a timer. This | 214 | ;; Install an invocation of savehist-autosave on a timer. This |
| 229 | ;; should not cause noticeable delays for users -- savehist-autosave | 215 | ;; should not cause noticeable delays for users -- savehist-autosave |
| 230 | ;; executes in under 5 ms on my system. | 216 | ;; executes in under 5 ms on my system. |
| @@ -233,16 +219,16 @@ To undo this, call `savehist-uninstall'." | |||
| 233 | (setq savehist-timer | 219 | (setq savehist-timer |
| 234 | (if (featurep 'xemacs) | 220 | (if (featurep 'xemacs) |
| 235 | (start-itimer | 221 | (start-itimer |
| 236 | "savehist" 'savehist-autosave savehist-autosave-interval | 222 | "savehist" #'savehist-autosave savehist-autosave-interval |
| 237 | savehist-autosave-interval) | 223 | savehist-autosave-interval) |
| 238 | (run-with-timer savehist-autosave-interval | 224 | (run-with-timer savehist-autosave-interval |
| 239 | savehist-autosave-interval 'savehist-autosave))))) | 225 | savehist-autosave-interval #'savehist-autosave))))) |
| 240 | 226 | ||
| 241 | (defun savehist-uninstall () | 227 | (defun savehist-uninstall () |
| 242 | "Undo installing savehist. | 228 | "Undo installing savehist. |
| 243 | Normally invoked by calling `savehist-mode' to unset the minor mode." | 229 | Normally invoked by calling `savehist-mode' to unset the minor mode." |
| 244 | (remove-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) | 230 | (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) |
| 245 | (remove-hook 'kill-emacs-hook 'savehist-autosave) | 231 | (remove-hook 'kill-emacs-hook #'savehist-autosave) |
| 246 | (when savehist-timer | 232 | (when savehist-timer |
| 247 | (if (featurep 'xemacs) | 233 | (if (featurep 'xemacs) |
| 248 | (delete-itimer savehist-timer) | 234 | (delete-itimer savehist-timer) |
| @@ -327,7 +313,7 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved, | |||
| 327 | (insert ?\n)))))) | 313 | (insert ?\n)))))) |
| 328 | ;; If autosaving, avoid writing if nothing has changed since the | 314 | ;; If autosaving, avoid writing if nothing has changed since the |
| 329 | ;; last write. | 315 | ;; last write. |
| 330 | (let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion))) | 316 | (let ((checksum (md5 (current-buffer) nil nil savehist-coding-system))) |
| 331 | (unless (and auto-save (equal checksum savehist-last-checksum)) | 317 | (unless (and auto-save (equal checksum savehist-last-checksum)) |
| 332 | ;; Set file-precious-flag when saving the buffer because we | 318 | ;; Set file-precious-flag when saving the buffer because we |
| 333 | ;; don't want a half-finished write ruining the entire | 319 | ;; don't want a half-finished write ruining the entire |