Stop project-root from going into infinite recursion
authorDmitry Gutov <dgutov@yandex.ru>
Wed, 17 Mar 2021 16:49:14 +0000 (18:49 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 17 Mar 2021 16:49:14 +0000 (18:49 +0200)
* lisp/progmodes/project.el (project--within-roots-fallback):
New variable.
(project-root, project-roots): Use it (bug#47168).

lisp/progmodes/project.el

index 18da4398f4675f663cfb7f024e02f5c16c336488..65897b008ca9f2f88f0139b6fbd48997a5cac629 100644 (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)