unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Manuel Uberti <manuel.uberti@inventati.org>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: project-find-file: switch to include non-tracked files
Date: Tue, 5 Oct 2021 22:47:41 +0300	[thread overview]
Message-ID: <2b9ae9f3-a253-f4f4-c08c-05e3c8ef1115@yandex.ru> (raw)
In-Reply-To: <da6e4eef-b759-5c3d-27a0-d8dc4f9ff800@inventati.org>

[-- Attachment #1: Type: text/plain, Size: 1831 bytes --]

Hi Manuel,

On 04.10.2021 11:33, Manuel Uberti wrote:
> Sorry to bring up this again, but is there anything that can be done on 
> this?
> 
> The proposed solution with C-u C-x p f seems very reasonable to me, I 
> don't know what others project.el users think though.

It kind of got lost among other issues, sorry. That's doubly easy to do 
with emacs-devel threads, so if you could use Debbugs for feature 
requests in the future, that would be great.

Now, I've whipped up a small POC. See the attachment, try it out.

Since 'find' without ignore instructions is as fast as 'git ls-files' 
(even faster, in my testing, on my machine), it didn't require any 
changes in the API so far.

But is that the behavior we want?

Currently it lists _all_ files in the directory, including, say, all 
contents of .git/ (of which there can be a lot, depending on the 
project, whether it uses 'git flow', etc).

Should we add the common ignores from vc-directory-exclusion-list? To 
simply filter those dirs out?

Maybe something else too? Like grep-find-ignored-files (it lists common 
compiled/object files which one usually doesn't want to search, or even 
visit)?

Combining the vars above would bring the file listing to the default 
'project-ignores' behavior. Which the 'transient' backend uses, for example.

But in the previous iteration of this thread you also referred to Helm's 
'C-c i' behavior. Does it only list the ignored files?

In any case, we could make 'C-u project-find-file' have this behavior: 
listing only ignored files instead. And maybe not all of them: skipping 
the contents of .git/, .bzr/, etc, still sounds useful. The upside is 
possibly having a lot fewer files to choose from.

That *would* require a more involved change in project.el, but at least 
we'd make it after carefully weighing the options.

[-- Attachment #2: project-find-file-no-ignores.diff --]
[-- Type: text/x-patch, Size: 2567 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 3eaa789b3e..15fa86f07c 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -835,28 +835,28 @@ project--read-regexp
                  project-regexp-history-variable)))
 
 ;;;###autoload
-(defun project-find-file ()
+(defun project-find-file (&optional no-ignores)
   "Visit a file (with completion) in the current project.
 
 The filename at point (determined by `thing-at-point'), if any,
 is available as part of \"future history\"."
-  (interactive)
+  (interactive "P")
   (let* ((pr (project-current t))
          (dirs (list (project-root pr))))
-    (project-find-file-in (thing-at-point 'filename) dirs pr)))
+    (project-find-file-in (thing-at-point 'filename) dirs pr no-ignores)))
 
 ;;;###autoload
-(defun project-or-external-find-file ()
+(defun project-or-external-find-file (&optional no-ignores)
   "Visit a file (with completion) in the current project or external roots.
 
 The filename at point (determined by `thing-at-point'), if any,
 is available as part of \"future history\"."
-  (interactive)
+  (interactive "P")
   (let* ((pr (project-current t))
          (dirs (cons
                 (project-root pr)
                 (project-external-roots pr))))
-    (project-find-file-in (thing-at-point 'filename) dirs pr)))
+    (project-find-file-in (thing-at-point 'filename) dirs pr no-ignores)))
 
 (defcustom project-read-file-name-function #'project--read-file-cpd-relative
   "Function to call to read a file name from a list.
@@ -909,12 +909,19 @@ project--read-file-absolute
                                    predicate
                                    hist mb-default))
 
-(defun project-find-file-in (suggested-filename dirs project)
+(defun project-find-file-in (suggested-filename dirs project &optional no-ignores)
   "Complete a file name in DIRS in PROJECT and visit the result.
 
 SUGGESTED-FILENAME is a relative file name, or part of it, which
-is used as part of \"future history\"."
-  (let* ((all-files (project-files project dirs))
+is used as part of \"future history\".
+
+If NO-IGNORES is specified, include all files from DIRS."
+  (let* ((all-files
+          (if no-ignores
+              (mapcan
+               (lambda (dir) (project--files-in-directory dir nil))
+               dirs)
+            (project-files project dirs)))
          (completion-ignore-case read-file-name-completion-ignore-case)
          (file (funcall project-read-file-name-function
                         "Find file" all-files nil nil

  parent reply	other threads:[~2021-10-05 19:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-04  8:33 project-find-file: switch to include non-tracked files Manuel Uberti
2021-10-04 11:24 ` Philip Kaludercic
2021-10-04 13:44   ` Stefan Kangas
2021-10-04 13:50     ` Manuel Uberti
2021-10-04 14:06       ` Stefan Kangas
2021-10-05 19:28         ` Dmitry Gutov
2021-10-05 19:47 ` Dmitry Gutov [this message]
2021-10-06  5:18   ` Manuel Uberti
2021-10-06  6:05     ` Dmitry Gutov
2021-10-06  6:12       ` Manuel Uberti
2021-10-14  0:47         ` Dmitry Gutov
2021-10-14  6:37           ` Manuel Uberti
2021-10-14 12:01             ` Dmitry Gutov
2021-10-14 12:06               ` Manuel Uberti
2021-10-14 21:55                 ` Dmitry Gutov
2021-10-15  5:24                   ` Manuel Uberti
2021-10-15 12:12                     ` Dmitry Gutov
2021-10-15 13:05                       ` Manuel Uberti
2021-10-15 13:25                         ` Dmitry Gutov
  -- strict thread matches above, loose matches on Subject: below --
2021-05-04 13:39 Manuel Uberti
2021-05-04 14:04 ` Stefan Kangas
2021-05-04 14:16 ` Dmitry Gutov
2021-05-04 14:55   ` Manuel Uberti
2021-05-04 16:43     ` Dmitry Gutov
2021-05-04 16:57       ` Manuel Uberti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b9ae9f3-a253-f4f4-c08c-05e3c8ef1115@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=manuel.uberti@inventati.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).