Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 46 lines (43 sloc) 2.276 kb
1791462 @emerleite First cleaned-up emacs configuration
authored
1 ;; Port this functionality back from Emacs 23 since it's Really Useful
2
3 (unless (functionp 'locate-dominating-file)
4 (defun locate-dominating-file (file name)
5 "Look up the directory hierarchy from FILE for a file named NAME.
6 Stop at the first parent directory containing a file NAME,
7 and return the directory. Return nil if not found."
8 ;; We used to use the above locate-dominating-files code, but the
9 ;; directory-files call is very costly, so we're much better off doing
10 ;; multiple calls using the code in here.
11 ;;
12 ;; Represent /home/luser/foo as ~/foo so that we don't try to look for
13 ;; `name' in /home or in /.
14 (setq file (abbreviate-file-name file))
15 (let ((root nil)
16 (prev-file file)
17 ;; `user' is not initialized outside the loop because
18 ;; `file' may not exist, so we may have to walk up part of the
19 ;; hierarchy before we find the "initial UID".
20 (user nil)
21 try)
22 (while (not (or root
23 (null file)
24 ;; FIXME: Disabled this heuristic because it is sometimes
25 ;; inappropriate.
26 ;; As a heuristic, we stop looking up the hierarchy of
27 ;; directories as soon as we find a directory belonging
28 ;; to another user. This should save us from looking in
29 ;; things like /net and /afs. This assumes that all the
30 ;; files inside a project belong to the same user.
31 ;; (let ((prev-user user))
32 ;; (setq user (nth 2 (file-attributes file)))
33 ;; (and prev-user (not (equal user prev-user))))
34 (string-match locate-dominating-stop-dir-regexp file)))
35 (setq try (file-exists-p (expand-file-name name file)))
36 (cond (try (setq root file))
37 ((equal file (setq prev-file file
38 file (file-name-directory
39 (directory-file-name file))))
40 (setq file nil))))
41 root))
42
43 (defvar locate-dominating-stop-dir-regexp
44 "\\`\\(?:[\\/][\\/][^\\/]+\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'"))
45
46 (provide 'dominating-file)
Something went wrong with that request. Please try again.