branch: elpa/magit
commit c52abfd66e863ff34fea13e93f83280e5051d843
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-completing-read: Support requiring non-empty input
---
 docs/magit.org          |  6 +++++-
 docs/magit.texi         |  7 ++++++-
 lisp/git-commit.el      |  2 +-
 lisp/magit-base.el      |  7 ++++++-
 lisp/magit-files.el     | 20 +++++++++-----------
 lisp/magit-git.el       | 31 +++++++++++++++----------------
 lisp/magit-gitignore.el |  2 +-
 lisp/magit-log.el       | 17 ++++++++---------
 lisp/magit-merge.el     |  2 +-
 lisp/magit-patch.el     |  5 ++---
 lisp/magit-push.el      |  4 ++--
 lisp/magit-repos.el     |  2 +-
 lisp/magit-transient.el |  9 ++++-----
 13 files changed, 61 insertions(+), 53 deletions(-)

diff --git a/docs/magit.org b/docs/magit.org
index cdc364c5d23..4c1089cc8fc 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -1794,7 +1794,11 @@ will also have to install the ~ido-completing-read+~ 
package and use
   - If REQUIRE-MATCH is ~nil~ and the user exits without a choice, then
     ~nil~ is returned instead of an empty string.
 
-  - If REQUIRE-MATCH is non-nil and the users exits without a choice,
+  - If REQUIRE-MATCH is ~any~, then do not require a match but
+    do require non-empty input (or non-nil DEFAULT, since that
+    is substituted for empty input).
+
+  - If REQUIRE-MATCH is non-~nil~ and the users exits without a choice,
     an user-error is raised.
 
   - FALLBACK specifies a secondary default that is only used if the
diff --git a/docs/magit.texi b/docs/magit.texi
index f8fdb856b80..4e96c3aff60 100644
--- a/docs/magit.texi
+++ b/docs/magit.texi
@@ -2102,7 +2102,12 @@ If REQUIRE-MATCH is @code{nil} and the user exits 
without a choice, then
 @code{nil} is returned instead of an empty string.
 
 @item
-If REQUIRE-MATCH is non-nil and the users exits without a choice,
+If REQUIRE-MATCH is @code{any}, then do not require a match but
+do require non-empty input (or non-nil DEFAULT, since that
+is substituted for empty input).
+
+@item
+If REQUIRE-MATCH is non-@code{nil} and the users exits without a choice,
 an user-error is raised.
 
 @item
diff --git a/lisp/git-commit.el b/lisp/git-commit.el
index 6c5975f5584..140e058d572 100644
--- a/lisp/git-commit.el
+++ b/lisp/git-commit.el
@@ -947,7 +947,7 @@ completion candidates.  The input must have the form \"NAME 
<EMAIL>\"."
               (sort (delete-dups
                      (magit-git-lines "log" "-n9999" "--format=%aN <%ae>"))
                     #'string<)
-              nil nil nil 'git-commit-read-ident-history)))
+              nil 'any nil 'git-commit-read-ident-history)))
     (save-match-data
       (if (string-match "\\`\\([^<]+\\) *<\\([^>]+\\)>\\'" str)
           (list (save-match-data (string-trim (match-str 1 str)))
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index b49f2a72677..b8d50a9d6ee 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -576,6 +576,10 @@ acts similarly to `completing-read', except for the 
following:
 - If REQUIRE-MATCH is nil and the user exits without a choice,
   then nil is returned instead of an empty string.
 
+- If REQUIRE-MATCH is `any', then do not require a match but
+  do require non-empty input (or non-nil DEFAULT, since that
+  is substituted for empty input).
+
 - If REQUIRE-MATCH is non-nil and the user exits without a
   choice, `user-error' is raised.
 
@@ -614,7 +618,8 @@ acts similarly to `completing-read', except for the 
following:
           (reply (funcall magit-completing-read-function
                           (magit--format-prompt prompt def)
                           collection predicate
-                          require-match initial-input hist def)))
+                          (if (eq require-match 'any) nil require-match)
+                          initial-input hist def)))
       (setq this-command command)
       ;; Note: Avoid `string=' to support `helm-comp-read-use-marked'.
       (if (equal reply "")
diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index a7abb089e84..b1836dc0bb1 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -68,17 +68,15 @@ the line and column corresponding to that location."
 
 (defun magit-find-file-read-args (prompt)
   (let ((pseudo-revs '("{worktree}" "{index}")))
-    (if-let ((rev (magit-completing-read "Find file from revision"
-                                         (append pseudo-revs
-                                                 (magit-list-refnames nil t))
-                                         nil nil nil 'magit-revision-history
-                                         (or (magit-branch-or-commit-at-point)
-                                             (magit-get-current-branch)))))
-        (list rev (magit-read-file-from-rev (if (member rev pseudo-revs)
-                                                "HEAD"
-                                              rev)
-                                            prompt))
-      (user-error "Nothing selected"))))
+    (let ((rev (magit-completing-read "Find file from revision"
+                                      (append pseudo-revs
+                                              (magit-list-refnames nil t))
+                                      nil 'any nil 'magit-revision-history
+                                      (or (magit-branch-or-commit-at-point)
+                                          (magit-get-current-branch)))))
+      (list rev
+            (magit-read-file-from-rev (if (member rev pseudo-revs) "HEAD" rev)
+                                      prompt)))))
 
 (defun magit-find-file--internal (rev file fn)
   (let ((buf (magit-find-file-noselect rev file))
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 22a31db37fd..44b135b2610 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -2662,10 +2662,9 @@ and this option only controls what face is used.")
     (when (and commit-at-point (not branch-at-point))
       (setq choices (cons commit-at-point choices)))
     (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
-      (or (magit-completing-read
-           prompt choices nil nil nil 'magit-revision-history
-           (or branch-at-point commit-at-point secondary-default current))
-          (user-error "Nothing selected")))))
+      (magit-completing-read
+       prompt choices nil 'any nil 'magit-revision-history
+       (or branch-at-point commit-at-point secondary-default current)))))
 
 (defun magit-read-range-or-commit (prompt &optional secondary-default)
   (magit-read-range
@@ -2686,7 +2685,7 @@ and this option only controls what face is used.")
     (magit-completing-read-multiple
      (concat prompt ": ")
      (magit-list-refnames)
-     nil nil nil 'magit-revision-history default nil t)))
+     nil 'any nil 'magit-revision-history default nil t)))
 
 (defun magit-read-remote-branch
     (prompt &optional remote default local-branch require-match)
@@ -2699,7 +2698,8 @@ and this option only controls what face is used.")
                                           (magit-list-remotes))))
                            (magit-list-remote-branch-names remote t)
                            :test #'equal)
