-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf-corfu.el
More file actions
147 lines (127 loc) · 5.34 KB
/
Copy pathconf-corfu.el
File metadata and controls
147 lines (127 loc) · 5.34 KB
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
;; -*- lexical-binding: t; -*-
(defun conf--corfu-active-p ()
(and corfu-mode completion-in-region-mode))
;; (defun conf--corfu-reset()
;; (interactive)
;; (corfu-quit)
;; (corfu--auto-complete-deferred))
;; (defun conf--corfu-post-command()
;; "Refresh completion when prefix length is 3 and no candidates are found."
;; (when (and corfu-mode completion-in-region-mode)
;; (let* ((input (car corfu--input))
;; (str (if (thing-at-point 'filename) (file-name-nondirectory input) input))
;; (len (length str))
;; (candidates corfu--candidates))
;; (when (and (= len 3)
;; ;; (>= len 3)
;; ;; (= (% len 3) 0)
;; (not (try-completion str candidates)))
;; (conf--corfu-reset)))))
(el-patch-feature corfu)
;; Disable completion starting with [ with pyright
(with-eval-after-load 'corfu
(el-patch-defun corfu--capf-wrapper (fun &optional prefix)
"Wrapper for `completion-at-point' FUN.
The wrapper determines if the Capf is applicable at the current
position, performs sanity checking on the returned result and computes
the initial completion state. PREFIX is the minimum prefix length."
(pcase (funcall fun)
(`(,beg ,end ,table . ,plist)
(and (integer-or-marker-p beg) ;; Valid Capf result
(<= beg (point) end) ;; Sanity checking
;; Check minimal prefix length if given.
(or (not prefix)
(let ((len (or (el-patch-swap
(plist-get plist :company-prefix-length)
(and (not (eq (char-before) (string-to-char "[")))
(plist-get plist :company-prefix-length)))
(- (point) beg))))
(or (eq len t) (>= len prefix))))
(let* ((str (buffer-substring-no-properties beg end))
(pt (- (point) beg))
(pred (plist-get plist :predicate))
(state (corfu--compute (cons str pt) table pred)))
(cond ((alist-get 'corfu--candidates state)
`(,fun ,beg ,end ,table :corfu--state ,state ,@plist))
;; Stop with empty result for exclusive Capf.
((not (eq 'no (plist-get plist :exclusive)))
'(nil)))))))))
(use-package corfu
:bind
(("M-RET" . completion-at-point))
(:map corfu-map
("C-a" . nil)
("C-e" . nil)
("C-j" . corfu-next)
("C-k" . corfu-previous)
("M-j" . corfu-next)
("M-k" . corfu-previous)
("<remap> <move-beginning-of-line>" . nil)
("<remap> <move-end-of-line>" . nil)
("C-s" . corfu-insert-separator)
("TAB" . corfu-expand)
("<tab>" . corfu-expand)
("RET" . corfu-insert)
("<ret>" . corfu-insert)
("C-<return>" . corfu-insert))
:hook
(corfu-mode . (lambda ()
(add-hook 'yas-keymap-disable-hook 'conf--corfu-active-p nil t)
;; (add-hook 'post-command-hook #'conf--corfu-post-command)
))
(git-commit-mode . (lambda () (corfu-mode -1)))
:custom
(corfu-auto t)
(corfu-auto-delay 0.01)
(corfu-auto-prefix 2)
(corfu-preview-current nil)
(corfu-popupinfo-delay '(0.5 . 0.0))
(corfu-on-exact-match nil)
:init
(global-corfu-mode)
(corfu-popupinfo-mode)
(add-hook 'after-save-hook #'corfu-quit))
(add-to-list 'completion-styles-alist
'(tab completion-basic-try-completion ignore
"Completion style which provides TAB completion only."))
(use-package orderless
:init
(setq completion-styles '(tab orderless basic)))
(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))
(defun conf--cape-dabbrev-and-enable-corfu ()
(interactive)
(when (not corfu-mode)
(corfu-mode))
(call-interactively 'cape-dabbrev))
(use-package cape
:bind
(("M-d" . conf--cape-dabbrev-and-enable-corfu))
:init
(require 'dabbrev)
(add-hook 'completion-at-point-functions #'cape-file)
(add-hook 'completion-at-point-functions (cape-capf-prefix-length #'cape-dabbrev 3))
(setq dabbrev-abbrev-char-regexp "\\sw\\|_\\|-")
(defun conf--dabbrev-buffers ()
(cape--buffer-list
(lambda (buf)
(let ((mode (buffer-local-value 'major-mode buf)))
(and (or (provided-mode-derived-p mode #'text-mode)
(provided-mode-derived-p mode #'prog-mode))
(< (buffer-size buf) 200000))))))
(setq cape-dabbrev-buffer-function 'conf--dabbrev-buffers)
(defun conf--setup-comint-mode-completions ()
(setq-local completion-at-point-functions
(list
(cape-capf-prefix-length (cape-capf-super
'conf--project-files-capf
#'cape-dabbrev
'conf--aidermacs-keywords-completion-at-point)
3)
(cape-capf-prefix-length #'cape-dabbrev 3)
'comint-completion-at-point t)))
(add-hook 'comint-mode-hook 'conf--setup-comint-mode-completions)
;; Disable ispell completion on text buffers
(setq text-mode-ispell-word-completion nil))
(provide 'conf-corfu)