From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#23224: 25.0.92; Can xref-find-references work without a "project"? Date: Tue, 05 Apr 2016 18:23:08 +0300 Message-ID: <83oa9om65f.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1459869902 4480 80.91.229.3 (5 Apr 2016 15:25:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Apr 2016 15:25:02 +0000 (UTC) To: 23224@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 05 17:24:48 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1anSqE-0003wL-EG for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Apr 2016 17:24:30 +0200 Original-Received: from localhost ([::1]:37703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSq8-0004vF-Ns for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Apr 2016 11:24:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSpp-0004aR-M7 for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:24:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anSpm-0004oE-9Q for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:24:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSpm-0004oA-5h for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1anSpm-0000Ou-2S for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Apr 2016 15:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23224 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14598698261517 (code B ref -1); Tue, 05 Apr 2016 15:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Apr 2016 15:23:46 +0000 Original-Received: from localhost ([127.0.0.1]:50501 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anSpV-0000OP-OF for submit@debbugs.gnu.org; Tue, 05 Apr 2016 11:23:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anSpU-0000OC-9z for submit@debbugs.gnu.org; Tue, 05 Apr 2016 11:23:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anSpN-0004kI-Mi for submit@debbugs.gnu.org; Tue, 05 Apr 2016 11:23:39 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:48105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSpN-0004kE-JE for submit@debbugs.gnu.org; Tue, 05 Apr 2016 11:23:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSpM-0003rX-6H for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:23:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anSpH-0004gz-Qx for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:23:36 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:50577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSpH-0004gt-Hr for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:23:31 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:4292 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1anSpG-0005Mf-ST for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2016 11:23:31 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:116064 Archived-At: 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@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))