From 437b19c42e7d0112041e561607fd10ef03ab90ec Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 16 Oct 2021 11:54:14 +0200 Subject: Generalize corfu-commit-predicate --- corfu.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/corfu.el b/corfu.el index 96b95fc..14f9f4d 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) -- cgit v1.0