mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-15 23:39:27 +08:00
feat(nvim-plug): support enabled
option
This commit is contained in:
parent
2bc42deaf8
commit
8368712a5e
23
bundle/nvim-plug/README.md
vendored
23
bundle/nvim-plug/README.md
vendored
@ -22,6 +22,12 @@ require('plug').add({
|
||||
events = { 'VimEnter' },
|
||||
config = function() end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/vim-chat',
|
||||
enabled = function()
|
||||
return vim.fn.has('nvim-0.10.0') == 1
|
||||
end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/flygrep.nvim',
|
||||
cmds = { 'FlyGrep' },
|
||||
@ -38,14 +44,15 @@ require('plug').add({
|
||||
|
||||
## Plugin Spec
|
||||
|
||||
| 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 |
|
||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
| 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 |
|
||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||
| `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 |
|
||||
|
||||
## Commands
|
||||
|
||||
|
40
bundle/nvim-plug/lua/plug/init.lua
vendored
40
bundle/nvim-plug/lua/plug/init.lua
vendored
@ -9,38 +9,42 @@ local M = {}
|
||||
|
||||
local all_plugins = {}
|
||||
|
||||
local hooks = require("plug.hooks")
|
||||
local loader = require("plug.loader")
|
||||
local config = require("plug.config")
|
||||
local hooks = require('plug.hooks')
|
||||
local loader = require('plug.loader')
|
||||
local config = require('plug.config')
|
||||
|
||||
function M.setup(opt)
|
||||
config.setup(opt)
|
||||
config.setup(opt)
|
||||
end
|
||||
|
||||
--- @param plugins table<PluginSpec>
|
||||
function M.add(plugins)
|
||||
for _, plug in ipairs(plugins) do
|
||||
loader.parser(plug)
|
||||
all_plugins[plug.name] = plug
|
||||
if plug.cmds then
|
||||
hooks.on_cmds(plug.cmds, plug)
|
||||
end
|
||||
if plug.events then
|
||||
hooks.on_events(plug.events, plug)
|
||||
end
|
||||
for _, plug in ipairs(plugins) do
|
||||
loader.parser(plug)
|
||||
if not plug.enabled then
|
||||
goto continue
|
||||
end
|
||||
all_plugins[plug.name] = plug
|
||||
if plug.cmds then
|
||||
hooks.on_cmds(plug.cmds, plug)
|
||||
end
|
||||
if plug.events then
|
||||
hooks.on_events(plug.events, plug)
|
||||
end
|
||||
|
||||
if plug.on_ft then
|
||||
hooks.on_ft(plug.on_ft, plug)
|
||||
end
|
||||
|
||||
if not plug.events and not plug.cmds and not plug.on_ft then
|
||||
loader.load(plug)
|
||||
end
|
||||
end
|
||||
if not plug.events and not plug.cmds and not plug.on_ft then
|
||||
loader.load(plug)
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
function M.get()
|
||||
return all_plugins
|
||||
return all_plugins
|
||||
end
|
||||
|
||||
return M
|
||||
|
9
bundle/nvim-plug/lua/plug/loader.lua
vendored
9
bundle/nvim-plug/lua/plug/loader.lua
vendored
@ -21,6 +21,7 @@ local config = require('plug.config')
|
||||
--- @field path string
|
||||
--- @field build string|table<string>
|
||||
--- @field is_local boolean true for local plugin
|
||||
--- @field when boolean|string|function
|
||||
|
||||
local function is_local_plugin(plugSpec)
|
||||
if plugSpec.is_local or vim.fn.isdirectory(plugSpec[1]) == 1 then
|
||||
@ -35,6 +36,14 @@ local function unique_name(plugSpec)
|
||||
end
|
||||
|
||||
function M.parser(plugSpec)
|
||||
if type(plugSpec.enabled) == "nil" then
|
||||
plugSpec.enabled = true
|
||||
elseif type(plugSpec.enabled) == "function" then
|
||||
plugSpec.enabled = plugSpec.enabled()
|
||||
elseif type(plugSpec.enabled) ~= "boolean" or plugSpec.enabled == false then
|
||||
plugSpec.enabled = false
|
||||
return plugSpec
|
||||
end
|
||||
plugSpec.name = unique_name(plugSpec)
|
||||
if is_local_plugin(plugSpec) then
|
||||
plugSpec.rtp = plugSpec[1]
|
||||
|
Loading…
Reference in New Issue
Block a user