summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2021-10-16 11:54:14 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2021-10-17 15:17:33 +0200
commit676395fbb5784a50f54985026d76929daee8ee4c (patch)
tree8be5cc8f530898ebef3dbfe4aad1dacae2e530f5
parentc42760f51ce009ad45eb8715aaccdd7ab018fc04 (diff)
Generalize corfu-commit-predicate
Fix #49, Fix #52
-rw-r--r--corfu.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/corfu.el b/corfu.el
index bf930c2..ab7a544 100644
--- a/corfu.el
+++ b/corfu.el
@@ -66,9 +66,9 @@
"Continue Corfu completion after executing these commands."
:type '(repeat (choice regexp symbol)))
-(defcustom corfu-commit-predicate t
- "Automatically commit the selected candidate if the predicate returns t."
- :type '(choice boolean (function :tag "Predicate function")))
+(defcustom corfu-commit-predicate #'corfu-candidate-selected-p
+ "Automatically commit if the predicate returns t."
+ :type 'function)
(defcustom corfu-quit-at-boundary nil
"Automatically quit at completion field/word boundary.
@@ -695,13 +695,15 @@ completion began less than that number of seconds ago."
(defun corfu--pre-command ()
"Insert selected candidate unless command is marked to continue completion."
(add-hook 'window-configuration-change-hook #'corfu-quit)
- (unless (or (< corfu--index 0) (corfu--match-symbol-p corfu-continue-commands this-command))
- (if (if (functionp corfu-commit-predicate)
- (funcall corfu-commit-predicate)
- corfu-commit-predicate)
+ (unless (corfu--match-symbol-p corfu-continue-commands this-command)
+ (if (funcall corfu-commit-predicate)
(corfu--insert 'exact)
(setq corfu--index -1))))
+(defun corfu-candidate-selected-p ()
+ "Return t if a candidate is selected."
+ (>= corfu--index 0))
+
(defun corfu--post-command ()
"Refresh Corfu after last command."
(remove-hook 'window-configuration-change-hook #'corfu-quit)