about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-completion.el
blob: 6449aef43b9a44f295a717e63a858e6bb218d9b1 (plain) (blame)
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
;;; init-completion.el --- Completion Configuration File -*- lexical-binding: t -*-
;;; Commentary:
;; Config for completion-at-point (corfu), as well as orderless (see also init-minibuffer.el)
;; Most of it is taken from the READMEs and wikis of those packages
;;; Code:

(use-package dabbrev
  :diminish
  :custom (dabbrev-case-fold-search nil)
  :bind
  ("M-/" . dabbrev-completion))

(use-package hippie-expand
  :ensure nil
  :init
  (setq hippie-expand-try-functions-list
      '(;yas-hippie-try-expand
        try-expand-dabbrev
        try-expand-all-abbrevs
        try-expand-dabbrev-all-buffers
        try-expand-dabbrev-from-kill
        try-complete-file-name-partially
        try-complete-file-name
        try-expand-list
        try-expand-line
        try-complete-lisp-symbol-partially
        try-complete-lisp-symbol))
  :config
  ;; https://www.emacswiki.org/emacs/HippieExpand#h5o-9
  (defadvice he-substitute-string (after he-paredit-fix)
    "Remove extra paren when expanding line in paredit."
    (if (and paredit-mode (equal (substring str -1) ")"))
        (progn (backward-delete-char 1) (forward-char))))
  :bind
  ("C-M-/" . hippie-expand))

(use-package fancy-dabbrev
  :diminish
  :config
  (global-fancy-dabbrev-mode))

(use-package emacs
  :init
  (setq completion-cycle-threshold 3)
  (setq tab-always-indent 'complete))

(use-package orderless
  :bind (:map minibuffer-local-completion-map
              ("C-l" . my/orderless-match-components-literally))
  :custom (orderless-component-separator 'orderless-escapable-split-on-space)
  :init
  (setq completion-styles '(orderless basic)
        completion-category-defaults nil
        completion-category-overrides '((file (styles . (partial-completion orderless)))))

  (defun my/orderless-match-components-literally ()
    "Components match literally for the rest of the session."
    (interactive)
    (setq-local orderless-matching-styles '(orderless-literal)
                orderless-style-dispatchers nil))
  :config
  ;; Recognizes the following patterns:
  ;; * ~flex flex~
  ;; * =literal literal=
  ;; * %char-fold char-fold%
  ;; * `initialism initialism`
  ;; * !without-literal without-literal!
  ;; * .ext (file extension)
  ;; * regexp$ (regexp matching at end)
  (defun my/orderless-dispatch (pattern _index _total)
    (cond
     ;; Ensure that $ works with Consult commands, which add disambiguation suffixes
     ((string-suffix-p "$" pattern) `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$")))
     ;; File extensions
     ((string-match-p "\\`\\.." pattern) `(orderless-regexp . ,(concat "\\." (substring pattern 1) "[\x100000-\x10FFFD]*$")))
     ;; Ignore single !
     ((string= "!" pattern) `(orderless-literal . ""))
     ;; Character folding
     ((string-prefix-p "%" pattern) `(char-fold-to-regexp . ,(substring pattern 1)))
     ((string-suffix-p "%" pattern) `(char-fold-to-regexp . ,(substring pattern 0 -1)))
     ;; Without literal
     ((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
     ((string-suffix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 0 -1)))
     ;; Initialism matching
     ((string-prefix-p "`" pattern) `(orderless-initialism . ,(substring pattern 1)))
     ((string-suffix-p "`" pattern) `(orderless-initialism . ,(substring pattern 0 -1)))
     ;; Literal matching
     ((string-prefix-p "=" pattern) `(orderless-literal . ,(substring pattern 1)))
     ((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1)))
     ;; Flex matching
     ((string-prefix-p "~" pattern) `(orderless-flex . ,(substring pattern 1)))
     ((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))))
  ;; (setq orderless-matching-styles '(orderless-literal orderless-regexp orderless-strict-leading-initialism)
  ;;       orderless-style-dispatchers '(my/orderless-dispatch))
  (setq orderless-matching-styles '(orderless-literal orderless-regexp orderless-initialism)
        orderless-style-dispatchers '(my/orderless-dispatch)))

;; code completion - corfu
(use-package corfu
  ;; Optional customizations
  :custom
  (corfu-cycle t)            ;; Enable cycling for `corfu-next/previous'
  :bind (:map corfu-map
         ("TAB" . corfu-next)
         ([tab] . corfu-next)
         ("S-TAB" . corfu-previous)
         ([backtab] . corfu-previous))
  :init
  (global-corfu-mode))

(use-package corfu-doc
  :config
  (add-hook 'corfu-mode-hook #'corfu-doc-mode))

(provide 'init-completion)
;;; init-completion.el ends here
the previous revision' href='/danisanti/profani-tty/blame/tests/test_cmd_statuses.c?id=a9a860cb1321415276c790cac0b58720d77c53e7'>^
a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^


383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^


e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^


383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^


e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^


383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^


e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^


383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^


e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^


383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^


e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
383e601f ^
79e9ab83 ^
a2726b6a ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
e5ac12af ^
79e9ab83 ^

a2726b6a ^

79e9ab83 ^
a2726b6a ^
79e9ab83 ^
2af418fd ^
79e9ab83 ^
383e601f ^
79e9ab83 ^
a2726b6a ^
2af418fd ^


e5ac12af ^
2af418fd ^

a2726b6a ^

2af418fd ^
a2726b6a ^
2af418fd ^


383e601f ^
2af418fd ^
a2726b6a ^
2af418fd ^

79e9ab83 ^
e5ac12af ^
79e9ab83 ^
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