Mercurial > dotfiles
annotate .chezmoitemplates/au.lua @ 773:bea7b91cf1e5
feat: update to neovim 0.9.0
author | zegervdv <zegervdv@me.com> |
---|---|
date | Sat, 08 Apr 2023 10:30:41 +0200 |
parents | e258ef0fb4cd |
children |
rev | line source |
---|---|
460 | 1 -- |
2 -- Copied from https://gist.github.com/numToStr/1ab83dd2e919de9235f9f774ef8076da | |
3 -- | |
4 | |
5 local function autocmd(this, event, spec) | |
6 local is_table = type(spec) == 'table' | |
7 local pattern = is_table and spec[1] or '*' | |
8 local action = is_table and spec[2] or spec | |
573 | 9 |
10 local opts = { pattern = pattern } | |
460 | 11 if type(action) == 'function' then |
573 | 12 opts.callback = action |
13 else | |
14 opts.command = action | |
460 | 15 end |
573 | 16 |
17 vim.api.nvim_create_autocmd(event, opts) | |
460 | 18 end |
19 | |
20 local S = { | |
21 __au = {}, | |
22 } | |
23 | |
24 local X = setmetatable({}, { | |
25 __index = S, | |
26 __newindex = autocmd, | |
27 __call = autocmd, | |
28 }) | |
29 | |
673
e258ef0fb4cd
Add prettier config (#1)
Zeger Van de Vannet <747627+zegervdv@users.noreply.github.com>
parents:
573
diff
changeset
|
30 function S.exec(id) S.__au[id]() end |
460 | 31 |
32 function S.set(fn) | |
33 local id = string.format('%p', fn) | |
34 S.__au[id] = fn | |
35 return string.format('lua require("au").exec("%s")', id) | |
36 end | |
37 | |
38 function S.group(grp, cmds) | |
573 | 39 vim.api.nvim_create_augroup(grp, { clear = true }) |
460 | 40 if type(cmds) == 'function' then |
573 | 41 -- TODO set group? |
460 | 42 cmds(X) |
43 else | |
44 for _, au in ipairs(cmds) do | |
573 | 45 local opts = { group = grp, pattern = au[2] } |
46 if type(au[3]) == 'function' then | |
47 opts.callback = au[3] | |
48 else | |
49 opts.command = au[3] | |
50 end | |
51 vim.api.nvim_create_autocmd(au[1], opts) | |
460 | 52 end |
53 end | |
54 end | |
55 | |
56 return X |