comparison lisp/savehist.el @ 66871:17486c85326e

(savehist-mode): Don't bother with `custom-set-minor-mode. (savehist-coding-system): Check XEmacs version. (history-length): Declare also at run time. (savehist-mode): Don't emit a message. Don't run the minor mode hook. Don't set the customize state. (savehist-minibuffer-hook): Special case for when minibuffer-history-variable is equal to t.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 14 Nov 2005 22:30:35 +0000
parents c948bf4e448e
children f24fb79ea180
comparison
equal deleted inserted replaced
66870:5b3373426595 66871:17486c85326e
2 2
3 ;; Copyright (C) 1997,2005 Free Software Foundation 3 ;; Copyright (C) 1997,2005 Free Software Foundation
4 4
5 ;; Author: Hrvoje Niksic <hniksic@xemacs.org> 5 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
6 ;; Keywords: minibuffer 6 ;; Keywords: minibuffer
7 ;; Version: 19 7 ;; Version: 23
8 8
9 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
10 10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
62 (defcustom savehist-mode nil 62 (defcustom savehist-mode nil
63 "Mode for automatic saving of minibuffer history. 63 "Mode for automatic saving of minibuffer history.
64 Set this by calling the `savehist-mode' function or using the customize 64 Set this by calling the `savehist-mode' function or using the customize
65 interface." 65 interface."
66 :type 'boolean 66 :type 'boolean
67 :set (if (fboundp 'custom-set-minor-mode) 67 :set (lambda (symbol value) (savehist-mode (or value 0)))
68 'custom-set-minor-mode
69 (lambda (symbol value) (funcall symbol (or value 0))))
70 :initialize 'custom-initialize-default 68 :initialize 'custom-initialize-default
71 :require 'savehist 69 :require 'savehist
72 :group 'savehist) 70 :group 'savehist)
73 71
74 (defcustom savehist-save-minibuffer-history t 72 (defcustom savehist-save-minibuffer-history t
133 "Hook called by `savehist-save' before saving the variables. 131 "Hook called by `savehist-save' before saving the variables.
134 You can use this hook to influence choice and content of variables to 132 You can use this hook to influence choice and content of variables to
135 save." 133 save."
136 :type 'hook) 134 :type 'hook)
137 135
138 (defvar savehist-coding-system 136 ;; This should be capable of representing characters used by Emacs.
139 ;; UTF-8 is usually preferable to ISO-2022-8 when available, but under 137 ;; We prefer UTF-8 over ISO 2022 because it is well-known outside
140 ;; XEmacs, UTF-8 is provided by external packages, and may not always be 138 ;; Mule. XEmacs prir to 21.5 had UTF-8 provided by an external
141 ;; available, so even if it currently is available, we prefer not to 139 ;; package which may not be loaded, which is why we check for version.
142 ;; use is. 140 (defvar savehist-coding-system (if (and (featurep 'xemacs)
143 (if (featurep 'xemacs) 'iso-2022-8 'utf-8) 141 (<= emacs-major-version 21)
142 (< emacs-minor-version 5))
143 'iso-2022-8 'utf-8)
144 "The coding system savehist uses for saving the minibuffer history. 144 "The coding system savehist uses for saving the minibuffer history.
145 Changing this value while Emacs is running is supported, but considered 145 Changing this value while Emacs is running is supported, but considered
146 unwise, unless you know what you are doing.") 146 unwise, unless you know what you are doing.")
147 147
148 ;; Internal variables. 148 ;; Internal variables.
155 "List of minibuffer histories. 155 "List of minibuffer histories.
156 The contents of this variable is built while Emacs is running, and saved 156 The contents of this variable is built while Emacs is running, and saved
157 along with minibuffer history. You can change its value off 157 along with minibuffer history. You can change its value off
158 `savehist-save-hook' to influence which variables are saved.") 158 `savehist-save-hook' to influence which variables are saved.")
159 159
160 (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion) 160 ;; Coding system without any conversion, used for calculating an
161 "Coding system without conversion, used for calculating internal checksums. 161 ;; internal checksum. Should be as fast as possible, ideally simply
162 Should be as fast as possible, ideally simply exposing the internal 162 ;; exposing the internal representation of buffer text.
163 representation of buffer text.") 163 (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion))
164 164
165 (defvar savehist-loaded nil 165 ;; Whether the history has already been loaded. This prevents
166 "Whether the history has already been loaded. 166 ;; toggling savehist-mode from destroying existing minibuffer history.
167 This prevents toggling `savehist-mode' from destroying existing 167 (defvar savehist-loaded nil)
168 minibuffer history.") 168
169 169 (when (featurep 'xemacs)
170 (eval-when-compile 170 ;; Must declare this under XEmacs, which doesn't have built-in
171 (when (featurep 'xemacs) 171 ;; minibuffer history truncation.
172 ;; Must declare this under XEmacs, which doesn't have built-in 172 (defvar history-length 100))
173 ;; minibuffer history truncation.
174 (defvar history-length 100)))
175 173
176 ;; Functions. 174 ;; Functions.
177 175
178 ;;;###autoload 176 ;;;###autoload
179 (defun savehist-mode (arg) 177 (defun savehist-mode (arg)
208 ;; effectively destroy the user's data at the next save. 206 ;; effectively destroy the user's data at the next save.
209 (setq savehist-mode nil) 207 (setq savehist-mode nil)
210 (savehist-uninstall) 208 (savehist-uninstall)
211 (signal (car errvar) (cdr errvar))))) 209 (signal (car errvar) (cdr errvar)))))
212 (savehist-install)) 210 (savehist-install))
213
214 ;; End with the usual minor-mode conventions normally provided
215 ;; transparently by define-minor-mode.
216 (run-hooks 'savehist-mode-hook)
217 (if (interactive-p)
218 (progn
219 (customize-mark-as-set 'savehist-mode)
220 (unless (current-message)
221 (message "Savehist mode %sabled" (if savehist-mode "en" "dis")))))
222 ;; Return the new setting. 211 ;; Return the new setting.
223 savehist-mode) 212 savehist-mode)
224 (add-minor-mode 'savehist-mode "") 213 (add-minor-mode 'savehist-mode "")
225 214
226 (defun savehist-load () 215 (defun savehist-load ()
371 t) 360 t)
372 ;; The attempt failed: the object is not printable. 361 ;; The attempt failed: the object is not printable.
373 (error nil)))))) 362 (error nil))))))
374 363
375 (defun savehist-minibuffer-hook () 364 (defun savehist-minibuffer-hook ()
376 (add-to-list 'savehist-minibuffer-history-variables 365 ;; XEmacs sets minibuffer-history-variable to t to mean "no history
377 minibuffer-history-variable)) 366 ;; is being recorded".
367 (unless (eq minibuffer-history-variable t)
368 (add-to-list 'savehist-minibuffer-history-variables
369 minibuffer-history-variable)))
378 370
379 (provide 'savehist) 371 (provide 'savehist)
380 372
381 ;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f 373 ;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f
382 374