mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 05:58:00 +08:00
feat(nvim-plug): support priority option
This commit is contained in:
parent
1d63b392be
commit
1e2b5afcf7
49
bundle/nvim-plug/README.md
vendored
49
bundle/nvim-plug/README.md
vendored
@ -14,6 +14,7 @@
|
|||||||
- [Commands](#commands)
|
- [Commands](#commands)
|
||||||
- [Default UI](#default-ui)
|
- [Default UI](#default-ui)
|
||||||
- [Custom Plugin UI](#custom-plugin-ui)
|
- [Custom Plugin UI](#custom-plugin-ui)
|
||||||
|
- [Plugin priority](#plugin-priority)
|
||||||
- [Feedback](#feedback)
|
- [Feedback](#feedback)
|
||||||
|
|
||||||
<!-- vim-markdown-toc -->
|
<!-- vim-markdown-toc -->
|
||||||
@ -50,6 +51,8 @@ require('plug').setup({
|
|||||||
https_proxy = 'http://127.0.0.1:7890',
|
https_proxy = 'http://127.0.0.1:7890',
|
||||||
-- default history depth for `git clone`
|
-- default history depth for `git clone`
|
||||||
clone_depth = 1,
|
clone_depth = 1,
|
||||||
|
-- plugin priority, readme [plugin priority] for more info
|
||||||
|
enable_priority = false
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -114,8 +117,10 @@ The plugin spec is inspired by [dein.nvim](https://github.com/Shougo/dein.vim).
|
|||||||
| `tag` | `string` specific git tag |
|
| `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 |
|
| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set |
|
||||||
| `autoload` | `boolean`, load plugin after git clone |
|
| `autoload` | `boolean`, load plugin after git clone |
|
||||||
|
| `priority` | `number`, default is 50, set the order in which plugins are loaded |
|
||||||
|
|
||||||
`config` and `config_after` function will be not be called if the plugin has not been installed.
|
- `config` and `config_after` function will be not be called if the plugin has not been installed.
|
||||||
|
- `priority` does not work for lazy plugins.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
@ -179,6 +184,48 @@ require('plug').setup({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Plugin priority
|
||||||
|
|
||||||
|
By default this feature is disabled, plugins will be loaded when run `add({plugins})` function.
|
||||||
|
To enable plugin priority feature, you need to call `plug.load()` after `plug.add()` function.
|
||||||
|
This option is not for lazy plugins.
|
||||||
|
|
||||||
|
for example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require('plug').setup({
|
||||||
|
max_processes = 5,
|
||||||
|
enable_priority = true,
|
||||||
|
})
|
||||||
|
require('plug').add({
|
||||||
|
{
|
||||||
|
'wsdjeg/scrollbar.vim',
|
||||||
|
events = { 'VimEnter' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'wsdjeg/vim-chat',
|
||||||
|
enabled = function()
|
||||||
|
return vim.fn.has('nvim-0.10.0') == 1
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'wsdjeg/flygrep.nvim',
|
||||||
|
cmds = { 'FlyGrep' },
|
||||||
|
config = function()
|
||||||
|
require('flygrep').setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'rakr/vim-one',
|
||||||
|
config = function()
|
||||||
|
vim.cmd('colorscheme one')
|
||||||
|
end,
|
||||||
|
priority = 100,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require('plug').load()
|
||||||
|
```
|
||||||
|
|
||||||
## Feedback
|
## Feedback
|
||||||
|
|
||||||
The development of this plugin is in [`SpaceVim/bundle/nvim-plug`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/nvim-plug) directory.
|
The development of this plugin is in [`SpaceVim/bundle/nvim-plug`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/nvim-plug) directory.
|
||||||
|
2
bundle/nvim-plug/lua/plug/config.lua
vendored
2
bundle/nvim-plug/lua/plug/config.lua
vendored
@ -13,6 +13,7 @@ M.max_processes = 5
|
|||||||
M.base_url = 'https://github.com/'
|
M.base_url = 'https://github.com/'
|
||||||
M.ui = 'notify'
|
M.ui = 'notify'
|
||||||
M.clone_depth = '1'
|
M.clone_depth = '1'
|
||||||
|
M.enable_priority = false
|
||||||
function M.setup(opt)
|
function M.setup(opt)
|
||||||
M.bundle_dir = opt.bundle_dir or M.bundle_dir
|
M.bundle_dir = opt.bundle_dir or M.bundle_dir
|
||||||
M.max_processes = opt.max_processes or M.max_processes
|
M.max_processes = opt.max_processes or M.max_processes
|
||||||
@ -22,6 +23,7 @@ function M.setup(opt)
|
|||||||
M.https_proxy = opt.https_proxy
|
M.https_proxy = opt.https_proxy
|
||||||
M.clone_depth = opt.clone_depth or M.clone_depth
|
M.clone_depth = opt.clone_depth or M.clone_depth
|
||||||
M.raw_plugin_dir = opt.raw_plugin_dir or M.raw_plugin_dir
|
M.raw_plugin_dir = opt.raw_plugin_dir or M.raw_plugin_dir
|
||||||
|
M.enable_priority = opt.enable_priority or M.enable_priority
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
37
bundle/nvim-plug/lua/plug/init.lua
vendored
37
bundle/nvim-plug/lua/plug/init.lua
vendored
@ -48,14 +48,16 @@ function M.add(plugins, skip_deps)
|
|||||||
hooks.on_func(plug.on_func, plug)
|
hooks.on_func(plug.on_func, plug)
|
||||||
end
|
end
|
||||||
|
|
||||||
if
|
if not config.enable_priority then
|
||||||
not plug.events
|
if
|
||||||
and not plug.cmds
|
not plug.events
|
||||||
and not plug.on_ft
|
and not plug.cmds
|
||||||
and not plug.on_map
|
and not plug.on_ft
|
||||||
and not plug.on_func
|
and not plug.on_map
|
||||||
then
|
and not plug.on_func
|
||||||
loader.load(plug)
|
then
|
||||||
|
loader.load(plug)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
@ -66,4 +68,23 @@ function M.get()
|
|||||||
return all_plugins
|
return all_plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.load()
|
||||||
|
if config.enable_priority then
|
||||||
|
local start = {}
|
||||||
|
for _, v in pairs(all_plugins) do
|
||||||
|
if not v.events and not v.cmds and not v.on_ft and not v.on_map and not v.on_func then
|
||||||
|
table.insert(start, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(start, function(a, b)
|
||||||
|
local priority_a = a.priority or 50
|
||||||
|
local priority_b = b.priority or 50
|
||||||
|
return priority_a > priority_b
|
||||||
|
end)
|
||||||
|
for _, v in ipairs(start) do
|
||||||
|
loader.load(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
3
bundle/nvim-plug/test/init.lua
vendored
3
bundle/nvim-plug/test/init.lua
vendored
@ -15,6 +15,7 @@ require('plug').setup({
|
|||||||
ui = 'default',
|
ui = 'default',
|
||||||
http_proxy = 'http://127.0.0.1:7890',
|
http_proxy = 'http://127.0.0.1:7890',
|
||||||
https_proxy = 'http://127.0.0.1:7890',
|
https_proxy = 'http://127.0.0.1:7890',
|
||||||
|
enable_priority = true
|
||||||
})
|
})
|
||||||
|
|
||||||
require('plug').add({
|
require('plug').add({
|
||||||
@ -70,6 +71,7 @@ require('plug').add({
|
|||||||
config = function()
|
config = function()
|
||||||
vim.cmd('colorscheme one')
|
vim.cmd('colorscheme one')
|
||||||
end,
|
end,
|
||||||
|
priority = 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'wsdjeg/flygrep.nvim',
|
'wsdjeg/flygrep.nvim',
|
||||||
@ -83,4 +85,5 @@ require('plug').add({
|
|||||||
on_map = { '<Plug>(clever-f' },
|
on_map = { '<Plug>(clever-f' },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
require('plug').load()
|
||||||
vim.cmd('nmap f <Plug>(clever-f-f)')
|
vim.cmd('nmap f <Plug>(clever-f-f)')
|
||||||
|
Loading…
Reference in New Issue
Block a user