2022-09-24 17:33:32 -03:00
|
|
|
;;; completion/corfu/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(defvar +corfu-completion-styles '(basic partial-completion flex)
|
|
|
|
"Completion styles for corfu to use.
|
|
|
|
|
|
|
|
If the user enables +orderless, `orderless' is automatically appended to this
|
|
|
|
list before fowarding to `completion-styles'.")
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
(use-package! corfu
|
|
|
|
:hook (doom-first-buffer . global-corfu-mode)
|
|
|
|
:hook (org-mode . corfu-mode)
|
|
|
|
:init
|
|
|
|
;; Auto-completion settings, must be set before calling `global-corfu-mode'.
|
2023-09-24 15:28:45 -05:00
|
|
|
;; Due to lazy-loading, overriding these in config.el works too.
|
2022-09-24 17:33:32 -03:00
|
|
|
(setq corfu-auto t
|
|
|
|
corfu-auto-delay 0.1
|
|
|
|
corfu-auto-prefix 2
|
|
|
|
corfu-excluded-modes '(erc-mode
|
|
|
|
circe-mode
|
|
|
|
help-mode
|
|
|
|
gud-mode
|
|
|
|
vterm-mode))
|
|
|
|
:config
|
|
|
|
(setq corfu-cycle t
|
|
|
|
corfu-separator (when (modulep! +orderless) ?\s)
|
|
|
|
corfu-preselect t
|
|
|
|
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)
|
|
|
|
;; In the case of +tng, TAB should be smart regarding completion;
|
|
|
|
;; However, it should otherwise behave like normal, whatever normal was.
|
|
|
|
tab-always-indent (if (modulep! +tng) 'complete tab-always-indent))
|
|
|
|
|
|
|
|
(when (modulep! +orderless)
|
2023-10-02 13:13:23 -03:00
|
|
|
(after! lsp-mode
|
2022-09-24 17:33:32 -03:00
|
|
|
(add-to-list 'completion-category-overrides
|
|
|
|
`(lsp-capf (styles ,@+corfu-completion-styles ,(when (modulep! +orderless) 'orderless)))))
|
2023-10-02 13:13:23 -03:00
|
|
|
(after! eglot
|
2022-09-24 17:33:32 -03:00
|
|
|
(add-to-list 'completion-category-overrides
|
|
|
|
`(eglot (styles ,@+corfu-completion-styles ,(when (modulep! +orderless) 'orderless))))))
|
|
|
|
|
2023-10-02 13:13:23 -03:00
|
|
|
(after! evil
|
|
|
|
(add-hook 'evil-insert-state-exit-hook #'corfu-quit))
|
|
|
|
|
2022-09-24 17:33:32 -03:00
|
|
|
(when (modulep! +icons)
|
2023-10-15 14:59:12 -03:00
|
|
|
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
|
2022-09-24 17:33:32 -03:00
|
|
|
|
|
|
|
;; This is to decouple the use of `completion-styles' in corfu from other
|
|
|
|
;; completion packages, such as vertico. That way, the user can leave the
|
|
|
|
;; global value of the variable alone, say, to be used by the default
|
|
|
|
;; front-end or consult. The vertico module also does something similar with
|
|
|
|
;; `+vertico-company-completion-styles'.
|
|
|
|
(defadvice! +corfu--completion-styles (orig &rest args)
|
|
|
|
"Try default completion styles before orderless.
|
|
|
|
|
|
|
|
Meant as :around advice for `corfu--recompute'."
|
|
|
|
:around #'corfu--recompute
|
|
|
|
(let ((completion-styles
|
|
|
|
(append +corfu-completion-styles (when (modulep! +orderless)
|
|
|
|
'(orderless))))
|
|
|
|
completion-category-overrides completion-category-defaults)
|
|
|
|
(apply orig args)))
|
|
|
|
|
|
|
|
(map! (:unless (modulep! +tng)
|
|
|
|
"C-SPC" #'completion-at-point)
|
|
|
|
(:map 'corfu-map
|
|
|
|
(:when (modulep! +orderless)
|
|
|
|
"C-SPC" #'corfu-insert-separator)
|
|
|
|
(:when (modulep! +tng)
|
|
|
|
[tab] #'corfu-next
|
|
|
|
[backtab] #'corfu-previous
|
|
|
|
"TAB" #'corfu-next
|
|
|
|
"S-TAB" #'corfu-previous)))
|
|
|
|
(after! evil-collection-corfu
|
|
|
|
(evil-collection-define-key 'insert 'corfu-map
|
|
|
|
(kbd "RET") #'corfu-insert
|
|
|
|
[return] #'corfu-insert))
|
|
|
|
|
|
|
|
(after! vertico
|
|
|
|
;; Taken from corfu's README.
|
|
|
|
;; TODO: extend this to other completion front-ends.
|
|
|
|
(defun corfu-move-to-minibuffer ()
|
|
|
|
(interactive)
|
|
|
|
(let ((completion-extra-properties corfu--extra)
|
|
|
|
(completion-cycle-threshold completion-cycling))
|
|
|
|
(apply #'consult-completion-in-region completion-in-region--data)))
|
2023-10-02 13:11:19 -03:00
|
|
|
(map! :map 'corfu-map "M-m" #'corfu-move-to-minibuffer
|
|
|
|
(:when (modulep! :editor evil) :i "M-j" #'corfu-move-to-minibuffer))))
|
2022-09-24 17:33:32 -03:00
|
|
|
|
|
|
|
(use-package! cape
|
2023-09-24 15:28:45 -05:00
|
|
|
:defer t
|
|
|
|
:init
|
2023-09-20 10:54:28 -03:00
|
|
|
(add-hook! prog-mode (add-to-list 'completion-at-point-functions #'cape-file))
|
|
|
|
(add-hook! (org-mode markdown-mode) (add-to-list 'completion-at-point-functions #'cape-elisp-block))
|
2022-09-24 17:33:32 -03:00
|
|
|
(advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible))
|
|
|
|
|
2023-07-26 19:57:21 -03:00
|
|
|
(use-package! yasnippet-capf
|
2023-09-24 15:28:45 -05:00
|
|
|
:when (modulep! :editor snippets)
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(after! yasnippet
|
|
|
|
(add-hook! yas-minor-mode
|
|
|
|
(add-to-list 'completion-at-point-functions #'yasnippet-capf))))
|
2023-07-26 19:57:21 -03:00
|
|
|
|
2022-09-24 17:33:32 -03:00
|
|
|
(use-package! corfu-terminal
|
|
|
|
:when (not (display-graphic-p))
|
|
|
|
:hook (corfu-mode . corfu-terminal-mode))
|
|
|
|
|
2023-10-15 14:59:12 -03:00
|
|
|
;;
|
2022-09-24 17:33:32 -03:00
|
|
|
;;; Extensions
|
2023-09-24 15:29:06 -05:00
|
|
|
|
2022-09-24 17:33:32 -03:00
|
|
|
(use-package! corfu-history
|
|
|
|
:hook (corfu-mode . corfu-history-mode)
|
|
|
|
:config
|
2023-09-24 15:29:06 -05:00
|
|
|
(after! savehist (add-to-list 'savehist-additional-variables 'corfu-history)))
|
|
|
|
|
|
|
|
|
2022-09-24 17:33:32 -03:00
|
|
|
(use-package! corfu-popupinfo
|
|
|
|
:hook (corfu-mode . corfu-popupinfo-mode)
|
|
|
|
:config
|
|
|
|
(setq corfu-popupinfo-delay '(0.5 . 1.0))
|
|
|
|
(map! (:map 'corfu-map
|
|
|
|
"C-<up>" #'corfu-popupinfo-scroll-down
|
|
|
|
"C-<down>" #'corfu-popupinfo-scroll-up
|
|
|
|
"C-S-p" #'corfu-popupinfo-scroll-down
|
|
|
|
"C-S-n" #'corfu-popupinfo-scroll-up
|
|
|
|
"C-h" #'corfu-popupinfo-toggle)
|
|
|
|
(:map 'corfu-popupinfo-map
|
|
|
|
:when (modulep! :editor evil)
|
|
|
|
;; Reversed because popupinfo assumes opposite of what feels intuitive
|
|
|
|
;; with evil.
|
|
|
|
"C-S-k" #'corfu-popupinfo-scroll-down
|
|
|
|
"C-S-j" #'corfu-popupinfo-scroll-up)))
|