45 |
;;; Code: |
;;; Code: |
46 |
|
|
47 |
(require 'custom) |
(require 'custom) |
|
(require 'cl) |
|
48 |
|
|
49 |
;; User variables |
;; User variables |
50 |
|
|
138 |
:type 'integer |
:type 'integer |
139 |
:group 'savehist) |
:group 'savehist) |
140 |
|
|
141 |
(defconst savehist-xemacs (string-match "XEmacs" emacs-version)) |
(defvar savehist-coding-system (if (coding-system-p 'utf-8) 'utf-8 'iso-2022-8) |
|
|
|
|
(defvar savehist-coding-system (if savehist-xemacs 'iso-2022-8 'utf-8) |
|
142 |
"The coding system savehist uses for saving the minibuffer history. |
"The coding system savehist uses for saving the minibuffer history. |
143 |
Changing this value while Emacs is running is supported, but considered |
Changing this value while Emacs is running is supported, but considered |
144 |
unwise, unless you know what you are doing.") |
unwise, unless you know what you are doing.") |
149 |
|
|
150 |
(defvar savehist-last-checksum nil) |
(defvar savehist-last-checksum nil) |
151 |
|
|
152 |
;; Coding system without conversion, only used for calculating and |
(defconst savehist-no-conversion (if (featurep 'xemacs) 'binary 'no-conversion) |
153 |
;; comparing checksums. |
;; FIXME: Why not use savehist-coding-system? |
154 |
(defconst savehist-no-conversion (if savehist-xemacs 'binary 'no-conversion)) |
"Coding system without conversion, only used for calculating checksums.") |
155 |
|
|
156 |
;; Functions |
;; Functions |
157 |
|
|
173 |
;; executes in under 5 ms on my system. |
;; executes in under 5 ms on my system. |
174 |
(unless savehist-timer |
(unless savehist-timer |
175 |
(setq savehist-timer |
(setq savehist-timer |
176 |
(if savehist-xemacs |
(if (fboundp 'start-itimer) |
177 |
(start-itimer |
(start-itimer |
178 |
"savehist" 'savehist-autosave savehist-autosave-interval |
"savehist" 'savehist-autosave savehist-autosave-interval |
179 |
savehist-autosave-interval) |
savehist-autosave-interval) |
180 |
(run-with-timer savehist-autosave-interval savehist-autosave-interval |
(run-with-idle-timer savehist-autosave-interval savehist-autosave-interval |
181 |
'savehist-autosave))))) |
'savehist-autosave))))) |
182 |
;; Don't set coding-system-for-read here. We rely on autodetection |
;; Don't set coding-system-for-read here. We rely on autodetection |
183 |
;; and the coding cookie to convey that information. That way, if |
;; and the coding cookie to convey that information. That way, if |
184 |
;; the user changes the value of savehist-coding-system, we can |
;; the user changes the value of savehist-coding-system, we can |
234 |
(cond |
(cond |
235 |
((listp value) |
((listp value) |
236 |
(when (and savehist-length (> (length value) savehist-length)) |
(when (and savehist-length (> (length value) savehist-length)) |
237 |
(setq value (subseq value 0 savehist-length))) |
(setq value (copy-sequence value)) |
238 |
(delete-if-not #'savehist-printable value)) |
(setcdr (nthcdr savehist-length value) nil)) |
239 |
|
(delq nil (mapcar (lambda (x) (if (savehist-printable x) x)) value))) |
240 |
((savehist-printable value) value) |
((savehist-printable value) value) |
241 |
(t nil))) |
(t nil))) |
242 |
|
|
243 |
(defun savehist-printable (value) |
(defun savehist-printable (value) |
244 |
"Returns non-nil if VALUE is printable." |
"Return non-nil if VALUE is printable." |
245 |
;; Quick response for oft-encountered types known to be printable. |
;; Quick response for oft-encountered types known to be printable. |
246 |
(cond |
(cond |
247 |
((stringp value)) |
((stringp value)) |