aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/filecache.el
diff options
context:
space:
mode:
authorRichard M. Stallman <[email protected]>1998-05-01 04:50:27 +0000
committerRichard M. Stallman <[email protected]>1998-05-01 04:50:27 +0000
commitb662c4bc6bc1503dac6cf2c27a3351232204de55 (patch)
tree568c64971045a118bfac511fbfe7f48b0ddcd9d2 /lisp/filecache.el
parent12857dfd21cd7f07bc6b2a9731203f36824f81a4 (diff)
(file-cache-add-file): Checks to see if file exists
before adding it. Non-existing files are simply skipped. (file-cache-add-directory): Checks to see if directory exists before adding it. Non-existing directories are simply skipped.
Diffstat (limited to 'lisp/filecache.el')
-rw-r--r--lisp/filecache.el77
1 files changed, 40 insertions, 37 deletions
diff --git a/lisp/filecache.el b/lisp/filecache.el
index 34d30a6456..0c0dcc3f59 100644
--- a/lisp/filecache.el
+++ b/lisp/filecache.el
@@ -1,9 +1,9 @@
;;; filecache.el --- Find files using a pre-loaded cache
;;
-;; Author: Peter Breton <[email protected]>
+;; Author: Peter Breton <[email protected]>
;; Created: Sun Nov 10 1996
;; Keywords:
-;; Time-stamp: <97/02/07 17:26:54 peter>
+;; Time-stamp: <1998-04-29 22:38:56 pbreton>
;;
;; Copyright (C) 1996 Free Software Foundation, Inc.
@@ -70,7 +70,8 @@
;; about extra files in the cache.
;;
;; The most convenient way to initialize the cache is with an
-;; `eval-after-load' function, as noted in the INSTALLATION section.
+;; `eval-after-load' function, as noted in the ADDING FILES
+;; AUTOMATICALLY section.
;;
;; FINDING FILES USING THE CACHE:
;;
@@ -96,11 +97,7 @@
;;
;; It is much easier to simply try it than trying to explain it :)
;;
-;;; INSTALLATION
-;;
-;; Insert the following into your .emacs:
-;;
-;; (autoload 'file-cache-minibuffer-complete "filecache" nil t)
+;;; ADDING FILES AUTOMATICALLY
;;
;; For maximum utility, you should probably define an `eval-after-load'
;; form which loads your favorite files:
@@ -148,7 +145,7 @@
:prefix "file-cache-")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Variables
+;; Customization Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User-modifiable variables
@@ -225,20 +222,24 @@ do not use this variable."
"Add DIRECTORY to the file cache.
If the optional REGEXP argument is non-nil, only files which match it will
be added to the cache."
- (interactive "DAdd files from directory: ")
- (let* ((dir (expand-file-name directory))
- (dir-files (directory-files dir t regexp))
- )
- ;; Filter out files we don't want to see
- (mapcar
- '(lambda (file)
+ (interactive "DAdd files from directory: ")
+ ;; Not an error, because otherwise we can't use load-paths that
+ ;; contain non-existent directories.
+ (if (not (file-accessible-directory-p directory))
+ (message "Directory %s does not exist" directory)
+ (let* ((dir (expand-file-name directory))
+ (dir-files (directory-files dir t regexp))
+ )
+ ;; Filter out files we don't want to see
+ (mapcar
+ '(lambda (file)
(mapcar
'(lambda (regexp)
(if (string-match regexp file)
(setq dir-files (delq file dir-files))))
file-cache-filter-regexps))
- dir-files)
- (file-cache-add-file-list dir-files)))
+ dir-files)
+ (file-cache-add-file-list dir-files))))
(defun file-cache-add-directory-list (directory-list &optional regexp)
"Add DIRECTORY-LIST (a list of directory names) to the file cache.
@@ -259,25 +260,27 @@ in each directory, not to the directory list itself."
(defun file-cache-add-file (file)
"Add FILE to the file cache."
(interactive "fAdd File: ")
- (let* ((file-name (file-name-nondirectory file))
- (dir-name (file-name-directory file))
- (the-entry (assoc file-name file-cache-alist))
- )
- ;; Does the entry exist already?
- (if the-entry
- (if (or (and (stringp (cdr the-entry))
- (string= dir-name (cdr the-entry)))
- (and (listp (cdr the-entry))
- (member dir-name (cdr the-entry))))
- nil
- (setcdr the-entry (append (list dir-name) (cdr the-entry)))
- )
- ;; If not, add it to the cache
- (setq file-cache-alist
- (cons (cons file-name (list dir-name))
- file-cache-alist)))
- ))
-
+ (if (not (file-exists-p file))
+ (message "File %s does not exist" file)
+ (let* ((file-name (file-name-nondirectory file))
+ (dir-name (file-name-directory file))
+ (the-entry (assoc file-name file-cache-alist))
+ )
+ ;; Does the entry exist already?
+ (if the-entry
+ (if (or (and (stringp (cdr the-entry))
+ (string= dir-name (cdr the-entry)))
+ (and (listp (cdr the-entry))
+ (member dir-name (cdr the-entry))))
+ nil
+ (setcdr the-entry (append (list dir-name) (cdr the-entry)))
+ )
+ ;; If not, add it to the cache
+ (setq file-cache-alist
+ (cons (cons file-name (list dir-name))
+ file-cache-alist)))
+ )))
+
(defun file-cache-add-directory-using-find (directory)
"Use the `find' command to add files to the file cache.
Find is run in DIRECTORY."