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

Previous Next

Package: emacs;

Reported by: Eli Zaretskii <eliz <at> gnu.org>

Date: Tue, 5 Apr 2016 15:24:01 UTC

Severity: normal

Found in version 25.0.92

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23224 in the body.
You can then email your comments to 23224 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#23224; Package emacs. (Tue, 05 Apr 2016 15:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eli Zaretskii <eliz <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 05 Apr 2016 15:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.92; Can xref-find-references work without a "project"?
Date: Tue, 05 Apr 2016 18:23:08 +0300
In an Emacs tree that is not under any VCS, type:

  emacs -Q
  M-x xref-find-references RET current_buffer RET

When prompted to choose a project directory, accept the default by
typing RET.  The result:

  No project found in ‘THE-DEFAULT-DIRECTORY/’

This is disappointing, since the default implementation of
xref-find-references is fully capable of producing the requested
results even if no project (in the project.el sense) was created in
the directory.

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.  The
proposed patch below implements this.  (I'm not married to the patch
as shown, so if someone comes up with a more elegant solution, I'd be
as happy.  The important part is that we should allow this command to
be usable even if no project infrastructure was created.)

--- lisp/progmodes/project.el~0	2016-01-31 06:43:03.000000000 +0200
+++ lisp/progmodes/project.el	2016-04-05 18:06:43.146022700 +0300
@@ -98,10 +98,12 @@
 that it is not applicable, or a project instance.")
 
 ;;;###autoload
