New command: project-find-dir

* doc/emacs/maintaining.texi (Project File Commands):
Mention the new command and update the bindings information.

* lisp/progmodes/project.el (project-find-dir):
New command (bug#43153).
(project-prefix-map): Use 'd' as its binding.
Move 'project-dired' to 'D'.
(project-switch-commands):
Replace 'project-dired' with 'project-find-dir'.
This commit is contained in:
Dmitry Gutov 2021-09-21 03:34:00 +03:00
parent de289d58a4
commit df1d4f5894
2 changed files with 29 additions and 3 deletions

View file

@ -1769,8 +1769,13 @@ Replace}), and continues to the next match after you respond. If your
response causes Emacs to exit the query-replace loop, you can later
continue with @w{@kbd{M-x fileloop-continue @key{RET}}}.
@findex project-find-dir
The command @kbd{C-x p d} (@code{project-find-dir}) prompts you to
choose a directory inside the current project, with completion.
And opens a Dired buffer (@pxref{Dired}) listing the files in it.
@findex project-dired
The command @kbd{C-x p d} (@code{project-dired}) opens a Dired
The command @kbd{C-x p D} (@code{project-dired}) opens a Dired
buffer (@pxref{Dired}) listing the files in the current project's root
directory.

View file

@ -674,7 +674,8 @@ DIRS must contain directory names."
(define-key map "F" 'project-or-external-find-file)
(define-key map "b" 'project-switch-to-buffer)
(define-key map "s" 'project-shell)
(define-key map "d" 'project-dired)
(define-key map "d" 'project-find-dir)
(define-key map "D" 'project-dired)
(define-key map "v" 'project-vc-dir)
(define-key map "c" 'project-compile)
(define-key map "e" 'project-eshell)
@ -930,6 +931,26 @@ is used as part of \"future history\"."
nil
hist)))
;;;###autoload
(defun project-find-dir ()
"Start Dired in a directory inside the current project."
(interactive)
(let* ((project (project-current t))
(all-files (project-files project))
(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"
;; Some completion UIs show duplicates.
(delete-dups all-dirs)
nil nil)))
(dired dir)))
;;;###autoload
(defun project-dired ()
"Start Dired in the current project's root."
@ -1342,7 +1363,7 @@ It's also possible to enter an arbitrary directory not in the list."
(defcustom project-switch-commands
'((project-find-file "Find file")
(project-find-regexp "Find regexp")
(project-dired "Dired")
(project-find-dir "Find directory")
(project-vc-dir "VC-Dir")
(project-eshell "Eshell"))
"Alist mapping commands to descriptions.