Mercurial > dotfiles
view .chezmoitemplates/au.lua @ 802:9c8698e50c5e
[pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/JohnnyMorganz/StyLua: v0.19.0 ? v0.19.1](https://github.com/JohnnyMorganz/StyLua/compare/v0.19.0...v0.19.1)
author | pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> |
---|---|
date | Mon, 20 Nov 2023 18:04:55 +0000 |
parents | e258ef0fb4cd |
children |
line wrap: on
line source
-- -- Copied from https://gist.github.com/numToStr/1ab83dd2e919de9235f9f774ef8076da -- local function autocmd(this, event, spec) local is_table = type(spec) == 'table' local pattern = is_table and spec[1] or '*' local action = is_table and spec[2] or spec local opts = { pattern = pattern } if type(action) == 'function' then opts.callback = action else opts.command = action end vim.api.nvim_create_autocmd(event, opts) end local S = { __au = {}, } local X = setmetatable({}, { __index = S, __newindex = autocmd, __call = autocmd, }) function S.exec(id) S.__au[id]() end function S.set(fn) local id = string.format('%p', fn) S.__au[id] = fn return string.format('lua require("au").exec("%s")', id) end function S.group(grp, cmds) vim.api.nvim_create_augroup(grp, { clear = true }) if type(cmds) == 'function' then -- TODO set group? cmds(X) else for _, au in ipairs(cmds) do local opts = { group = grp, pattern = au[2] } if type(au[3]) == 'function' then opts.callback = au[3] else opts.command = au[3] end vim.api.nvim_create_autocmd(au[1], opts) end end end return X