Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Backport locate-dominating-file functionality to Emacs22; look for .g…

…it by default.
  • Loading branch information...
commit 5e7ade84d34e12b6cca348ef8c6b6c430a87bfcf 1 parent 312d1e6
@technomancy authored
Showing with 18 additions and 10 deletions.
  1. +18 −10 find-file-in-project.el
28 find-file-in-project.el
@@ -94,6 +94,9 @@ Use this to exclude portions of your project: \"-not -regex \\\".*vendor.*\\\"\"
(defvar ffip-project-root nil
"If non-nil, overrides the project root directory location.")
+(defvar ffip-project-file ".git"
+ "What file should ffip look for to define a project?")
(defun ffip-project-files ()
"Return an alist of all filenames in the project and their path.
@@ -149,17 +152,22 @@ If `locate-dominating-file' is bound, it will use Emacs' built-in
functionality; otherwise it will fall back on the definition from
(let ((project-root
- (if (featurep 'project)
- (project-root)
- (if (functionp 'locate-dominating-file)
- (or
- (locate-dominating-file default-directory ".dir-locals.el")
- (locate-dominating-file default-directory ".dir-settings.el"))
- (require 'project-local-variables)
- (plv-find-project-file default-directory "")))))
- (if project-root
- project-root
+ (if (featurep 'project) (project-root)
+ ;; TODO: provide a list of files that can be fallen back upon
+ (ffip-locate-dominating-file default-directory ffip-project-file))))
+ (or project-root
(message "No project was defined for the current file."))))
+;; Backport functionality to Emacs 22
+(if (functionp 'locate-dominating-file)
+ (defalias 'ffip-locate-dominating-file 'locate-dominating-file)
+ (defun ffip-locate-dominating-file (file name)
+ "Look up the project file in and above `file'."
+ (let ((parent (file-truename (expand-file-name ".." file))))
+ (cond ((string= file parent) nil)
+ ((file-exists-p (concat file name)) file)
+ (t (plv-find-project-file parent name))))))
(provide 'find-file-in-project)
;;; find-file-in-project.el ends here

3 comments on commit 5e7ade8


This change seems to override the ability to use .dir-locals.el as the project file. Do I have to setq ffip-project-file to get that behavior back?


I only bring it up because the comments at the top make it sound like there's a whole flowchart that is checked, when in reality it's just looking for .git.

Now I see that just dir-locals.el is not working. dir-settings.el and the various version control options work if I have project.el loaded, which requires a manual git submodule update and package install.


I think dir-locals.el was only honored in prerelease versions of Emacs 23. With this change you can set the ffip-project-file var to whatever value you like (including "dir-settings.el") from within dir-settings.el.

Please sign in to comment.
Something went wrong with that request. Please try again.