From 5b0fdd9ec99f8490902a3c2edf46958301fb6db1 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 12 Feb 2022 16:42:19 +0100 Subject: Add corfu-insert-single configuration option (Fix #109) --- corfu.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/corfu.el b/corfu.el index e428fc4..5fb0cdc 100644 --- a/corfu.el +++ b/corfu.el @@ -64,6 +64,10 @@ The value should lie between 0 and corfu-count/2." "Enable cycling for `corfu-next' and `corfu-previous'." :type 'boolean) +(defcustom corfu-insert-single t + "Automatically insert single matching candidate." + :type 'boolean) + (defcustom corfu-continue-commands ;; nil is undefined command '(nil ignore universal-argument universal-argument-more digit-argument @@ -811,21 +815,22 @@ there hasn't been any input, then quit." nil) (error (corfu-quit) (message "Corfu completion error: %s" (error-message-string err))))) - ;; 1) Initializing, no candidates => Quit (happens during auto completion!) + ;; 1) Initializing, no candidates => Quit. Happens during auto completion. ((and initializing (not corfu--candidates)) (corfu-quit)) - ;; 2) Single matching candidate and no further completion is possible + ;; 2) Single matching candidate and no further completion is possible. ((and (not (equal str "")) - (equal corfu--candidates (list str)) - (not (consp (completion-try-completion str table pred pt corfu--metadata)))) - ;; Quit directly, happens during auto completion! + (equal (car corfu--candidates) str) (not (cdr corfu--candidates)) + (not (consp (completion-try-completion str table pred pt corfu--metadata))) + (or initializing corfu-insert-single)) + ;; Quit directly, happens during auto completion. (if initializing (corfu-quit) (corfu--done str 'finished))) - ;; 3) There exist candidates => Show candidates popup + ;; 3) There exist candidates => Show candidates popup. (corfu--candidates (corfu--candidates-popup beg) (corfu--echo-documentation) (corfu--preview-current beg end str)) - ;; 4) There are no candidates & corfu-quit-no-match => Confirmation popup + ;; 4) There are no candidates & corfu-quit-no-match => Confirmation popup. ((and (not corfu--candidates) (pcase-exhaustive corfu-quit-no-match ('t nil) -- cgit v1.0