branch: master
commit 533b7885ecc69c4e1275ec93a066283a31ba50ac
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy-done): Be more strict for `require-match'
When `require-match' isn't in (nil confirm confirm-after-completion),
don't allow to exit if there isn't a match. Instead, amend the prompt
with "(match required)".
---
ivy.el | 59 +++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/ivy.el b/ivy.el
index 8619f3e..e6b07d4 100644
--- a/ivy.el
+++ b/ivy.el
@@ -165,28 +165,43 @@ When non-nil, it should contain one %d.")
"Exit the minibuffer with the selected candidate."
(interactive)
(delete-minibuffer-contents)
- (cond (ivy--directory
- (insert
- (cond ((string= ivy-text "")
- (if (equal ivy--current "./")
- ivy--directory
- (if (string-match "\\*" ivy--current)
- ivy--current
- (expand-file-name ivy--current ivy--directory))))
- ((zerop ivy--length)
- (expand-file-name ivy-text ivy--directory))
- (t
- (expand-file-name ivy--current ivy--directory))))
- (setq ivy-exit 'done))
- ((zerop ivy--length)
- (when (memq ivy-require-match
- '(nil confirm confirm-after-completion))
- (insert ivy-text)
- (setq ivy-exit 'done)))
- (t
- (insert ivy--current)
- (setq ivy-exit 'done)))
- (exit-minibuffer))
+ (when (cond (ivy--directory
+ (insert
+ (cond ((string= ivy-text "")
+ (if (equal ivy--current "./")
+ ivy--directory
+ (if (string-match "\\*" ivy--current)
+ ivy--current
+ (expand-file-name ivy--current ivy--directory))))
+ ((zerop ivy--length)
+ (expand-file-name ivy-text ivy--directory))
+ (t
+ (expand-file-name ivy--current ivy--directory))))
+ (setq ivy-exit 'done))
+ ((zerop ivy--length)
+ (if (memq ivy-require-match
+ '(nil confirm confirm-after-completion))
+ (if (= ivy--length 0)
+ t
+ (insert ivy-text)
+ (setq ivy-exit 'done))
+ (progn
+ (unless (string-match "match required" ivy--prompt)
+ (setq ivy--prompt
+ (if (string-match ": $" ivy--prompt)
+ (concat
+ (substring ivy--prompt 0 -2)
+ " (match required): ")
+ (concat
+ ivy--prompt
+ "(match required) "))))
+ (insert ivy-text)
+ (ivy--exhibit)
+ nil)))
+ (t
+ (insert ivy--current)
+ (setq ivy-exit 'done)))
+ (exit-minibuffer)))
(defun ivy-alt-done (&optional arg)
"Exit the minibuffer with the selected candidate.