diff options
| author | Richard M. Stallman | 1998-05-01 04:50:27 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-01 04:50:27 +0000 |
| commit | b662c4bc6bc1503dac6cf2c27a3351232204de55 (patch) | |
| tree | 568c64971045a118bfac511fbfe7f48b0ddcd9d2 | |
| parent | 12857dfd21cd7f07bc6b2a9731203f36824f81a4 (diff) | |
| download | emacs-b662c4bc6bc1503dac6cf2c27a3351232204de55.tar.gz emacs-b662c4bc6bc1503dac6cf2c27a3351232204de55.zip | |
(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.
| -rw-r--r-- | lisp/filecache.el | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/lisp/filecache.el b/lisp/filecache.el index 34d30a6456b..0c0dcc3f59b 100644 --- a/lisp/filecache.el +++ b/lisp/filecache.el | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | ;;; filecache.el --- Find files using a pre-loaded cache | 1 | ;;; filecache.el --- Find files using a pre-loaded cache |
| 2 | ;; | 2 | ;; |
| 3 | ;; Author: Peter Breton <pbreton@i-kinetics.com> | 3 | ;; Author: Peter Breton <pbreton@cs.umb.edu> |
| 4 | ;; Created: Sun Nov 10 1996 | 4 | ;; Created: Sun Nov 10 1996 |
| 5 | ;; Keywords: | 5 | ;; Keywords: |
| 6 | ;; Time-stamp: <97/02/07 17:26:54 peter> | 6 | ;; Time-stamp: <1998-04-29 22:38:56 pbreton> |
| 7 | ;; | 7 | ;; |
| 8 | ;; Copyright (C) 1996 Free Software Foundation, Inc. | 8 | ;; Copyright (C) 1996 Free Software Foundation, Inc. |
| 9 | 9 | ||
| @@ -70,7 +70,8 @@ | |||
| 70 | ;; about extra files in the cache. | 70 | ;; about extra files in the cache. |
| 71 | ;; | 71 | ;; |
| 72 | ;; The most convenient way to initialize the cache is with an | 72 | ;; The most convenient way to initialize the cache is with an |
| 73 | ;; `eval-after-load' function, as noted in the INSTALLATION section. | 73 | ;; `eval-after-load' function, as noted in the ADDING FILES |
| 74 | ;; AUTOMATICALLY section. | ||
| 74 | ;; | 75 | ;; |
| 75 | ;; FINDING FILES USING THE CACHE: | 76 | ;; FINDING FILES USING THE CACHE: |
| 76 | ;; | 77 | ;; |
| @@ -96,11 +97,7 @@ | |||
| 96 | ;; | 97 | ;; |
| 97 | ;; It is much easier to simply try it than trying to explain it :) | 98 | ;; It is much easier to simply try it than trying to explain it :) |
| 98 | ;; | 99 | ;; |
| 99 | ;;; INSTALLATION | 100 | ;;; ADDING FILES AUTOMATICALLY |
| 100 | ;; | ||
| 101 | ;; Insert the following into your .emacs: | ||
| 102 | ;; | ||
| 103 | ;; (autoload 'file-cache-minibuffer-complete "filecache" nil t) | ||
| 104 | ;; | 101 | ;; |
| 105 | ;; For maximum utility, you should probably define an `eval-after-load' | 102 | ;; For maximum utility, you should probably define an `eval-after-load' |
| 106 | ;; form which loads your favorite files: | 103 | ;; form which loads your favorite files: |
| @@ -148,7 +145,7 @@ | |||
| 148 | :prefix "file-cache-") | 145 | :prefix "file-cache-") |
| 149 | 146 | ||
| 150 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 147 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 151 | ;; Variables | 148 | ;; Customization Variables |
| 152 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 149 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 153 | 150 | ||
| 154 | ;; User-modifiable variables | 151 | ;; User-modifiable variables |
| @@ -225,20 +222,24 @@ do not use this variable." | |||
| 225 | "Add DIRECTORY to the file cache. | 222 | "Add DIRECTORY to the file cache. |
| 226 | If the optional REGEXP argument is non-nil, only files which match it will | 223 | If the optional REGEXP argument is non-nil, only files which match it will |
| 227 | be added to the cache." | 224 | be added to the cache." |
| 228 | (interactive "DAdd files from directory: ") | 225 | (interactive "DAdd files from directory: ") |
| 229 | (let* ((dir (expand-file-name directory)) | 226 | ;; Not an error, because otherwise we can't use load-paths that |
| 230 | (dir-files (directory-files dir t regexp)) | 227 | ;; contain non-existent directories. |
| 231 | ) | 228 | (if (not (file-accessible-directory-p directory)) |
| 232 | ;; Filter out files we don't want to see | 229 | (message "Directory %s does not exist" directory) |
| 233 | (mapcar | 230 | (let* ((dir (expand-file-name directory)) |
| 234 | '(lambda (file) | 231 | (dir-files (directory-files dir t regexp)) |
| 232 | ) | ||
| 233 | ;; Filter out files we don't want to see | ||
| 234 | (mapcar | ||
| 235 | '(lambda (file) | ||
| 235 | (mapcar | 236 | (mapcar |
| 236 | '(lambda (regexp) | 237 | '(lambda (regexp) |
| 237 | (if (string-match regexp file) | 238 | (if (string-match regexp file) |
| 238 | (setq dir-files (delq file dir-files)))) | 239 | (setq dir-files (delq file dir-files)))) |
| 239 | file-cache-filter-regexps)) | 240 | file-cache-filter-regexps)) |
| 240 | dir-files) | 241 | dir-files) |
| 241 | (file-cache-add-file-list dir-files))) | 242 | (file-cache-add-file-list dir-files)))) |
| 242 | 243 | ||
| 243 | (defun file-cache-add-directory-list (directory-list &optional regexp) | 244 | (defun file-cache-add-directory-list (directory-list &optional regexp) |
| 244 | "Add DIRECTORY-LIST (a list of directory names) to the file cache. | 245 | "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." | |||
| 259 | (defun file-cache-add-file (file) | 260 | (defun file-cache-add-file (file) |
| 260 | "Add FILE to the file cache." | 261 | "Add FILE to the file cache." |
| 261 | (interactive "fAdd File: ") | 262 | (interactive "fAdd File: ") |
| 262 | (let* ((file-name (file-name-nondirectory file)) | 263 | (if (not (file-exists-p file)) |
| 263 | (dir-name (file-name-directory file)) | 264 | (message "File %s does not exist" file) |
| 264 | (the-entry (assoc file-name file-cache-alist)) | 265 | (let* ((file-name (file-name-nondirectory file)) |
| 265 | ) | 266 | (dir-name (file-name-directory file)) |
| 266 | ;; Does the entry exist already? | 267 | (the-entry (assoc file-name file-cache-alist)) |
| 267 | (if the-entry | 268 | ) |
| 268 | (if (or (and (stringp (cdr the-entry)) | 269 | ;; Does the entry exist already? |
| 269 | (string= dir-name (cdr the-entry))) | 270 | (if the-entry |
| 270 | (and (listp (cdr the-entry)) | 271 | (if (or (and (stringp (cdr the-entry)) |
| 271 | (member dir-name (cdr the-entry)))) | 272 | (string= dir-name (cdr the-entry))) |
| 272 | nil | 273 | (and (listp (cdr the-entry)) |
| 273 | (setcdr the-entry (append (list dir-name) (cdr the-entry))) | 274 | (member dir-name (cdr the-entry)))) |
| 274 | ) | 275 | nil |
| 275 | ;; If not, add it to the cache | 276 | (setcdr the-entry (append (list dir-name) (cdr the-entry))) |
| 276 | (setq file-cache-alist | 277 | ) |
| 277 | (cons (cons file-name (list dir-name)) | 278 | ;; If not, add it to the cache |
| 278 | file-cache-alist))) | 279 | (setq file-cache-alist |
| 279 | )) | 280 | (cons (cons file-name (list dir-name)) |
| 280 | 281 | file-cache-alist))) | |
| 282 | ))) | ||
| 283 | |||
| 281 | (defun file-cache-add-directory-using-find (directory) | 284 | (defun file-cache-add-directory-using-find (directory) |
| 282 | "Use the `find' command to add files to the file cache. | 285 | "Use the `find' command to add files to the file cache. |
| 283 | Find is run in DIRECTORY." | 286 | Find is run in DIRECTORY." |