Merge changes from emacs-23 branch.
[bpt/emacs.git] / lisp / savehist.el
index d05a29f..15c841a 100644 (file)
@@ -1,8 +1,10 @@
 ;;; savehist.el --- Save minibuffer history.
 
-;; Copyright (C) 1997, 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation, Inc.
 
 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
+;; Maintainer: FSF
 ;; Keywords: minibuffer
 ;; Version: 24
 
   :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 you want to save only specific histories, use `savehist-save-hook' to
@@ -120,7 +111,8 @@ the user's privacy."
 (defcustom savehist-autosave-interval (* 5 60)
   "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
@@ -178,7 +170,7 @@ minibuffer history.")
 ;; 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.
@@ -188,11 +180,7 @@ previous minibuffer history to be loaded from `savehist-file'.
 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)
@@ -203,7 +191,7 @@ which is probably undesirable."
            ;; 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
@@ -211,11 +199,7 @@ which is probably undesirable."
         (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'.
@@ -351,7 +335,7 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
        (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)))))