comparison lisp/utils/savehist.el @ 171:929b76928fce r20-3b12

Import from CVS: tag r20-3b12
author cvs
date Mon, 13 Aug 2007 09:47:52 +0200
parents 6b37e6ddd302
children 8eaf7971accc
comparison
equal deleted inserted replaced
170:98a42ee61975 171:929b76928fce
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.3 7 ;; Version: 0.4
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
43 43
44 ;; Be sure to have `savehist.el' in a directory that is in your 44 ;; Be sure to have `savehist.el' in a directory that is in your
45 ;; load-path, and byte-compile it. 45 ;; load-path, and byte-compile it.
46 46
47 ;; This code should work on XEmacs 19.14 and later, as well as GNU 47 ;; This code should work on XEmacs 19.14 and later, as well as GNU
48 ;; Emacs 19.34 and later. 48 ;; Emacs 19.34 and later. It requires the Customize library, however
49 ;; (shipped with XEmacs 19.15 and later, and with GNU Emacs 20.x).
49 50
50 51
51 ;;; Code: 52 ;;; Code:
52 53
53 (require 'custom) 54 (require 'custom)
122 :type '(choice integer 123 :type '(choice integer
123 (const :tag "Unlimited" nil)) 124 (const :tag "Unlimited" nil))
124 :group 'savehist) 125 :group 'savehist)
125 126
126 (defcustom savehist-modes 384 127 (defcustom savehist-modes 384
127 "*Default permissions of the history file." 128 "*Default permissions of the history file.
129 This is decimal, not octal. The default is 384 (0600 in octal)."
128 :type 'integer 130 :type 'integer
129 :group 'savehist) 131 :group 'savehist)
130 132
131 133
132 ;; Functions 134 ;; Functions
133 135
134 ;;;###autoload 136 ;;;###autoload
135 (defun savehist-load (&optional prefix) 137 (defun savehist-load (&optional no-hook)
136 "Load the histories saved to `savehist-file'. 138 "Load the minibuffer histories from `savehist-file'.
137 Unless PREFIX is non-nil, the function will also add the save function to 139 Unless NO-HOOK is specified, the function will also add the save function
138 `kill-emacs-hook'. 140 to `kill-emacs-hook', thus ensuring that the minibuffer contents will be
141 saved before leaving Emacs.
139 142
140 This function should be normally used from your Emacs init file. Since it 143 This function should be normally used from your Emacs init file. Since it
141 removes your current minibuffer histories (if any), it is unwise to call it 144 removes your current minibuffer histories, it is unwise to call it at any
142 at any other time." 145 other time."
143 (interactive "P") 146 (interactive "P")
144 (unless prefix 147 (unless no-hook
145 (add-hook 'kill-emacs-hook 'savehist-save)) 148 (add-hook 'kill-emacs-hook 'savehist-save))
146 (load savehist-file t)) 149 (load savehist-file t))
147 150
148 ;;;###autoload 151 ;;;###autoload
149 (defun savehist-save () 152 (defun savehist-save ()
164 ";; Minibuffer history file.\n\n" 167 ";; Minibuffer history file.\n\n"
165 ";; This file is automatically generated by `savehist-save'" 168 ";; This file is automatically generated by `savehist-save'"
166 " or when\n" 169 " or when\n"
167 ";; exiting Emacs.\n" 170 ";; exiting Emacs.\n"
168 ";; Do not edit. Unless you really want to, that is.\n\n") 171 ";; Do not edit. Unless you really want to, that is.\n\n")
169 (dolist (sym savehist-history-variables) 172 (let ((print-length nil)
170 (when (and (boundp sym) 173 (print-string-length nil)
171 (symbol-value sym)) 174 (print-level nil)
172 (prin1 175 (print-readably t))
173 `(setq ,sym (quote ,(savehist-delimit (symbol-value sym) 176 (dolist (sym savehist-history-variables)
174 savehist-length))) 177 (when (and (boundp sym)
175 (current-buffer)) 178 (symbol-value sym))
176 (insert ?\n))) 179 (prin1
180 `(setq ,sym (quote ,(savehist-delimit (symbol-value sym)
181 savehist-length)))
182 (current-buffer))
183 (insert ?\n))))
177 (save-buffer) 184 (save-buffer)
178 (set-file-modes savehist-file savehist-modes)) 185 (set-file-modes savehist-file savehist-modes))
179 (or buffer-exists-p 186 (or buffer-exists-p
180 (kill-buffer (current-buffer))))))) 187 (kill-buffer (current-buffer)))))))
181 188