mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 06:28:00 +08:00
feat(nvim-plug): improve lazy loading opt
make `on_ft/map/func/cmd` support string or table<string>
This commit is contained in:
parent
d7b95d3f45
commit
0532e157f3
11
bundle/nvim-plug/README.md
vendored
11
bundle/nvim-plug/README.md
vendored
@ -43,7 +43,7 @@ require('plug').setup({
|
|||||||
max_processes = 5,
|
max_processes = 5,
|
||||||
base_url = 'https://github.com',
|
base_url = 'https://github.com',
|
||||||
-- default ui is `notify`, use `default` for split window UI
|
-- default ui is `notify`, use `default` for split window UI
|
||||||
ui = 'notify',
|
ui = 'default',
|
||||||
-- default is nil
|
-- default is nil
|
||||||
http_proxy = 'http://127.0.0.1:7890',
|
http_proxy = 'http://127.0.0.1:7890',
|
||||||
-- default is nil
|
-- default is nil
|
||||||
@ -60,7 +60,6 @@ require('plug').add({
|
|||||||
{
|
{
|
||||||
'wsdjeg/scrollbar.vim',
|
'wsdjeg/scrollbar.vim',
|
||||||
events = { 'VimEnter' },
|
events = { 'VimEnter' },
|
||||||
config = function() end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'wsdjeg/vim-chat',
|
'wsdjeg/vim-chat',
|
||||||
@ -98,13 +97,13 @@ The plugin spec is inspired by [dein.nvim](https://github.com/Shougo/dein.vim).
|
|||||||
| name | description |
|
| name | description |
|
||||||
| --------------- | ------------------------------------------------------------------------------------------------------------- |
|
| --------------- | ------------------------------------------------------------------------------------------------------------- |
|
||||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||||
| `cmds` | `table<string>`, commands lazy loading |
|
| `cmds` | `string` or `table<string>`, commands lazy loading |
|
||||||
| `events` | `table<string>`, events lazy loading |
|
| `events` | `string` or `table<string>`, events lazy loading |
|
||||||
| `config` | `function`, function called after adding plugin path to nvim rtp, before loading files in `plugin/` directory |
|
| `config` | `function`, function called after adding plugin path to nvim rtp, before loading files in `plugin/` directory |
|
||||||
| `config_after` | `function`, function called after loading files in `plugin/` directory |
|
| `config_after` | `function`, function called after loading files in `plugin/` directory |
|
||||||
| `config_before` | `function`, function called when `plug.add()` function is called |
|
| `config_before` | `function`, function called when `plug.add()` function is called |
|
||||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
| `on_ft` | `string` or `table<string>`, filetypes lazy loading |
|
||||||
| `on_map` | `table<string>`, key bindings lazy loading |
|
| `on_map` | `string` or `table<string>`, key bindings lazy loading |
|
||||||
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
||||||
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
|
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
|
||||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||||
|
20
bundle/nvim-plug/lua/plug/hooks.lua
vendored
20
bundle/nvim-plug/lua/plug/hooks.lua
vendored
@ -9,7 +9,12 @@ local cmd_plugins = {}
|
|||||||
local on_ft_plugins = {}
|
local on_ft_plugins = {}
|
||||||
local on_fn_plugins = {}
|
local on_fn_plugins = {}
|
||||||
|
|
||||||
|
--- @param events string | table<string>
|
||||||
|
--- @param plugSpec PluginSpec
|
||||||
function M.on_events(events, plugSpec)
|
function M.on_events(events, plugSpec)
|
||||||
|
if type(events) == 'string' then
|
||||||
|
events = { events }
|
||||||
|
end
|
||||||
event_plugins[plugSpec.name] = vim.api.nvim_create_autocmd(events, {
|
event_plugins[plugSpec.name] = vim.api.nvim_create_autocmd(events, {
|
||||||
group = group,
|
group = group,
|
||||||
pattern = { '*' },
|
pattern = { '*' },
|
||||||
@ -23,9 +28,12 @@ function M.on_events(events, plugSpec)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param cmds table<string>
|
--- @param cmds string | table<string>
|
||||||
--- @param plugSpec PluginSpec
|
--- @param plugSpec PluginSpec
|
||||||
function M.on_cmds(cmds, plugSpec)
|
function M.on_cmds(cmds, plugSpec)
|
||||||
|
if type(cmds) == 'string' then
|
||||||
|
cmds = { cmds }
|
||||||
|
end
|
||||||
for _, cmd in ipairs(cmds) do
|
for _, cmd in ipairs(cmds) do
|
||||||
cmd_plugins[cmd] = plugSpec
|
cmd_plugins[cmd] = plugSpec
|
||||||
vim.api.nvim_create_user_command(cmd, function(opt)
|
vim.api.nvim_create_user_command(cmd, function(opt)
|
||||||
@ -33,7 +41,7 @@ function M.on_cmds(cmds, plugSpec)
|
|||||||
vim.cmd(opt.name .. ' ' .. opt.args)
|
vim.cmd(opt.name .. ' ' .. opt.args)
|
||||||
end, {
|
end, {
|
||||||
nargs = '*',
|
nargs = '*',
|
||||||
complete = function(...)
|
complete = function(_)
|
||||||
return {}
|
return {}
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -41,6 +49,9 @@ function M.on_cmds(cmds, plugSpec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.on_ft(fts, plugSpec)
|
function M.on_ft(fts, plugSpec)
|
||||||
|
if type(fts) == 'string' then
|
||||||
|
fts = { fts }
|
||||||
|
end
|
||||||
on_ft_plugins[plugSpec.name] = vim.api.nvim_create_autocmd({ 'FileType' }, {
|
on_ft_plugins[plugSpec.name] = vim.api.nvim_create_autocmd({ 'FileType' }, {
|
||||||
group = group,
|
group = group,
|
||||||
pattern = fts,
|
pattern = fts,
|
||||||
@ -55,6 +66,9 @@ function M.on_ft(fts, plugSpec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.on_map(maps, plugSpec)
|
function M.on_map(maps, plugSpec)
|
||||||
|
if type(maps) == 'string' then
|
||||||
|
maps = { maps }
|
||||||
|
end
|
||||||
for _, lhs in ipairs(maps) do
|
for _, lhs in ipairs(maps) do
|
||||||
vim.keymap.set('n', lhs, function()
|
vim.keymap.set('n', lhs, function()
|
||||||
for _, v in ipairs(plugSpec.on_map) do
|
for _, v in ipairs(plugSpec.on_map) do
|
||||||
@ -100,12 +114,10 @@ function M.on_func(fn, plugSpec)
|
|||||||
group = group,
|
group = group,
|
||||||
pattern = fns,
|
pattern = fns,
|
||||||
callback = function(_)
|
callback = function(_)
|
||||||
|
|
||||||
if on_fn_plugins[plugSpec.name] then
|
if on_fn_plugins[plugSpec.name] then
|
||||||
vim.api.nvim_del_autocmd(on_fn_plugins[plugSpec.name])
|
vim.api.nvim_del_autocmd(on_fn_plugins[plugSpec.name])
|
||||||
end
|
end
|
||||||
plugin_loader.load(plugSpec)
|
plugin_loader.load(plugSpec)
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user