Skip to content

Commit 5e26ac1

Browse files
committed
feat: add support for snacks.bufdelete to buffer utilities
1 parent 1ad0d8d commit 5e26ac1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lua/astrocore/buffer.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,29 @@ end
188188
---@param force? boolean Whether or not to foce close the buffers or confirm changes (default: false)
189189
function M.close(bufnr, force)
190190
if not bufnr or bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() end
191-
if astro.is_available "mini.bufremove" and M.is_valid(bufnr) and #vim.t.bufs > 1 then
192-
mini_confirm(require("mini.bufremove").delete, bufnr, force)
193-
else
194-
local buftype = vim.bo[bufnr].buftype
195-
vim.cmd(("silent! %s %d"):format((force or buftype == "terminal") and "bdelete!" or "confirm bdelete", bufnr))
191+
if M.is_valid(bufnr) and #vim.t.bufs > 1 then
192+
if astro.is_available "snacks.nvim" then return require("snacks").bufdelete { buf = bufnr, force = force } end
193+
if astro.is_available "mini.bufremove" then return mini_confirm(require("mini.bufremove").delete, bufnr, force) end
196194
end
195+
-- fallback
196+
local buftype = vim.bo[bufnr].buftype
197+
vim.cmd(("silent! %s %d"):format((force or buftype == "terminal") and "bdelete!" or "confirm bdelete", bufnr))
197198
end
198199

199200
--- Fully wipeout a given buffer
200201
---@param bufnr? integer The buffer to wipe or the current buffer if not provided
201202
---@param force? boolean Whether or not to foce close the buffers or confirm changes (default: false)
202203
function M.wipe(bufnr, force)
203204
if not bufnr or bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() end
204-
if astro.is_available "mini.bufremove" and M.is_valid(bufnr) and #vim.t.bufs > 1 then
205-
mini_confirm(require("mini.bufremove").wipeout, bufnr, force)
206-
else
207-
local buftype = vim.bo[bufnr].buftype
208-
vim.cmd(("silent! %s %d"):format((force or buftype == "terminal") and "bwipeout!" or "confirm bwipeout", bufnr))
205+
if M.is_valid(bufnr) and #vim.t.bufs > 1 then
206+
if astro.is_available "snacks.nvim" then
207+
return require("snacks").bufdelete { buf = bufnr, force = force, wipe = true }
208+
end
209+
if astro.is_available "mini.bufremove" then return mini_confirm(require("mini.bufremove").wipeout, bufnr, force) end
209210
end
211+
-- fallback
212+
local buftype = vim.bo[bufnr].buftype
213+
vim.cmd(("silent! %s %d"):format((force or buftype == "terminal") and "bwipeout!" or "confirm bwipeout", bufnr))
210214
end
211215

212216
--- Close all buffers

0 commit comments

Comments
 (0)