changeset 81973:761ac74a9c02

(locate-dominating-file): New function.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 19 Jul 2007 03:29:47 +0000
parents 7447c9b7efeb
children a7c29f19fb83
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Jul 18 21:02:29 2007 +0000
+++ b/lisp/ChangeLog	Thu Jul 19 03:29:47 2007 +0000
@@ -1,3 +1,7 @@
+2007-07-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* files.el (locate-dominating-file): New function.
+
 2007-07-18  Michael Albinus  <michael.albinus@gmx.de>
 
 	* progmodes/grep.el (grep-host-defaults-alist): New defvar.
@@ -13,6 +17,7 @@
 	files.  Change two keybindings to point to new function names.
 
 2007-07-18  Juanma Barranquero  <lekktu@gmail.com>
+
 	* follow.el (follow-mode-hook, follow-mode-off-hook, follow-mode)
 	(follow-delete-other-windows-and-split, follow-recenter)
 	(follow-windows-aligned-p, follow-point-visible-all-windows-p)
--- a/lisp/files.el	Wed Jul 18 21:02:29 2007 +0000
+++ b/lisp/files.el	Thu Jul 19 03:29:47 2007 +0000
@@ -711,6 +711,24 @@
        ((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'."