-(defun project-current (&optional maybe-prompt dir)
+(defun project-current (&optional maybe-prompt dir noerror)
   "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.
+Optional third argument NOERROR, if non-nil, means don't signal
+an error if no project is found in the specified directory."
   (unless dir (setq dir default-directory))
   (let ((pr (project--find-in-directory dir)))
     (cond
@@ -109,6 +111,8 @@
      (maybe-prompt
       (setq dir (read-directory-name "Choose the project directory: " dir nil t)
             pr (project--find-in-directory dir))
+      (if (and (not pr) noerror)
+          (setq pr dir))
       (unless pr
         (user-error "No project found in `%s'" dir))))
     pr))
--- lisp/progmodes/xref.el~0	2016-03-20 06:53:36.000000000 +0200
+++ lisp/progmodes/xref.el	2016-04-05 18:18:47.257475600 +0300
@@ -245,14 +245,19 @@
 
 The default implementation uses `semantic-symref-tool-alist' to
 find a search tool; by default, this uses \"find | grep\" in the
-`project-current' roots."
+`project-current' roots, falling back to the directory tree
+rooted at the directory specified by user."
   (cl-mapcan
    (lambda (dir)
      (xref-collect-references identifier dir))
-   (let ((pr (project-current t)))
-     (append
-      (project-roots pr)
-      (project-external-roots pr)))))
+   (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))))
 
 (cl-defgeneric xref-backend-apropos (backend pattern)
   "Find all symbols that match PATTERN.




In GNU Emacs 25.0.92.75 (i686-pc-mingw32)
 of 2016-04-04 built on HOME-C4E4A596F7
Repository revision: f501116ea896b20f195f5c841e8770d7fe0418b9
Windowing system distributor 'Microsoft Corp.', version 5.1.2600
Configured using:
 'configure --prefix=/d/usr --enable-checking=yes,glyphs --with-wide-int
 --with-modules 'CFLAGS=-O0 -gdwarf-4 -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS MODULES

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255

Major mode: Message

Minor modes in effect:
  mml-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  auto-fill-function: message-do-auto-fill
  transient-mark-mode: t
  abbrev-mode: t

Recent messages:
Checking 167 files in d:/gnu/git/emacs/branch/lisp/emacs-lisp...
Checking 24 files in d:/gnu/git/emacs/branch/lisp/cedet...
Checking 57 files in d:/gnu/git/emacs/branch/lisp/calendar...
Checking 87 files in d:/gnu/git/emacs/branch/lisp/calc...
Checking 122 files in d:/gnu/git/emacs/branch/lisp/obsolete...
Checking for load-path shadows...done
Mark set [2 times]
Saved text from "From: eliz <at> HOME-C4E4A596F7.i-did-not-set"
Auto-saving...
Modification-flag cleared

Load-path shadows:
None found.

Features:
(pp shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util help-fns help-mode easymenu
cl-loaddefs pcase cl-lib mail-prsvr mail-utils time-date mule-util
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel dos-w32 ls-lisp disp-table w32-win w32-vars term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote w32notify w32 multi-tty
make-network-process emacs)

Memory information:
((conses 16 95005 11151)
 (symbols 56 20730 0)
 (miscs 48 46 126)
 (strings 16 17838 6291)
 (string-bytes 1 448071)
 (vectors 16 12532)
 (vector-slots 8 432331 7162)
 (floats 8 167 313)
 (intervals 40 563 63)
 (buffers 856 13))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23224; Package emacs. (Tue, 05 Apr 2016 17:24:02 GMT) Full text and rfc822 format available.

Message #8 received at 23224 <at> debbugs.gnu.org (full text, mbox):

From: John Wiegley <jwiegley <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23224 <at> debbugs.gnu.org
Subject: Re: bug#23224: 25.0.92;
 Can xref-find-references work without a "project"?
Date: Tue, 05 Apr 2016 10:22:59 -0700
>>>>> Eli Zaretskii <eliz <at> gnu.org> writes:

> 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.

I agree.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23224; Package emacs. (Wed, 06 Apr 2016 00:19:01 GMT) Full text and rfc822 format available.

Message #11 received at 23224 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>, 23224 <at> debbugs.gnu.org
Subject: Re: bug#23224: 25.0.92; Can xref-find-references work without a
 "project"?
Date: Wed, 6 Apr 2016 03:18:09 +0300
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"





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23224; Package emacs. (Wed, 06 Apr 2016 17:10:02 GMT) Full text and rfc822 format available.

Message #14 received at 23224 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 23224 <at> debbugs.gnu.org
Subject: Re: bug#23224: 25.0.92; Can xref-find-references work without a
 "project"?
Date: Wed, 06 Apr 2016 20:08:59 +0300
> From: Dmitry Gutov <dgutov <at> yandex.ru>
> Date: Wed, 6 Apr 2016 03:18:09 +0300
> 
> On 04/05/2016 06:23 PM, Eli Zaretskii wrote:
> 
> > +   (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. :)

A little bit.

> 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.

I don't know anything about project.el and its users, so I wasn't sure
such a change won't break something.  But if you say it's okay, I'll
stop worrying.

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

"ad-hoc"?

Please go ahead and push.  Thanks.




Reply sent to Dmitry Gutov <dgutov <at> yandex.ru>:
You have taken responsibility. (Wed, 06 Apr 2016 23:10:01 GMT) Full text and rfc822 format available.

Notification sent to Eli Zaretskii <eliz <at> gnu.org>:
bug acknowledged by developer. (Wed, 06 Apr 2016 23:10:02 GMT) Full text and rfc822 format available.

Message #19 received at 23224-done <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23224-done <at> debbugs.gnu.org
Subject: Re: bug#23224: 25.0.92; Can xref-find-references work without a
 "project"?
Date: Thu, 7 Apr 2016 02:08:54 +0300
On 04/06/2016 08:08 PM, Eli Zaretskii wrote:

> I don't know anything about project.el and its users, so I wasn't sure
> such a change won't break something.  But if you say it's okay, I'll
> stop worrying.

project.el users are an unknowable bunch, so far. This change is 
unlikely to break anything, it just might make using project commands 
more "magical", possibly not in a good way. Let's just wait for feedback.

>> If 'transient' doesn't sound great, alternative suggestions welcome.
>
> "ad-hoc"?

The other options I had: temporary, and simple. But I wanted to 
emphasize the fact that the user will be asked for the project's 
directory every time they'll try to use a project-related command.

Anyway, you're welcome to change the name, retouch the newly updated 
docstring, etc.

> Please go ahead and push.  Thanks.

Done, and closing.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 05 May 2016 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 98 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.