From df1d4f58948b6db8a4063c1458748deb684d4a1b Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 21 Sep 2021 03:34:00 +0300 Subject: [PATCH] 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'. --- doc/emacs/maintaining.texi | 7 ++++++- lisp/progmodes/project.el | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index b692c995513..f98e7b1edaf 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -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. diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 67c34b4e5c5..f1437c6a238 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -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. -- 2.39.5