diff --git a/CHANGELOG.org b/CHANGELOG.org index b0026d3..96ee5fb 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -6,6 +6,7 @@ - =corfu-popupinfo=: Add commands =corfu-popupinfo-beginning/end= - =corfu-popupinfo=: Improve popup placement +- Add =corfu-preselect= option, deprecate =corfu-preselect-first=. * Version 0.34 (2022-12-03) diff --git a/README.org b/README.org index dfa7542..7dd6feb 100644 --- a/README.org +++ b/README.org @@ -85,7 +85,7 @@ Here is an example configuration: ;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary ;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match ;; (corfu-preview-current nil) ;; Disable current candidate preview - ;; (corfu-preselect-first nil) ;; Disable candidate preselection + ;; (corfu-preselect 'prompt) ;; Preselect the prompt ;; (corfu-on-exact-match nil) ;; Configure handling of exact matches ;; (corfu-scroll-margin 5) ;; Use scroll margin @@ -385,8 +385,8 @@ force snippet expansion, confirm a candidate explicitly with ~RET~. (use-package corfu ;; TAB-and-Go customizations :custom - (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' - (corfu-preselect-first nil) ;; Disable candidate preselection + (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' + (corfu-preselect 'prompt) ;; Always preselect the prompt ;; Use TAB for cycling, default is `corfu-complete'. :bind diff --git a/corfu.el b/corfu.el index 1670113..bde82e4 100644 --- a/corfu.el +++ b/corfu.el @@ -81,9 +81,16 @@ If the variable has the value `insert', the candidate is automatically inserted on further input." :type '(choice boolean (const insert))) -(defcustom corfu-preselect-first t - "Preselect first candidate." - :type 'boolean) +(defcustom corfu-preselect 'valid + "Configure if the prompt or first candidate is preselected. +- prompt: Always select the prompt. +- first: Always select the first candidate. +- valid: Only select the prompt if valid and not equal to the first candidate. +- directory: Like first, but select the prompt if it is a directory." + :type '(choice (const prompt) (const valid) (const first) (const directory))) + +(defvar corfu-preselect-first t) +(make-obsolete-variable 'corfu-preselect-first "Use `corfu-preselect' instead." "0.34") (defcustom corfu-separator ?\s "Component separator character. @@ -640,12 +647,12 @@ A scroll bar is displayed from LO to LO+BAR." (corfu--candidates . ,all) (corfu--total . ,(length all)) (corfu--highlight . ,hl) - ;; Select the prompt when the input is a valid completion and if it is not - ;; equal to the first candidate. This condition prevents jumping to prompt - ;; during completion for the full candidate when the incomplete candidate - ;; is invalid. - (corfu--preselect . ,(if (or (not corfu-preselect-first) (not all) - (and (not (equal field (car all))) + (corfu--preselect . ,(if (or (eq corfu-preselect 'prompt) (not all) + (and completing-file (eq corfu-preselect 'directory) + (= (length corfu--base) (length str)) + (test-completion str table pred)) + (and (eq corfu-preselect 'valid) + (not (equal field (car all))) (not (and completing-file (equal (concat field "/") (car all)))) (test-completion str table pred))) -1 0)))))