module: add :completion corfu
This commit's primary goal is allowing use of [Corfu](https://github.com/minad/corfu) as an alternative to [Company](https://github.com/company-mode/company-mode). It introduces a module under `:completion` for this purpose, plus some conditionals on other relevant modules to toggle functionality like lsp back-ends and [Cape](https://github.com/minad/cape) capfs for certain modes. Other optional or miscellaneous features include: - Corfu is enabled in the minibuffer if `completion-at-point` is bound; - Support for displaying the completion's documentation on a secondary popup; - Support for terminal display if :os tty; - Support for icons if +icons;
This commit is contained in:
parent
85ce866953
commit
6949451b00
9 changed files with 422 additions and 8 deletions
92
modules/completion/corfu/config.el
Normal file
92
modules/completion/corfu/config.el
Normal file
|
@ -0,0 +1,92 @@
|
|||
;;; completion/corfu/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +corfu-want-ret-to-confirm t
|
||||
"Configure how the user expects RET to behave.
|
||||
Possible values are:
|
||||
- t (default): Insert candidate if one is selected, pass-through otherwise;
|
||||
- `minibuffer': Insert candidate if one is selected, pass-through otherwise,
|
||||
and immediatelly exit if in the minibuffer;
|
||||
- nil: Pass-through without inserting.")
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
(use-package! corfu
|
||||
:hook (doom-first-input . global-corfu-mode)
|
||||
:init
|
||||
(add-hook! 'minibuffer-setup-hook
|
||||
(defun +corfu-enable-in-minibuffer ()
|
||||
"Enable Corfu in the minibuffer if `completion-at-point' is bound."
|
||||
(when (where-is-internal #'completion-at-point (list (current-local-map)))
|
||||
(setq-local corfu-echo-delay nil)
|
||||
(corfu-mode +1))))
|
||||
:config
|
||||
(setq corfu-auto t
|
||||
corfu-auto-delay 0.1
|
||||
corfu-auto-prefix 2
|
||||
global-corfu-modes '((not
|
||||
erc-mode
|
||||
circe-mode
|
||||
help-mode
|
||||
gud-mode
|
||||
vterm-mode)
|
||||
t)
|
||||
corfu-cycle t
|
||||
corfu-separator (when (modulep! +orderless) ?\s)
|
||||
corfu-preselect 'prompt
|
||||
corfu-count 16
|
||||
corfu-max-width 120
|
||||
corfu-preview-current 'insert
|
||||
corfu-on-exact-match nil
|
||||
corfu-quit-at-boundary (if (modulep! +orderless) 'separator t)
|
||||
corfu-quit-no-match (if (modulep! +orderless) 'separator t)
|
||||
tab-always-indent 'complete)
|
||||
(add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles)))
|
||||
(add-to-list 'corfu-auto-commands #'lispy-colon)
|
||||
(add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer)
|
||||
(add-hook 'evil-insert-state-exit-hook #'corfu-quit))
|
||||
|
||||
(use-package! cape
|
||||
:defer t
|
||||
:init
|
||||
(add-hook! prog-mode
|
||||
(defun +corfu-add-cape-file-h ()
|
||||
(add-to-list 'completion-at-point-functions #'cape-file)))
|
||||
(add-hook! (org-mode markdown-mode)
|
||||
(defun +corfu-add-cape-elisp-block-h ()
|
||||
(add-hook 'completion-at-point-functions #'cape-elisp-block 0 t)))
|
||||
|
||||
;; Make these capfs composable.
|
||||
(advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible)
|
||||
(advice-add #'lsp-completion-at-point :around #'cape-wrap-nonexclusive)
|
||||
(advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)
|
||||
(advice-add #'eglot-completion-at-point :around #'cape-wrap-nonexclusive)
|
||||
(advice-add #'pcomplete-completions-at-point :around #'cape-wrap-nonexclusive)
|
||||
;; From the `cape' readme. Without this, Eshell autocompletion is broken on
|
||||
;; Emacs28.
|
||||
(when (< emacs-major-version 29)
|
||||
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
|
||||
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify)))
|
||||
|
||||
(use-package! corfu-terminal
|
||||
:when (not (display-graphic-p))
|
||||
:hook ((corfu-mode . corfu-terminal-mode)))
|
||||
|
||||
;;
|
||||
;;; Extensions
|
||||
|
||||
(use-package! corfu-history
|
||||
:hook ((corfu-mode . corfu-history-mode))
|
||||
:config
|
||||
(after! savehist (add-to-list 'savehist-additional-variables 'corfu-history)))
|
||||
|
||||
(use-package! corfu-popupinfo
|
||||
:hook ((corfu-mode . corfu-popupinfo-mode))
|
||||
:config
|
||||
(setq corfu-popupinfo-delay '(0.5 . 1.0)))
|
||||
|
||||
(use-package! nerd-icons-corfu
|
||||
:when (modulep! +icons)
|
||||
:defer t
|
||||
:init
|
||||
(after! corfu
|
||||
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)))
|
Loading…
Add table
Add a link
Reference in a new issue