aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-03-06 00:22:42 -0800
committerGlenn Morris2012-03-06 00:22:42 -0800
commit99a8306435502146d52cd97377d95c93963d8ae4 (patch)
treeaaa3e20217651b90bbb3bf059c23b17ffa7732e5
parent2e86d8576c668e149cc100f3222bcf19b38019dc (diff)
downloademacs-99a8306435502146d52cd97377d95c93963d8ae4.tar.gz
emacs-99a8306435502146d52cd97377d95c93963d8ae4.zip
Tweak previous dir-locals-find-file change
* lisp/files.el (locate-dominating-file): Add optional predicate argument. (dir-locals-find-file): Make use of above change.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/files.el32
2 files changed, 19 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6a9b1808cdf..e9dce6280a6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12012-03-06 Glenn Morris <rgm@gnu.org>
2
3 * files.el (locate-dominating-file): Add optional predicate argument.
4 (dir-locals-find-file): Make use of above change.
5
12012-03-06 Thien-Thi Nguyen <ttn@gnuvola.org> 62012-03-06 Thien-Thi Nguyen <ttn@gnuvola.org>
2 7
3 * info.el (Info-insert-dir): Also try "dir.gz". 8 * info.el (Info-insert-dir): Also try "dir.gz".
diff --git a/lisp/files.el b/lisp/files.el
index fae834daefe..1d54ef81869 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -877,13 +877,14 @@ or mount points potentially requiring authentication as a different user.")
877;; (setq dir nil)))) 877;; (setq dir nil))))
878;; nil))) 878;; nil)))
879 879
880(defun locate-dominating-file (file name) 880(defun locate-dominating-file (file name &optional predicate)
881 "Look up the directory hierarchy from FILE for a file named NAME. 881 "Look up the directory hierarchy from FILE for a file named NAME.
882Stop at the first parent directory containing a file NAME, 882Stop at the first parent directory containing a file NAME,
883and return the directory. Return nil if not found. 883and return the directory. Return nil if not found.
884 884
885This function only tests if FILE exists. If you care about whether 885Optional argument PREDICATE is a function of one argument, a file.
886it is readable, regular, etc., you should test the result." 886It should return non-nil if the file is acceptable. The default is
887`file-exists-p'; you might, e.g., want to use `file-readable-p' instead."
887 ;; We used to use the above locate-dominating-files code, but the 888 ;; We used to use the above locate-dominating-files code, but the
888 ;; directory-files call is very costly, so we're much better off doing 889 ;; directory-files call is very costly, so we're much better off doing
889 ;; multiple calls using the code in here. 890 ;; multiple calls using the code in here.
@@ -910,11 +911,8 @@ it is readable, regular, etc., you should test the result."
910 ;; (setq user (nth 2 (file-attributes file))) 911 ;; (setq user (nth 2 (file-attributes file)))
911 ;; (and prev-user (not (equal user prev-user)))) 912 ;; (and prev-user (not (equal user prev-user))))
912 (string-match locate-dominating-stop-dir-regexp file))) 913 (string-match locate-dominating-stop-dir-regexp file)))
913 ;; FIXME? maybe this function should (optionally?) 914 (setq try (funcall (or predicate 'file-exists-p)
914 ;; use file-readable-p instead. In many cases, an unreadable 915 (expand-file-name name file)))
915 ;; FILE is no better than a non-existent one.
916 ;; See eg dir-locals-find-file.
917 (setq try (file-exists-p (expand-file-name name file)))
918 (cond (try (setq root file)) 916 (cond (try (setq root file))
919 ((equal file (setq file (file-name-directory 917 ((equal file (setq file (file-name-directory
920 (directory-file-name file)))) 918 (directory-file-name file))))
@@ -3552,7 +3550,7 @@ across different environments and users.")
3552 "Find the directory-local variables for FILE. 3550 "Find the directory-local variables for FILE.
3553This searches upward in the directory tree from FILE. 3551This searches upward in the directory tree from FILE.
3554It stops at the first directory that has been registered in 3552It stops at the first directory that has been registered in
3555`dir-locals-directory-cache' or contains a `dir-locals-file'. 3553`dir-locals-directory-cache' or contains a readable `dir-locals-file'.
3556If it finds an entry in the cache, it checks that it is valid. 3554If it finds an entry in the cache, it checks that it is valid.
3557A cache entry with no modification time element (normally, one that 3555A cache entry with no modification time element (normally, one that
3558has been assigned directly using `dir-locals-set-directory-class', not 3556has been assigned directly using `dir-locals-set-directory-class', not
@@ -3570,17 +3568,15 @@ of no valid cache entry."
3570 (if (eq system-type 'ms-dos) 3568 (if (eq system-type 'ms-dos)
3571 (dosified-file-name dir-locals-file) 3569 (dosified-file-name dir-locals-file)
3572 dir-locals-file)) 3570 dir-locals-file))
3573 (locals-file (locate-dominating-file file dir-locals-file-name)) 3571 ;; FIXME? Is it right to silently ignore unreadable files?
3572 (locals-file (locate-dominating-file file dir-locals-file-name
3573 (lambda (file)
3574 (and (file-readable-p file)
3575 (file-regular-p file)))))
3574 (dir-elt nil)) 3576 (dir-elt nil))
3575 ;; `locate-dominating-file' may have abbreviated the name. 3577 ;; `locate-dominating-file' may have abbreviated the name.
3576 (and locals-file 3578 (if locals-file
3577 (setq locals-file (expand-file-name dir-locals-file-name locals-file)) 3579 (setq locals-file (expand-file-name dir-locals-file-name locals-file)))
3578 ;; FIXME? is it right to silently ignore an unreadable file?
3579 ;; Maybe we'd want to keep searching in that case.
3580 ;; That is a locate-dominating-file issue.
3581 (or (not (file-readable-p locals-file))
3582 (not (file-regular-p locals-file)))
3583 (setq locals-file nil))
3584 ;; Find the best cached value in `dir-locals-directory-cache'. 3580 ;; Find the best cached value in `dir-locals-directory-cache'.
3585 (dolist (elt dir-locals-directory-cache) 3581 (dolist (elt dir-locals-directory-cache)
3586 (when (and (eq t (compare-strings file nil (length (car elt)) 3582 (when (and (eq t (compare-strings file nil (length (car elt))