fix(plugin): LazyFile now properly deals with deleted buffers. Fixes #1877

This commit is contained in:
Folke Lemaitre 2023-10-26 07:38:53 +02:00
parent 09eafc60ef
commit 4558407574
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -76,11 +76,13 @@ function M.lazy_file()
local events = {} ---@type {event: string, buf: number, data?: any}[]
local done = false
local function load()
if #events == 0 then
if #events == 0 or done then
return
end
pcall(vim.api.nvim_del_augroup_by_name, "lazy_file")
done = true
vim.api.nvim_del_augroup_by_name("lazy_file")
---@type table<string,string[]>
local skips = {}
@ -90,6 +92,7 @@ function M.lazy_file()
vim.api.nvim_exec_autocmds("User", { pattern = "LazyFile", modeline = false })
for _, event in ipairs(events) do
if vim.api.nvim_buf_is_valid(event.buf) then
Event.trigger({
event = event.event,
exclude = skips[event.event],
@ -103,6 +106,7 @@ function M.lazy_file()
})
end
end
end
vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false })
events = {}
end