Stefan Monnier writes:
So this is my somewhat verbose request to say "yes, let's do this" and
pick a library to provide the functionality.
Agreed. There are already different such things distributed with Emacs:
.dir-locals.el is one of them. CEDET has its own notion.
As mentioned .dir-local.el often acts as a project root, but it can also
appear in sub-directories of a project, so it's not sufficient.
It should at least be augmented so that some .dir-locals.el can be
flagged as "non-root".
If the only need is to figure out the "root directory of the project",
then maybe a simple solution is:
(defvar project-root-predicate
(lambda () (file-exists-p ".dir-locals.el")))
(defun project-root ()
(locate-dominating-file default-directory project-root-predicate))
where packages can (add-function :until-before (default-value
project-root-predicate)<mypredicate>) to recognize other "tell tale
sign" of a project root (e.g. a Tupfile).
CEDET provides this in two ways (as part of the EDE subsystem):
* If a Project.ede file exists, that's the root (similar to .dir-locals.el in
this context)
* If signs of a "project-like" structure exist (e.g., (auto)makefiles, scons,
java, etc), uses system-specific knowledge to automatically detect the
project
root.
I'm commenting this because, first, managing projects is the purpose of EDE
(although it tries to do more than just identifying their root) and it's
integrated in Emacs; and second, because the auto-detection could help in making
the process simpler and, in the best case, auto-magical.