diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2021-10-16 11:54:14 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2021-10-16 11:54:14 +0200 |
| commit | 437b19c42e7d0112041e561607fd10ef03ab90ec (patch) | |
| tree | d8abfc5447097082e35afc85539a75d617aea3ed | |
| parent | aec6277571b49bd9fc6518b12b129a1484c9202f (diff) | |
Generalize corfu-commit-predicate
| -rw-r--r-- | corfu.el | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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) |
