Skip to content

Commit

Permalink
Backport locate-dominating-file functionality to Emacs22; look for .g…
Browse files Browse the repository at this point in the history
…it by default.
  • Loading branch information
technomancy committed Jan 12, 2009
1 parent 312d1e6 commit 5e7ade8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions find-file-in-project.el
Expand Up @@ -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.
Expand Down Expand Up @@ -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
project-local-variables.el."
(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

@shoover
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@shoover
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@technomancy
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.