From 1b57b25107be19250aeca9f4bede0764f94c32c9 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Mon, 27 Nov 2023 11:39:05 -0500 Subject: [PATCH] feat(buffer): add ability for `close_tab` to close a specific tabpage Co-authored-by: Lou Greenwood --- lua/astrocore/buffer.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/astrocore/buffer.lua b/lua/astrocore/buffer.lua index dfbaa00..b192d84 100644 --- a/lua/astrocore/buffer.lua +++ b/lua/astrocore/buffer.lua @@ -122,7 +122,7 @@ function M.prev() end --- Close a given buffer ----@param bufnr? number The buffer to close or the current buffer if not provided +---@param bufnr? integer The buffer to close or the current buffer if not provided ---@param force? boolean Whether or not to foce close the buffers or confirm changes (default: false) function M.close(bufnr, force) if not bufnr or bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() end @@ -197,12 +197,14 @@ function M.sort(compare_func, skip_autocmd) return false end ---- Close the current tab -function M.close_tab() +--- Close a given tab +---@param tabpage? integer The tabpage to close or the current tab if not provided +function M.close_tab(tabpage) if #vim.api.nvim_list_tabpages() > 1 then - vim.t.bufs = nil + tabpage = tabpage or vim.api.nvim_get_current_tabpage() + vim.t[tabpage].bufs = nil astro.event "BufsUpdated" - vim.cmd.tabclose() + vim.cmd.tabclose(vim.api.nvim_tabpage_get_number(tabpage)) end end