aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2004-02-21 14:07:11 +0000
committerEli Zaretskii2004-02-21 14:07:11 +0000
commit467997b7f343c3268df2828bb63ac500a19ed3c8 (patch)
tree8599f9f2a460d3f12efc3783ce55ee14942f4c5c
parent235de3729648571932a837a5333d1c7388afaba0 (diff)
downloademacs-467997b7f343c3268df2828bb63ac500a19ed3c8.tar.gz
emacs-467997b7f343c3268df2828bb63ac500a19ed3c8.zip
(save-place-forget-unreadable-files)
(save-place-save-skipped, save-place-skip-check-regexp): New defcustoms. (save-place-forget-unreadable-files): New function. (save-place-alist-to-file): Use it to filter out files that are no longer readable.
-rw-r--r--lisp/saveplace.el63
1 files changed, 63 insertions, 0 deletions
diff --git a/lisp/saveplace.el b/lisp/saveplace.el
index d8706de70e8..3e40f118a41 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -94,6 +94,40 @@ value of `version-control'."
94 (const :tag "No Limit" nil)) 94 (const :tag "No Limit" nil))
95 :group 'save-place) 95 :group 'save-place)
96 96
97(defcustom save-place-forget-unreadable-files t
98 "Non-nil means forget place in unreadable files.
99
100The filenames in `save-place-alist' that do not match
101`save-place-skip-check-regexp' are filtered through
102`file-readable-p'. if nil, their alist entries are removed.
103
104You may do this anytime by calling the complementary function,
105`save-place-forget-unreadable-files'. When this option is turned on,
106this happens automatically before saving `save-place-alist' to
107`save-place-file'."
108 :type 'boolean :group 'save-place)
109
110(defcustom save-place-save-skipped t
111 "If non-nil, remember files matching `save-place-skip-check-regexp'.
112
113When filtering `save-place-alist' for unreadable files, some will not
114be checked, based on said regexp, and instead saved or forgotten based
115on this flag."
116 :type 'boolean :group 'save-place)
117
118(defcustom save-place-skip-check-regexp
119 ;; thanks to ange-ftp-name-format
120 "\\`/\\(?:cdrom\\|floppy\\|mnt\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)"
121 "Regexp whose file names shall not be checked for readability.
122
123When forgetting unreadable files, file names matching this regular
124expression shall not be checked for readability, but instead be
125subject to `save-place-save-skipped'.
126
127Files for which such a check may be inconvenient include those on
128removable and network volumes."
129 :type 'regexp :group 'save-place)
130
97(defun toggle-save-place (&optional parg) 131(defun toggle-save-place (&optional parg)
98 "Toggle whether to save your place in this file between sessions. 132 "Toggle whether to save your place in this file between sessions.
99If this mode is enabled, point is recorded when you kill the buffer 133If this mode is enabled, point is recorded when you kill the buffer
@@ -138,12 +172,41 @@ To save places automatically in all files, put this in your `.emacs' file:
138 (cons (cons buffer-file-name position) 172 (cons (cons buffer-file-name position)
139 save-place-alist))))))) 173 save-place-alist)))))))
140 174
175(defun save-place-forget-unreadable-files ()
176 "Remove unreadable files from `save-place-alist'.
177For each entry in the alist, if `file-readable-p' returns nil for the
178filename, remove the entry. Save the new alist \(as the first pair
179may have changed\) back to `save-place-alist'."
180 (interactive)
181 ;; the following was adapted from an in-place filtering function,
182 ;; `filter-mod', used in the original.
183 (unless (null save-place-alist) ;says it better than `when'
184 ;; first, check all except first
185 (let ((fmprev save-place-alist) (fmcur (cdr save-place-alist)))
186 (while fmcur ;not null
187 ;; a value is only saved when it becomes FMPREV.
188 (if (if (string-match save-place-skip-check-regexp (caar fmcur))
189 save-place-save-skipped
190 (file-readable-p (caar fmcur)))
191 (setq fmprev fmcur)
192 (setcdr fmprev (cdr fmcur)))
193 (setq fmcur (cdr fmcur))))
194 ;; test first pair, keep it if OK, otherwise 2nd element, which
195 ;; may be '()
196 (unless (if (string-match save-place-skip-check-regexp
197 (caar save-place-alist))
198 save-place-save-skipped
199 (file-readable-p (caar save-place-alist)))
200 (setq save-place-alist (cdr save-place-alist)))))
201
141(defun save-place-alist-to-file () 202(defun save-place-alist-to-file ()
142 (let ((file (expand-file-name save-place-file))) 203 (let ((file (expand-file-name save-place-file)))
143 (save-excursion 204 (save-excursion
144 (message "Saving places to %s..." file) 205 (message "Saving places to %s..." file)
145 (set-buffer (get-buffer-create " *Saved Places*")) 206 (set-buffer (get-buffer-create " *Saved Places*"))
146 (delete-region (point-min) (point-max)) 207 (delete-region (point-min) (point-max))
208 (when save-place-forget-unreadable-files
209 (save-place-forget-unreadable-files))
147 (print save-place-alist (current-buffer)) 210 (print save-place-alist (current-buffer))
148 (let ((version-control 211 (let ((version-control
149 (cond 212 (cond