This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcmp.fnl
56 lines (49 loc) · 2.25 KB
/
cmp.fnl
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
(module config.plugin.cmp
{autoload {nvim aniseed.nvim
cmp cmp
luasnip luasnip}})
;; Sources for autocompletion
(def- cmp-src-menu-items
{:buffer "buff"
:conjure "conj"
:nvim_lsp "lsp"
:vsnip "vsnp"
:luasnip "lsnp"})
(def- cmp-srcs
[{:name :nvim_lsp}
{:name :conjure}
{:name :buffer}
{:name :vsnip}
{:name :luasnip}])
(fn has-words-before []
(let [(line col) (unpack (vim.api.nvim_win_get_cursor 0))]
(and (not= col 0)
(= (: (: (. (vim.api.nvim_buf_get_lines 0 (- line 1) line true) 1) :sub col col) :match "%s") nil))))
(cmp.setup {:formatting
{:format (fn [entry item]
(set item.menu (or (. cmp-src-menu-items entry.source.name) ""))
item)}
:mapping {:<C-p> (cmp.mapping.select_prev_item)
:<C-n> (cmp.mapping.select_next_item)
:<C-b> (cmp.mapping.scroll_docs (- 4))
:<C-f> (cmp.mapping.scroll_docs 4)
:<C-Space> (cmp.mapping.complete)
:<C-e> (cmp.mapping.close)
:<CR> (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Insert
:select true})
:<Tab> (cmp.mapping (fn [fallback]
(if
(cmp.visible) (cmp.select_next_item)
(luasnip.expand_or_jumpable) (luasnip.expand_or_jump)
(has-words-before) (cmp.complete)
:else (fallback)))
{1 :i 2 :s})
:<S-Tab> (cmp.mapping (fn [fallback]
(if
(cmp.visible) (cmp.select_prev_item)
(luasnip.jumpable -1) (luasnip.jump -1)
:else (fallback)))
{1 :i 2 :s})}
:snippet {:expand (fn [args]
(luasnip.lsp_expand args.body))}
:sources cmp-srcs})