aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ponce2005-09-30 06:18:55 +0000
committerDavid Ponce2005-09-30 06:18:55 +0000
commitad8b6d89ef6f038921104c219ff9010ee08cb0ca (patch)
treef2725e1e87f47a1f56124dda2164c04995dd7df7
parent6aabfecf9939b9f2e4a8fed8ee82434726f0851a (diff)
downloademacs-ad8b6d89ef6f038921104c219ff9010ee08cb0ca.tar.gz
emacs-ad8b6d89ef6f038921104c219ff9010ee08cb0ca.zip
(recentf-filename-handlers): Rename from
`recentf-filename-handler'. Allow a list of functions. (recentf-menu-items-for-commands): Fix :help strings. (recentf-apply-filename-handlers): New function. (recentf-expand-file-name): Use it. (recentf-cleanup): Remove duplicates too.
-rw-r--r--lisp/recentf.el85
1 files changed, 51 insertions, 34 deletions
diff --git a/lisp/recentf.el b/lisp/recentf.el
index df12debe453..a2392fb852c 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -260,14 +260,17 @@ If `file-name-history' is not empty, do nothing."
260 :group 'recentf 260 :group 'recentf
261 :type 'hook) 261 :type 'hook)
262 262
263(defcustom recentf-filename-handler nil 263(defcustom recentf-filename-handlers nil
264 "Function to call to process filename handled by recentf. 264 "Functions to post process recent file names.
265It is passed a filename to give a chance to transform it. 265They are successively passed a file name to transform it."
266If it returns nil, the filename is left unchanged."
267 :group 'recentf 266 :group 'recentf
268 :type '(choice (const :tag "None" nil) 267 :type '(choice
269 (const abbreviate-file-name) 268 (const :tag "None" nil)
270 function)) 269 (repeat :tag "Functions"
270 (choice
271 (const file-truename)
272 (const abbreviate-file-name)
273 (function :tag "Other function")))))
271 274
272(defcustom recentf-show-file-shortcuts-flag t 275(defcustom recentf-show-file-shortcuts-flag t
273 "Whether to show ``[N]'' for the Nth item up to 10. 276 "Whether to show ``[N]'' for the Nth item up to 10.
@@ -362,15 +365,25 @@ filenames."
362 (and m (setq recentf-list (delq (car m) recentf-list))) 365 (and m (setq recentf-list (delq (car m) recentf-list)))
363 (push filename recentf-list))) 366 (push filename recentf-list)))
364 367
368(defun recentf-apply-filename-handlers (name)
369 "Apply `recentf-filename-handlers' to file NAME.
370Return the transformed file name, or NAME if any handler failed, or
371returned nil."
372 (or (condition-case nil
373 (let ((handlers recentf-filename-handlers)
374 (filename name))
375 (while (and filename handlers)
376 (setq filename (funcall (car handlers) filename)
377 handlers (cdr handlers)))
378 filename)
379 (error nil))
380 name))
381
365(defsubst recentf-expand-file-name (name) 382(defsubst recentf-expand-file-name (name)
366 "Convert filename NAME to absolute, and canonicalize it. 383 "Convert file NAME to absolute, and canonicalize it.
367See also the function `expand-file-name'. 384NAME is first passed to the function `expand-file-name', then to
368If defined, call the function `recentf-filename-handler' 385`recentf-filename-handlers' to post process it."
369to post process the canonical name." 386 (recentf-apply-filename-handlers (expand-file-name name)))
370 (let* ((filename (expand-file-name name)))
371 (or (and recentf-filename-handler
372 (funcall recentf-filename-handler filename))
373 filename)))
374 387
375(defun recentf-include-p (filename) 388(defun recentf-include-p (filename)
376 "Return non-nil if FILENAME should be included in the recent list. 389 "Return non-nil if FILENAME should be included in the recent list.
@@ -436,23 +449,24 @@ Return non-nil if F1 is less than F2."
436;;; Menu building 449;;; Menu building
437;; 450;;
438(defvar recentf-menu-items-for-commands 451(defvar recentf-menu-items-for-commands
439 (list ["Cleanup list" 452 (list
440 recentf-cleanup 453 ["Cleanup list"
441 :help "Remove all excluded and non-kept files from the recent list" 454 recentf-cleanup
442 :active t] 455 :help "Remove duplicates, and obsoletes files from the recent list"
443 ["Edit list..." 456 :active t]
444 recentf-edit-list 457 ["Edit list..."
445 :help "Edit the files that are kept in the recent list" 458 recentf-edit-list
446 :active t] 459 :help "Manually remove files from the recent list"
447 ["Save list now" 460 :active t]
448 recentf-save-list 461 ["Save list now"
449 :help "Save the list of recently opened files now" 462 recentf-save-list
450 :active t] 463 :help "Save the list of recently opened files now"
451 ["Options..." 464 :active t]
452 (customize-group "recentf") 465 ["Options..."
453 :help "Customize recently opened files menu and options" 466 (customize-group "recentf")
454 :active t] 467 :help "Customize recently opened files menu and options"
455 ) 468 :active t]
469 )
456 "List of menu items for recentf commands.") 470 "List of menu items for recentf commands.")
457 471
458(defvar recentf-menu-filter-commands nil 472(defvar recentf-menu-filter-commands nil
@@ -1236,13 +1250,16 @@ empty `file-name-history' with the recent list."
1236 recentf-list)))))) 1250 recentf-list))))))
1237 1251
1238(defun recentf-cleanup () 1252(defun recentf-cleanup ()
1239 "Remove all non-kept and excluded files from the recent list." 1253 "Cleanup the recent list.
1254That is, remove duplicates, non-kept, and excluded files."
1240 (interactive) 1255 (interactive)
1241 (message "Cleaning up the recentf list...") 1256 (message "Cleaning up the recentf list...")
1242 (let ((n 0) newlist) 1257 (let ((n 0) newlist)
1243 (dolist (f recentf-list) 1258 (dolist (f recentf-list)
1259 (setq f (recentf-expand-file-name f))
1244 (if (and (recentf-include-p f) 1260 (if (and (recentf-include-p f)
1245 (recentf-keep-p f)) 1261 (recentf-keep-p f)
1262 (not (recentf-string-member f newlist)))
1246 (push f newlist) 1263 (push f newlist)
1247 (setq n (1+ n)) 1264 (setq n (1+ n))
1248 (message "File %s removed from the recentf list" f))) 1265 (message "File %s removed from the recentf list" f)))