summaryrefslogtreecommitdiff
path: root/lisp/recentf.el
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2003-09-15 16:24:35 +0000
committerGlenn Morris <rgm@gnu.org>2003-09-15 16:24:35 +0000
commitf6a9235a431cb6d3f0c0cbc7c08b800f935408f3 (patch)
tree7e2e95c5ba8e6365158d84cd6b9bf21374f2488b /lisp/recentf.el
parent96c6fd77e045483719e814cbef770e842d656ee2 (diff)
downloademacs-f6a9235a431cb6d3f0c0cbc7c08b800f935408f3.tar.gz
David Ponce <david@dponce.com>
(recentf-exclude): Accept predicates too. (recentf-file-readable-p): New function. (recentf-include-p): Handle predicates in recentf-exclude. (recentf-add-file): Doc fix. Use recentf-file-readable-p. (recentf-cleanup): Likewise. (recentf-save-list): Use write-file to handle backup of recentf-save-file.
Diffstat (limited to 'lisp/recentf.el')
-rw-r--r--lisp/recentf.el48
1 files changed, 35 insertions, 13 deletions
diff --git a/lisp/recentf.el b/lisp/recentf.el
index 76c29995a57..a35e33d5742 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -8,7 +8,7 @@
;; Maintainer: FSF
;; Keywords: files
-(defconst recentf-version "$Revision: 1.25 $")
+(defconst recentf-version "$Revision: 1.26 $")
;; This file is part of GNU Emacs.
@@ -78,9 +78,13 @@ See the command `recentf-save-list'."
:type 'file)
(defcustom recentf-exclude nil
- "*List of regexps for filenames excluded from the recent list."
+"*List of regexps and predicates for filenames excluded from the recent list.
+When a filename matches any of the regexps or satisfies any of the
+predicates it is excluded from the recent list.
+A predicate is a function that is passed a filename to check and that
+must return non-nil to exclude it."
:group 'recentf
- :type '(repeat regexp))
+ :type '(repeat (choice regexp function)))
(defun recentf-menu-customization-changed (variable value)
"Function called when the recentf menu customization has changed.
@@ -343,17 +347,34 @@ process the canonical name."
(funcall recentf-filename-handler filename))
filename)))
+(defsubst recentf-file-readable-p (filename)
+ "Return t if file FILENAME exists and you can read it.
+Like the function `file-readable-p' but return nil on error."
+ (condition-case nil
+ (file-readable-p filename)
+ (error nil)))
+
(defun recentf-include-p (filename)
- "Return t if FILENAME match none of the `recentf-exclude' regexps."
+ "Return non-nil if FILENAME should be included in the recent list.
+That is, if it doesn't match any of the `recentf-exclude' checks."
(let ((case-fold-search recentf-case-fold-search)
- (rl recentf-exclude))
- (while (and rl (not (string-match (car rl) filename)))
- (setq rl (cdr rl)))
- (null rl)))
+ (checks recentf-exclude)
+ (keepit t)
+ check)
+ (while (and checks keepit)
+ (setq check (car checks)
+ checks (cdr checks)
+ keepit (not (if (stringp check)
+ ;; A regexp
+ (string-match check filename)
+ ;; A predicate
+ (funcall check filename)))))
+ keepit))
(defsubst recentf-add-file (filename)
"Add or move FILENAME at the beginning of the recent list.
-Does nothing it if it matches any of the `recentf-exclude' regexps."
+Does nothing if the name satisfies any of the `recentf-exclude' regexps or
+predicates."
(setq filename (recentf-expand-file-name filename))
(when (recentf-include-p filename)
(recentf-push filename)))
@@ -361,7 +382,7 @@ Does nothing it if it matches any of the `recentf-exclude' regexps."
(defsubst recentf-remove-if-non-readable (filename)
"Remove FILENAME from the recent list, if file is not readable.
Return non-nil if FILENAME has been removed."
- (unless (file-readable-p filename)
+ (unless (recentf-file-readable-p filename)
(let ((m (recentf-string-member
(recentf-expand-file-name filename) recentf-list)))
(and m (setq recentf-list (delq (car m) recentf-list))))))
@@ -1112,11 +1133,12 @@ default."
"Save the recent list.
Write data into the file specified by `recentf-save-file'."
(interactive)
- (with-temp-file (expand-file-name recentf-save-file)
+ (with-temp-buffer
(erase-buffer)
(insert (format recentf-save-file-header (current-time-string)))
(recentf-dump-variable 'recentf-list recentf-max-saved-items)
(recentf-dump-variable 'recentf-filter-changer-state)
+ (write-file (expand-file-name recentf-save-file))
nil))
(defun recentf-load-list ()
@@ -1128,12 +1150,12 @@ Read data from the file specified by `recentf-save-file'."
(load-file file))))
(defun recentf-cleanup ()
- "Remove all non-readable and excluded files from the recent list."
+ "Remove all excluded or non-readable files from the recent list."
(interactive)
(message "Cleaning up the recentf list...")
(let (newlist)
(dolist (f recentf-list)
- (if (and (recentf-include-p f) (file-readable-p f))
+ (if (and (recentf-include-p f) (recentf-file-readable-p f))
(push f newlist)
(message "File %s removed from the recentf list" f)))
(setq recentf-list (nreverse newlist))