Merge from emacs-24; up to 2012-11-15T23:31:37Z!dancol@dancol.org
[bpt/emacs.git] / lisp / filecache.el
index 422b33f..f868ef5 100644 (file)
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'find-lisp))
-
 (defgroup file-cache nil
   "Find files using a pre-loaded cache."
   :group 'files
@@ -315,23 +312,22 @@ should evaluate to the desired list of file names."
 (defun file-cache-add-file (file)
   "Add FILE to the file cache."
   (interactive "fAdd File: ")
-  (if (not (file-exists-p file))
-      (message "Filecache: file %s does not exist" file)
-    (let* ((file-name (file-name-nondirectory file))
-          (dir-name  (file-name-directory    file))
-          (the-entry (assoc-string
-                      file-name file-cache-alist
-                      file-cache-ignore-case)))
-      ;; 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 (cons dir-name (cdr the-entry))))
-       ;; If not, add it to the cache
-       (push (list file-name dir-name) file-cache-alist)))))
+  (setq file (file-truename file))
+  (unless (file-exists-p file)
+    (error "Filecache: file %s does not exist" file))
+  (let* ((file-name (file-name-nondirectory file))
+        (dir-name  (file-name-directory file))
+        (the-entry (assoc-string file-name file-cache-alist
+                                 file-cache-ignore-case)))
+    ;; Does the entry exist already?
+    (if the-entry
+       (unless (or (and (stringp (cdr the-entry))
+                        (string= dir-name (cdr the-entry)))
+                   (and (listp (cdr the-entry))
+                        (member dir-name (cdr the-entry))))
+         (setcdr the-entry (cons dir-name (cdr the-entry))))
+      ;; If not, add it to the cache
+      (push (list file-name dir-name) file-cache-alist))))
 
 ;;;###autoload
 (defun file-cache-add-directory-using-find (directory)
@@ -368,6 +364,8 @@ STRING is passed as an argument to the locate command."
                string)
   (file-cache-add-from-file-cache-buffer))
 
+(autoload 'find-lisp-find-files "find-lisp")
+
 ;;;###autoload
 (defun file-cache-add-directory-recursively  (dir &optional regexp)
   "Adds DIR and any subdirectories to the file-cache.
@@ -376,18 +374,16 @@ If the optional REGEXP argument is non-nil, only files which match it
 will be added to the cache.  Note that the REGEXP is applied to the
 files in each directory, not to the directory list itself."
   (interactive "DAdd directory: ")
-  (require 'find-lisp)
   (mapcar
-   (function
-    (lambda (file)
-      (or (file-directory-p file)
-         (let (filtered)
-           (dolist (regexp file-cache-filter-regexps)
-              (and (string-match regexp file)
-                   (setq filtered t)))
-            filtered)
-         (file-cache-add-file file))))
-   (find-lisp-find-files dir (if regexp regexp "^"))))
+   (lambda (file)
+     (or (file-directory-p file)
+         (let (filtered)
+           (dolist (regexp file-cache-filter-regexps)
+             (and (string-match regexp file)
+                  (setq filtered t)))
+           filtered)
+         (file-cache-add-file file)))
+   (find-lisp-find-files dir (or regexp "^"))))
 
 (defun file-cache-add-from-file-cache-buffer (&optional regexp)
   "Add any entries found in the file cache buffer.