Subject: Re: bug#43153: Add new command project-find-dir (and move binding of project-dired)

From: Dmitry Gutov <[email-masked]>
Date: Mon, 20 Sep 2021 04:34:43 +0300

Hi all!

On 19.09.2021 23:42, Stefan Kangas wrote:
> Juri Linkov<[email-masked]>  writes:
> 
>> Maybe then better to rename `project-dired' to `project-root-dired',
>> then bind `C-x p D' to `project-root-dired' without the prompt,
>> and bind `project-dired' to `C-x p d' with a prompt that
>> asks for a directory like `C-x p f' (project-find-file).
> Agreed.  Let's see what Dmitry thinks about it.

Here's a quick implementation of this feature inside project-dired:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 563b9c3c90..3a21cc15a4 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -963,7 +963,18 @@ project--completing-read-strict
  (defun project-dired ()
    "Start Dired in the current project's root."
    (interactive)
-  (dired (project-root (project-current t))))
+  (let* ((project (project-current t))
+         (all-files (project-files (project-current)))
+         (completion-ignore-case read-file-name-completion-ignore-case)
+         ;; FIXME: This misses directories without any files directly
+         ;; inside.  Consider DIRS-ONLY as an argument for
+         ;; `project-files-filtered', and see
+         ;; https://stackoverflow.com/a/50685235/615245 for possible
+         ;; implementation.
+         (all-dirs (mapcar #'file-name-directory all-files))
+         (dir (funcall project-read-file-name-function
+                       "Dired" all-dirs nil nil)))
+    (dired dir)))

  ;;;###autoload
  (defun project-vc-dir ()

It's a little flawed, but that shouldn't stop us from installing it.

Note that the user can simply press RET without typing any directory 
name and that will launch Dired in the project root.

That seems like it might make having a separate command unnecessary, 
since 'C-x p D' and 'C-x p d RET' take the same number of keypresses. 
The latter might make you move your hand farther, though.

But I don't mind having a separate command if you both think it's a good 
idea. Then we either call it project-root-dired, and this new one -- 
just project-dired. Or we move project-dired to 'C-x p D' without 
changing it, and add this functionality in 'project-find-dir', bound to 
'C-x p d'.

OTOH, it might make sense to keep 'project-dired' on 'C-x p d' and move 
project-find-dir to 'C-x p D' because the users of the latter must be 
prepared to do more typing anyway during completion, so having to also 
press Shift once won't hurt their efficiency much. But compatibility 
with Projectile can be important, too.

Cast your votes, everybody ;-)