[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH]saveplace.el: forget saved places for unreadable files
From: |
Stephen Compall |
Subject: |
[PATCH]saveplace.el: forget saved places for unreadable files |
Date: |
Tue, 22 Jul 2003 03:47:30 -0500 |
"Bug": save-place doesn't "garbage collect" useless saved places.
Upon looking in my `.emacs-places' file for the first time, I noticed
that I no longer had many of the files it had saved places for.
Long-gone source trees were still meticulously bookmarked in the
alist. Theoretically, `save-place-alist' can grow indefinitely,
filling with entries that no longer refer to a file.
I feel the solution is to provide some way for users to automatically
remove useless entries in `save-place-alist'. As all save-place users
have an interest in cleaning this up, I feel this functionality is
generally useful enough to be included with the Emacs distribution.
"Semifix": This is a patch against emacs/lisp/saveplace.el, CVS
revision 1.25. I added an interactive function,
`save-place-forget-unreadable-files', that removes entries from
`save-place-alist' whose CARs return nil when `file-readable-p' is
applied. In short, it forgets unreadable files. As I can immediately
think of reasons why automatically doing this may not be desirable, I
added a customizable toggle, named same as the function, to call the
function before writing to `save-place-file' 's buffer.
Reasons this may not be desirable:
* removable/network drives, tarballs: files with useful saved places
may not always be present
* file-readable-p can be slow applied to certain volumes, such as
CD-ROM drives. The first time I ran it, on my formerly 1000-item
save-place-alist, emacs hung on exit while the CD-ROM spun up for
the necessary tests
* only one static test available: file-readable-p. Perhaps should
allow user-defined filtering, as is available with midnight mode,
so users could limit saved places as they saw fit. I suppose this
could be done with a find-file-hook that sets `save-place'
accordingly, but there's already one test I know of for which this
method would be ineffective: the one this patch includes.
If anyone has interest in expanding this feature, particularly in
making the test(s?) more configurable, please share a good way to go
about that, if you please. For that matter, any other suggestions are
welcome, of course.
This patch runs until the signature; you may also retrieve it from
http://csserver.evansville.edu/~sc87/dist/saveplace-forget.1S11.patch.
I have tested it against Emacs 21.3; however, the patch is made
against CVS revision 1.25 (in HEAD branch).
*** /mnt/cdrom/emacs-cvs/lisp/saveplace.el 2003-03-25 13:32:39.000000000
-0600
--- /home/sirian/ide/scripts/saveplace.el 2003-07-21 15:59:39.000000000
-0500
***************
*** 94,99 ****
--- 94,111 ----
(const :tag "No Limit" nil))
:group 'save-place)
+ (defcustom save-place-forget-unreadable-files nil
+ "Non-nil means forget place in unreadable files.
+
+ The filenames in `save-place-alist' are filtered through
+ `file-readable-p'. if nil, the alist entry is removed.
+
+ You may do this anytime by calling the complementary function,
+ `save-place-forget-unreadable-files'. When this option is turned on,
+ this happens automatically before saving `save-place-alist' to
+ `save-place-file'."
+ :type '(boolean) :group 'save-place)
+
(defun toggle-save-place (&optional parg)
"Toggle whether to save your place in this file between sessions.
If this mode is enabled, point is recorded when you kill the buffer
***************
*** 138,149 ****
--- 150,185 ----
(cons (cons buffer-file-name position)
save-place-alist)))))))
+ (defun save-place-forget-unreadable-files ()
+ "Remove unreadable files from `save-place-alist'.
+ For each entry in the alist, if `file-readable-p' returns nil for the
+ filename, remove the entry. Save the new alist \(as the first pair
+ may have changed\) back to `save-place-alist'."
+ (interactive)
+ ;; the following was adapted from an in-place filtering function,
+ ;; `filter-mod', used in the original.
+ (unless (null save-place-alist) ;says it better than `when'
+ ;; first, check all except first
+ (let ((fmprev save-place-alist) (fmcur (cdr save-place-alist)))
+ (while fmcur ;not null
+ ;; a value is only saved when it becomes FMPREV.
+ (if (file-readable-p (caar fmcur))
+ (setq fmprev fmcur)
+ (setcdr fmprev (cdr fmcur)))
+ (setq fmcur (cdr fmcur))))
+ ;; test first pair, keep it if OK, otherwise 2nd element, which
+ ;; may be '()
+ (unless (file-readable-p (caar save-place-alist))
+ (setq save-place-alist (cdr save-place-alist)))))
+
(defun save-place-alist-to-file ()
(let ((file (expand-file-name save-place-file)))
(save-excursion
(message "Saving places to %s..." file)
(set-buffer (get-buffer-create " *Saved Places*"))
(delete-region (point-min) (point-max))
+ (when save-place-forget-unreadable-files
+ (save-place-forget-unreadable-files))
(print save-place-alist (current-buffer))
(let ((version-control
(cond
--
Stephen Compall or s11 or sirian
Worrying is like rocking in a rocking chair -- It gives you something to do,
but it doesn't get you anywhere.
AUTODIN fraud Blowpipe IDEA offensive information warfare AVN
chameleon man AMW LLNL NWO Commecen industrial intelligence MD5 Rubin
Albright
- [PATCH]saveplace.el: forget saved places for unreadable files,
Stephen Compall <=