-;;; savehist.el --- Save minibuffer history.
+;;; savehist.el --- Save minibuffer history
-;; Copyright (C) 1997, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2005-2011 Free Software Foundation, Inc.
;; Author: Hrvoje Niksic <hniksic@xemacs.org>
+;; Maintainer: FSF
;; Keywords: minibuffer
;; Version: 24
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
:version "22.1"
:group 'minibuffer)
-;;;###autoload
-(defcustom savehist-mode nil
- "Mode for automatic saving of minibuffer history.
-Set this by calling the `savehist-mode' function or using the customize
-interface."
- :type 'boolean
- :set (lambda (symbol value) (savehist-mode (or value 0)))
- :initialize 'custom-initialize-default
- :require 'savehist
- :group 'savehist)
-
(defcustom savehist-save-minibuffer-history t
- "*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' to
modify the value of `savehist-minibuffer-history-variables'."
:type 'boolean
:group 'savehist)
(defcustom savehist-additional-variables ()
- "*List of additional variables to save.
+ "List of additional variables to save.
Each element is a symbol whose value will be persisted across Emacs
sessions that use savehist. The contents of variables should be
printable with the Lisp printer. You don't need to add minibuffer
:group 'savehist)
(defcustom savehist-ignored-variables nil ;; '(command-history)
- "*List of additional variables not to save."
+ "List of additional variables not to save."
:type '(repeat variable)
:group 'savehist)
(defcustom savehist-file
- (cond
- ;; Backward compatibility with previous versions of savehist.
- ((file-exists-p "~/.emacs-history") "~/.emacs-history")
- ((and (not (featurep 'xemacs)) (file-directory-p user-emacs-directory))
- (concat user-emacs-directory "history"))
- ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/"))
- "~/.xemacs/history")
- ;; For users without `~/.emacs.d/' or `~/.xemacs/'.
- (t "~/.emacs-history"))
- "*File name where minibuffer history is saved to and loaded from.
+ (locate-user-emacs-file "history" ".emacs-history")
+ "File name where minibuffer history is saved to and loaded from.
The minibuffer history is a series of Lisp expressions loaded
automatically when `savehist-mode' is turned on. See `savehist-mode'
for more details.
:group 'savehist)
(defcustom savehist-file-modes #o600
- "*Default permissions of the history file.
+ "Default permissions of the history file.
This is decimal, not octal. The default is 384 (0600 in octal).
Set to nil to use the default permissions that Emacs uses, typically
mandated by umask. The default is a bit more restrictive to protect
:group 'savehist)
(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."
- :type 'integer
+ :type '(choice (const :tag "Disabled" nil)
+ (integer :tag "Seconds"))
:group 'savehist)
(defcustom savehist-mode-hook nil
;; Functions.
;;;###autoload
-(defun savehist-mode (arg)
+(define-minor-mode savehist-mode
"Toggle savehist-mode.
Positive ARG turns on `savehist-mode'. When on, savehist-mode causes
minibuffer history to be saved periodically and when exiting Emacs.
This mode should normally be turned on from your Emacs init file.
Calling it at any other time replaces your current minibuffer histories,
which is probably undesirable."
- (interactive "P")
- (setq savehist-mode
- (if (null arg)
- (not savehist-mode)
- (> (prefix-numeric-value arg) 0)))
+ :global t
(if (not savehist-mode)
(savehist-uninstall)
(when (and (not savehist-loaded)
;; coding cookie to convey that information. That way, if
;; the user changes the value of savehist-coding-system,
;; we can still correctly load the old file.
- (load savehist-file nil (not (interactive-p)))
+ (load savehist-file nil (not (called-interactively-p 'interactive)))
(setq savehist-loaded t))
(error
;; Don't install the mode if reading failed. Doing so would
(setq savehist-mode nil)
(savehist-uninstall)
(signal (car errvar) (cdr errvar)))))
- (savehist-install)
- (run-hooks 'savehist-mode-hook))
- ;; Return the new setting.
- savehist-mode)
-(add-minor-mode 'savehist-mode "")
+ (savehist-install)))
(defun savehist-load ()
"Load the variables stored in `savehist-file' and turn on `savehist-mode'.
(cancel-timer savehist-timer))
(setq savehist-timer nil)))
+;; From XEmacs?
+(defvar print-readably)
+(defvar print-string-length)
+
(defun savehist-save (&optional auto-save)
"Save the values of minibuffer history variables.
Unbound symbols referenced in `savehist-additional-variables' are ignored.
(dolist (elt value)
(let ((start (point)))
(insert " ")
- (prin1 elt (current-buffer))
- ;; Try to read the element we just printed.
+ ;; Try to print and then to read an element.
(condition-case nil
- (save-excursion
- (goto-char start)
- (read (current-buffer)))
+ (progn
+ (prin1 elt (current-buffer))
+ (save-excursion
+ (goto-char start)
+ (read (current-buffer))))
(error
- ;; If reading it gets an error, comment it out.
+ ;; If writing or reading gave an error, comment it out.
(goto-char start)
(insert "\n")
(while (not (eobp))
(let ((file-precious-flag t)
(coding-system-for-write savehist-coding-system))
(write-region (point-min) (point-max) savehist-file nil
- (unless (interactive-p) 'quiet)))
+ (unless (called-interactively-p 'interactive) 'quiet)))
(when savehist-file-modes
(set-file-modes savehist-file savehist-file-modes))
(setq savehist-last-checksum checksum)))))
(provide 'savehist)
\f
-;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f
;;; savehist.el ends here