Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ use {
section_separators = {'', ''},
component_separators = {'', ''},
max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3
show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named
show_devicons = true, -- this shows devicons in buffer section
show_bufnr = false, -- this appends [bufnr] to buffer section,
show_filename_only = false, -- shows base filename only instead of relative path in filename
modified_icon = "+ ", -- change the default modified icon
modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified
show_tabs_only = false, -- this shows only tabs instead of tabs + buffers
show_tabline_buffers = 2, -- this shows buffer names (the left section of the tabline) always, when there is more than one buffer, or never
show_tabline_tabs = 1, -- this shows tab names (the right section of the tabline) always, when there is more than one or a named tab, or never
}
}
vim.cmd[[
Expand Down Expand Up @@ -102,6 +103,14 @@ Show separator after the last buffer or tab (default = false)

Show only tabs instead of tabs + buffers (default = false)

### tabline_show_tabline_buffers

Shows the buffer names (the left section of the tabline) always (2), when there is more than one buffer (1), or never (0) (default = 2)

### tabline_show_tabline_tabs

Shows the tab names (the right section of the tabline) always (2), when there is more than one or a named tab (1), or never (0) (default = 1)

# Lualine tabline support

[`nvim-lualine/lualine.nvim`](https://github.com/nvim-lualine/lualine.nvim) now has buffers and tabs as components.
Expand Down
80 changes: 67 additions & 13 deletions lua/tabline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ function M.format_tabs(tabs, max_length)
end
end
M.total_tab_length = total_length
if M.options.show_tabs_always then
if M.options.show_tabline_tabs == 2 then
line = "%=%#TabLineFill#%999X" .. line
elseif #tabs == 1 and tabs[1].name ~= "1 " then
elseif M.options.show_tabline_tabs == 1 and #tabs == 1 and tabs[1].name ~= "1 " then
line = "%=%#TabLineFill#%999X" .. line
elseif #tabs > 1 then
elseif M.options.show_tabline_tabs == 1 and #tabs > 1 then
line = "%=%#TabLineFill#%999X" .. line
else
line = "%=%#TabLineFill#%999X"
Expand Down Expand Up @@ -462,6 +462,13 @@ function M.format_buffers(buffers, max_length)
end
end
end

if M.options.show_tabline_buffers == 1 and #buffers == 1 then
line = "%#tabline_c_normal#"
elseif M.options.show_tabline_buffers == 0 then
line = "%#tabline_c_normal#"
end

return line
end

Expand Down Expand Up @@ -810,10 +817,11 @@ function M.setup(opts)
let g:tabline_show_bufnr = get(g:, "tabline_show_bufnr", v:false)
let g:tabline_show_filename_only = get(g:, "tabline_show_filename_only", v:false)
let g:tabline_show_last_separator = get(g:, "tabline_show_last_separator", v:false)
let g:tabline_show_tabs_always = get(g:, "tabline_show_tabs_always", v:false)
let g:tabline_modified_icon = get(g:, "tabline_modified_icon", " ")
let g:tabline_modified_italic = get(g:, "tabline_modified_italic", v:true)
let g:tabline_show_tabs_only = get(g:, "tabline_show_tabs_only", v:false)
let g:tabline_show_tabline_buffers = get(g:, "tabline_show_tabline_buffers", 2)
let g:tabline_show_tabline_tabs = get(g:, "tabline_show_tabline_tabs", 1)
]])

if opts == nil then
Expand Down Expand Up @@ -865,12 +873,16 @@ function M.setup(opts)
end
end

if opts.options.always_show_tabs ~= nil then
M.options.show_tabs_always = opts.options.always_show_tabs
elseif opts.options.show_tabs_always ~= nil then
M.options.show_tabs_always = opts.options.show_tabs_always
if opts.options.show_tabline_tabs ~= nil then
M.options.show_tabline_tabs = opts.options.show_tabline_tabs
else
M.options.show_tabline_tabs = vim.g.tabline_show_tabline_tabs
end

if opts.options.show_tabline_buffers ~= nil then
M.options.show_tabline_buffers= opts.options.show_tabline_buffers
else
M.options.show_tabs_always = vim.g.tabline_show_tabs_always
M.options.show_tabline_buffers= vim.g.tabline_show_tabline_buffers
end

if opts.options.show_bufnr ~= nil then
Expand Down Expand Up @@ -946,16 +958,58 @@ function M.setup(opts)
]])

function _G.tabline_buffers_tabs()
local buffers
local tabs = M.tabline_tabs(M.options)
if M.options.show_tabs_only then
return M.tabline_buffers_tabs_only(M.options)
buffers = M.tabline_buffers_tabs_only(M.options)
else
buffers = M.tabline_buffers(M.options)
end
local tabs = M.tabline_tabs(M.options)
return M.tabline_buffers(M.options) .. tabs

return buffers .. tabs
end

-- to_delete: the count of buffers to be deleted after this call
function _G.update_tabline_visibility(to_delete)
local tab_count = vim.fn.tabpagenr('$')
local buf_count
if M.options.show_tabs_only == false then
buf_count = -to_delete
for b = 1, vim.fn.bufnr('$') do
-- this should be a function (same tests repeated for 4 times...)
if vim.fn.buflisted(b) ~= 0 and vim.fn.getbufvar(b, "&buftype") ~= "quickfix" then
buf_count = buf_count + 1
end
end
else
buf_count = tab_count
end

local function is_shown(opt, count)
return opt == 2 or (opt == 1 and count > 1)
end

local v
if is_shown(M.options.show_tabline_buffers, buf_count)
or is_shown(M.options.show_tabline_tabs, tab_count) then
v = 2
else
v = 0
end

vim.o.showtabline = v
end

if opts.enable then
vim.o.tabline = "%!v:lua.tabline_buffers_tabs()"
vim.o.showtabline = 2
update_tabline_visibility(0)
vim.cmd([[
augroup TablineUpdateVisibility
autocmd!
autocmd BufAdd,TabNew,TabClosed * call v:lua.update_tabline_visibility(0)
autocmd BufDelete * call v:lua.update_tabline_visibility(1)
augroup END
]])
end
end

Expand Down