Skip to content

Commit

Permalink
Add generalized corfu-preselect user option
Browse files Browse the repository at this point in the history
This replaces the old corfu-preselect-first option.
  • Loading branch information
minad committed Dec 22, 2022
1 parent 8b4c3c2 commit d524a0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions corfu.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))))
Expand Down

0 comments on commit d524a0c

Please sign in to comment.