@@ -9,13 +9,12 @@ M.dirty = false
9
9
M .config = {
10
10
enabled = true ,
11
11
path = vim .fn .stdpath (" state" ) .. " /lazy.state" ,
12
- -- choose what should be cached
13
- -- * lazy: cache all lazy.nvim core modules and your config files
14
- -- * init: all of the above and any module needed to init your plugins
15
- -- * VimEnter: any module till VimEnter
16
- -- * VeryLazy: any module till VeryLazy
17
- -- * allthethings: all mdules. Not recommended
18
- strategy = " VimEnter" , --- @type " lazy" | " init" | " VimEnter" | " allthethings"
12
+ -- Once one of the following events triggers, caching will be disabled.
13
+ -- To cache all modules, set this to `{}`, but that is not recommended.
14
+ -- The default is to disable on:
15
+ -- * VimEnter: not useful to cache anything else beyond startup
16
+ -- * BufReadPre: this will be triggered early when opening a file from the command line directly
17
+ disable_events = { " VimEnter" , " BufReadPre" },
19
18
}
20
19
M .debug = false
21
20
@@ -40,15 +39,10 @@ function M.check_load(modname, modpath)
40
39
require (" lazy.core.loader" ).autoload (modname , modpath )
41
40
end
42
41
43
- --- @param step ? string
44
- function M .disable (step )
42
+ function M .disable ()
45
43
if not M .enabled then
46
44
return
47
45
end
48
- if step and M .config .strategy ~= step then
49
- return
50
- end
51
-
52
46
local idx = M .idx ()
53
47
if idx then
54
48
table.remove (package.loaders , idx )
@@ -141,17 +135,8 @@ function M.setup(opts)
141
135
M .load_cache ()
142
136
table.insert (package.loaders , M .loader_idx , M .loader )
143
137
144
- if M .config .strategy == " VimEnter" then
145
- vim .api .nvim_create_autocmd (" VimEnter" , {
146
- once = true ,
147
- callback = function ()
148
- -- use schedule so all other VimEnter handlers will have run
149
- vim .schedule (function ()
150
- -- startup done, so stop caching
151
- M .disable ()
152
- end )
153
- end ,
154
- })
138
+ if # M .config .disable_events > 0 then
139
+ vim .api .nvim_create_autocmd (M .config .disable_events , { once = true , callback = M .disable })
155
140
end
156
141
return M
157
142
end
0 commit comments