From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: make project--find-in-file generic, add interactive filename to project-find-file Date: Thu, 28 Jan 2016 05:06:37 -0600 Message-ID: <86k2mu7yki.fsf@stephe-leake.org> References: <86wpqu8qf9.fsf@stephe-leake.org> <56A9DDA8.9080504@yandex.ru> <86si1i813n.fsf@stephe-leake.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1453979236 12250 80.91.229.3 (28 Jan 2016 11:07:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jan 2016 11:07:16 +0000 (UTC) Cc: emacs-devel To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 28 12:07:05 2016 Return-path: Envelope-to: ged-emacs-devel@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 1aOkPl-0008D0-Cc for ged-emacs-devel@m.gmane.org; Thu, 28 Jan 2016 12:07:01 +0100 Original-Received: from localhost ([::1]:55353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOkPk-0003j8-Mo for ged-emacs-devel@m.gmane.org; Thu, 28 Jan 2016 06:07:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOkPg-0003gO-LO for emacs-devel@gnu.org; Thu, 28 Jan 2016 06:06:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOkPd-0008S3-Te for emacs-devel@gnu.org; Thu, 28 Jan 2016 06:06:56 -0500 Original-Received: from gproxy2-pub.mail.unifiedlayer.com ([69.89.18.3]:44280) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1aOkPd-0008QO-MW for emacs-devel@gnu.org; Thu, 28 Jan 2016 06:06:53 -0500 Original-Received: (qmail 2038 invoked by uid 0); 28 Jan 2016 11:06:48 -0000 Original-Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy2.mail.unifiedlayer.com with SMTP; 28 Jan 2016 11:06:48 -0000 Original-Received: from host114.hostmonster.com ([74.220.207.114]) by cmgw2 with id BP6d1s00M2UdiVW01P6gib; Thu, 28 Jan 2016 04:06:46 -0700 X-Authority-Analysis: v=2.1 cv=dqRIVTQ4 c=1 sm=1 tr=0 a=CQdxDb2CKd3SRg4I0/XZPQ==:117 a=CQdxDb2CKd3SRg4I0/XZPQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=hEr_IkYJT6EA:10 a=x_XPkuGwIRMA:10 a=7aQ_Q-yQQ-AA:10 a=9i_RQKNPAAAA:8 a=vaJtXVxTAAAA:8 a=NH2Ne5r97FBEZfblwpUA:9 a=Xw5gidO4V2je-f1-bhoA:9 Original-Received: from [76.218.37.33] (port=64233 helo=TAKVER3) by host114.hostmonster.com with esmtpa (Exim 4.84) (envelope-from ) id 1aOkPP-0004tW-09; Thu, 28 Jan 2016 04:06:39 -0700 In-Reply-To: <86si1i813n.fsf@stephe-leake.org> (Stephen Leake's message of "Thu, 28 Jan 2016 04:11:56 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (windows-nt) X-Identified-User: {2442:host114.hostmonster.com:stephele:stephe-leake.org} {sentby:smtp auth 76.218.37.33 authed with stephen_leake@stephe-leake.org} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 69.89.18.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198943 Archived-At: --=-=-= Content-Type: text/plain Stephen Leake writes: > Dmitry Gutov writes: > >> On 01/28/2016 04:04 AM, Stephen Leake wrote: >>> Any objections to the attached patch? >> > >> - More importantly, the new generic function should not do too much. >> It should return a completion table, which can dispatch to ede, >> ada-mode, or any other facility. I believe we've went over this a >> couple of times already. > > So instead of computing `table' in project--find-file-in, it would > call (project--file-completion-table dirs project). The default > implementation of `project--file-completion-table' would be the code > using `find-program'. > > I'll give that a try. That works nicely; new patch attached. -- -- Stephe --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=project-find-file-patch.diff diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 85f3907..41dc810 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -154,6 +154,14 @@ project--find-in-directory vc-directory-exclusion-list) grep-find-ignored-files)) +(cl-defgeneric project--file-completion-table (_project _dirs) + "Return a completion table for files in directories DIRS in PROJECT. +If non-nil, DIRS is a list of absolute directories; it should be some +subset of the project roots and external roots. If nil, the backend +uses all the directories it knows about. +PROJECT is used to find the project ignores and other project meta-data." + ) + (defgroup project-vc nil "Project implementation using the VC package." :version "25.1" @@ -313,51 +321,57 @@ project--find-regexp-in ;;;###autoload (defun project-find-file () - "Visit a file in the current project's roots. - -This is like `find-file', but it limits the file-name completion -candidates to the files within the current project roots." + "Visit a file (with completion) in the current project's roots. +The completion default is the filename at point, if one is +recognized." (interactive) (let* ((pr (project-current t)) (dirs (project-roots pr))) - (project--find-file-in dirs pr))) + (project--find-file-in (thing-at-point 'filename) dirs pr))) ;;;###autoload (defun project-or-external-find-file () "Visit a file in the current project's roots or external roots. - -This is like `find-file', but it limits the file-name completion -candidates to the files within the current project roots and external roots." +The completion default is the filename at point, if one is +recognized." (interactive) (let* ((pr (project-current t)) (dirs (append (project-roots pr) (project-external-roots pr)))) - (project--find-file-in dirs pr))) + (project--find-file-in (thing-at-point 'filename) dirs pr))) ;; FIXME: Uniquely abbreviate the roots? -(defun project--find-file-in (dirs project) +(cl-defmethod project--file-completion-table (project dirs) + "Default implementation using `find-program'." (require 'xref) - (let* ((all-files - (cl-mapcan - (lambda (dir) - (let ((command - (format "%s %s %s -type f -print0" - find-program - dir - (xref--find-ignores-arguments - (project-ignores project dir) - (expand-file-name dir))))) - (split-string (shell-command-to-string command) "\0" t))) - dirs)) - (table (lambda (string pred action) - (cond - ((eq action 'metadata) - '(metadata . ((category . project-file)))) - (t - (complete-with-action action all-files string pred)))))) - (find-file - (completing-read "Find file: " table nil t)))) + (let ((all-files + (cl-mapcan + (lambda (dir) + (let ((command + (format "%s %s %s -type f -print0" + find-program + dir + (xref--find-ignores-arguments + (project-ignores project dir) + (expand-file-name dir))))) + (split-string (shell-command-to-string command) "\0" t))) + dirs))) + (lambda (string pred action) + (cond + ((eq action 'metadata) + '(metadata . ((category . project-file)))) + (t + (complete-with-action action all-files string pred)))) + )) + +(defun project--find-file-in (filename dirs project) + "Complete FILENAME in DIRS in PROJECT, visit the file." + (find-file + (completing-read + (format "Find file (%s): " filename) + (project--file-completion-table project dirs) + nil t nil nil filename))) (provide 'project) ;;; project.el ends here diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 267853d..2fd7297 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -854,6 +854,7 @@ xref-etags-mode (declare-function semantic-symref-find-references-by-name "semantic/symref") (declare-function semantic-find-file-noselect "semantic/fw") (declare-function grep-expand-template "grep") +(defvar ede-minor-mode) ;; ede.el (defun xref-collect-references (symbol dir) "Collect references to SYMBOL inside DIR. @@ -948,6 +949,9 @@ xref--rgrep-command (xref--find-ignores-arguments ignores dir))) (defun xref--find-ignores-arguments (ignores dir) + "Convert IGNORES and DIR to a list of arguments for 'find'. +IGNORES is a list of glob patterns. DIR is an absolute +directory, used as the root of the ignore globs." ;; `shell-quote-argument' quotes the tilde as well. (cl-assert (not (string-match-p "\\`~" dir))) (when ignores --=-=-=--