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: find-file-project Date: Fri, 08 Jan 2016 13:11:20 -0600 Message-ID: <86a8of7up3.fsf@stephe-leake.org> References: <86pp1j4ejm.fsf@stephe-leake.org> <55F899EA.7050700@yandex.ru> <86lhc73wog.fsf@stephe-leake.org> <55F8F2FA.6060902@yandex.ru> <867fnq1oe9.fsf@stephe-leake.org> <55F9A13A.3070101@yandex.ru> <55FB01BD.1070909@yandex.ru> <568C6DE5.8040201@yandex.ru> <86egdt982b.fsf@stephe-leake.org> <568EADC5.2030604@yandex.ru> <86oacx6u1e.fsf@stephe-leake.org> <568ED4BA.4030108@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1452280339 13851 80.91.229.3 (8 Jan 2016 19:12:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2016 19:12:19 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 08 20:12:09 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 1aHcSH-0007Zz-2U for ged-emacs-devel@m.gmane.org; Fri, 08 Jan 2016 20:12:09 +0100 Original-Received: from localhost ([::1]:37774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHcSG-0000kx-Bm for ged-emacs-devel@m.gmane.org; Fri, 08 Jan 2016 14:12:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHcRw-0000j3-MH for emacs-devel@gnu.org; Fri, 08 Jan 2016 14:11:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHcRr-0006ZG-Fd for emacs-devel@gnu.org; Fri, 08 Jan 2016 14:11:48 -0500 Original-Received: from gproxy6-pub.mail.unifiedlayer.com ([67.222.39.168]:35291) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1aHcRr-0006Wo-8z for emacs-devel@gnu.org; Fri, 08 Jan 2016 14:11:43 -0500 Original-Received: (qmail 29646 invoked by uid 0); 8 Jan 2016 19:11:35 -0000 Original-Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy6.mail.unifiedlayer.com with SMTP; 8 Jan 2016 19:11:35 -0000 Original-Received: from host114.hostmonster.com ([74.220.207.114]) by cmgw2 with id 3XBV1s00A2UdiVW01XBYrX; Fri, 08 Jan 2016 12:11:33 -0700 X-Authority-Analysis: v=2.1 cv=dqRIVTQ4 c=1 sm=1 tr=0 a=CQdxDb2CKd3SRg4I0/XZPQ==:117 a=CQdxDb2CKd3SRg4I0/XZPQ==:17 a=DsvgjBjRAAAA:8 a=f5113yIGAAAA:8 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=9i_RQKNPAAAA:8 a=hEr_IkYJT6EA:10 a=x_XPkuGwIRMA:10 a=7aQ_Q-yQQ-AA:10 a=vaJtXVxTAAAA:8 a=JgGXGdr272sKM_eh3SsA:9 Original-Received: from [76.218.37.33] (port=52629 helo=TAKVER2) by host114.hostmonster.com with esmtpa (Exim 4.84) (envelope-from ) id 1aHcRe-0008V8-PP; Fri, 08 Jan 2016 12:11:30 -0700 In-Reply-To: <568ED4BA.4030108@yandex.ru> (Dmitry Gutov's message of "Fri, 8 Jan 2016 00:12:26 +0300") 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: 67.222.39.168 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:197844 Archived-At: Dmitry Gutov writes: > On 01/07/2016 10:58 PM, Stephen Leake wrote: > >>> Thanks, I'll have to play with it. >>> >>> Does it handle ignores? >> >> Yes, in the path iterator object. > > Tried it, and it did what advertised after I added (find-file ...) to > the locate-uniquified-file's definition. Hmm? the doc string of `locate-uniquified-file' says "return an absolute-filename", not "visit a file". Here's how I implement find-file-in-project: (cl-defgeneric project-find-file (prj filename) "Find FILENAME with completion in project PRJ." (let* ((iter (make-path-iterator :user-path-non-recursive nil :user-path-recursive (project-all-roots prj) :ignore-function (lambda (dir) (project-ignore-dir prj dir)))) (pred (lambda (abs-file-name) (not (string-match ;; FIXME: this assumes `project-ignores' can accept dir that is not root (project-ignores-regexp prj (file-name-directory abs-file-name)) abs-file-name)))) (absfilename (locate-uniquified-file-iter iter pred filename))) (if (file-readable-p absfilename) (find-file absfilename) ;; FIXME: need human-readable name for project (error "'%s' not found/readable in project." filename))) ) (defun find-file-in-project (filename) "Find FILENAME (default prompt) with completion in current project. With prefix arg, FILENAME defaults to filename at point." (interactive (list (when current-prefix-arg (thing-at-point 'filename)))) (project-find-file (project-current) filename)) > As written, though, it only lists files at the top-level of load-path, > without recursing. Yes, that's consistent with `locate-file', and all other uses of `load-path'. To add all directories that contain elisp files, you need to build the path iterator directly: (let ((emacs-root (file-name-directory (directory-file-name (file-name-directory (locate-library "man")))))) (make-path-iterator :user-path-non-recursive (append load-path (list (concat emacs-root "test/automated") (concat emacs-root "lisp/term"))) :user-path-recursive (list (concat emacs-root "lisp/cedet"))) ) > Note that it doesn't list lisp/cedet/ede/locate.el that you brought up > as an example earlier (maybe because I don't have EDE loaded). Because you did not add the "cedet/ede" directory to the path iterator. As we have discussed before, the user must tell the code what directories in `load-path' should be treated recursively. > FWIW, I'm not partial to the suffix-style of uniquification. Right; one of these days I'll see if I can convert that to prefix. But the completion code makes the assumption that the prefix of the strings match, so it would be a big change. But once you get used to it, you'll find that you simply don't care about the directory; you really only need it to disambiguate colliding names. So the suffix style makes sense. >>> How's the performance in the Emacs repository? >> >> There is a noticeable delay, mostly due to computing the partial >> completion (before I added that, there was no noticeable delay). > > Did you try that using an iterator that visits the whole of Emacs > repo, not just load-path? E.g., I can't visit xdisp.c this way. Yes; I use a variant of the above path-iterator constructor that adds the C directories. But that also requires the project code to know about multiple languages, so it's part of a multi-language project package. >> This is a pure elisp implementation. However, the path iterator object >> could provide the directory list to the subprocess find function as >> well. > > Will Emacs then call `find' for each of the "shallow" directories in > the list? Only if you write the code that way. The path-iterator constructor takes both recursive and non-recursive arguments. 'find' requires a single recursive root plus ignores, so to be really useful with 'find', the path-iterator object would have to be enhanced to return those values. -- -- Stephe