Skip to content

Commit

Permalink
feat(util): added util.on_load to execute code when a plugin loads
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 12, 2023
1 parent b1721bc commit 9fd8970
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lua/lazyvim/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,25 @@ function M.lsp_disable(server, cond)
end)
end

---@param name string
---@param fn fun(name:string)
function M.on_load(name, fn)
local Config = require("lazy.core.config")
if Config.plugins[name] and Config.plugins[name]._.loaded then
vim.schedule(function()
fn(name)
end)
else
vim.api.nvim_create_autocmd("User", {
pattern = "LazyLoad",
callback = function(event)
if event.data == name then
fn(name)
return true
end
end,
})
end
end

return M

0 comments on commit 9fd8970

Please sign in to comment.