emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fa89537: Change how project-find-file's completion works


From: Dmitry Gutov
Subject: master fa89537: Change how project-find-file's completion works
Date: Thu, 5 Aug 2021 20:30:38 -0400 (EDT)

branch: master
commit fa895379d6166c52b89774a9e450a94c2e429dae
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    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).
---
 etc/NEWS                  |  6 ++++++
 lisp/progmodes/project.el | 27 ++++++++++-----------------
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 6495fd0..7fc53ff 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 0e73286..6a330ec 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 ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]