fix: oil.close doesn't error when no other buffers exist (#79)

This commit is contained in:
Steven Arcangeli 2023-03-20 09:22:46 -07:00
parent 08c4b71ef1
commit 4b05ebdf20
2 changed files with 14 additions and 1 deletions

View file

@ -317,7 +317,11 @@ M.close = function()
-- Deleting the buffer closes all windows with that buffer open, so navigate to a different
-- buffer first
local oilbuf = vim.api.nvim_get_current_buf()
vim.cmd.bprev()
ok = pcall(vim.cmd.bprev)
if not ok then
-- If `bprev` failed, there are no buffers open so we should create a new one with enew
vim.cmd.enew()
end
vim.api.nvim_buf_delete(oilbuf, { force = true })
end