summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2007-07-19 03:29:47 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2007-07-19 03:29:47 +0000
commit418fd37516f85b5b017f9db2a58eb48e20208769 (patch)
tree0678e8ee8552b8ff2966ceed0a50026ab6900382 /lisp/files.el
parent6e3aa3f58ef253559ce6416d6aa02885cd944ff1 (diff)
downloademacs-418fd37516f85b5b017f9db2a58eb48e20208769.tar.gz
emacs-418fd37516f85b5b017f9db2a58eb48e20208769.tar.bz2
emacs-418fd37516f85b5b017f9db2a58eb48e20208769.zip
(locate-dominating-file): New function.
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el
index ed76e16b183..631e75f98d0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -711,6 +711,24 @@ PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
((null action) (try-completion string names))
(t (test-completion string names))))))
+(defun locate-dominating-file (file regexp)
+ "Look up the directory hierarchy from FILE for a file matching REGEXP."
+ (while (and file (not (file-directory-p file)))
+ (setq file (file-name-directory (directory-file-name file))))
+ (catch 'found
+ (let ((user (nth 2 (file-attributes file)))
+ ;; Abbreviate, so as to stop when we cross ~/.
+ (dir (abbreviate-file-name (file-name-as-directory file)))
+ files)
+ (while (and dir (equal user (nth 2 (file-attributes dir))))
+ (if (setq files (directory-files dir 'full regexp))
+ (throw 'found (car files))
+ (if (equal dir
+ (setq dir (file-name-directory
+ (directory-file-name dir))))
+ (setq dir nil))))
+ nil)))
+
(defun executable-find (command)
"Search for COMMAND in `exec-path' and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'."