From: Dmitry Gutov Date: Fri, 6 Aug 2021 00:30:10 +0000 (+0300) Subject: Change how project-find-file's completion works X-Git-Tag: emacs-28.0.90~1591^2~18 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fa895379d6166c52b89774a9e450a94c2e429dae;p=emacs.git Change how project-find-file's completion works * lisp/progmodes/project.el (project--completing-read-strict): Allow to choose a non-existent file, with confirmation (bug#49204). Don't use the string at point as a "real" default, and instead only include it in "future history": meaning, it will be inserted on 'M-n' (bug#49865). --- diff --git a/etc/NEWS b/etc/NEWS index 6495fd09515..7fc53ff6c01 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2074,6 +2074,12 @@ project's root directory, respectively. This command lets you interactively remove an entry from the list of projects in 'project-list-file'. +*** 'project-find-file' now accepts non-existent file names (to +facilitate creating a file inside some nested sub-directory easily). + +*** 'project-find-file' doesn't use the string at point as default +input, now it's only suggested as part of "future history". + ** xref --- diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0e732864268..6a330ecb2b3 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -879,23 +879,16 @@ PREDICATE, HIST, and DEFAULT have the same meaning as in (defun project--completing-read-strict (prompt collection &optional predicate hist default) - ;; Tried both expanding the default before showing the prompt, and - ;; removing it when it has no matches. Neither seems natural - ;; enough. Removal is confusing; early expansion makes the prompt - ;; too long. - (let* ((new-prompt (if (and default (not (string-equal default ""))) - (format "%s (default %s): " prompt default) - (format "%s: " prompt))) - (res (completing-read new-prompt - collection predicate t - nil ;; initial-input - hist default))) - (when (and (equal res default) - (not (test-completion res collection predicate))) - (setq res - (completing-read (format "%s: " prompt) - collection predicate t res hist nil))) - res)) + (minibuffer-with-setup-hook + (lambda () + (setq-local minibuffer-default-add-function + (lambda () + (let ((minibuffer-default default)) + (minibuffer-default-add-completions))))) + (completing-read prompt + collection predicate 'confirm + nil + hist))) ;;;###autoload (defun project-dired ()