comparison lisp/recentf.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
5 5
6 ;; Author: David Ponce <david@dponce.com> 6 ;; Author: David Ponce <david@dponce.com>
7 ;; Created: July 19 1999 7 ;; Created: July 19 1999
8 ;; Maintainer: FSF 8 ;; Maintainer: FSF
9 ;; Keywords: files 9 ;; Keywords: files
10
11 (defconst recentf-version "$Revision: 1.23 $")
12 10
13 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
14 12
15 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published 14 ;; it under the terms of the GNU General Public License as published
76 "*File to save the recent list into." 74 "*File to save the recent list into."
77 :group 'recentf 75 :group 'recentf
78 :type 'file) 76 :type 'file)
79 77
80 (defcustom recentf-exclude nil 78 (defcustom recentf-exclude nil
81 "*List of regexps for filenames excluded from the recent list." 79 "*List of regexps and predicates for filenames excluded from the recent list.
82 :group 'recentf 80 When a filename matches any of the regexps or satisfies any of the
83 :type '(repeat regexp)) 81 predicates it is excluded from the recent list.
82 A predicate is a function that is passed a filename to check and that
83 must return non-nil to exclude it."
84 :group 'recentf
85 :type '(repeat (choice regexp function)))
84 86
85 (defun recentf-menu-customization-changed (variable value) 87 (defun recentf-menu-customization-changed (variable value)
86 "Function called when the recentf menu customization has changed. 88 "Function called when the recentf menu customization has changed.
87 Set VARIABLE with VALUE, and force a rebuild of the recentf menu." 89 Set VARIABLE with VALUE, and force a rebuild of the recentf menu."
88 (when (featurep 'recentf) 90 (when (featurep 'recentf)
96 :type 'string 98 :type 'string
97 :set 'recentf-menu-customization-changed) 99 :set 'recentf-menu-customization-changed)
98 100
99 (defcustom recentf-menu-path '("files") 101 (defcustom recentf-menu-path '("files")
100 "*Path where to add the recentf menu. 102 "*Path where to add the recentf menu.
101 If nil add it at top level (see also `easy-menu-change')." 103 If nil add it at top level (see also `easy-menu-add-item')."
102 :group 'recentf 104 :group 'recentf
103 :type '(choice (const :tag "Top Level" nil) 105 :type '(choice (const :tag "Top Level" nil)
104 (sexp :tag "Menu Path")) 106 (sexp :tag "Menu Path"))
105 :set 'recentf-menu-customization-changed) 107 :set 'recentf-menu-customization-changed)
106 108
107 (defcustom recentf-menu-before "Open File..." 109 (defcustom recentf-menu-before "Open File..."
108 "*Name of the menu before which the recentf menu will be added. 110 "*Name of the menu before which the recentf menu will be added.
109 If nil add it at end of menu (see also `easy-menu-change')." 111 If nil add it at end of menu (see also `easy-menu-add-item')."
110 :group 'recentf 112 :group 'recentf
111 :type '(choice (string :tag "Name") 113 :type '(choice (string :tag "Name")
112 (const :tag "Last" nil)) 114 (const :tag "Last" nil))
113 :set 'recentf-menu-customization-changed) 115 :set 'recentf-menu-customization-changed)
114 116
234 (set-default variable value) 236 (set-default variable value)
235 (when (featurep 'recentf) 237 (when (featurep 'recentf)
236 ;; Unavailable until recentf has been loaded. 238 ;; Unavailable until recentf has been loaded.
237 (recentf-auto-cleanup)))) 239 (recentf-auto-cleanup))))
238 240
241 (defcustom recentf-initialize-file-name-history t
242 "*non-nil means to initialize `file-name-history' with the recent list.
243 If `file-name-history' is not empty, do nothing."
244 :group 'recentf
245 :type 'boolean)
246
239 (defcustom recentf-load-hook nil 247 (defcustom recentf-load-hook nil
240 "*Normal hook run at end of loading the `recentf' package." 248 "*Normal hook run at end of loading the `recentf' package."
241 :group 'recentf 249 :group 'recentf
242 :type 'hook) 250 :type 'hook)
243 251
341 (let* ((filename (expand-file-name name))) 349 (let* ((filename (expand-file-name name)))
342 (or (and recentf-filename-handler 350 (or (and recentf-filename-handler
343 (funcall recentf-filename-handler filename)) 351 (funcall recentf-filename-handler filename))
344 filename))) 352 filename)))
345 353
354 (defsubst recentf-file-readable-p (filename)
355 "Return t if file FILENAME exists and you can read it.
356 Like the function `file-readable-p' but return nil on error."
357 (condition-case nil
358 (file-readable-p filename)
359 (error nil)))
360
346 (defun recentf-include-p (filename) 361 (defun recentf-include-p (filename)
347 "Return t if FILENAME match none of the `recentf-exclude' regexps." 362 "Return non-nil if FILENAME should be included in the recent list.
363 That is, if it doesn't match any of the `recentf-exclude' checks."
348 (let ((case-fold-search recentf-case-fold-search) 364 (let ((case-fold-search recentf-case-fold-search)
349 (rl recentf-exclude)) 365 (checks recentf-exclude)
350 (while (and rl (not (string-match (car rl) filename))) 366 (keepit t)
351 (setq rl (cdr rl))) 367 check)
352 (null rl))) 368 (while (and checks keepit)
369 (setq check (car checks)
370 checks (cdr checks)
371 keepit (not (if (stringp check)
372 ;; A regexp
373 (string-match check filename)
374 ;; A predicate
375 (funcall check filename)))))
376 keepit))
353 377
354 (defsubst recentf-add-file (filename) 378 (defsubst recentf-add-file (filename)
355 "Add or move FILENAME at the beginning of the recent list. 379 "Add or move FILENAME at the beginning of the recent list.
356 Does nothing it if it matches any of the `recentf-exclude' regexps." 380 Does nothing if the name satisfies any of the `recentf-exclude' regexps or
381 predicates."
357 (setq filename (recentf-expand-file-name filename)) 382 (setq filename (recentf-expand-file-name filename))
358 (when (recentf-include-p filename) 383 (when (recentf-include-p filename)
359 (recentf-push filename))) 384 (recentf-push filename)))
360 385
361 (defsubst recentf-remove-if-non-readable (filename) 386 (defsubst recentf-remove-if-non-readable (filename)
362 "Remove FILENAME from the recent list, if file is not readable. 387 "Remove FILENAME from the recent list, if file is not readable.
363 Return non-nil if FILENAME has been removed." 388 Return non-nil if FILENAME has been removed."
364 (unless (file-readable-p filename) 389 (unless (recentf-file-readable-p filename)
365 (let ((m (recentf-string-member 390 (let ((m (recentf-string-member
366 (recentf-expand-file-name filename) recentf-list))) 391 (recentf-expand-file-name filename) recentf-list)))
367 (and m (setq recentf-list (delq (car m) recentf-list)))))) 392 (and m (setq recentf-list (delq (car m) recentf-list))))))
368 393
369 (defun recentf-find-file (filename) 394 (defun recentf-find-file (filename)
518 (cons item (mapcar 'recentf-make-menu-item value)) 543 (cons item (mapcar 'recentf-make-menu-item value))
519 (vector item (list recentf-menu-action value) 544 (vector item (list recentf-menu-action value)
520 :help (concat "Open " value) 545 :help (concat "Open " value)
521 :active t)))) 546 :active t))))
522 547
548 (defsubst recentf-menu-bar ()
549 "Return the keymap of the global menu bar."
550 (lookup-key global-map [menu-bar]))
551
523 (defun recentf-clear-data () 552 (defun recentf-clear-data ()
524 "Clear data used to build the recentf menu. 553 "Clear data used to build the recentf menu.
525 This force a rebuild of the menu." 554 This force a rebuild of the menu."
526 (easy-menu-remove-item nil recentf-menu-path recentf-menu-title) 555 (easy-menu-remove-item (recentf-menu-bar)
556 recentf-menu-path recentf-menu-title)
527 (setq recentf-data-cache nil)) 557 (setq recentf-data-cache nil))
528 558
529 ;;; Predefined menu filters 559 ;;; Predefined menu filters
530 ;; 560 ;;
531 (defsubst recentf-sort-ascending (l) 561 (defsubst recentf-sort-ascending (l)
914 (let ((cache (cons default-directory recentf-list))) 944 (let ((cache (cons default-directory recentf-list)))
915 ;; Does nothing, if nothing has changed. 945 ;; Does nothing, if nothing has changed.
916 (unless (equal recentf-data-cache cache) 946 (unless (equal recentf-data-cache cache)
917 (setq recentf-data-cache cache) 947 (setq recentf-data-cache cache)
918 (condition-case err 948 (condition-case err
919 (easy-menu-change recentf-menu-path 949 (easy-menu-add-item
920 recentf-menu-title 950 (recentf-menu-bar) recentf-menu-path
921 (recentf-make-menu-items) 951 (easy-menu-create-menu recentf-menu-title
922 recentf-menu-before) 952 (recentf-make-menu-items))
953 recentf-menu-before)
923 (error 954 (error
924 (message "recentf update menu failed: %s" 955 (message "recentf update menu failed: %s"
925 (error-message-string err))))))) 956 (error-message-string err)))))))
926 957
927 (defconst recentf-used-hooks 958 (defconst recentf-used-hooks
1104 1135
1105 (defun recentf-save-list () 1136 (defun recentf-save-list ()
1106 "Save the recent list. 1137 "Save the recent list.
1107 Write data into the file specified by `recentf-save-file'." 1138 Write data into the file specified by `recentf-save-file'."
1108 (interactive) 1139 (interactive)
1109 (with-temp-file (expand-file-name recentf-save-file) 1140 (with-temp-buffer
1110 (erase-buffer) 1141 (erase-buffer)
1111 (insert (format recentf-save-file-header (current-time-string))) 1142 (insert (format recentf-save-file-header (current-time-string)))
1112 (recentf-dump-variable 'recentf-list recentf-max-saved-items) 1143 (recentf-dump-variable 'recentf-list recentf-max-saved-items)
1113 (recentf-dump-variable 'recentf-filter-changer-state) 1144 (recentf-dump-variable 'recentf-filter-changer-state)
1145 (write-file (expand-file-name recentf-save-file))
1114 nil)) 1146 nil))
1115 1147
1116 (defun recentf-load-list () 1148 (defun recentf-load-list ()
1117 "Load a previously saved recent list. 1149 "Load a previously saved recent list.
1118 Read data from the file specified by `recentf-save-file'." 1150 Read data from the file specified by `recentf-save-file'.
1151 When `recentf-initialize-file-name-history' is non-nil, initialize an
1152 empty `file-name-history' with the recent list."
1119 (interactive) 1153 (interactive)
1120 (let ((file (expand-file-name recentf-save-file))) 1154 (let ((file (expand-file-name recentf-save-file)))
1121 (when (file-readable-p file) 1155 (when (file-readable-p file)
1122 (load-file file)))) 1156 (load-file file)
1157 (and recentf-initialize-file-name-history
1158 (not file-name-history)
1159 (setq file-name-history (mapcar 'abbreviate-file-name
1160 recentf-list))))))
1123 1161
1124 (defun recentf-cleanup () 1162 (defun recentf-cleanup ()
1125 "Remove all non-readable and excluded files from the recent list." 1163 "Remove all excluded or non-readable files from the recent list."
1126 (interactive) 1164 (interactive)
1127 (message "Cleaning up the recentf list...") 1165 (message "Cleaning up the recentf list...")
1128 (let (newlist) 1166 (let (newlist)
1129 (dolist (f recentf-list) 1167 (dolist (f recentf-list)
1130 (if (and (recentf-include-p f) (file-readable-p f)) 1168 (if (and (recentf-include-p f) (recentf-file-readable-p f))
1131 (push f newlist) 1169 (push f newlist)
1132 (message "File %s removed from the recentf list" f))) 1170 (message "File %s removed from the recentf list" f)))
1133 (setq recentf-list (nreverse newlist)) 1171 (setq recentf-list (nreverse newlist))
1134 (message "Cleaning up the recentf list...done"))) 1172 (message "Cleaning up the recentf list...done")))
1135 1173
1159 1197
1160 (provide 'recentf) 1198 (provide 'recentf)
1161 1199
1162 (run-hooks 'recentf-load-hook) 1200 (run-hooks 'recentf-load-hook)
1163 1201
1202 ;;; arch-tag: 78f1eec9-0d16-4d19-a4eb-2e4529edb62a
1164 ;;; recentf.el ends here 1203 ;;; recentf.el ends here