branch: elpa/magit
commit f593e8dc8784d772b49284bf5cffaf52ceea6f81
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-completing-read: Support empty choice when match is required
If "" is a member of COLLECTION, then do not error if the user exits
with empty input, even when REQUIRE-MATCH is t. In that case, the
empty string/input is one of the valid matches. Return nil instead.
This is used by `forge-read-topic-milestone' to support removing the
currently set milestone.
---
lisp/magit-base.el | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index 7007a6488f9..0bd7a444d9d 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -604,21 +604,21 @@ acts similarly to `completing-read', except for the
following:
def)
(unless def
(setq def fallback))
+ (when (and def
+ (not (functionp collection))
+ (not (member def collection)))
+ (setq collection (cons def collection)))
(let ((command this-command)
- (reply (funcall
- magit-completing-read-function
- (magit--format-prompt prompt def)
- (if (and (not (functionp collection))
- def
- (not (member def collection)))
- (cons def collection)
- collection)
- predicate
- require-match initial-input hist def)))
+ (reply (funcall magit-completing-read-function
+ (magit--format-prompt prompt def)
+ collection predicate
+ require-match initial-input hist def)))
(setq this-command command)
;; Note: Avoid `string=' to support `helm-comp-read-use-marked'.
(if (equal reply "")
- (if require-match
+ (if (and require-match
+ (not (and (listp collection)
+ (member "" collection))))
(user-error "Nothing selected")
nil)
reply))))