comparison lisp/utils/savehist.el @ 157:6b37e6ddd302 r20-3b5

Import from CVS: tag r20-3b5
author cvs
date Mon, 13 Aug 2007 09:40:41 +0200
parents 25f70ba0133c
children 929b76928fce
comparison
equal deleted inserted replaced
156:60baf0b43294 157:6b37e6ddd302
2 2
3 ;; Copyright (c) 1997 Free Software Foundation 3 ;; Copyright (c) 1997 Free Software Foundation
4 4
5 ;; Author: Hrvoje Niksic <hniksic@srce.hr> 5 ;; Author: Hrvoje Niksic <hniksic@srce.hr>
6 ;; Keywords: minibuffer 6 ;; Keywords: minibuffer
7 ;; Version: 0.2 7 ;; Version: 0.3
8 8
9 ;; This file is part of XEmacs. 9 ;; This file is part of XEmacs.
10 10
11 ;; XEmacs is free software; you can redistribute it and/or modify 11 ;; XEmacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
73 query-replace-history 73 query-replace-history
74 ;; eval-expression (`M-:') 74 ;; eval-expression (`M-:')
75 read-expression-history 75 read-expression-history
76 ;; shell-command (`M-!') 76 ;; shell-command (`M-!')
77 shell-command-history 77 shell-command-history
78 ;; compile
79 compile-history
80 ;; find-tag (`M-.')
81 find-tag-history
82 ;; grep
83 grep-history
78 ;; Viper stuff 84 ;; Viper stuff
79 vip-ex-history vip-search-history 85 vip-ex-history vip-search-history
80 vip-replace1-history vip-replace2-history 86 vip-replace1-history vip-replace2-history
81 vip-shell-history vip-search-history 87 vip-shell-history vip-search-history
82 88
88 ;; Extended commands 94 ;; Extended commands
89 read-command-history 95 read-command-history
90 96
91 ;; GNU Emacs-specific: 97 ;; GNU Emacs-specific:
92 ;; Extended commands 98 ;; Extended commands
93 extended-command-history 99 extended-command-history)
94
95 ;; This is not a list, but it's cool to have it anyway, since it's
96 ;; minibuffer history too.
97 compile-command)
98 "*List of symbols to be saved. 100 "*List of symbols to be saved.
99 Every symbol should refer to a variable. The variable will be saved only 101 Every symbol should refer to a variable. The variable will be saved
100 if it is bound is bound, and has a non-nil value. Thus it is safe to 102 only if it is bound and has a non-nil value. Thus it is safe to
101 specify a superset of the variables a user is expected to want to save. 103 specify a superset of the variables a user is expected to want to
104 save.
102 105
103 Default value contains minibuffer history variables used by XEmacs, GNU 106 Default value contains minibuffer history variables used by XEmacs, GNU
104 Emacs and Viper (uh-oh). `compile-command' was added for good measure." 107 Emacs and Viper (uh-oh)."
105 :type '(repeat (symbol :tag "Variable")) 108 :type '(repeat (symbol :tag "Variable"))
106 :group 'minibuffer) 109 :group 'savehist)
107 110
108 (defcustom savehist-file "~/.emacs-history" 111 (defcustom savehist-file "~/.emacs-history"
109 "*File name to save minibuffer history to. 112 "*File name to save minibuffer history to.
110 The minibuffer history is a series of Lisp expressions, which should be 113 The minibuffer history is a series of Lisp expressions, which should be
111 loaded using `savehist-load' from your .emacs. See `savehist-load' for 114 loaded using `savehist-load' from your .emacs. See `savehist-load' for
116 (defcustom savehist-length 100 119 (defcustom savehist-length 100
117 "*Maximum length of a minibuffer list. 120 "*Maximum length of a minibuffer list.
118 If set to nil, the length is unlimited." 121 If set to nil, the length is unlimited."
119 :type '(choice integer 122 :type '(choice integer
120 (const :tag "Unlimited" nil)) 123 (const :tag "Unlimited" nil))
124 :group 'savehist)
125
126 (defcustom savehist-modes 384
127 "*Default permissions of the history file."
128 :type 'integer
121 :group 'savehist) 129 :group 'savehist)
122 130
123 131
124 ;; Functions 132 ;; Functions
125 133
133 removes your current minibuffer histories (if any), it is unwise to call it 141 removes your current minibuffer histories (if any), it is unwise to call it
134 at any other time." 142 at any other time."
135 (interactive "P") 143 (interactive "P")
136 (unless prefix 144 (unless prefix
137 (add-hook 'kill-emacs-hook 'savehist-save)) 145 (add-hook 'kill-emacs-hook 'savehist-save))
138 (when (file-exists-p savehist-file) 146 (load savehist-file t))
139 (load savehist-file)))
140 147
141 ;;;###autoload 148 ;;;###autoload
142 (defun savehist-save () 149 (defun savehist-save ()
143 "Save the histories from `savehist-history-variables' to `savehist-file'. 150 "Save the histories from `savehist-history-variables' to `savehist-file'.
144 A variable will be saved if it is bound and non-nil." 151 A variable will be saved if it is bound and non-nil."
165 (prin1 172 (prin1
166 `(setq ,sym (quote ,(savehist-delimit (symbol-value sym) 173 `(setq ,sym (quote ,(savehist-delimit (symbol-value sym)
167 savehist-length))) 174 savehist-length)))
168 (current-buffer)) 175 (current-buffer))
169 (insert ?\n))) 176 (insert ?\n)))
170 (save-buffer)) 177 (save-buffer)
178 (set-file-modes savehist-file savehist-modes))
171 (or buffer-exists-p 179 (or buffer-exists-p
172 (kill-buffer (current-buffer))))))) 180 (kill-buffer (current-buffer)))))))
173 181
174 ;; If ARG is a arg with less than N elements, return it, else return 182 ;; If ARG is a list with less than N elements, return it, else return
175 ;; its subsequence of N elements. If N is nil, always return ARG. If 183 ;; its subsequence of N elements. If N is nil or ARG is not a list,
176 ;; ARG is not a list, just return it. 184 ;; always return ARG.
177 (defun savehist-delimit (arg n) 185 (defun savehist-delimit (arg n)
178 (if (and n 186 (if (and n
179 (listp arg) 187 (listp arg)
180 (> (length arg) n)) 188 (> (length arg) n))
181 (subseq arg 0 n) 189 (subseq arg 0 n)