Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option always_show_tabs to control whether show tabline when there are only one tab. #1013

Merged
merged 3 commits into from
Nov 1, 2024

Conversation

milanglacier
Copy link
Contributor

No description provided.

@milanglacier milanglacier changed the title feat: add option always_show_tabs. feat: add option always_show_tabs to control whether show tabline when there are only one tab. Apr 9, 2023
@wwkayak
Copy link

wwkayak commented Apr 30, 2023

Works good... thanks

@milanglacier
Copy link
Contributor Author

Works good... thanks

Thanks for your feedback... Hope we can merge this patch ASAP...

@deponian
Copy link

In the meantime you can use this snippet until this PR is merged:

require('lualine').hide({place = {'tabline'}})
local lualine_tmp = vim.api.nvim_create_augroup('lualine_tmp', { clear = true })
vim.api.nvim_create_autocmd({ 'TabNew', 'TabClosed' }, {
  group = lualine_tmp,
  callback = function()
    if vim.fn.tabpagenr('$') == 1 then
      require('lualine').hide({place = {'tabline'}})
    else
      require('lualine').hide({place = {'tabline'}, unhide = true})
    end
  end,
})

Place this right after require('lualine').setup{ ... }

@milanglacier
Copy link
Contributor Author

In the meantime you can use this snippet until this PR is merged:

require('lualine').hide({place = {'tabline'}})
local lualine_tmp = vim.api.nvim_create_augroup('lualine_tmp', { clear = true })
vim.api.nvim_create_autocmd({ 'TabNew', 'TabClosed' }, {
  group = lualine_tmp,
  callback = function()
    if vim.fn.tabpagenr('$') == 1 then
      require('lualine').hide({place = {'tabline'}})
    else
      require('lualine').hide({place = {'tabline'}, unhide = true})
    end
  end,
})

Place this right after require('lualine').setup{ ... }

Actually, this snippet doesn't work, because when lualine.hide is called, the showtabline will still be 2, so the effect of lualine.hide is simply that lualine will not try to decorate the tabline and the tabline will fallback to the default appearance.

Here is my workaround way to make showtabline always be 1:

        tabline = {
            lualine_a = {
                { 'filetype', icon_only = true },
            },
            lualine_b = {
                { 'tabs', mode = 2, max_length = vim.o.columns },
                {
                    function()
                        vim.o.showtabline = 1
                        return ''
                        --HACK: lualine will set &showtabline to 2 if you have configured
                        --lualine for displaying tabline. We want to restore the default
                        --behavior here.
                    end,
                },
            },
        },

It might be expensive to constantly call vim.o.showtabline = 1 but I absolutely don't feel any latency caused by this call at all... So I am satisfied with this workaround.

@deponian
Copy link

Actually, this snippet doesn't work, because when lualine.hide is called, the showtabline will still be 2, so the effect of lualine.hide is simply that lualine will not try to decorate the tabline and the tabline will fallback to the default appearance.

You are not quite right. hide() restores previous setting for tabline and showtabline options. See here:

modules.nvim_opts.restore('tabline', { global = true })
modules.nvim_opts.restore('showtabline', { global = true })

So if you have showtabline=1 (which is default) then my snippet is correct.

@masterbloxx
Copy link

what’s the status of this?

@milanglacier
Copy link
Contributor Author

what’s the status of this?

I hope it can be merged ASAP, or at least get some feedback.

Since all the tests (except for those which are resulted in CI bugs) have passed.

So currently I have to use my own workaround to bypass it.

@milanglacier
Copy link
Contributor Author

Any updates on this?

README.md Outdated Show resolved Hide resolved
@shadmansaleh shadmansaleh merged commit 2563fa4 into nvim-lualine:master Nov 1, 2024
5 checks passed
@shadmansaleh
Copy link
Member

lgtm. Thanks. Also sorry for the late reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants