Mercurial > emacs
annotate lisp/savehist.el @ 83395:b31326248cf6
Merged from miles@gnu.org--gnu-2005 (patch 142-148, 615-628)
Patches applied:
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-616
Add lisp/mh-e/.arch-inventory
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-617
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-618
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-619
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-620
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-622
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-623
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-624
Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-625
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-626
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-627
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-628
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-142
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-143
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-144
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-145
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-146
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-147
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-148
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-435
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Tue, 01 Nov 2005 06:23:08 +0000 |
parents | 9ee3fe90596c |
children | 00e4363eadb1 |
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 | 2 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
3 ;; Copyright (C) 1997,2005 Free Software Foundation |
66106 | 4 |
5 ;; Author: Hrvoje Niksic <hniksic@xemacs.org> | |
6 ;; Keywords: minibuffer | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
7 ;; Version: 9 |
66106 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
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 | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
24 ;; Boston, MA 02110-1301, USA. | |
25 | |
26 ;;; Commentary: | |
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 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
30 ;; same feature in Emacs. When set up, it saves recorded minibuffer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
31 ;; histories to a file (`~/.emacs-history' by default). Additional |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
32 ;; variables may be specified by customizing |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
33 ;; `savehist-additional-variables'. |
66106 | 34 |
35 ;; To use savehist, put the following to `~/.emacs': | |
36 ;; | |
37 ;; (require 'savehist) | |
38 ;; (savehist-load) | |
39 | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
40 ;; If you are using a version of Emacs that does not ship with this |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
41 ;; package, be sure to have `savehist.el' in a directory that is in |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
42 ;; your load-path, and to byte-compile it. |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
43 |
66106 | 44 ;;; Code: |
45 | |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
46 (require 'custom) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
47 (eval-when-compile |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
48 (require 'cl)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
49 |
66106 | 50 ;; User variables |
51 | |
52 (defgroup savehist nil | |
53 "Save minibuffer history." | |
54 :group 'minibuffer) | |
55 | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
56 (defcustom savehist-save-minibuffer-history t |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
57 "If non-nil, save all recorded minibuffer histories." |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
58 :type 'boolean |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
59 :group 'savehist) |
66106 | 60 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
61 (defcustom savehist-additional-variables () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
62 "List of additional variables to save. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
63 Each element is a symbol whose value will be persisted across Emacs |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
64 sessions that use savehist. The contents of variables should be |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
65 printable with the Lisp printer. If the variable's value is a list, |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
66 it will be trimmed to `savehist-length' elements. |
66106 | 67 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
68 You don't need to add minibuffer history variables to this list. All |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
69 minibuffer histories will be saved automatically." |
66106 | 70 :type '(repeat (symbol :tag "Variable")) |
71 :group 'savehist) | |
72 | |
73 (defcustom savehist-file "~/.emacs-history" | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
74 "File name to save minibuffer history to. |
66106 | 75 The minibuffer history is a series of Lisp expressions, which should be |
76 loaded using `savehist-load' from your .emacs. See `savehist-load' for | |
77 more details." | |
78 :type 'file | |
79 :group 'savehist) | |
80 | |
81 (defcustom savehist-length 100 | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
82 "Maximum length of a minibuffer list. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
83 Minibuffer histories with more entries are trimmed when saved, the older |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
84 entries being removed first. If set to nil, the length is unlimited." |
66106 | 85 :type '(choice integer |
86 (const :tag "Unlimited" nil)) | |
87 :group 'savehist) | |
88 | |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
89 (defcustom savehist-modes #o600 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
90 "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
|
91 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
|
92 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
|
93 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
|
94 the user's privacy." |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
95 :type 'integer |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
96 :group 'savehist) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
97 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
98 (defcustom savehist-autosave-interval (* 5 60) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
99 "The interval during which savehist should autosave the history buffer." |
66106 | 100 :type 'integer |
101 :group 'savehist) | |
102 | |
66205
e52f114d1dc3
(savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66191
diff
changeset
|
103 (defvar savehist-coding-system |
e52f114d1dc3
(savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66191
diff
changeset
|
104 ;; 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
|
105 ;; 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
|
106 ;; 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
|
107 ;; use is. |
e52f114d1dc3
(savehist-coding-system): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66191
diff
changeset
|
108 (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
|
109 "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
|
110 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
|
111 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
|
112 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
113 ;; Internal variables. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
114 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
115 (defvar savehist-timer nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
116 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
117 (defvar savehist-last-checksum nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
118 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
119 (defvar savehist-minibuffer-history-variables nil) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
120 |
66121
b1015e4158db
Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66120
diff
changeset
|
121 (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
122 "Coding system without conversion, only used for calculating checksums. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
123 It should be as discriminating as `savehist-coding-system' but faster.") |
66106 | 124 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
125 ;; Functions. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
126 |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
127 (defun savehist-install () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
128 "Hook savehist into Emacs. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
129 This will install `savehist-autosave' in `kill-emacs-hook' and on a timer. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
130 To undo this, call `savehist-uninstall'." |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
131 (add-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
132 (add-hook 'kill-emacs-hook 'savehist-autosave) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
133 ;; Install an invocation of savehist-autosave on a timer. This |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
134 ;; should not cause noticeable delays for users -- savehist-autosave |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
135 ;; executes in under 5 ms on my system. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
136 (unless savehist-timer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
137 (setq savehist-timer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
138 (if (featurep 'xemacs) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
139 (start-itimer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
140 "savehist" 'savehist-autosave savehist-autosave-interval |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
141 savehist-autosave-interval) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
142 (run-with-timer savehist-autosave-interval savehist-autosave-interval |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
143 'savehist-autosave))))) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
144 |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
145 (defun savehist-uninstall () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
146 "Undo installing savehist." |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
147 (remove-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
148 (remove-hook 'kill-emacs-hook 'savehist-autosave) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
149 (when savehist-timer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
150 (if (featurep 'xemacs) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
151 (delete-itimer savehist-timer) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
152 (cancel-timer savehist-timer)) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
153 (setq savehist-timer nil))) |
66106 | 154 |
155 ;;;###autoload | |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
156 (defun savehist-load (&optional no-install) |
66106 | 157 "Load the minibuffer histories from `savehist-file'. |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
158 Unless NO-INSTALL is present and non-nil, the function will also install |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
159 `savehist-autosave' in `kill-emacs-hook' and on a timer, ensuring that |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
160 history is saved before leaving Emacs. |
66106 | 161 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
162 This function should be normally used from your Emacs init file. Since |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
163 it removes your current minibuffer histories, it is unwise to call it at |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
164 any other time." |
66106 | 165 (interactive "P") |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
166 ;; 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
|
167 ;; 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
|
168 ;; 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
|
169 ;; still correctly load the old file. |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
170 (load savehist-file t (not (interactive-p))) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
171 (unless no-install |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
172 (savehist-install))) |
66106 | 173 |
174 ;;;###autoload | |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
175 (defun savehist-save (&optional auto-save) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
176 "Save the values of minibuffer history variables. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
177 Unbound symbols referenced in `savehist-additional-variables' are ignored. |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
178 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
|
179 and don't save the buffer if they are the same." |
66106 | 180 (interactive) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
181 (with-temp-buffer |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
182 (insert |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
183 (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
|
184 ";; 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
|
185 (let ((print-length nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
186 (print-string-length nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
187 (print-level nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
188 (print-readably t) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
189 (print-quoted t) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
190 (symbol-list (append |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
191 (and savehist-save-minibuffer-history |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
192 (cons 'savehist-minibuffer-history-variables |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
193 savehist-minibuffer-history-variables)) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
194 savehist-additional-variables))) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
195 (dolist (sym symbol-list) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
196 (when (boundp sym) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
197 (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
|
198 (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
|
199 (insert ?\n))))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
200 ;; 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
|
201 ;; last write. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
202 (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
|
203 (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
|
204 ;; 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
|
205 ;; don't want a half-finished write ruining the entire |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
206 ;; history. Remember that this is run from a timer and from |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
207 ;; kill-emacs-hook, and also that multiple Emacs instances |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
208 ;; could write to this file at once. |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
209 (let ((file-precious-flag t) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
210 (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
|
211 (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
|
212 (unless (interactive-p) 'quiet))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
213 (when savehist-modes |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
214 (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
|
215 (setq savehist-last-checksum checksum))))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
216 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
217 (defun savehist-autosave () |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
218 "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
|
219 (savehist-save t)) |
66106 | 220 |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
221 (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
|
222 ;; 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
|
223 ;; 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
|
224 ;; 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
|
225 ;; nil otherwise. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
226 (cond |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
227 ((listp value) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
228 (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
|
229 ;; 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
|
230 (setq value (copy-sequence value)) |
b1015e4158db
Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66120
diff
changeset
|
231 (setcdr (nthcdr savehist-length value) nil)) |
66191
3b427dc36c6e
(savehist-load): Revert to checking XEmacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66129
diff
changeset
|
232 ;; 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
|
233 (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
|
234 ((savehist-printable value) value) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
235 (t nil))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
236 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
237 (defun savehist-printable (value) |
66121
b1015e4158db
Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66120
diff
changeset
|
238 "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
|
239 ;; 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
|
240 (cond |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
241 ((stringp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
242 ((numberp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
243 ((symbolp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
244 (t |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
245 ;; For others, check explicitly. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
246 (condition-case nil |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
247 (let ((print-readably t) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
248 (print-level nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
249 (chars ())) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
250 ;; 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
|
251 (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
|
252 ;; ...and attempt to read it. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
253 (read (apply #'string (nreverse chars))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
254 ;; 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
|
255 t) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
256 ;; 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
|
257 (error nil))))) |
66106 | 258 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
259 (defun savehist-minibuffer-hook () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
260 (add-to-list 'savehist-minibuffer-history-variables |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
261 minibuffer-history-variable)) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
262 |
66106 | 263 (provide 'savehist) |
264 | |
66129 | 265 ;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f |
66106 | 266 ;;; savehist.el ends here |