bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23224: 25.0.92; Can xref-find-references work without a "project"?


From: Dmitry Gutov
Subject: bug#23224: 25.0.92; Can xref-find-references work without a "project"?
Date: Wed, 6 Apr 2016 03:18:09 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0

On 04/05/2016 06:23 PM, Eli Zaretskii wrote:

I think we shouldn't fail the operation in this case, but instead use
the directory specified by the user as the single project root.

Sure, fine by me.

+   (let* ((pr (project-current t nil 'noerror))
+          (roots (ignore-errors (project-roots pr)))
+          (eroots (ignore-errors (project-external-roots pr))))
+     ;; If we didn't find any project files in PR, default to PR
+     ;; itself as the project's single root.
+     (if (and (null roots) (null eroots))
+         (setq roots (list (expand-file-name pr))))
+     (append roots eroots))))

I'm going to assume you're teasing here. :)

See the counter-proposal below, it should provide a more universal benefit along the same line of reasoning. Unless we come upon situations where we *do* want to abort with an error after asking the user for a project and not finding a "real" one.

If 'transient' doesn't sound great, alternative suggestions welcome.

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 1251bca..9c8a88c 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -101,7 +101,9 @@ project-find-functions
 (defun project-current (&optional maybe-prompt dir)
   "Return the project instance in DIR or `default-directory'.
 When no project found in DIR, and MAYBE-PROMPT is non-nil, ask
-the user for a different directory to look in."
+the user for a different directory to look in.  If that directory
+is not a part of a detectable project either, return a
+`transient' project instance rooted in it."
   (unless dir (setq dir default-directory))
   (let ((pr (project--find-in-directory dir)))
     (cond
@@ -110,7 +112,8 @@ project-current
(setq dir (read-directory-name "Choose the project directory: " dir nil t)
             pr (project--find-in-directory dir))
       (unless pr
-        (user-error "No project found in `%s'" dir))))
+        (message "Using '%s' as a transient project root" dir)
+        (setq pr (cons 'transient dir)))))
     pr))

 (defun project--find-in-directory (dir)
@@ -182,6 +185,9 @@ project--find-in-directory
        (t
        (complete-with-action action all-files string pred))))))

+(cl-defmethod project-roots ((project (head transient)))
+  (list (cdr project)))
+
 (defgroup project-vc nil
   "Project implementation using the VC package."
   :version "25.1"






reply via email to

[Prev in Thread] Current Thread [Next in Thread]