Mercurial > emacs
diff 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 |
line wrap: on
line diff
--- a/lisp/recentf.el Thu Apr 15 01:08:34 2004 +0000 +++ b/lisp/recentf.el Fri Apr 16 12:51:06 2004 +0000 @@ -8,8 +8,6 @@ ;; Maintainer: FSF ;; Keywords: files -(defconst recentf-version "$Revision: 1.23 $") - ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify @@ -78,9 +76,13 @@ :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. @@ -98,7 +100,7 @@ (defcustom recentf-menu-path '("files") "*Path where to add the recentf menu. -If nil add it at top level (see also `easy-menu-change')." +If nil add it at top level (see also `easy-menu-add-item')." :group 'recentf :type '(choice (const :tag "Top Level" nil) (sexp :tag "Menu Path")) @@ -106,7 +108,7 @@ (defcustom recentf-menu-before "Open File..." "*Name of the menu before which the recentf menu will be added. -If nil add it at end of menu (see also `easy-menu-change')." +If nil add it at end of menu (see also `easy-menu-add-item')." :group 'recentf :type '(choice (string :tag "Name") (const :tag "Last" nil)) @@ -236,6 +238,12 @@ ;; Unavailable until recentf has been loaded. (recentf-auto-cleanup)))) +(defcustom recentf-initialize-file-name-history t + "*non-nil means to initialize `file-name-history' with the recent list. +If `file-name-history' is not empty, do nothing." + :group 'recentf + :type 'boolean) + (defcustom recentf-load-hook nil "*Normal hook run at end of loading the `recentf' package." :group 'recentf @@ -343,17 +351,34 @@ (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 +386,7 @@ (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)))))) @@ -520,10 +545,15 @@ :help (concat "Open " value) :active t)))) +(defsubst recentf-menu-bar () + "Return the keymap of the global menu bar." + (lookup-key global-map [menu-bar])) + (defun recentf-clear-data () "Clear data used to build the recentf menu. This force a rebuild of the menu." - (easy-menu-remove-item nil recentf-menu-path recentf-menu-title) + (easy-menu-remove-item (recentf-menu-bar) + recentf-menu-path recentf-menu-title) (setq recentf-data-cache nil)) ;;; Predefined menu filters @@ -916,10 +946,11 @@ (unless (equal recentf-data-cache cache) (setq recentf-data-cache cache) (condition-case err - (easy-menu-change recentf-menu-path - recentf-menu-title - (recentf-make-menu-items) - recentf-menu-before) + (easy-menu-add-item + (recentf-menu-bar) recentf-menu-path + (easy-menu-create-menu recentf-menu-title + (recentf-make-menu-items)) + recentf-menu-before) (error (message "recentf update menu failed: %s" (error-message-string err))))))) @@ -1106,28 +1137,35 @@ "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 () "Load a previously saved recent list. -Read data from the file specified by `recentf-save-file'." +Read data from the file specified by `recentf-save-file'. +When `recentf-initialize-file-name-history' is non-nil, initialize an +empty `file-name-history' with the recent list." (interactive) (let ((file (expand-file-name recentf-save-file))) (when (file-readable-p file) - (load-file file)))) + (load-file file) + (and recentf-initialize-file-name-history + (not file-name-history) + (setq file-name-history (mapcar 'abbreviate-file-name + recentf-list)))))) (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)) @@ -1161,4 +1199,5 @@ (run-hooks 'recentf-load-hook) +;;; arch-tag: 78f1eec9-0d16-4d19-a4eb-2e4529edb62a ;;; recentf.el ends here