Stop project-root from going into infinite recursion

* lisp/progmodes/project.el (project--within-roots-fallback):
New variable.
(project-root, project-roots): Use it (bug#47168).
This commit is contained in:
Dmitry Gutov 2021-03-17 18:49:14 +02:00
parent f5e1fc371a
commit 6e796b52e1

View file

@ -208,6 +208,8 @@ of the project instance object."
(defun project--find-in-directory (dir)
(run-hook-with-args-until-success 'project-find-functions dir))
(defvar project--within-roots-fallback nil)
(cl-defgeneric project-root (project)
"Return root directory of the current project.
@ -215,7 +217,9 @@ It usually contains the main build file, dependencies
configuration file, etc. Though neither is mandatory.
The directory name must be absolute."
(car (project-roots project)))
(if project--within-roots-fallback
(signal 'cl-no-applicable-method (list 'project-root project))
(car (project-roots project))))
(cl-defgeneric project-roots (project)
"Return the list containing the current project root.
@ -226,7 +230,8 @@ and the rest should be possible to express through
;; FIXME: Can we specify project's version here?
;; FIXME: Could we make this affect cl-defmethod calls too?
(declare (obsolete project-root "0.3.0"))
(list (project-root project)))
(let ((project--within-roots-fallback t))
(list (project-root project))))
;; FIXME: Add MODE argument, like in `ede-source-paths'?
(cl-defgeneric project-external-roots (_project)