/
init-completion.el
308 lines (282 loc) · 9.93 KB
/
init-completion.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
;;; -*- lexical-binding: t -*-
;;; 代码补全
;; 可以使用 M-/ 进行简单的补全
(use-package dabbrev
:straight t
:config
(setq dabbrev-ignored-buffer-regexps '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'"))
:bind
("M-'" . dabbrev-expand))
;;; corfu & tempel 方案,缺点是会自动触发 yasnippet
(use-package tempel
:straight t
:bind (:map tempel-map
("RET" . tempel-next)
("S-<RET>" . tempel-previous))
:hook (((prog-mode text-mode) . +tempel-setup-capf)
((prog-mode text-mode) . tempel-abbrev-mode))
:config
(defun +tempel-setup-capf ()
(push #'tempel-complete completion-at-point-functions))
(setq tempel-trigger-prefix "`"
tempel-path (no-littering-expand-etc-file-name "tempel-templates"))
)
(use-package tempel-collection
:straight t
:after tempel)
;; ;; [corfu] compleletion frontend
;; (use-package corfu
;; :straight (:files (:defaults "extensions/*.el"))
;; :hook (((prog-mode conf-mode yaml-mode shell-mode eshell-mode) . corfu-mode)
;; ((eshell-mode shell-mode) . (lambda () (setq-local corfu-auto nil)))
;; (minibuffer-setup . corfu-enable-in-minibuffer))
;; :bind (:map corfu-map
;; ([tab] . corfu-next)
;; ([backtab] . corfu-previous))
;; :config
;; (setq corfu-cycle t ;; Enable cycling for `corfu-next/previous'
;; corfu-auto t ;; Enable auto completion
;; corfu-separator "&" ;; Orderless field separator
;; corfu-auto-prefix 2 ;; minimun prefix to enable completion
;; corfu-preview-current nil
;; corfu-on-exact-match nil
;; corfu-auto-delay 0.1)
;; ;; Transfer completion to the minibuffer
;; (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)))
;; ;; Completing in the minibuffer
;; (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)))
;; (corfu-mode 1)))
;; )
(use-package corfu
:straight (:files (:defaults "extensions/*.el"))
:hook (((tex-mode prog-mode conf-mode yaml-mode shell-mode eshell-mode org-mode markdown-mode) . corfu-mode)
((eshell-mode shell-mode) . (lambda () (setq-local corfu-auto nil)))
(minibuffer-setup . +corfu-enable-in-minibuffer)
)
:bind (:map corfu-map
("A-m" . +corfu-move-to-minibuffer)
("RET" . nil))
:config
(setq corfu-cycle t ;; Enable cycling for `corfu-next/previous'
corfu-auto t ;; Enable auto completion
corfu-auto-prefix 1 ;; minimun prefix to enable completion
corfu-preview-current nil
corfu-auto-delay 0.1)
;; Transfer completion to the minibuffer
(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)))
;; Completing in the minibuffer
(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)))
(corfu-mode 1)))
)
(use-package corfu-history
:straight nil
:after corfu
:init
(corfu-history-mode 1)
:config
(with-eval-after-load 'savehist
(cl-pushnew 'corfu-history savehist-additional-variables))
)
(use-package corfu-popupinfo
:straight nil
:after corfu
:init
(corfu-popupinfo-mode 1)
:config
(setq corfu-popupinfo-delay '(1.0 . 1.0)))
;; 美化 corfu
(use-package nerd-icons-corfu
:straight t
:after corfu
:init
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
;; 这是与补全前端 corfu 配合的补全后端 cape
(use-package cape
:straight t
:hook ((corfu-mode . +corfu-add-cape-backends)
((tex-mode latex-mode markdown-mode) . +corfu-add-cape-tex-backends))
:config
(defun +corfu-add-cape-backends ()
(add-to-list 'completion-at-point-functions #'cape-file :append)
(add-to-list 'completion-at-point-functions #'cape-dabbrev :append))
(defun +corfu-add-cape-tex-backends ()
(add-to-list 'completion-at-point-functions #'cape-tex :append))
)
;;; company & yasnippet 方案
;; (use-package company
;; :init
;; (add-hook 'prog-mode-hook 'company-mode)
;; :bind
;; (:map company-mode-map
;; ([remap completion-at-point] . company-complete)
;; :map company-active-map
;; ([tab] . company-complete-common-or-cycle)
;; ([backtab] . company-select-previous-or-abort))
;; :config
;; (setq company-minimum-prefix-length 1) ; 只需敲 1 个字母就开始进行自动补全
;; (setq company-tooltip-align-annotations t)
;; (setq company-idle-delay 0)
;; (setq company-selection-wrap-around t)
;; (setq company-transformers '(company-sort-by-occurrence))
;; )
;; (use-package yasnippet
;; :after company
;; :init
;; (yas-global-mode)
;; :config
;; ;; add company-yasnippet to company-backends
;; (defun company-mode/backend-with-yas (backend)
;; (if (and (listp backend) (member 'company-yasnippet backend))
;; backend
;; (append (if (consp backend) backend (list backend))
;; '(:with company-yasnippet))))
;; (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
;; )
;; (use-package yasnippet-snippets)
;;; corfu & yasnippet 方案
;; ;; 提供模板
;; (use-package yasnippet-snippets
;; :straight t)
;;
;; ;; 提供补全后端
;; (use-package yasnippet-capf
;; :straight t)
;;
;; ;; snippet 功能
;; (use-package yasnippet
;; :straight t
;; :hook
;; ((prog-mode text-mode) . yas-minor-mode-on)
;; ((prog-mode text-mode) . +yas-setup-capf) ; 这里的顺序很关键,似乎 yas 必须在 corfu 之前才可以
;; :config
;; (defun +yas-setup-capf ()
;; (setq-local completion-at-point-functions
;; (cons #'yasnippet-capf
;; completion-at-point-functions))) ; 在后端登记补全信息
;; :custom
;; (yas-keymap-disable-hook
;; (lambda () (and (frame-live-p corfu--frame)
;; (frame-visible-p corfu--frame)))) ; 使得 corfu 的优先级比 yas 高,使 tab 先满足 corfu
;; :bind
;; (:map yas-keymap
;; ("<tab>" . nil)
;; ("TAB" . nil)
;; ("RET" . yas-next-field-or-maybe-expand)) ; 修改 <enter> 为下一个键位
;; )
;;
;; ;; consult 模式的 yasnippet 检索
;; (use-package consult-yasnippet
;; :straight t
;; :bind
;; ("C-c y" . consult-yasnippet))
;;
;; ;; 补全前端
;; (use-package corfu
;; :straight
;; (:files (:defaults "extensions/*.el")) ;; 可以减少加载 corfu 的默认配置
;; :hook
;; ((prog-mode text-mode conf-mode yaml-mode shell-mode eshell-mode) . corfu-mode)
;; ((eshell-mode shell-mode) . (lambda () (setq-local corfu-auto nil))) ; 在 shell 模式取消补全
;; :bind
;; (:map corfu-map
;; ;; ([tab] . corfu-next)
;; ;; ([backtab] . corfu-previous)
;; ("RET" . nil)
;; )
;; :init
;; (setq corfu-cycle t ; Enable cycling for `corfu-next/previous'
;; corfu-auto t ; Enable auto completion
;; ;; corfu-separator "&" ; Orderless field separator
;; corfu-auto-prefix 1 ; minimun prefix to enable completion
;; corfu-preview-current t
;; corfu-auto-delay 0
;; corfu-on-exact-match nil ; 解决 dd 自动展开的关键
;; corfu-min-width 25
;; corfu-preselect 'directory ; 不知道为啥,这个可以避免自动选择,可以使 tab 更加方便
;; )
;; )
;;
;; ;; 使得 corfu 排序为历史频率排序
;; (use-package corfu-history
;; :straight nil
;; :after corfu
;; :init
;; (corfu-history-mode 1)
;; :config
;; (with-eval-after-load 'savehist
;; (cl-pushnew 'corfu-history savehist-additional-variables))
;; )
;;
;; ;; 弹出相关信息
;; (use-package corfu-popupinfo
;; :straight nil
;; :after corfu
;; :init
;; (corfu-popupinfo-mode 1)
;; :config
;; (setq corfu-popupinfo-delay '(1.0 . 1.0)))
;;
;; ;; 美化 corfu
;; (use-package nerd-icons-corfu
;; :straight t
;; :after corfu
;; :init
;; (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
;;
;; (use-package corfu-terminal
;; :straight t
;; :when (not (display-graphic-p))
;; :after corfu
;; :init (corfu-terminal-mode 1))
;;
;; ;; ;; TODO: 显示有问题
;; ;; (use-package corfu-popupinfo
;; ;; :straight nil
;; ;; :after corfu
;; ;; :hook
;; ;; (corfu-mode . corfu-popupinfo-mode)
;; ;; :config
;; ;; (setq corfu-popupinfo-delay '(1.0 1.0)))
;;
;; ;; 补全后端
;; (use-package cape
;; :straight t
;; :hook ((corfu-mode . +corfu-add-cape-backends)
;; ((TeX-mode LaTeX-mode org-mode markdown-mode) . +corfu-add-cape-tex-backends))
;; :config
;; (defun +corfu-add-cape-backends ()
;; (add-to-list 'completion-at-point-functions #'cape-file :append)
;; (add-to-list 'completion-at-point-functions #'cape-dabbrev :append))
;;
;; (defun +corfu-add-cape-tex-backends ()
;; (add-to-list 'completion-at-point-functions #'cape-tex :append))
;; )
;;; lsp-bridge & yasnippet 方案
;; (use-package yasnippet
;; :hook
;; ((prog-mode text-mode) . yas-minor-mode-on)
;; )
;;
;; (use-package lsp-bridge
;; :straight '(lsp-bridge :type git :host github :repo "manateelazycat/lsp-bridge"
;; :files (:defaults "*.el" "*.py" "acm" "core" "langserver" "multiserver" "resources")
;; :build (:not compile))
;; :config
;; (setq acm-enable-citre t)
;; (setq acm-enable-preview t)
;; (setq lsp-bridge-enable-diagnostics nil)
;; :hook
;; ((prog-mode text-mode) . lsp-bridge-mode)
;; )