mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 05:48:00 +08:00
feat(nvim-plug): add config_{before, after} func
This commit is contained in:
parent
3b5568952e
commit
202ea3637c
35
bundle/nvim-plug/README.md
vendored
35
bundle/nvim-plug/README.md
vendored
@ -99,22 +99,25 @@ require('plug').add({
|
||||
|
||||
The plugin spec is inspired by dein.nvim.
|
||||
|
||||
| name | description |
|
||||
| ------------- | ---------------------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `on_map` | `table<string>`, key bindings lazy loading |
|
||||
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
||||
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
|
||||
| `frozen` | update only when specific with `PlugUpdate name` |
|
||||
| `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 |
|
||||
| name | description |
|
||||
| --------------- | ------------------------------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `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_before` | `function`, function called when `plug.add()` function is called |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `on_map` | `table<string>`, key bindings lazy loading |
|
||||
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
||||
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
|
||||
| `frozen` | update only when specific with `PlugUpdate name` |
|
||||
| `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
|
||||
|
||||
|
5
bundle/nvim-plug/lua/plug/init.lua
vendored
5
bundle/nvim-plug/lua/plug/init.lua
vendored
@ -18,10 +18,11 @@ function M.setup(opt)
|
||||
end
|
||||
|
||||
--- @param plugins table<PluginSpec>
|
||||
function M.add(plugins)
|
||||
function M.add(plugins, skip_deps)
|
||||
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 }, true)
|
||||
else
|
||||
loader.parser(plug)
|
||||
if not plug.enabled then
|
||||
|
15
bundle/nvim-plug/lua/plug/loader.lua
vendored
15
bundle/nvim-plug/lua/plug/loader.lua
vendored
@ -15,7 +15,6 @@ local add_raw_rtp = false
|
||||
--- @field rtp string
|
||||
--- @field events table<string>
|
||||
--- @field cmds table<string>
|
||||
--- @field config function
|
||||
--- @field name string
|
||||
--- @field branch string
|
||||
--- @field tag string
|
||||
@ -27,6 +26,10 @@ local add_raw_rtp = false
|
||||
--- @field frozen boolean
|
||||
--- @field 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
|
||||
--- @return boolean
|
||||
@ -91,6 +94,10 @@ function M.parser(plugSpec)
|
||||
plugSpec.url = config.base_url .. '/' .. plugSpec[1]
|
||||
end
|
||||
|
||||
if type(plugSpec.config_before) == 'function' then
|
||||
plugSpec.config_before()
|
||||
end
|
||||
|
||||
return plugSpec
|
||||
end
|
||||
|
||||
@ -117,11 +124,17 @@ end
|
||||
function M.load(plugSpec)
|
||||
if plugSpec.rtp and vim.fn.isdirectory(plugSpec.rtp) == 1 then
|
||||
vim.opt.runtimepath:append(plugSpec.rtp)
|
||||
if type(plugSpec.config) == 'function' then
|
||||
plugSpec.config()
|
||||
end
|
||||
if vim.fn.has('vim_starting') ~= 1 then
|
||||
local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, 'plugin/*.{lua,vim}', 0, 1)
|
||||
for _, f in ipairs(plugin_directory_files) do
|
||||
vim.cmd.source(f)
|
||||
end
|
||||
if type(plugSpec.config_after) == 'function' then
|
||||
plugSpec.config_after()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user