Mercurial > emacs
annotate lisp/savehist.el @ 66631:d362d1ac4dbb
*** empty log message ***
author | Lars Hansen <larsh@soem.dk> |
---|---|
date | Wed, 02 Nov 2005 07:05:56 +0000 |
parents | c948bf4e448e |
children | 17486c85326e |
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 | |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
7 ;; Version: 19 |
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 |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
35 ;; To use savehist, turn on savehist-mode by putting the following in |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
36 ;; `~/.emacs': |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
37 ;; |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
38 ;; (savehist-mode 1) |
66106 | 39 ;; |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
40 ;; or with customize: `M-x customize-option RET savehist-mode RET'. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
41 ;; |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
42 ;; You can also explicitly save history with `M-x savehist-save' and |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
43 ;; load it by loading the `savehist-file' with `M-x load-file'. |
66106 | 44 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
45 ;; 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
|
46 ;; 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
|
47 ;; 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
|
48 |
66106 | 49 ;;; Code: |
50 | |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
51 (require 'custom) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
52 (eval-when-compile |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
53 (require 'cl)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
54 |
66106 | 55 ;; User variables |
56 | |
57 (defgroup savehist nil | |
58 "Save minibuffer history." | |
59 :group 'minibuffer) | |
60 | |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
61 ;;;###autoload |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
62 (defcustom savehist-mode nil |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
63 "Mode for automatic saving of minibuffer history. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
64 Set this by calling the `savehist-mode' function or using the customize |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
65 interface." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
66 :type 'boolean |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
67 :set (if (fboundp 'custom-set-minor-mode) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
68 'custom-set-minor-mode |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
69 (lambda (symbol value) (funcall symbol (or value 0)))) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
70 :initialize 'custom-initialize-default |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
71 :require 'savehist |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
72 :group 'savehist) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
73 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
74 (defcustom savehist-save-minibuffer-history t |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
75 "*If non-nil, save all recorded minibuffer histories. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
76 If you want to save only specific histories, use `savehist-save-hook' to |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
77 modify the value of `savehist-minibuffer-history-variables'." |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
78 :type 'boolean |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
79 :group 'savehist) |
66106 | 80 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
81 (defcustom savehist-additional-variables () |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
82 "*List of additional variables to save. |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
83 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
|
84 sessions that use savehist. The contents of variables should be |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
85 printable with the Lisp printer. You don't need to add minibuffer |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
86 history variables to this list, all minibuffer histories will be |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
87 saved automatically as long as `savehist-save-minibuffer-history' is |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
88 non-nil. |
66106 | 89 |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
90 User options should be saved with the customize interface. This |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
91 list is useful for saving automatically updated variables that are not |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
92 minibuffer histories, such as `compile-command' or `kill-ring'." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
93 :type '(repeat variable) |
66106 | 94 :group 'savehist) |
95 | |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
96 (defcustom savehist-file |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
97 (cond |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
98 ;; Backward compatibility with previous versions of savehist. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
99 ((file-exists-p "~/.emacs-history") "~/.emacs-history") |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
100 ((and (not (featurep 'xemacs)) (file-directory-p "~/.emacs.d/")) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
101 "~/.emacs.d/history") |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
102 ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/")) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
103 "~/.xemacs/history") |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
104 ;; For users without `~/.emacs.d/' or `~/.xemacs/'. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
105 (t "~/.emacs-history")) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
106 "*File name where minibuffer history is saved to and loaded from. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
107 The minibuffer history is a series of Lisp expressions loaded |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
108 automatically when `savehist-mode' is turned on. See `savehist-mode' |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
109 for more details. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
110 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
111 If you want your minibuffer history shared between Emacs and XEmacs, |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
112 customize this value and make sure that `savehist-coding-system' is |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
113 set to a coding system that exists in both emacsen." |
66106 | 114 :type 'file |
115 :group 'savehist) | |
116 | |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
117 (defcustom savehist-file-modes #o600 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
118 "*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
|
119 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
|
120 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
|
121 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
|
122 the user's privacy." |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
123 :type 'integer |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
124 :group 'savehist) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
125 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
126 (defcustom savehist-autosave-interval (* 5 60) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
127 "*The interval between autosaves of minibuffer history. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
128 If set to nil, disables timer-based autosaving." |
66106 | 129 :type 'integer |
130 :group 'savehist) | |
131 | |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
132 (defcustom savehist-save-hook nil |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
133 "Hook called by `savehist-save' before saving the variables. |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
134 You can use this hook to influence choice and content of variables to |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
135 save." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
136 :type 'hook) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
137 |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
138 (defvar savehist-coding-system |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
139 ;; UTF-8 is usually preferable to ISO-2022-8 when available, but under |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
140 ;; XEmacs, UTF-8 is provided by external packages, and may not always be |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
141 ;; available, so even if it currently is available, we prefer not to |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
142 ;; use is. |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
143 (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
|
144 "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
|
145 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
|
146 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
|
147 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
148 ;; Internal variables. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
149 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
150 (defvar savehist-timer nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
151 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
152 (defvar savehist-last-checksum nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
153 |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
154 (defvar savehist-minibuffer-history-variables nil |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
155 "List of minibuffer histories. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
156 The contents of this variable is built while Emacs is running, and saved |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
157 along with minibuffer history. You can change its value off |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
158 `savehist-save-hook' to influence which variables are saved.") |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
159 |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
160 (defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
161 "Coding system without conversion, used for calculating internal checksums. |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
162 Should be as fast as possible, ideally simply exposing the internal |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
163 representation of buffer text.") |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
164 |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
165 (defvar savehist-loaded nil |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
166 "Whether the history has already been loaded. |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
167 This prevents toggling `savehist-mode' from destroying existing |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
168 minibuffer history.") |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
169 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
170 (eval-when-compile |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
171 (when (featurep 'xemacs) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
172 ;; Must declare this under XEmacs, which doesn't have built-in |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
173 ;; minibuffer history truncation. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
174 (defvar history-length 100))) |
66106 | 175 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
176 ;; Functions. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
177 |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
178 ;;;###autoload |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
179 (defun savehist-mode (arg) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
180 "Toggle savehist-mode. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
181 Positive ARG turns on `savehist-mode'. When on, savehist-mode causes |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
182 minibuffer history to be saved periodically and when exiting Emacs. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
183 When turned on for the first time in an Emacs session, it causes the |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
184 previous minibuffer history to be loaded from `savehist-file'. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
185 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
186 This mode should normally be turned on from your Emacs init file. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
187 Calling it at any other time replaces your current minibuffer histories, |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
188 which is probably undesirable." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
189 (interactive "P") |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
190 (setq savehist-mode |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
191 (if (null arg) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
192 (not savehist-mode) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
193 (> (prefix-numeric-value arg) 0))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
194 (if (not savehist-mode) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
195 (savehist-uninstall) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
196 (when (and (not savehist-loaded) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
197 (file-exists-p savehist-file)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
198 (condition-case errvar |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
199 (progn |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
200 ;; Don't set coding-system-for-read -- we rely on the |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
201 ;; coding cookie to convey that information. That way, if |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
202 ;; the user changes the value of savehist-coding-system, |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
203 ;; we can still correctly load the old file. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
204 (load savehist-file nil (not (interactive-p))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
205 (setq savehist-loaded t)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
206 (error |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
207 ;; Don't install the mode if reading failed. Doing so would |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
208 ;; effectively destroy the user's data at the next save. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
209 (setq savehist-mode nil) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
210 (savehist-uninstall) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
211 (signal (car errvar) (cdr errvar))))) |
66586
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
212 (savehist-install)) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
213 |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
214 ;; End with the usual minor-mode conventions normally provided |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
215 ;; transparently by define-minor-mode. |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
216 (run-hooks 'savehist-mode-hook) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
217 (if (interactive-p) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
218 (progn |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
219 (customize-mark-as-set 'savehist-mode) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
220 (unless (current-message) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
221 (message "Savehist mode %sabled" (if savehist-mode "en" "dis"))))) |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
222 ;; Return the new setting. |
c948bf4e448e
(savehist-mode) <defcustom>: Use custom-set-minor-mode if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66585
diff
changeset
|
223 savehist-mode) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
224 (add-minor-mode 'savehist-mode "") |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
225 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
226 (defun savehist-load () |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
227 "Obsolete function provided for transition from old versions of savehist. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
228 Don't call this from new code, use (savehist-mode 1) instead. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
229 |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
230 This function loads the variables stored in `savehist-file' and turns on |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
231 savehist-mode. If savehist-file is in the old format that doesn't record |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
232 the value of `savehist-minibuffer-history-variables', that value is |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
233 deducted from the contents of the file." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
234 (savehist-mode 1) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
235 ;; Old versions of savehist distributed with XEmacs didn't save |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
236 ;; savehist-minibuffer-history-variables. If that variable is nil |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
237 ;; after loading the file, try to intuit the intended value. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
238 (when (null savehist-minibuffer-history-variables) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
239 (setq savehist-minibuffer-history-variables |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
240 (with-temp-buffer |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
241 (ignore-errors |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
242 (insert-file-contents savehist-file)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
243 (let ((vars ()) form) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
244 (while (setq form (condition-case nil |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
245 (read (current-buffer)) (error nil))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
246 ;; Each form read is of the form (setq VAR VALUE). |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
247 ;; Collect VAR, i.e. (nth form 1). |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
248 (push (nth 1 form) vars)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
249 vars))))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
250 (make-obsolete 'savehist-load 'savehist-mode) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
251 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
252 (defun savehist-install () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
253 "Hook savehist into Emacs. |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
254 Normally invoked by calling `savehist-mode' to set the minor mode. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
255 Installs `savehist-autosave' in `kill-emacs-hook' and on a timer. To |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
256 undo this, call `savehist-uninstall'." |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
257 (add-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
258 (add-hook 'kill-emacs-hook 'savehist-autosave) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
259 ;; 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
|
260 ;; should not cause noticeable delays for users -- savehist-autosave |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
261 ;; executes in under 5 ms on my system. |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
262 (when (and savehist-autosave-interval |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
263 (null savehist-timer)) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
264 (setq savehist-timer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
265 (if (featurep 'xemacs) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
266 (start-itimer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
267 "savehist" 'savehist-autosave savehist-autosave-interval |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
268 savehist-autosave-interval) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
269 (run-with-timer savehist-autosave-interval |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
270 savehist-autosave-interval 'savehist-autosave))))) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
271 |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
272 (defun savehist-uninstall () |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
273 "Undo installing savehist. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
274 Normally invoked by calling `savehist-mode' to unset the minor mode." |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
275 (remove-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
276 (remove-hook 'kill-emacs-hook 'savehist-autosave) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
277 (when savehist-timer |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
278 (if (featurep 'xemacs) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
279 (delete-itimer savehist-timer) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
280 (cancel-timer savehist-timer)) |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
281 (setq savehist-timer nil))) |
66106 | 282 |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
283 (defun savehist-save (&optional auto-save) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
284 "Save the values of minibuffer history variables. |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
285 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
|
286 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
|
287 and don't save the buffer if they are the same." |
66106 | 288 (interactive) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
289 (with-temp-buffer |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
290 (insert |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
291 (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
|
292 ";; Minibuffer history file, automatically generated by `savehist'.\n\n") |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
293 (run-hooks 'savehist-save-hook) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
294 (let ((print-length nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
295 (print-string-length nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
296 (print-level nil) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
297 (print-readably t) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
298 (print-quoted t)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
299 ;; Save the minibuffer histories, along with the value of |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
300 ;; savehist-minibuffer-history-variables itself. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
301 (when savehist-save-minibuffer-history |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
302 (prin1 `(setq savehist-minibuffer-history-variables |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
303 ',savehist-minibuffer-history-variables) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
304 (current-buffer)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
305 (insert ?\n) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
306 (dolist (symbol savehist-minibuffer-history-variables) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
307 (when (boundp symbol) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
308 (let ((value (savehist-trim-history (symbol-value symbol)))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
309 (when value ; don't save empty histories |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
310 (prin1 `(setq ,symbol ',value) (current-buffer)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
311 (insert ?\n)))))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
312 ;; Save the additional variables. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
313 (dolist (symbol savehist-additional-variables) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
314 (when (boundp symbol) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
315 (let ((value (symbol-value symbol))) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
316 (when (savehist-printable value) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
317 (prin1 `(setq ,symbol ',value) (current-buffer)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
318 (insert ?\n)))))) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
319 ;; 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
|
320 ;; last write. |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
321 (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
|
322 (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
|
323 ;; 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
|
324 ;; 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
|
325 ;; 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
|
326 ;; kill-emacs-hook, and also that multiple Emacs instances |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
327 ;; 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
|
328 (let ((file-precious-flag t) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
329 (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
|
330 (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
|
331 (unless (interactive-p) 'quiet))) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
332 (when savehist-file-modes |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
333 (set-file-modes savehist-file savehist-file-modes)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
334 (setq savehist-last-checksum checksum))))) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
335 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
336 (defun savehist-autosave () |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
337 "Save the minibuffer history if it has been modified since the last save. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
338 Does nothing if savehist-mode is off." |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
339 (when savehist-mode |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
340 (savehist-save t))) |
66106 | 341 |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
342 (defun savehist-trim-history (value) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
343 ;; Retain only the first history-length items in VALUE. Only used |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
344 ;; under XEmacs, which doesn't (yet) implement automatic trimming of |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
345 ;; history lists to history-length items. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
346 (if (and (featurep 'xemacs) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
347 (natnump history-length) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
348 (> (length value) history-length)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
349 ;; Equivalent to `(subseq value 0 history-length)', but doesn't |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
350 ;; need cl-extra at run-time. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
351 (loop repeat history-length collect (pop value)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
352 value)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
353 |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
354 (defun savehist-printable (value) |
66121
b1015e4158db
Don't require CL at runtime.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66120
diff
changeset
|
355 "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
|
356 (cond |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
357 ;; Quick response for oft-encountered types known to be printable. |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
358 ((stringp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
359 ((numberp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
360 ((symbolp value)) |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
361 (t |
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
362 ;; For others, check explicitly. |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
363 (with-temp-buffer |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
364 (condition-case nil |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
365 (let ((print-readably t) (print-level nil)) |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
366 ;; Print the value into a buffer... |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
367 (prin1 value (current-buffer)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
368 ;; ...and attempt to read it. |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
369 (read (point-min-marker)) |
66120
87310076f109
(savehist-autosave-interval, savehist-coding-system, savehist-timer)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66106
diff
changeset
|
370 ;; 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
|
371 t) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
372 ;; The attempt failed: the object is not printable. |
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
373 (error nil)))))) |
66106 | 374 |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
375 (defun savehist-minibuffer-hook () |
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
376 (add-to-list 'savehist-minibuffer-history-variables |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
377 minibuffer-history-variable)) |
66406
9ee3fe90596c
Require CL while compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66316
diff
changeset
|
378 |
66106 | 379 (provide 'savehist) |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
380 |
66129 | 381 ;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f |
66585
00e4363eadb1
Sync up to version 19.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66406
diff
changeset
|
382 |
66106 | 383 ;;; savehist.el ends here |