1 |
;;; recentf.el --- setup a menu of recently opened files |
;;; recentf.el --- setup a menu of recently opened files |
2 |
|
|
3 |
;; Copyright (C) 1999, 2000, 2001, 2002, 2003 |
;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 |
4 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: David Ponce <david@dponce.com> |
;; Author: David Ponce <david@dponce.com> |
84 |
:group 'recentf |
:group 'recentf |
85 |
:type '(repeat (choice regexp function))) |
:type '(repeat (choice regexp function))) |
86 |
|
|
87 |
|
(defcustom recentf-keep |
88 |
|
'(file-readable-p) |
89 |
|
"*List of regexps and predicates for filenames kept in the recent list. |
90 |
|
Regexps and predicates are tried in the specified order. |
91 |
|
When nil all filenames are kept in the recent list. |
92 |
|
When a filename matches any of the regexps or satisfies any of the |
93 |
|
predicates it is kept in the recent list. |
94 |
|
The default is to keep readable files. |
95 |
|
A predicate is a function that is passed a filename to check and that |
96 |
|
must return non-nil to keep it. For example, you can add the |
97 |
|
`file-remote-p' predicate in front of this list to keep remote file |
98 |
|
names in the recent list without checking their readability through a |
99 |
|
remote access." |
100 |
|
:group 'recentf |
101 |
|
:type '(repeat (choice regexp function))) |
102 |
|
|
103 |
(defun recentf-menu-customization-changed (variable value) |
(defun recentf-menu-customization-changed (variable value) |
104 |
"Function called when the recentf menu customization has changed. |
"Function called when the recentf menu customization has changed. |
105 |
Set VARIABLE with VALUE, and force a rebuild of the recentf menu." |
Set VARIABLE with VALUE, and force a rebuild of the recentf menu." |
130 |
(const :tag "Last" nil)) |
(const :tag "Last" nil)) |
131 |
:set 'recentf-menu-customization-changed) |
:set 'recentf-menu-customization-changed) |
132 |
|
|
133 |
(defcustom recentf-menu-action 'recentf-find-file |
(defcustom recentf-menu-action 'find-file |
134 |
"*Function to invoke with a filename item of the recentf menu. |
"*Function to invoke with a filename item of the recentf menu. |
135 |
The default is to call `recentf-find-file' to edit the selected file." |
The default is to call `find-file' to edit the selected file." |
136 |
:group 'recentf |
:group 'recentf |
137 |
:type 'function |
:type 'function |
138 |
:set 'recentf-menu-customization-changed) |
:set 'recentf-menu-customization-changed) |
210 |
'recentf-menu-append-commands-flag |
'recentf-menu-append-commands-flag |
211 |
"22.1") |
"22.1") |
212 |
|
|
|
(defcustom recentf-keep-non-readable-files-flag nil |
|
|
"*non-nil means to keep non readable files in the recent list." |
|
|
:group 'recentf |
|
|
:type 'boolean) |
|
|
|
|
|
(defvaralias 'recentf-keep-non-readable-files-p |
|
|
'recentf-keep-non-readable-files-flag) |
|
|
(make-obsolete-variable 'recentf-keep-non-readable-files-p |
|
|
'recentf-keep-non-readable-files-flag |
|
|
"22.1") |
|
|
|
|
213 |
(defcustom recentf-auto-cleanup 'mode |
(defcustom recentf-auto-cleanup 'mode |
214 |
"*Define when to automatically cleanup the recent list. |
"*Define when to automatically cleanup the recent list. |
215 |
The following values can be set: |
The following values can be set: |
260 |
If it returns nil, the filename is left unchanged." |
If it returns nil, the filename is left unchanged." |
261 |
:group 'recentf |
:group 'recentf |
262 |
:type 'function) |
:type 'function) |
|
|
|
|
(defcustom recentf-cleanup-remote t |
|
|
"*non-nil means to auto cleanup remote files." |
|
|
:group 'recentf |
|
|
:type 'boolean) |
|
263 |
|
|
264 |
;;; Utilities |
;;; Utilities |
265 |
;; |
;; |
356 |
(funcall recentf-filename-handler filename)) |
(funcall recentf-filename-handler filename)) |
357 |
filename))) |
filename))) |
358 |
|
|
|
(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))) |
|
|
|
|
359 |
(defun recentf-include-p (filename) |
(defun recentf-include-p (filename) |
360 |
"Return non-nil if FILENAME should be included in the recent list. |
"Return non-nil if FILENAME should be included in the recent list. |
361 |
That is, if it doesn't match any of the `recentf-exclude' checks." |
That is, if it doesn't match any of the `recentf-exclude' checks." |
362 |
(let ((case-fold-search recentf-case-fold-search) |
(let ((case-fold-search recentf-case-fold-search) |
363 |
(checks recentf-exclude) |
(checks recentf-exclude) |
364 |
(keepit t) |
(keepit t)) |
|
check) |
|
365 |
(while (and checks keepit) |
(while (and checks keepit) |
366 |
(setq check (car checks) |
(setq keepit (condition-case nil |
367 |
checks (cdr checks) |
(not (if (stringp (car checks)) |
368 |
keepit (not (if (stringp check) |
;; A regexp |
369 |
;; A regexp |
(string-match (car checks) filename) |
370 |
(string-match check filename) |
;; A predicate |
371 |
;; A predicate |
(funcall (car checks) filename))) |
372 |
(funcall check filename))))) |
(error nil)) |
373 |
|
checks (cdr checks))) |
374 |
|
keepit)) |
375 |
|
|
376 |
|
(defun recentf-keep-p (filename) |
377 |
|
"Return non-nil if FILENAME should be kept in the recent list. |
378 |
|
That is, if it matches any of the `recentf-keep' checks." |
379 |
|
(let* ((case-fold-search recentf-case-fold-search) |
380 |
|
(checks recentf-keep) |
381 |
|
(keepit (null checks))) |
382 |
|
(while (and checks (not keepit)) |
383 |
|
(setq keepit (condition-case nil |
384 |
|
(if (stringp (car checks)) |
385 |
|
;; A regexp |
386 |
|
(string-match (car checks) filename) |
387 |
|
;; A predicate |
388 |
|
(funcall (car checks) filename)) |
389 |
|
(error nil)) |
390 |
|
checks (cdr checks))) |
391 |
keepit)) |
keepit)) |
392 |
|
|
393 |
(defsubst recentf-add-file (filename) |
(defsubst recentf-add-file (filename) |
394 |
"Add or move FILENAME at the beginning of the recent list. |
"Add or move FILENAME at the beginning of the recent list. |
395 |
Does nothing if the name satisfies any of the `recentf-exclude' regexps or |
Does nothing if the name satisfies any of the `recentf-exclude' |
396 |
predicates." |
regexps or predicates." |
397 |
(setq filename (recentf-expand-file-name filename)) |
(setq filename (recentf-expand-file-name filename)) |
398 |
(when (recentf-include-p filename) |
(when (recentf-include-p filename) |
399 |
(recentf-push filename))) |
(recentf-push filename))) |
400 |
|
|
401 |
(defsubst recentf-remove-if-non-readable (filename) |
(defsubst recentf-remove-if-non-kept (filename) |
402 |
"Remove FILENAME from the recent list, if file is not readable. |
"Remove FILENAME from the recent list, if file is not kept. |
403 |
Return non-nil if FILENAME has been removed." |
Return non-nil if FILENAME has been removed." |
404 |
(unless (recentf-file-readable-p filename) |
(unless (recentf-keep-p filename) |
405 |
(let ((m (recentf-string-member |
(let ((m (recentf-string-member |
406 |
(recentf-expand-file-name filename) recentf-list))) |
(recentf-expand-file-name filename) recentf-list))) |
407 |
(and m (setq recentf-list (delq (car m) recentf-list)))))) |
(and m (setq recentf-list (delq (car m) recentf-list)))))) |
408 |
|
|
|
(defun recentf-find-file (filename) |
|
|
"Edit file FILENAME using `find-file'. |
|
|
If the file does not exist or is non readable, and |
|
|
`recentf-keep-non-readable-files-flag' is nil, it is not edited and |
|
|
its name is removed from the recent list." |
|
|
(if (and (not recentf-keep-non-readable-files-flag) |
|
|
(recentf-remove-if-non-readable filename)) |
|
|
(message "File `%s' not found" filename) |
|
|
(find-file filename))) |
|
|
|
|
409 |
(defsubst recentf-directory-compare (f1 f2) |
(defsubst recentf-directory-compare (f1 f2) |
410 |
"Compare absolute filenames F1 and F2. |
"Compare absolute filenames F1 and F2. |
411 |
First compare directories, then filenames sans directory. |
First compare directories, then filenames sans directory. |
422 |
(defvar recentf-menu-items-for-commands |
(defvar recentf-menu-items-for-commands |
423 |
(list ["Cleanup list" |
(list ["Cleanup list" |
424 |
recentf-cleanup |
recentf-cleanup |
425 |
:help "Remove all non-readable and excluded files from the recent list" |
:help "Remove all excluded and non-kept files from the recent list" |
426 |
:active t] |
:active t] |
427 |
["Edit list..." |
["Edit list..." |
428 |
recentf-edit-list |
recentf-edit-list |
938 |
|
|
939 |
(defun recentf-track-closed-file () |
(defun recentf-track-closed-file () |
940 |
"Update the recent list when a buffer is killed. |
"Update the recent list when a buffer is killed. |
941 |
That is, remove a non readable file from the recent list, if |
That is, remove a non kept file from the recent list." |
|
`recentf-keep-non-readable-files-flag' is nil." |
|
942 |
(and buffer-file-name |
(and buffer-file-name |
943 |
(not recentf-keep-non-readable-files-flag) |
(recentf-remove-if-non-kept buffer-file-name))) |
|
(recentf-remove-if-non-readable buffer-file-name))) |
|
944 |
|
|
945 |
(defun recentf-update-menu () |
(defun recentf-update-menu () |
946 |
"Update the recentf menu from the current recent list." |
"Update the recentf menu from the current recent list." |
1167 |
recentf-list)))))) |
recentf-list)))))) |
1168 |
|
|
1169 |
(defun recentf-cleanup () |
(defun recentf-cleanup () |
1170 |
"Remove all excluded or non-readable files from the recent list." |
"Remove all non-kept and excluded files from the recent list." |
1171 |
(interactive) |
(interactive) |
1172 |
(message "Cleaning up the recentf list...") |
(message "Cleaning up the recentf list...") |
1173 |
(let (newlist) |
(let ((n 0) newlist) |
1174 |
(dolist (f recentf-list) |
(dolist (f recentf-list) |
1175 |
(if (and (recentf-include-p f) |
(if (and (recentf-include-p f) |
1176 |
(or (and (file-remote-p f) |
(recentf-keep-p f)) |
|
(not recentf-cleanup-remote)) |
|
|
(recentf-file-readable-p f))) |
|
1177 |
(push f newlist) |
(push f newlist) |
1178 |
|
(setq n (1+ n)) |
1179 |
(message "File %s removed from the recentf list" f))) |
(message "File %s removed from the recentf list" f))) |
1180 |
(setq recentf-list (nreverse newlist)) |
(message "Cleaning up the recentf list...done (%d removed)" n) |
1181 |
(message "Cleaning up the recentf list...done"))) |
(setq recentf-list (nreverse newlist)))) |
1182 |
|
|
1183 |
;;;###autoload |
;;;###autoload |
1184 |
(define-minor-mode recentf-mode |
(define-minor-mode recentf-mode |