From 14bfb31dba47a947538f2dec76a059fcab496280 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 14 Oct 2021 03:43:42 +0300 Subject: [PATCH] Add new argument INCLUDE-ALL to project-find-file * lisp/progmodes/project.el (project-find-file): Add new argument INCLUDE-ALL. Have 'C-u' make it non-nil. (project-or-external-find-file): Ditto. (project-find-file-in): Add new argument INCLUDE-ALL. (https://lists.gnu.org/archive/html/emacs-devel/2021-10/msg00209.html) --- etc/NEWS | 5 +++++ lisp/progmodes/project.el | 43 +++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 82847cf9b99..7dd4d14274f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -123,6 +123,11 @@ also handle ANSI codes for faint, italic and blinking text, displaying it with new 'ansi-term-faint/italic/slow-blinking/fast-blinking' faces. +** Xref + +*** 'project-find-file' and 'project-or-external-find-file' now accept +a prefix argument which is interpreted to mean "include all files". + * New Modes and Packages in Emacs 29.1 diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index da7435cddf3..79d2e050d95 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -840,28 +840,36 @@ pattern to search for." project-regexp-history-variable))) ;;;###autoload -(defun project-find-file () +(defun project-find-file (&optional include-all) "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) +is available as part of \"future history\". + +If INCLUDE-ALL is non-nil, or with prefix argument when called +interactively, include all files under the project root, except +for VCS directories listed in `vc-directory-exclusion-list'." + (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 include-all))) ;;;###autoload -(defun project-or-external-find-file () +(defun project-or-external-find-file (&optional include-all) "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) +is available as part of \"future history\". + +If INCLUDE-ALL is non-nil, or with prefix argument when called +interactively, include all files under the project root, except +for VCS directories listed in `vc-directory-exclusion-list'." + (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 include-all))) (defcustom project-read-file-name-function #'project--read-file-cpd-relative "Function to call to read a file name from a list. @@ -914,12 +922,25 @@ by the user at will." predicate hist mb-default)) -(defun project-find-file-in (suggested-filename dirs project) +(defun project-find-file-in (suggested-filename dirs project &optional include-all) "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 INCLUDE-ALL is non-nil, or with prefix argument when called +interactively, include all files from DIRS, except for VCS +directories listed in `vc-directory-exclusion-list'." + (let* ((vc-dirs-ignores (mapcar + (lambda (dir) + (concat dir "/")) + vc-directory-exclusion-list)) + (all-files + (if include-all + (mapcan + (lambda (dir) (project--files-in-directory dir vc-dirs-ignores)) + 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 -- 2.39.5