]> code.delx.au - gnu-emacs/blobdiff - lisp/filecache.el
(comint-postoutput-scroll-to-bottom): Cope with unset
[gnu-emacs] / lisp / filecache.el
index 08ae14c739553cddce693833c0e70531725d4bf8..a580ee67ba1cea6e600fd204b128643024a63720 100644 (file)
@@ -1,9 +1,9 @@
 ;;; filecache.el --- Find files using a pre-loaded cache
 ;;
-;; Author:  Peter Breton
+;; Author:  Peter Breton <pbreton@cs.umb.edu>
 ;; Created: Sun Nov 10 1996
-;; Keywords: 
-;; Time-stamp: <97/02/07 17:26:54 peter>
+;; Keywords: convenience
+;; 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:
 ;;
 ;;
 ;; 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:
 
 ;;; Code:
 
+(defgroup file-cache nil
+  "Find files using a pre-loaded cache."
+  :group 'files
+  :group 'convenience
+  :prefix "file-cache-")
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Variables
+;; Customization Variables
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; User-modifiable variables
-(defvar file-cache-filter-regexps 
+(defcustom file-cache-filter-regexps 
   (list "~$" "\\.o$" "\\.exe$" "\\.a$" "\\.elc$" ",v$" "\\.output$" 
        "\\.$" "#$")
   "*List of regular expressions used as filters by the file cache.
 File names which match these expressions will not be added to the cache.
 Note that the functions `file-cache-add-file' and `file-cache-add-file-list' 
-do not use this variable.")
+do not use this variable."
+  :type '(repeat regexp)
+  :group 'file-cache)
 
-(defvar file-cache-find-command "find"
-  "*External program used by `file-cache-add-directory-using-find'.")
+(defcustom file-cache-find-command "find"
+  "*External program used by `file-cache-add-directory-using-find'."
+  :type 'string
+  :group 'file-cache)
 
-(defvar file-cache-locate-command "locate"
-  "*External program used by `file-cache-add-directory-using-locate'.")
+(defcustom file-cache-locate-command "locate"
+  "*External program used by `file-cache-add-directory-using-locate'."
+  :type 'string
+  :group 'file-cache)
 
 ;; Minibuffer messages
-(defvar file-cache-no-match-message " [File Cache: No match]"
-  "Message to display when there is no completion.")
-
-(defvar file-cache-sole-match-message " [File Cache: sole completion]"
-  "Message to display when there is only one completion.")
-
-(defvar file-cache-non-unique-message " [File Cache: complete but not unique]"
-  "Message to display when there is a non-unique completion.")
+(defcustom file-cache-no-match-message " [File Cache: No match]"
+  "Message to display when there is no completion."
+  :type 'string
+  :group 'file-cache)
+
+(defcustom file-cache-sole-match-message " [File Cache: sole completion]"
+  "Message to display when there is only one completion."
+  :type 'string
+  :group 'file-cache)
+
+(defcustom file-cache-non-unique-message
+  " [File Cache: complete but not unique]"
+  "Message to display when there is a non-unique completion."
+  :type 'string
+  :group 'file-cache)
 
 (defvar file-cache-multiple-directory-message nil)
 
 ;; Internal variables
 ;; This should be named *Completions* because that's what the function
 ;; switch-to-completions in simple.el expects
-(defvar file-cache-completions-buffer "*Completions*"
-  "Buffer to display completions when using the file cache.")
+(defcustom file-cache-completions-buffer "*Completions*"
+  "Buffer to display completions when using the file cache."
+  :type 'string
+  :group 'file-cache)
 
-(defvar file-cache-buffer "*File Cache*"  
-  "Buffer to hold the cache of file names.")
+(defcustom file-cache-buffer "*File Cache*"  
+  "Buffer to hold the cache of file names."
+  :type 'string
+  :group 'file-cache)
 
-(defvar file-cache-buffer-default-regexp "^.+$"
-  "Regexp to match files in `file-cache-buffer'.")
+(defcustom file-cache-buffer-default-regexp "^.+$"
+  "Regexp to match files in `file-cache-buffer'."
+  :type 'regexp
+  :group 'file-cache)
 
 (defvar file-cache-last-completion nil)
 
@@ -201,20 +223,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.
@@ -235,25 +261,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."