Skip to content

Commit

Permalink
feat(buffer): add ability for close_tab to close a specific tabpage
Browse files Browse the repository at this point in the history
Co-authored-by: Lou Greenwood <lougreenwood@me.com>
  • Loading branch information
mehalter and lougreenwood committed Nov 27, 2023
1 parent 2ac1b29 commit 1b57b25
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lua/astrocore/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 1b57b25

Please sign in to comment.