feat(api): handler.post_load for setting up custom events (#82)

* feat(handler post_load): for setting up custom events
added a post_load callback for handlers to use to set
their own events such as DeferredUIEnter

In addition, made event handler use this feature to create DeferredUIEnter
further decoupling the handlers from the core of lz.n

* Update README.md

Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>

* Update lua/lz/n/meta.lua

Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>

---------

Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>
This commit is contained in:
Birdee
2024-08-29 18:13:48 -07:00
committed by GitHub
parent 079aba3c59
commit ed9b8a4a1c
5 changed files with 36 additions and 17 deletions
+20
View File
@@ -178,4 +178,24 @@ end
M.del = state.del
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)
function M.post_load()
if vim.v.vim_did_enter == 1 then
deferred_ui_enter()
elseif not vim.g.lz_n_did_create_deferred_ui_enter_autocmd then
vim.api.nvim_create_autocmd("UIEnter", {
once = true,
callback = deferred_ui_enter,
})
vim.g.lz_n_did_create_deferred_ui_enter_autocmd = true
end
end
return M
+9
View File
@@ -105,6 +105,15 @@ function M.disable(name)
end)
end
function M.run_post_load()
---@param handler lz.n.Handler
vim.iter(handlers):each(function(_, handler)
if handler.post_load then
handler.post_load()
end
end)
end
---@param plugins table<string, lz.n.Plugin>
function M.init(plugins)
---@param plugin lz.n.Plugin