1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-13 22:47:59 +08:00

feat(nvim-plug): add on_func option

This commit is contained in:
Eric Wong 2025-02-07 13:17:29 +08:00
parent a927ce3844
commit fa8ebb30c7
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
2 changed files with 33 additions and 1 deletions

View File

@ -7,6 +7,7 @@ local plugin_loader = require('plug.loader')
local event_plugins = {}
local cmd_plugins = {}
local on_ft_plugins = {}
local on_fn_plugins = {}
function M.on_events(events, plugSpec)
event_plugins[plugSpec.name] = vim.api.nvim_create_autocmd(events, {
@ -88,4 +89,25 @@ function M.on_map(maps, plugSpec)
end
end
function M.on_func(fn, plugSpec)
local fns
if type(fn) == 'table' then
fns = fn
elseif type(fn) == 'string' then
fns = { fn }
end
on_fn_plugins[plugSpec.name] = vim.api.nvim_create_autocmd({ 'FuncUndefined' }, {
group = group,
pattern = fns,
callback = function(_)
if on_fn_plugins[plugSpec.name] then
vim.api.nvim_del_autocmd(on_fn_plugins[plugSpec.name])
end
plugin_loader.load(plugSpec)
end,
})
end
return M

View File

@ -40,7 +40,17 @@ function M.add(plugins)
hooks.on_map(plug.on_map, plug)
end
if not plug.events and not plug.cmds and not plug.on_ft and not plug.on_map then
if plug.on_func then
hooks.on_func(plug.on_func, plug)
end
if
not plug.events
and not plug.cmds
and not plug.on_ft
and not plug.on_map
and not plug.on_func
then
loader.load(plug)
end
::continue::