1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 05:58:00 +08:00

feat(nvim-plug): add config_{before, after} func

This commit is contained in:
Eric Wong 2025-02-09 22:16:50 +08:00
parent 3b5568952e
commit 202ea3637c
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
3 changed files with 36 additions and 19 deletions

View File

@ -99,22 +99,25 @@ require('plug').add({
The plugin spec is inspired by dein.nvim. The plugin spec is inspired by dein.nvim.
| 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` | `table<string>`, commands lazy loading |
| `events` | `table<string>`, events lazy loading | | `events` | `table<string>`, events lazy loading |
| `on_ft` | `table<string>`, filetypes lazy loading | | `config` | `function`, function called after adding plugin path to nvim rtp, before loading files in `plugin/` directory |
| `on_map` | `table<string>`, key bindings lazy loading | | `config_after` | `function`, function called after loading files in `plugin/` directory |
| `on_func` | `string` or `table<string>`, vim function lazy loading | | `config_before` | `function`, function called when `plug.add()` function is called |
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. | | `on_ft` | `table<string>`, filetypes lazy loading |
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api | | `on_map` | `table<string>`, key bindings lazy loading |
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | | `on_func` | `string` or `table<string>`, vim function lazy loading |
| `frozen` | update only when specific with `PlugUpdate name` | | `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
| `depends` | `table<PluginSpec>` a list of plugins | | `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
| `branch` | `string` specific git branch | | `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
| `tag` | `string` specific git tag | | `frozen` | update only when specific with `PlugUpdate name` |
| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set | | `depends` | `table<PluginSpec>` a list of plugins |
| `branch` | `string` specific git branch |
| `tag` | `string` specific git tag |
| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set |
## Commands ## Commands

View File

@ -18,10 +18,11 @@ function M.setup(opt)
end end
--- @param plugins table<PluginSpec> --- @param plugins table<PluginSpec>
function M.add(plugins) function M.add(plugins, skip_deps)
for _, plug in ipairs(plugins) do for _, plug in ipairs(plugins) do
if plug.depends then if plug.depends and not skip_deps then
M.add(plug.depends) M.add(plug.depends)
M.add({ plug }, true)
else else
loader.parser(plug) loader.parser(plug)
if not plug.enabled then if not plug.enabled then

View File

@ -15,7 +15,6 @@ local add_raw_rtp = false
--- @field rtp string --- @field rtp string
--- @field events table<string> --- @field events table<string>
--- @field cmds table<string> --- @field cmds table<string>
--- @field config function
--- @field name string --- @field name string
--- @field branch string --- @field branch string
--- @field tag string --- @field tag string
@ -27,6 +26,10 @@ local add_raw_rtp = false
--- @field frozen boolean --- @field frozen boolean
--- @field type string "git", "raw" or "none" --- @field type string "git", "raw" or "none"
--- @field script_type string "git", "raw" or "none" --- @field script_type string "git", "raw" or "none"
--- @field config function function called after update rtp
--- @field config_before function function called after update rtp
--- @field config_after function function called after update rtp
--- @field hook_install_done? function
--- @param plugSpec PluginSpec --- @param plugSpec PluginSpec
--- @return boolean --- @return boolean
@ -91,6 +94,10 @@ function M.parser(plugSpec)
plugSpec.url = config.base_url .. '/' .. plugSpec[1] plugSpec.url = config.base_url .. '/' .. plugSpec[1]
end end
if type(plugSpec.config_before) == 'function' then
plugSpec.config_before()
end
return plugSpec return plugSpec
end end
@ -117,11 +124,17 @@ end
function M.load(plugSpec) function M.load(plugSpec)
if plugSpec.rtp and vim.fn.isdirectory(plugSpec.rtp) == 1 then if plugSpec.rtp and vim.fn.isdirectory(plugSpec.rtp) == 1 then
vim.opt.runtimepath:append(plugSpec.rtp) vim.opt.runtimepath:append(plugSpec.rtp)
if type(plugSpec.config) == 'function' then
plugSpec.config()
end
if vim.fn.has('vim_starting') ~= 1 then if vim.fn.has('vim_starting') ~= 1 then
local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}', 0, 1) local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}', 0, 1)
for _, f in ipairs(plugin_directory_files) do for _, f in ipairs(plugin_directory_files) do
vim.cmd.source(f) vim.cmd.source(f)
end end
if type(plugSpec.config_after) == 'function' then
plugSpec.config_after()
end
end end
end end
end end