Skip to content

Commit

Permalink
[-] tabs and a forgiving error handling for tabclose
Browse files Browse the repository at this point in the history
  • Loading branch information
Pheon-Dev committed Sep 8, 2023
1 parent 92ca331 commit 4824b92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
23 changes: 0 additions & 23 deletions lua/buffalo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local Dev = require("buffalo.dev")
local api = require("buffalo.api")
local log = Dev.log
local buffer_is_valid = require("buffalo.utils").buffer_is_valid
local tab_is_valid = require("buffalo.utils").tab_is_valid
local merge_tables = require("buffalo.utils").merge_tables
--
local M = {}
Expand Down Expand Up @@ -60,27 +59,6 @@ function M.init_buffers()
end
end

function M.init_tabs()
local tabs = api.get_tabs()

for idx = 1, #tabs do
local tab_id = tabs[idx]
local tab_name = api.get_tab_number(tab_id)
local tab_wins = api.get_wins()
-- if buffer is listed, then add to contents and marks
if tab_is_valid(tab_id, tab_name) then
table.insert(
M.tab_marks,
{
tab_name = tab_name,
tab_id = tab_id,
tab_wins = tab_wins,
}
)
end
end
end

function M.setup(config)
log.trace("setup(): Setting up...")

Expand Down Expand Up @@ -138,6 +116,5 @@ end
M.setup()

M.init_buffers()
M.init_tabs()

return M
13 changes: 10 additions & 3 deletions lua/buffalo/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,17 @@ function M.toggle_tab_menu()
if current_tab == current_tab_id then
current_tab_line = idx
end
local twins = api.get_tab_wins(idx)
local window = #twins > 1 and #twins .. " windows" or #twins .. " window"

if current_tab == 0 then
return
end
contents[idx] = string.format("Tab %s [%s]", current_tab, window)
if current_tab > 0 then
local twins = api.get_tab_wins(idx)
local window = #twins > 1 and "[ " .. #twins .. " windows ]" or "[ " .. #twins .. " window ]"
contents[idx] = string.format("Tab %s %s", current_tab, window)
else
contents[idx] = string.format("Tab [ deleted ]")
end
end

vim.api.nvim_set_option_value("number", true, { win = Buffalo_Tabs_win_id })
Expand Down Expand Up @@ -472,6 +476,9 @@ function M.nav_tab(id, command)
if tabid ~= -1 then
vim.cmd(tabid .. "tabnext")
end
elseif command == "tabclose" then
-- vim.api.nvim_tabpage_del_var(id, "buffalo")
vim.cmd(id .. "tabclose")
else
vim.cmd(id .. command)
end
Expand Down

0 comments on commit 4824b92

Please sign in to comment.