neovim-confs/lua/core/hooks.lua

27 lines
478 B
Lua
Raw Normal View History

2021-11-13 17:29:31 +01:00
local hooks, M = {}, {}
2021-11-14 08:13:36 +01:00
local allowed_hooks = {
["install_plugins"] = true,
["setup_mappings"] = true,
}
M.add = function(name, fn)
if not allowed_hooks[name] then
2021-11-13 17:29:31 +01:00
print("Custom lua uses unallowed hook " .. name)
2021-10-02 07:15:50 +02:00
end
if not hooks[name] then
2021-10-02 07:15:50 +02:00
hooks[name] = {}
end
table.insert(hooks[name], fn)
end
M.run = function(name, args)
if hooks[name] then
2021-11-13 17:29:31 +01:00
for _, hook in pairs(hooks[name]) do
hook(args)
2021-08-31 16:20:57 +02:00
end
2021-10-02 07:15:50 +02:00
end
2021-08-31 16:20:57 +02:00
end
2021-10-02 07:15:50 +02:00
return M