mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 04:21:08 +00:00
fix: check buffer validity in autocmd to prevent keymap.set() throwing
the buffer that triggered the autocmd could be gone by the time vim.schedule runs keymap.set, e.g. with transient buffers created by nvim_get_option_value
This commit is contained in:
parent
7c1301b895
commit
de3cd1fb32
1 changed files with 4 additions and 0 deletions
|
|
@ -74,6 +74,10 @@ vim.api.nvim_create_autocmd("FileType", {
|
|||
callback = function(event)
|
||||
vim.bo[event.buf].buflisted = false
|
||||
vim.schedule(function()
|
||||
-- without this, vim.keymap.set below may throw on transient buffers
|
||||
if not vim.api.nvim_buf_is_valid(event.buf) then
|
||||
return
|
||||
end
|
||||
vim.keymap.set("n", "q", function()
|
||||
vim.cmd("close")
|
||||
pcall(vim.api.nvim_buf_delete, event.buf, { force = true })
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue