mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-02 02:45:11 +00:00
feat: add DeferredUIEnter user event
This commit is contained in:
@@ -132,6 +132,14 @@ require("lz.n").load(plugins)
|
||||
it would have to know where the plugin is installed in order to determine
|
||||
which plugin to load.
|
||||
|
||||
### User events
|
||||
|
||||
- `DeferredUIEnter`: Triggered when `load()` is done and after `UIEnter`.
|
||||
Can be used as an `event` to lazy-load plugins that are not immediately needed
|
||||
for the initial UI[^3].
|
||||
|
||||
[^3]: This is equivalent to `lazy.nvim`'s `VeryLazy` event.
|
||||
|
||||
#### Example
|
||||
|
||||
```lua
|
||||
|
||||
@@ -6,6 +6,14 @@ if vim.fn.has("nvim-0.10.0") ~= 1 then
|
||||
error("lz.n requires Neovim >= 0.10.0")
|
||||
end
|
||||
|
||||
local deferred_ui_enter = vim.schedule_wrap(function()
|
||||
if vim.v.exiting ~= vim.NIL then
|
||||
return
|
||||
end
|
||||
vim.g.lz_n_did_deferred_ui_enter = true
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "DeferredUIEnter", modeline = false })
|
||||
end)
|
||||
|
||||
---@param spec string | lz.n.Spec
|
||||
function M.load(spec)
|
||||
if vim.g.lz_n_did_load then
|
||||
@@ -21,6 +29,14 @@ function M.load(spec)
|
||||
require("lz.n.loader").load_startup_plugins(plugins)
|
||||
require("lz.n.state").plugins = plugins
|
||||
require("lz.n.handler").init(plugins)
|
||||
if vim.v.vim_did_enter == 1 then
|
||||
deferred_ui_enter()
|
||||
else
|
||||
vim.api.nvim_create_autocmd("UIEnter", {
|
||||
once = true,
|
||||
callback = deferred_ui_enter,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user