mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-19 13:13:43 +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' },
|
events = { 'VimEnter' },
|
||||||
config = function() end,
|
config = function() end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'wsdjeg/vim-chat',
|
||||||
|
enabled = function()
|
||||||
|
return vim.fn.has('nvim-0.10.0') == 1
|
||||||
|
end,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'wsdjeg/flygrep.nvim',
|
'wsdjeg/flygrep.nvim',
|
||||||
cmds = { 'FlyGrep' },
|
cmds = { 'FlyGrep' },
|
||||||
@ -38,14 +44,15 @@ require('plug').add({
|
|||||||
|
|
||||||
## Plugin Spec
|
## Plugin Spec
|
||||||
|
|
||||||
| 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 |
|
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||||
| `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 |
|
||||||
|
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
|
||||||
|
|
||||||
## Commands
|
## 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 all_plugins = {}
|
||||||
|
|
||||||
local hooks = require("plug.hooks")
|
local hooks = require('plug.hooks')
|
||||||
local loader = require("plug.loader")
|
local loader = require('plug.loader')
|
||||||
local config = require("plug.config")
|
local config = require('plug.config')
|
||||||
|
|
||||||
function M.setup(opt)
|
function M.setup(opt)
|
||||||
config.setup(opt)
|
config.setup(opt)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param plugins table<PluginSpec>
|
--- @param plugins table<PluginSpec>
|
||||||
function M.add(plugins)
|
function M.add(plugins)
|
||||||
for _, plug in ipairs(plugins) do
|
for _, plug in ipairs(plugins) do
|
||||||
loader.parser(plug)
|
loader.parser(plug)
|
||||||
all_plugins[plug.name] = plug
|
if not plug.enabled then
|
||||||
if plug.cmds then
|
goto continue
|
||||||
hooks.on_cmds(plug.cmds, plug)
|
end
|
||||||
end
|
all_plugins[plug.name] = plug
|
||||||
if plug.events then
|
if plug.cmds then
|
||||||
hooks.on_events(plug.events, plug)
|
hooks.on_cmds(plug.cmds, plug)
|
||||||
end
|
end
|
||||||
|
if plug.events then
|
||||||
|
hooks.on_events(plug.events, plug)
|
||||||
|
end
|
||||||
|
|
||||||
if plug.on_ft then
|
if plug.on_ft then
|
||||||
hooks.on_ft(plug.on_ft, plug)
|
hooks.on_ft(plug.on_ft, plug)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not plug.events and not plug.cmds and not plug.on_ft then
|
if not plug.events and not plug.cmds and not plug.on_ft then
|
||||||
loader.load(plug)
|
loader.load(plug)
|
||||||
end
|
end
|
||||||
end
|
::continue::
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get()
|
function M.get()
|
||||||
return all_plugins
|
return all_plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
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 path string
|
||||||
--- @field build string|table<string>
|
--- @field build string|table<string>
|
||||||
--- @field is_local boolean true for local plugin
|
--- @field is_local boolean true for local plugin
|
||||||
|
--- @field when boolean|string|function
|
||||||
|
|
||||||
local function is_local_plugin(plugSpec)
|
local function is_local_plugin(plugSpec)
|
||||||
if plugSpec.is_local or vim.fn.isdirectory(plugSpec[1]) == 1 then
|
if plugSpec.is_local or vim.fn.isdirectory(plugSpec[1]) == 1 then
|
||||||
@ -35,6 +36,14 @@ local function unique_name(plugSpec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.parser(plugSpec)
|
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)
|
plugSpec.name = unique_name(plugSpec)
|
||||||
if is_local_plugin(plugSpec) then
|
if is_local_plugin(plugSpec) then
|
||||||
plugSpec.rtp = plugSpec[1]
|
plugSpec.rtp = plugSpec[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user