-                 nil require-match nil 'magit-revision-history default)))
+                 nil (or require-match 'any)
+                 nil 'magit-revision-history default)))
     (if (or remote (string-match "\\`\\([^/]+\\)/\\(.+\\)" choice))
         choice
       (user-error "`%s' doesn't have the form REMOTE/BRANCH" choice))))
@@ -2708,7 +2708,8 @@ and this option only controls what face is used.")
   (magit-completing-read prompt
                          (prog2 (message "Determining available refs...")
                              (magit-remote-list-refs remote)
-                           (message "Determining available refs...done"))))
+                           (message "Determining available refs...done"))
+                         nil 'any))
 
 (defun magit-read-local-branch (prompt &optional secondary-default)
   (magit-completing-read prompt (magit-list-local-branch-names)
@@ -2724,10 +2725,9 @@ and this option only controls what face is used.")
     (when commit
       (push commit choices))
     (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
-      (or (magit-completing-read prompt choices
-                                 nil nil nil 'magit-revision-history
-                                 (or (magit-local-branch-at-point) commit))
-          (user-error "Nothing selected")))))
+      (magit-completing-read prompt choices
+                             nil 'any nil 'magit-revision-history
+                             (or (magit-local-branch-at-point) commit)))))
 
 (defun magit-read-local-branch-or-ref (prompt &optional secondary-default)
   (magit-completing-read prompt (nconc (magit-list-local-branch-names)
@@ -2762,9 +2762,8 @@ and this option only controls what face is used.")
                       secondary-default
                       (magit-get-previous-branch))))
     (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
-      (or (magit-completing-read prompt (delete exclude (magit-list-refnames))
-                                 nil nil nil 'magit-revision-history default)
-          (user-error "Nothing selected")))))
+      (magit-completing-read prompt (delete exclude (magit-list-refnames))
+                             nil 'any nil 'magit-revision-history default))))
 
 (defun magit-read-other-local-branch
     (prompt &optional exclude secondary-default)
@@ -2827,7 +2826,7 @@ out.  Only existing branches can be selected."
        (nconc (list "HEAD")
               (magit-list-refnames)
               (directory-files (magit-gitdir) nil "_HEAD\\'"))
-       nil nil nil 'magit-revision-history
+       nil 'any nil 'magit-revision-history
        (or default (magit--default-starting-point)))
       (user-error "Nothing selected")))
 
@@ -2875,7 +2874,7 @@ out.  Only existing branches can be selected."
   (magit-completing-read prompt
                          (nconc (magit-list-remotes)
                                 (list "https://"; "git://" "git@"))
-                         nil nil nil nil
+                         nil 'any nil nil
                          (or default
                              (magit-remote-at-point)
                              (magit-get-remote))))
diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el
index 4f8baf95d8d..62b0ef5c7f4 100644
--- a/lisp/magit-gitignore.el
+++ b/lisp/magit-gitignore.el
@@ -138,7 +138,7 @@ Rules that are defined in that file affect all local 
repositories."
         (unless (member default choices)
           (setq default nil))))
     (magit-completing-read "File or pattern to ignore"
-                           choices nil nil nil nil default)))
+                           choices nil 'any nil nil default)))
 
 ;;; Skip Worktree Commands
 
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index 66b30a366b4..c82cc95c02b 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -651,7 +651,7 @@ commits before and half after."
         (split-string (magit-completing-read-multiple
                        "Log rev,s: "
                        (magit-list-refnames nil t)
-                       nil nil nil 'magit-revision-history
+                       nil 'any nil 'magit-revision-history
                        (or (magit-branch-or-commit-at-point)
                            (and (not use-current)
                                 (magit-get-previous-branch)))
@@ -953,14 +953,13 @@ nothing else.
 If invoked outside any log buffer, then display the log buffer
 of the current repository first; creating it if necessary."
   (interactive
-   (list (or (magit-completing-read
-              "In log, jump to"
-              (magit-list-refnames nil t)
-              nil nil nil 'magit-revision-history
-              (or (and-let* ((rev (magit-commit-at-point)))
-                    (magit-rev-fixup-target rev))
-                  (magit-get-current-branch)))
-             (user-error "Nothing selected"))))
+   (list (magit-completing-read
+          "In log, jump to"
+          (magit-list-refnames nil t)
+          nil 'any nil 'magit-revision-history
+          (or (and-let* ((rev (magit-commit-at-point)))
+                (magit-rev-fixup-target rev))
+              (magit-get-current-branch)))))
   (with-current-buffer
       (cond ((derived-mode-p 'magit-log-mode)
              (current-buffer))
diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el
index 28a702c00af..47865af44ab 100644
--- a/lisp/magit-merge.el
+++ b/lisp/magit-merge.el
@@ -241,7 +241,7 @@ then also remove the respective remote branch."
   "During a conflict checkout and stage side, or restore conflict."
   (interactive
    (let ((file (magit-completing-read "Checkout file"
-                                      (magit-tracked-files) nil nil nil
+                                      (magit-tracked-files) nil 'any nil
                                       'magit-read-file-hist
                                       (magit-current-file))))
      (cond ((member file (magit-unmerged-files))
diff --git a/lisp/magit-patch.el b/lisp/magit-patch.el
index 8b5529910bc..4c1b44f2605 100644
--- a/lisp/magit-patch.el
+++ b/lisp/magit-patch.el
@@ -150,9 +150,8 @@ which creates patches for all commits that are reachable 
from
   :reader #'magit-format-patch-select-base)
 
 (defun magit-format-patch-select-base (prompt initial-input history)
-  (or (magit-completing-read prompt (cons "auto" (magit-list-refnames))
-                             nil nil initial-input history "auto")
-      (user-error "Nothing selected")))
+  (magit-completing-read prompt (cons "auto" (magit-list-refnames))
+                         nil 'any initial-input history "auto"))
 
 (transient-define-argument magit-format-patch:--reroll-count ()
   :description "Reroll count"
diff --git a/lisp/magit-push.el b/lisp/magit-push.el
index 9fc944e369b..4b8f221f1d4 100644
--- a/lisp/magit-push.el
+++ b/lisp/magit-push.el
@@ -134,7 +134,7 @@ the upstream."
                                  :test #'equal))
              (upstream (magit-completing-read
                         (format "Set upstream of %s and push there" branch)
-                        branches nil nil nil 'magit-revision-history
+                        branches nil 'any nil 'magit-revision-history
                         (or (car (member (magit-remote-branch-at-point) 
branches))
                             (car (member "origin/master" branches)))))
              (upstream* (or (magit-get-tracked upstream)
@@ -218,7 +218,7 @@ is used."
          (magit-completing-read-multiple
           "Push refspec,s: "
           (cons "HEAD" (magit-list-local-branch-names))
-          nil nil nil 'magit-push-refspecs-history)
+          nil 'any nil 'magit-push-refspecs-history)
          (magit-push-arguments)))
   (run-hooks 'magit-credential-hook)
   (magit-run-git-async "push" "-v" args remote refspecs))
diff --git a/lisp/magit-repos.el b/lisp/magit-repos.el
index dcf6808ec14..497df494712 100644
--- a/lisp/magit-repos.el
+++ b/lisp/magit-repos.el
@@ -492,7 +492,7 @@ instead."
   (if-let ((repos (and (not read-directory-name)
                        magit-repository-directories
                        (magit-repos-alist))))
-      (let ((reply (magit-completing-read "Git repository" repos)))
+      (let ((reply (magit-completing-read "Git repository" repos nil 'any)))
         (file-name-as-directory
          (or (cdr (assoc reply repos))
              (if (file-directory-p reply)
diff --git a/lisp/magit-transient.el b/lisp/magit-transient.el
index 55dc374c041..ad7135b8397 100644
--- a/lisp/magit-transient.el
+++ b/lisp/magit-transient.el
@@ -118,11 +118,10 @@
    nil nil initial-input history))
 
 (defun magit-transient-read-revision (prompt initial-input history)
-  (or (magit-completing-read prompt (cons "HEAD" (magit-list-refnames))
-                             nil nil initial-input history
-                             (or (magit-branch-or-commit-at-point)
-                                 (magit-get-current-branch)))
-      (user-error "Nothing selected")))
+  (magit-completing-read prompt (cons "HEAD" (magit-list-refnames))
+                         nil 'any initial-input history
+                         (or (magit-branch-or-commit-at-point)
+                             (magit-get-current-branch))))
 
 ;;;; Set
 

Reply via email to