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:
parent
a927ce3844
commit
fa8ebb30c7
22
bundle/nvim-plug/lua/plug/hooks.lua
vendored
22
bundle/nvim-plug/lua/plug/hooks.lua
vendored
@ -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
|
||||
|
12
bundle/nvim-plug/lua/plug/init.lua
vendored
12
bundle/nvim-plug/lua/plug/init.lua
vendored
@ -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::
|
||||
|
Loading…
Reference in New Issue
Block a user