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

Bug: showtabline is affected by seemingly irrelevant options #1294

Closed
2 tasks done
neeshy opened this issue Aug 18, 2024 · 8 comments
Closed
2 tasks done

Bug: showtabline is affected by seemingly irrelevant options #1294

neeshy opened this issue Aug 18, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@neeshy
Copy link

neeshy commented Aug 18, 2024

Self Checks

  • I'm using the latest lualine.
  • I didn't find the issue in existing issues or PRs.

How to reproduce the problem

I have a configuration that conditionally shows the tabline based on the number of open buffers. This is accomplished with auto commands that set the showtabline option. I would prefer to use lualine's builtin cond option, but even when no conditions are satisfied on any tabline segments, the tabline itself doesn't become hidden.

I noticed that the value of background will influence the behavior of the tabline on startup. If background is set to dark, showtabline will eventually be set to 2. This is despite showtabline being set to 1 after lualine's setup and through the end of the configuration.

Expected behaviour

The value of background shouldn't affect showtabline.

Actual behaviour

When background=light, showtabline isn't modified. If background=dark (the default), sometime after startup showtabline=2.

Minimal config to reproduce the issue

vim.opt.showtabline = 1 -- default
vim.opt.background = 'light' -- commenting this out will cause showtabline to be set to '2' sometime after startup

require('lualine').setup {
  tabline = {
    lualine_a = { { 'buffers' } },
  },
}

-- Don't allow lualine to modify 'showtabline'. From this point on it should be set to 1.
require('lualine.utils.nvim_opts').restore('showtabline', { global = true })

-- This should print '1' irrespective of the value of vim.opt.background
print(vim.opt.showtabline:get())
@neeshy neeshy added the bug Something isn't working label Aug 18, 2024
@ferdinandrau
Copy link

This is really annoying. While it makes sense for the plugin to modify showtabline initially to always show the tabline, it should respect the option being set back to 1. The PR #1013 solves this, but is being ignored.

@neeshy
Copy link
Author

neeshy commented Sep 23, 2024

Removing the following autocmds:

vim.cmd([[autocmd lualine ColorScheme * lua require'lualine'.setup()
autocmd lualine OptionSet background lua require'lualine'.setup()]])

fixes the issue for me.

vim.cmd.autocmd { 'lualine ColorScheme', bang = true }
vim.cmd.autocmd { 'lualine OptionSet background', bang = true }

@shadmansaleh
Copy link
Member

fixed with #1013

use always_show_tabline = false in config.

@neeshy
Copy link
Author

neeshy commented Nov 20, 2024

@shadmansaleh
#1013 Doesn't entirely work, since it sets showtabline to 1 when always_show_tabline is false no matter the state of tabline segments. Basically, if you have a tabline configuration with a buffers segment, and multiple buffers open but only a single tab, having always_show_tabline = false will currently result in a hidden tabline.

Ideally, when always_show_tabline is false it would determine if there are any visible tabline segments (based on cond) and set showtabline appropriately.

@neeshy
Copy link
Author

neeshy commented Nov 20, 2024

A workaround is to set showtabline within a relevant cond function:

require('lualine').setup {
  tabline = {
    lualine_a = {
      {
        'buffers',
        cond = function()
          local cond = #vim.fn.getbufinfo { buflisted = 1 } > 1
          vim.opt.showtabline = cond and 2 or 1
          return cond
        end,
      },
    },
  },
}

@neeshy
Copy link
Author

neeshy commented Dec 2, 2024

WTF, #1294 (comment) triggers this bug: #1141

@neeshy
Copy link
Author

neeshy commented Dec 2, 2024

I guess you could do something like this:

require('lualine').setup {
  tabline = {
    lualine_a = {
      {
        'buffers',
        cond = function()
          if #vim.fn.getbufinfo { buflisted = 1 } > 1 then
            if vim.opt.showtabline:get() ~= 2 then
              vim.opt.showtabline = 2
            end
            return true
          else
            if vim.opt.showtabline:get() ~= 1 then
              vim.opt.showtabline = 1
            end
            return false
          end
        end,
      },
    },
  },
}

But the solution in #1294 (comment) works fine at least on commit e9b935c (I haven't done a full bisect).

@neeshy
Copy link
Author

neeshy commented Dec 2, 2024

@shadmansaleh
In light of #1294 (comment) can you reopen this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants