Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 1e2b5af

Browse files
committed
feat(nvim-plug): support priority option
1 parent 1d63b39 commit 1e2b5af

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

bundle/nvim-plug/README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Commands](#commands)
1515
- [Default UI](#default-ui)
1616
- [Custom Plugin UI](#custom-plugin-ui)
17+
- [Plugin priority](#plugin-priority)
1718
- [Feedback](#feedback)
1819

1920
<!-- vim-markdown-toc -->
@@ -50,6 +51,8 @@ require('plug').setup({
5051
https_proxy = 'http://127.0.0.1:7890',
5152
-- default history depth for `git clone`
5253
clone_depth = 1,
54+
-- plugin priority, readme [plugin priority] for more info
55+
enable_priority = false
5356
})
5457
```
5558

@@ -114,8 +117,10 @@ The plugin spec is inspired by [dein.nvim](https://github.com/Shougo/dein.vim).
114117
| `tag` | `string` specific git tag |
115118
| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set |
116119
| `autoload` | `boolean`, load plugin after git clone |
120+
| `priority` | `number`, default is 50, set the order in which plugins are loaded |
117121

118-
`config` and `config_after` function will be not be called if the plugin has not been installed.
122+
- `config` and `config_after` function will be not be called if the plugin has not been installed.
123+
- `priority` does not work for lazy plugins.
119124

120125
## Commands
121126

@@ -179,6 +184,48 @@ require('plug').setup({
179184
})
180185
```
181186

187+
### Plugin priority
188+
189+
By default this feature is disabled, plugins will be loaded when run `add({plugins})` function.
190+
To enable plugin priority feature, you need to call `plug.load()` after `plug.add()` function.
191+
This option is not for lazy plugins.
192+
193+
for example:
194+
195+
```lua
196+
require('plug').setup({
197+
max_processes = 5,
198+
enable_priority = true,
199+
})
200+
require('plug').add({
201+
{
202+
'wsdjeg/scrollbar.vim',
203+
events = { 'VimEnter' },
204+
},
205+
{
206+
'wsdjeg/vim-chat',
207+
enabled = function()
208+
return vim.fn.has('nvim-0.10.0') == 1
209+
end,
210+
},
211+
{
212+
'wsdjeg/flygrep.nvim',
213+
cmds = { 'FlyGrep' },
214+
config = function()
215+
require('flygrep').setup()
216+
end,
217+
},
218+
{
219+
'rakr/vim-one',
220+
config = function()
221+
vim.cmd('colorscheme one')
222+
end,
223+
priority = 100,
224+
},
225+
})
226+
require('plug').load()
227+
```
228+
182229
## Feedback
183230

184231
The development of this plugin is in [`SpaceVim/bundle/nvim-plug`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/nvim-plug) directory.

bundle/nvim-plug/lua/plug/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ M.max_processes = 5
1313
M.base_url = 'https://github.com/'
1414
M.ui = 'notify'
1515
M.clone_depth = '1'
16+
M.enable_priority = false
1617
function M.setup(opt)
1718
M.bundle_dir = opt.bundle_dir or M.bundle_dir
1819
M.max_processes = opt.max_processes or M.max_processes
@@ -22,6 +23,7 @@ function M.setup(opt)
2223
M.https_proxy = opt.https_proxy
2324
M.clone_depth = opt.clone_depth or M.clone_depth
2425
M.raw_plugin_dir = opt.raw_plugin_dir or M.raw_plugin_dir
26+
M.enable_priority = opt.enable_priority or M.enable_priority
2527
end
2628

2729
return M

bundle/nvim-plug/lua/plug/init.lua

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ function M.add(plugins, skip_deps)
4848
hooks.on_func(plug.on_func, plug)
4949
end
5050

51-
if
52-
not plug.events
53-
and not plug.cmds
54-
and not plug.on_ft
55-
and not plug.on_map
56-
and not plug.on_func
57-
then
58-
loader.load(plug)
51+
if not config.enable_priority then
52+
if
53+
not plug.events
54+
and not plug.cmds
55+
and not plug.on_ft
56+
and not plug.on_map
57+
and not plug.on_func
58+
then
59+
loader.load(plug)
60+
end
5961
end
6062
::continue::
6163
end
@@ -66,4 +68,23 @@ function M.get()
6668
return all_plugins
6769
end
6870

71+
function M.load()
72+
if config.enable_priority then
73+
local start = {}
74+
for _, v in pairs(all_plugins) do
75+
if not v.events and not v.cmds and not v.on_ft and not v.on_map and not v.on_func then
76+
table.insert(start, v)
77+
end
78+
end
79+
table.sort(start, function(a, b)
80+
local priority_a = a.priority or 50
81+
local priority_b = b.priority or 50
82+
return priority_a > priority_b
83+
end)
84+
for _, v in ipairs(start) do
85+
loader.load(v)
86+
end
87+
end
88+
end
89+
6990
return M

bundle/nvim-plug/test/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require('plug').setup({
1515
ui = 'default',
1616
http_proxy = 'http://127.0.0.1:7890',
1717
https_proxy = 'http://127.0.0.1:7890',
18+
enable_priority = true
1819
})
1920

2021
require('plug').add({
@@ -70,6 +71,7 @@ require('plug').add({
7071
config = function()
7172
vim.cmd('colorscheme one')
7273
end,
74+
priority = 100,
7375
},
7476
{
7577
'wsdjeg/flygrep.nvim',
@@ -83,4 +85,5 @@ require('plug').add({
8385
on_map = { '<Plug>(clever-f' },
8486
},
8587
})
88+
require('plug').load()
8689
vim.cmd('nmap f <Plug>(clever-f-f)')

0 commit comments

Comments
 (0)