Skip to content

Commit

Permalink
feat: added Pre events. Fixes #856. Fixes #877
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 17, 2023
1 parent 10d4371 commit 0bca18d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ The following user events will be triggered:
- **LazyClean**: after a clean
- **LazyCheck**: after checking for updates
- **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
- **VeryLazy**: triggered after `LazyDone` and processing `VimEnter` auto commands
- **LazyVimStarted**: triggered after `UIEnter` when `require("lazy").stats().startuptime` has been calculated.
Expand Down
11 changes: 8 additions & 3 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ local M = {}
function M.run(ropts, opts)
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
---@param plugin string|LazyPlugin
opts.plugins = vim.tbl_map(function(plugin)
Expand Down Expand Up @@ -49,9 +56,7 @@ function M.run(ropts, opts)
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
Plugin.update_state()
require("lazy.manage.checker").fast_check({ report = false })
local mode = opts.mode
if mode then
local event = "Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2)
if event then
vim.api.nvim_exec_autocmds("User", { pattern = event, modeline = false })
end
end)
Expand Down

0 comments on commit 0bca18d

Please sign in to comment.