-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-corfu.el
99 lines (81 loc) · 3.18 KB
/
my-corfu.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;; my-corfu --- Corfu customisation
;;
;;; Commentary:
;;
;; This is an alternative completion engine to company. Currently I am
;; experimenting with it as an alternative.
;;
;;; Code:
;; Helpers for tweaking completion, we want flex first followed by
;; orderless.
(defun my-orderless-dispatch-flex-first (_pattern index _total)
(and (eq index 0) 'orderless-flex))
;; ensure we use flex matching
(defun my-lsp-mode-setup-completion ()
"Setup flex matching for LSP."
(message "setting up flex matching")
(setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
'(orderless))) ;; Configure flex
;; Optional cape package.
;; See the Cape README for more tweaks!
(use-package cape
:ensure t)
(use-package orderless
:ensure t
:init
;; Tune the global completion style settings to your liking!
;; This affects the minibuffer and non-lsp completion at point.
(setq completion-styles '(orderless partial-completion basic)
completion-category-defaults nil
completion-category-overrides nil)
;; Optionally configure the first word as flex filtered.
(add-hook 'orderless-style-dispatchers #'my-orderless-dispatch-flex-first nil 'local)
;; Optionally configure the cape-capf-buster. FIXME
(setq-local completion-at-point-functions (list (cape-capf-buster #'lsp-completion-at-point))))
(use-package corfu
:ensure t
:hook (lsp-completion-mode . my-lsp-mode-setup-completion)
:init (global-corfu-mode)
:config (setq corfu-auto t))
;; we also need to handle disabling on new frames
(defun my-maybe-enable-corfu-terminal-mode ()
"Enable corfu-terminal-mode if non-graphic frame.
This should be called from a hook such as `server-after-make-frame-hook'"
(if (display-graphic-p)
(corfu-terminal-mode -1)
(corfu-terminal-mode +1)))
(use-package corfu-terminal
:ensure t
:commands corfu-terminal-mode
:hook (server-after-make-frame . my-maybe-enable-corfu-terminal-mode))
;; Disable for now as it breaks ement:
;; https://github.com/alphapapa/ement.el/issues/212
;; https://github.com/rougier/svg-lib/issues/18
(use-package kind-icon
:disabled t
:after corfu
:custom
(kind-icon-default-face 'corfu-default) ; to compute blended backgrounds correctly
:config
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
;; a few more useful configurations...
(use-package emacs
:init
;; TAB cycle if there are only few candidates
(setq completion-cycle-threshold 3)
;; Emacs 28: Hide commands in M-x which do not apply to the current mode.
;; Corfu commands are hidden, since they are not supposed to be used via M-x.
;; (setq read-extended-command-predicate
;; #'command-completion-default-include-p)
;; Enable indentation+completion using the TAB key.
;; `completion-at-point' is often bound to M-TAB.
(setq tab-always-indent 'complete))
;; :custom (lsp-completion-provider :none) ;; we use Corfu!
;; :init
;; (defun my-lsp-mode-setup-completion ()
;; (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
;; '(flex))) ;; Configure flex
;; :custom (lsp-completion-provider :none) ;; we use Corfu!
;; :init
(provide 'my-corfu)
;;; my-corfu.el ends here