Commit 624a232a authored by Stefan Monnier's avatar Stefan Monnier

* 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.
parent d2dea704
Pipeline #1659 passed with stage
in 63 minutes and 19 seconds
;;; savehist.el --- Save minibuffer history ;;; savehist.el --- Save minibuffer history -*- lexical-binding:t -*-
;; Copyright (C) 1997, 2005-2019 Free Software Foundation, Inc. ;; Copyright (C) 1997, 2005-2019 Free Software Foundation, Inc.
...@@ -62,8 +62,7 @@ ...@@ -62,8 +62,7 @@
"If non-nil, save all recorded minibuffer histories. "If non-nil, save all recorded minibuffer histories.
If you want to save only specific histories, use `savehist-save-hook' If you want to save only specific histories, use `savehist-save-hook'
to modify the value of `savehist-minibuffer-history-variables'." to modify the value of `savehist-minibuffer-history-variables'."
:type 'boolean :type 'boolean)
:group 'savehist)
(defcustom savehist-additional-variables () (defcustom savehist-additional-variables ()
"List of additional variables to save. "List of additional variables to save.
...@@ -77,13 +76,11 @@ non-nil. ...@@ -77,13 +76,11 @@ non-nil.
User options should be saved with the Customize interface. This User options should be saved with the Customize interface. This
list is useful for saving automatically updated variables that are not list is useful for saving automatically updated variables that are not
minibuffer histories, such as `compile-command' or `kill-ring'." minibuffer histories, such as `compile-command' or `kill-ring'."
:type '(repeat variable) :type '(repeat variable))
:group 'savehist)
(defcustom savehist-ignored-variables nil ;; '(command-history) (defcustom savehist-ignored-variables nil ;; '(command-history)
"List of additional variables not to save." "List of additional variables not to save."
:type '(repeat variable) :type '(repeat variable))
:group 'savehist)
(defcustom savehist-file (defcustom savehist-file
(locate-user-emacs-file "history" ".emacs-history") (locate-user-emacs-file "history" ".emacs-history")
...@@ -95,8 +92,7 @@ for more details. ...@@ -95,8 +92,7 @@ for more details.
If you want your minibuffer history shared between Emacs and XEmacs, If you want your minibuffer history shared between Emacs and XEmacs,
customize this value and make sure that `savehist-coding-system' is customize this value and make sure that `savehist-coding-system' is
set to a coding system that exists in both emacsen." set to a coding system that exists in both emacsen."
:type 'file :type 'file)
:group 'savehist)
(defcustom savehist-file-modes #o600 (defcustom savehist-file-modes #o600
"Default permissions of the history file. "Default permissions of the history file.
...@@ -104,27 +100,23 @@ This is decimal, not octal. The default is 384 (0600 in octal). ...@@ -104,27 +100,23 @@ This is decimal, not octal. The default is 384 (0600 in octal).
Set to nil to use the default permissions that Emacs uses, typically Set to nil to use the default permissions that Emacs uses, typically
mandated by umask. The default is a bit more restrictive to protect mandated by umask. The default is a bit more restrictive to protect
the user's privacy." the user's privacy."
:type 'integer :type 'integer)
:group 'savehist)
(defcustom savehist-autosave-interval (* 5 60) (defcustom savehist-autosave-interval (* 5 60)
"The interval between autosaves of minibuffer history. "The interval between autosaves of minibuffer history.
If set to nil, disables timer-based autosaving." If set to nil, disables timer-based autosaving."
:type '(choice (const :tag "Disabled" nil) :type '(choice (const :tag "Disabled" nil)
(integer :tag "Seconds")) (integer :tag "Seconds")))
:group 'savehist)
(defcustom savehist-mode-hook nil (defcustom savehist-mode-hook nil
"Hook called when Savehist mode is turned on." "Hook called when Savehist mode is turned on."
:type 'hook :type 'hook)
:group 'savehist)
(defcustom savehist-save-hook nil (defcustom savehist-save-hook nil
"Hook called by `savehist-save' before saving the variables. "Hook called by `savehist-save' before saving the variables.
You can use this hook to influence choice and content of variables You can use this hook to influence choice and content of variables
to save." to save."
:type 'hook :type 'hook)
:group 'savehist)
;; This should be capable of representing characters used by Emacs. ;; This should be capable of representing characters used by Emacs.
;; We prefer UTF-8 over ISO 2022 because it is well-known outside ;; 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,12 +142,6 @@ The contents of this variable is built while Emacs is running, and saved
along with minibuffer history. You can change its value off along with minibuffer history. You can change its value off
`savehist-save-hook' to influence which variables are saved.") `savehist-save-hook' to influence which variables are saved.")
(defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion)
"Coding system without any conversion.
This is used for calculating an internal checksum. Should be as fast
as possible, ideally simply exposing the internal representation of
buffer text.")
(defvar savehist-loaded nil (defvar savehist-loaded nil
"Whether the history has already been loaded. "Whether the history has already been loaded.
This prevents toggling Savehist mode from destroying existing This prevents toggling Savehist mode from destroying existing
...@@ -223,8 +209,8 @@ histories, which is probably undesirable." ...@@ -223,8 +209,8 @@ histories, which is probably undesirable."
Normally invoked by calling `savehist-mode' to set the minor mode. Normally invoked by calling `savehist-mode' to set the minor mode.
Installs `savehist-autosave' in `kill-emacs-hook' and on a timer. Installs `savehist-autosave' in `kill-emacs-hook' and on a timer.
To undo this, call `savehist-uninstall'." To undo this, call `savehist-uninstall'."
(add-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) (add-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook)
(add-hook 'kill-emacs-hook 'savehist-autosave) (add-hook 'kill-emacs-hook #'savehist-autosave)
;; Install an invocation of savehist-autosave on a timer. This ;; Install an invocation of savehist-autosave on a timer. This
;; should not cause noticeable delays for users -- savehist-autosave ;; should not cause noticeable delays for users -- savehist-autosave
;; executes in under 5 ms on my system. ;; executes in under 5 ms on my system.
...@@ -233,16 +219,16 @@ To undo this, call `savehist-uninstall'." ...@@ -233,16 +219,16 @@ To undo this, call `savehist-uninstall'."
(setq savehist-timer (setq savehist-timer
(if (featurep 'xemacs) (if (featurep 'xemacs)
(start-itimer (start-itimer
"savehist" 'savehist-autosave savehist-autosave-interval "savehist" #'savehist-autosave savehist-autosave-interval
savehist-autosave-interval) savehist-autosave-interval)
(run-with-timer savehist-autosave-interval (run-with-timer savehist-autosave-interval
savehist-autosave-interval 'savehist-autosave))))) savehist-autosave-interval #'savehist-autosave)))))
(defun savehist-uninstall () (defun savehist-uninstall ()
"Undo installing savehist. "Undo installing savehist.
Normally invoked by calling `savehist-mode' to unset the minor mode." Normally invoked by calling `savehist-mode' to unset the minor mode."
(remove-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook)
(remove-hook 'kill-emacs-hook 'savehist-autosave) (remove-hook 'kill-emacs-hook #'savehist-autosave)
(when savehist-timer (when savehist-timer
(if (featurep 'xemacs) (if (featurep 'xemacs)
(delete-itimer savehist-timer) (delete-itimer savehist-timer)
...@@ -327,7 +313,7 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved, ...@@ -327,7 +313,7 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
(insert ?\n)))))) (insert ?\n))))))
;; If autosaving, avoid writing if nothing has changed since the ;; If autosaving, avoid writing if nothing has changed since the
;; last write. ;; last write.
(let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion))) (let ((checksum (md5 (current-buffer) nil nil savehist-coding-system)))
(unless (and auto-save (equal checksum savehist-last-checksum)) (unless (and auto-save (equal checksum savehist-last-checksum))
;; Set file-precious-flag when saving the buffer because we ;; Set file-precious-flag when saving the buffer because we
;; don't want a half-finished write ruining the entire ;; don't want a half-finished write ruining the entire
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment