annotate lisp/savehist.el @ 66311:cf092daa39de

(make-temp-file): Moved to files.el. (get-buffer-window-list): Moved to window.el.
author Richard M. Stallman <rms@gnu.org>
date Sat, 22 Oct 2005 15:35:45 +0000
parents e52f114d1dc3
children 71bac038fa51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
1 ;;; savehist.el --- Save minibuffer history.
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
3 ;; Copyright (C) 1997, 2005 Free Software Foundation
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: minibuffer
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
7 ;; Version: 7
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
28 ;; Many editors (e.g. Vim) have the feature of saving minibuffer
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
29 ;; history to an external file after exit. This package provides the
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
30 ;; same feature in Emacs. When Emacs is about the exit,
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; `savehist-save' will dump the contents of various minibuffer
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; histories (as determined by `savehist-history-variables') to a save
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; file (`~/.emacs-history' by default). Although the package was
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; designed for saving the minibuffer histories, any variables can be
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; saved that way.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; To use savehist, put the following to `~/.emacs':
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; (require 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (savehist-load)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Be sure to have `savehist.el' in a directory that is in your
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; load-path, and byte-compile it.
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
44
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; Code:
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
47 (require 'custom)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
48
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; User variables
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (defgroup savehist nil
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 "Save minibuffer history."
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 :group 'minibuffer)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (defcustom savehist-history-variables
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 '(
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Catch-all minibuffer history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 minibuffer-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; File-oriented commands
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 file-name-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; Regexp-related reads
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 regexp-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; Searches in minibuffer (via `M-r' and such)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 minibuffer-history-search-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; Query replace
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 query-replace-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; eval-expression (`M-:')
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 read-expression-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; shell-command (`M-!')
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 shell-command-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; compile
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 compile-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; find-tag (`M-.')
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 find-tag-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; grep
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 grep-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; Viper stuff
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 vip-ex-history vip-search-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 vip-replace1-history vip-replace2-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 vip-shell-history vip-search-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; XEmacs-specific:
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; Buffer-related commands
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 buffer-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; Reads of variables and functions
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 variable-history function-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Extended commands
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 read-command-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; Info, lookup, and bookmark historys
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 Info-minibuffer-history
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
92 Info-search-history
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 Manual-page-minibuffer-history
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; Emacs-specific:
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; Extended commands
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 extended-command-history)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 "*List of symbols to be saved.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 Every symbol should refer to a variable. The variable will be saved
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 only if it is bound and has a non-nil value. Thus it is safe to
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 specify a superset of the variables a user is expected to want to
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 save.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
104 Default value contains minibuffer history variables used by Emacs, XEmacs,
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
105 and Viper (uh-oh). Note that, if you customize this variable, you
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
106 can lose the benefit of future versions of Emacs adding new values to
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
107 the list. Because of that it might be more useful to add values using
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
108 `add-to-list'."
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 :type '(repeat (symbol :tag "Variable"))
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 :group 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defcustom savehist-file "~/.emacs-history"
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 "*File name to save minibuffer history to.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 The minibuffer history is a series of Lisp expressions, which should be
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 loaded using `savehist-load' from your .emacs. See `savehist-load' for
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 more details."
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 :type 'file
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 :group 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (defcustom savehist-length 100
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "*Maximum length of a minibuffer list.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 If set to nil, the length is unlimited."
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 :type '(choice integer
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (const :tag "Unlimited" nil))
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 :group 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
127 (defcustom savehist-modes #o600
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "*Default permissions of the history file.
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
129 This is decimal, not octal. The default is 384 (0600 in octal).
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
130 Set to nil to use the default permissions that Emacs uses, typically
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
131 mandated by umask. The default is a bit more restrictive to protect
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
132 the user's privacy."
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
133 :type 'integer
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
134 :group 'savehist)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
135
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
136 (defcustom savehist-autosave-interval (* 5 60)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
137 "*The interval during which savehist should autosave the history buffer."
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 :type 'integer
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 :group 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
66205
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
141 (defvar savehist-coding-system
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
142 ;; UTF-8 is usually preferable to ISO-2022-8 when available, but under
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
143 ;; XEmacs, UTF-8 is provided by external packages, and may not always be
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
144 ;; available, so even if it currently is available, we prefer not to
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
145 ;; use is.
e52f114d1dc3 (savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66191
diff changeset
146 (if (featurep 'xemacs) 'iso-2022-8 'utf-8)
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
147 "The coding system savehist uses for saving the minibuffer history.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
148 Changing this value while Emacs is running is supported, but considered
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
149 unwise, unless you know what you are doing.")
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
150
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
151 ;; Internal variables.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
152
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
153 (defvar savehist-timer nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
154
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
155 (defvar savehist-last-checksum nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
156
66121
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
157 (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion)
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
158 ;; FIXME: Why not use savehist-coding-system?
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
159 "Coding system without conversion, only used for calculating checksums.")
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; Functions
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;;;###autoload
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defun savehist-load (&optional no-hook)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 "Load the minibuffer histories from `savehist-file'.
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 Unless NO-HOOK is specified, the function will also add the save function
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
167 to `kill-emacs-hook' and on a timer, ensuring that the minibuffer contents
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
168 will be saved before leaving Emacs.
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 This function should be normally used from your Emacs init file. Since it
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 removes your current minibuffer histories, it is unwise to call it at any
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 other time."
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (interactive "P")
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (unless no-hook
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
175 (add-hook 'kill-emacs-hook 'savehist-autosave)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
176 ;; Install an invocation of savehist-autosave on a timer. This
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
177 ;; should not cause a noticeable delay -- savehist-autosave
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
178 ;; executes in under 5 ms on my system.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
179 (unless savehist-timer
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
180 (setq savehist-timer
66191
3b427dc36c6e (savehist-load): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66129
diff changeset
181 (if (featurep 'xemacs)
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
182 (start-itimer
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
183 "savehist" 'savehist-autosave savehist-autosave-interval
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
184 savehist-autosave-interval)
66121
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
185 (run-with-idle-timer savehist-autosave-interval savehist-autosave-interval
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
186 'savehist-autosave)))))
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
187 ;; Don't set coding-system-for-read here. We rely on autodetection
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
188 ;; and the coding cookie to convey that information. That way, if
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
189 ;; the user changes the value of savehist-coding-system, we can
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
190 ;; still correctly load the old file.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
191 (load savehist-file t (not (interactive-p))))
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;;;###autoload
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
194 (defun savehist-save (&optional auto-save)
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "Save the histories from `savehist-history-variables' to `savehist-file'.
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
196 Unbound symbols referenced in `savehist-history-variables' are ignored.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
197 If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
198 and don't save the buffer if they are the same."
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (interactive)
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
200 (with-temp-buffer
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
201 (insert
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
202 (format ";; -*- mode: emacs-lisp; coding: %s -*-\n" savehist-coding-system)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
203 ";; Minibuffer history file, automatically generated by `savehist'.\n\n")
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
204 (let ((print-length nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
205 (print-string-length nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
206 (print-level nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
207 (print-readably t)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
208 (print-quoted t))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
209 (dolist (sym savehist-history-variables)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
210 (when (boundp sym)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
211 (let ((value (savehist-process-for-saving (symbol-value sym))))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
212 (prin1 `(setq ,sym ',value) (current-buffer))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
213 (insert ?\n)))))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
214 ;; If autosaving, avoid writing if nothing has changed since the
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
215 ;; last write.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
216 (let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion)))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
217 (unless (and auto-save (equal checksum savehist-last-checksum))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
218 ;; Set file-precious-flag when saving the buffer because we
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
219 ;; don't want a half-finished write ruining the entire
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
220 ;; history. (Remember that this is run from a timer and from
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
221 ;; kill-emacs-hook.)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
222 (let ((file-precious-flag t)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
223 (coding-system-for-write savehist-coding-system))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
224 (write-region (point-min) (point-max) savehist-file nil
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
225 (unless (interactive-p) 'quiet)))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
226 (when savehist-modes
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
227 (set-file-modes savehist-file savehist-modes))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
228 (setq savehist-last-checksum checksum)))))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
229
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
230 (defun savehist-autosave ()
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
231 "Save the minibuffer history if it has been modified since the last save."
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
232 (savehist-save t))
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
234 (defun savehist-process-for-saving (value)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
235 ;; Process VALUE for saving to file. If it is a list, retain only
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
236 ;; the first `savehist-length' values and prune non-printable ones.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
237 ;; If VALUE is not a list, return it as-is if it is printable and
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
238 ;; nil otherwise.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
239 (cond
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
240 ((listp value)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
241 (when (and savehist-length (> (length value) savehist-length))
66191
3b427dc36c6e (savehist-load): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66129
diff changeset
242 ;; This should be: (setq value (subseq value 0 savehist-length))
66121
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
243 (setq value (copy-sequence value))
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
244 (setcdr (nthcdr savehist-length value) nil))
66191
3b427dc36c6e (savehist-load): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66129
diff changeset
245 ;; And this should be (remove-if-not #'savehist-printable value)
66121
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
246 (delq nil (mapcar (lambda (x) (if (savehist-printable x) x)) value)))
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
247 ((savehist-printable value) value)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
248 (t nil)))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
249
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
250 (defun savehist-printable (value)
66121
b1015e4158db Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66120
diff changeset
251 "Return non-nil if VALUE is printable."
66120
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
252 ;; Quick response for oft-encountered types known to be printable.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
253 (cond
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
254 ((stringp value))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
255 ((numberp value))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
256 ((symbolp value))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
257 (t
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
258 ;; For others, check explicitly.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
259 (condition-case nil
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
260 (let ((print-readably t)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
261 (print-level nil)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
262 (chars ()))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
263 ;; Print the value into a string...
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
264 (prin1 value (lambda (char) (push char chars)))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
265 ;; ...and attempt to read it.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
266 (read (apply #'string (nreverse chars)))
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
267 ;; The attempt worked: the object is printable.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
268 t)
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
269 ;; The attempt failed: the object is not printable.
87310076f109 (savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66106
diff changeset
270 (error nil)))))
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (provide 'savehist)
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
66129
b6299ce0d13f Add arch tagline
Miles Bader <miles@gnu.org>
parents: 66121
diff changeset
274 ;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f
66106
9b8e76617c8c New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 ;;; savehist.el ends here