feat: added `Pre` events. Fixes #856. Fixes #877

This commit is contained in:
Folke Lemaitre 2023-06-17 08:37:33 +02:00
parent 10d4371745
commit 0bca18de5d
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 14 additions and 3 deletions

View File

@ -575,6 +575,12 @@ The following user events will be triggered:
- **LazyClean**: after a clean - **LazyClean**: after a clean
- **LazyCheck**: after checking for updates - **LazyCheck**: after checking for updates
- **LazyLog**: after running log - **LazyLog**: after running log
- **LazySyncPre**: before running sync
- **LazyInstallPre**: before an install
- **LazyUpdatePre**: before an update
- **LazyCleanPre**: before a clean
- **LazyCheckPre**: before checking for updates
- **LazyLogPre**: before running log
- **LazyReload**: triggered by change detection after reloading plugin specs - **LazyReload**: triggered by change detection after reloading plugin specs
- **VeryLazy**: triggered after `LazyDone` and processing `VimEnter` auto commands - **VeryLazy**: triggered after `LazyDone` and processing `VimEnter` auto commands
- **LazyVimStarted**: triggered after `UIEnter` when `require("lazy").stats().startuptime` has been calculated. - **LazyVimStarted**: triggered after `UIEnter` when `require("lazy").stats().startuptime` has been calculated.

View File

@ -18,6 +18,13 @@ local M = {}
function M.run(ropts, opts) function M.run(ropts, opts)
opts = opts or {} opts = opts or {}
local mode = opts.mode
local event = mode and ("Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2))
if event then
vim.api.nvim_exec_autocmds("User", { pattern = event .. "Pre", modeline = false })
end
if opts.plugins then if opts.plugins then
---@param plugin string|LazyPlugin ---@param plugin string|LazyPlugin
opts.plugins = vim.tbl_map(function(plugin) opts.plugins = vim.tbl_map(function(plugin)
@ -49,9 +56,7 @@ function M.run(ropts, opts)
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false }) vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
Plugin.update_state() Plugin.update_state()
require("lazy.manage.checker").fast_check({ report = false }) require("lazy.manage.checker").fast_check({ report = false })
local mode = opts.mode if event then
if mode then
local event = "Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2)
vim.api.nvim_exec_autocmds("User", { pattern = event, modeline = false }) vim.api.nvim_exec_autocmds("User", { pattern = event, modeline = false })
end end
end) end)