Skip to content

Commit

Permalink
Customizable auto_hide count (romgrk#529)
Browse files Browse the repository at this point in the history
* feat: allow setting arbitrary `auto_hide` value

Users can now specify how many buffers they would like to tolerate
before showing the tabline, e.g. `auto_hide = 0` for hiding the
tabline when there are zero buffers left.

* docs: new `auto_hide` functionality
  • Loading branch information
Iron-E committed Sep 14, 2023
1 parent f8d1b44 commit 283bcea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ require'barbar'.setup {
-- Enable/disable animations
animation = true,

-- Enable/disable auto-hiding the tab bar when there is a single buffer
-- Automatically hide the tabline when there are this many buffers left.
-- Set to any value >=0 to enable.
auto_hide = false,

-- Enable/disable current/total tabpages indicator (top right corner)
Expand Down
13 changes: 9 additions & 4 deletions doc/barbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Highlight groups are created in this way: `Buffer<STATUS><PART>`.

Lua example: >
require'barbar'.setup {
auto_hide = true,
auto_hide = 1,
clickable = false,
icons = {current = {filetype = {enabled = false}}},
maximum_padding = math.huge,
Expand All @@ -139,7 +139,7 @@ Highlight groups are created in this way: `Buffer<STATUS><PART>`.
Vimscript example (see |:lua-heredoc| for more details): >
lua << EOF
require'barbar'.setup {
auto_hide = true,
auto_hide = 1,
clickable = false,
icons = {current = {filetype = {enabled = false}}},
maximum_padding = math.huge,
Expand All @@ -153,8 +153,13 @@ animation ~

*barbar-setup.auto_hide*
auto_hide ~
`boolean` (default: `false`)
Enable/disable auto-hiding the tab bar when there is a single buffer.
`false|integer` (default: `-1`)
Automatically hide the 'tabline' when there are this many buffers left. Set
to any value less than `0` to disable.

For example: `auto_hide = 0` hides the 'tabline' when there would be zero
buffers shown, `auto_hide = 1` hides the 'tabline' when there would only be
one, etc.

*barbar-setup.clickable*
clickable ~
Expand Down
13 changes: 10 additions & 3 deletions lua/barbar/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ local DEPRECATED_OPTIONS = {

--- @class barbar.config.options
--- @field animation boolean
--- @field auto_hide boolean
--- @field auto_hide integer
--- @field clickable boolean
--- @field exclude_ft string[]
--- @field exclude_name string[]
Expand Down Expand Up @@ -273,7 +273,14 @@ function config.setup(options)
options.closable = nil
end

do
-- convert `auto_hide = true`|`false` to `auto_hide = -1`|`1`
if options.auto_hide == false then
options.auto_hide = -1
elseif options.auto_hide == true then
options.auto_hide = 1
end

do -- convert `{Foo = true}` to `{Foo = {event = nil, text = nil}}`
local sidebar_filetypes = options.sidebar_filetypes
if sidebar_filetypes then
for k, v in pairs(sidebar_filetypes) do
Expand Down Expand Up @@ -309,7 +316,7 @@ function config.setup(options)

config.options = tbl_deep_extend('keep', options, {
animation = true,
auto_hide = false,
auto_hide = -1,
clickable = true,
exclude_ft = {},
exclude_name = {},
Expand Down
4 changes: 2 additions & 2 deletions lua/barbar/ui/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ function render.update(update_names, refocus)
local buffers = layout.hide(render.get_updated_buffers(update_names))

-- Auto hide/show if applicable
if config.options.auto_hide then
if #buffers + #list_tabpages() < 3 then -- 3 because the condition for auto-hiding is 1 visible buffer and 1 tabpage (2).
if config.options.auto_hide > -1 then
if #buffers <= config.options.auto_hide and #list_tabpages() < 2 then
if get_option'showtabline' == 2 then
set_option('showtabline', 0)
end
Expand Down

0 comments on commit 283bcea

Please sign in to comment.