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

Add a "more buffers" indicator + option to customize the tabpage section #1539

Open
2 tasks done
Dupond opened this issue Jan 30, 2025 · 14 comments
Open
2 tasks done
Labels
feature-request Request for a feature to existing module mini.tabline

Comments

@Dupond
Copy link

Dupond commented Jan 30, 2025

Contributing guidelines

Module(s)

mini.tabline

Description

First of all, thank you very much for those great plugins!

  • In mini.tabline, the tabpage section is formatted as follows: Tab #/#. It would be nice if it could be customized, or if it could simply be formatted as #/# to have more space for the buffer names.
  • For the moment, it's impossible to know whether other buffers are open or not: there's no indicator in the tabline showing whether other buffers exist. It would be nice if < and > were displayed on the left and/or the right of the tabbar when other names exist on the left or on the right of the visible buffer names. That's what is used for example in the Vem Tabline plugin.
  • Furthermore, I find the * sign displayed when an unnamed buffer is opened quite confusing: it's barely visible when you have many opened buffers; so an option to customize the name of an "unnamed buffer" would be great. For example [ No Name ] would be much more easier to see in the tabline.

Thank you very much!

@Dupond Dupond added the feature-request Request for a feature to existing module label Jan 30, 2025
@echasnovski
Copy link
Owner

Thanks for the suggestions!

'mini.tabline' is one of those modules which I'd like to keep with as minimal config as possible. With that in mind:

  • In mini.tabline, the tabpage section is formatted as follows: Tab #/#. It would be nice if it could be customized, or if it could simply be formatted as #/# to have more space for the buffer names.

I initially thought about that, but 4 extra cells doesn't look like a huge issue. Certainly not worth adding a new config entry for.

  • For the moment, it's impossible to know whether other buffers are open or not: there's no indicator in the tabline showing whether other buffers exist. It would be nice if < and > were displayed on the left and/or the right of the tabbar when other names exist on the left or on the right of the visible buffer names. That's what is used for example in the Vem Tabline plugin.

I also thought about doing that, but it seems a bit redundant. It is usually inferrable from the tabline content based on some visual clues:

  • If there is space highlighted with MiniTablineFillto the right - visible buffers buffers show all listed buffers.
  • If current buffer's tab is visibly in the left/right half, then probably there are no buffers to the left/right of the most left/right visible one. There are probably buffers to the right/left, though.

That said, I think it would be interesting to see if reusing extends and precedes entries of 'listchars' option makes it visually better. This way no extra config is needed and there is a nice visual system. I'll take a look later.

  • Furthermore, I find the * sign displayed when an unnamed buffer is opened quite confusing: it's barely visible when you have many opened buffers; so an option to customize the name of an "unnamed buffer" would be great. For example [ No Name ] would be much more easier to see in the tabline.

You can use config.format to override it the way you want. Beware, that there is not only * (which is for a regular unnamed buffer), but also ! for an unnamed scratch buffer.

@Dupond
Copy link
Author

Dupond commented Jan 30, 2025

I initially thought about that, but 4 extra cells doesn't look like a huge issue. Certainly not worth adding a new config entry for.

There's also that "Tab" is an English word... It's "Onglet" in french :) But, well, I understand it's not in your goals... Without adding an option, I think a simple #/# format (without the "Tab" word) would still be better.

That said, I think it would be interesting to see if reusing extends and precedes entries of 'listchars' option makes it visually better. This way no extra config is needed and there is a nice visual system.

Is there something I could read so that I can understand what you mean? Thanks!

You can use config.format to override it the way you want. Beware, that there is not only * (which is for a regular unnamed buffer), but also ! for an unnamed scratch buffer.

OK, I've spent an hour trying to adapt the code in your link, but it doesn't work. Here's what I have now in my init.vim:

lua << EOF
require('mini.tabline').setup({
  show_icons = false,
  format = function(buf_id, label)
    if vim.bo[buf_id].buftype == 'nofile' or vim.bo[buf_id].buftype == 'scratch' then
      label = '[ No_name ]'
    end
    return label
  end,
  tabpage_section = 'right',
})
EOF

The tabpage_section and show_icons parameters are taken into account, but my format function is wrong and seems to do nothing. Could you help me?

Thank you very much for your help!

@echasnovski
Copy link
Owner

That said, I think it would be interesting to see if reusing extends and precedes entries of 'listchars' option makes it visually better. This way no extra config is needed and there is a nice visual system.

Is there something I could read so that I can understand what you mean? Thanks!

The :h 'listchars'. But it was more of a note to self for the future. There will be a better explanation in help if/when this feature is implemented.

OK, I've spent an hour trying to adapt the code in your link, but it doesn't work. Here's what I have now in my init.vim:
...
The tabpage_section and show_icons parameters are taken into account, but my format function is wrong and seems to do nothing. Could you help me?

Not sure why format is doing nothing for you. Using this exact setup works as expected and format modifies tab labels. Here is something that is a bit neater (and is to the point as there is no need in using icons):

require('mini.tabline').setup({
  format = function(buf_id, label)
    local buftype = vim.bo[buf_id].buftype
    if buftype == 'nofile' or buftype == 'acwrite' then return ' [No_name] ' end
    return ' ' .. label .. ' '
  end,
  tabpage_section = 'right',
})

@Dupond
Copy link
Author

Dupond commented Jan 30, 2025

Well, I thank you very much for your help and for your time, but it doesn't work either. Your code doesn't work for me, the name of the empty buffer is still * when I simply open nvim.

@krovuxdev
Copy link

Well, I thank you very much for your help and for your time, but it doesn't work either. Your code doesn't work for me, the name of the empty buffer is still * when I simply open nvim.

@Dupond Did you mean this?

vim.api.nvim_create_autocmd({ "BufAdd", "BufEnter" }, {
    callback = function(args)
        if vim.bo[args.buf].buftype == "" and vim.api.nvim_buf_get_name(args.buf) == "" then
            vim.bo[args.buf].buflisted = false
        end
    end,
})

@Dupond
Copy link
Author

Dupond commented Jan 30, 2025

@krovuxdev Sorry, I don't understand your answer.

local buftype = vim.bo[buf_id].buftypev

I've added the following line to try to debug: print("Buffer ID:", buf_id, "BufType:", vim.bo[buf_id].buftype)

It turns out that vim.bo[buf_id].buftype is always empty, even when I open a new file (e.g. :e my_test_file.sh)

I've tested with the following minimal init.vim:

if empty(glob('~/.config/nvim/autoload/plug.vim'))
    silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

call plug#begin('~/.config/nvim/bundle')
    Plug 'https://github.com/echasnovski/mini.tabline'
call plug#end()

lua << EOF
require('mini.tabline').setup({
  format = function(buf_id, label)
    print("Buffer ID:", buf_id, "BufType:", vim.bo[buf_id].buftype)
    if vim.bo[buf_id].buftype == 'nofile' or vim.bo[buf_id].buftype == 'acwrite' then
      return '[ No_name ]' end
    return ' ' .. label .. ' '
  end,
  tabpage_section = 'right',
})
EOF

It displays: Buffer ID: 1 BufType:

I use Neovim in ArchLinux:

$ nvim -v
NVIM v0.10.4
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260

@krovuxdev
Copy link

Sorry, I don't understand your answer.

@Dupond, I think you said something like, "The name of the empty buffer is still * when I simply open nvim."
When you open Neovim, does an empty buffer appear with a *? I provided the code as a solution? are you referring to this?

@krovuxdev
Copy link

Or this might also work for you:

require('mini.tabline').setup({
  format = function(buf_id, label)
    if vim.bo[buf_id].buftype == "" then
      return '[ No_name ]'
    end
    -- your other code
  end
})

@Dupond
Copy link
Author

Dupond commented Jan 31, 2025

this might also work for you:

No, it doesn't:

It turns out that vim.bo[buf_id].buftype is always empty, even when I open a new file

@echasnovski
Copy link
Owner

Your code doesn't work for me, the name of the empty buffer is still * when I simply open nvim.

Yes, this is because the initial buffer is a regular buffer (i.e. with empty string as 'buftype'). For the unnamed regular buffer 'mini.tabline' shows * with number suffix, as was said in the first comment. The code from the second comment was a reply to the previous "... but my format function is wrong and seems to do nothing.", which is not the case as it did something. Just not what you expected it to do, evidently.

If you want to show [No name] for any buffer that doesn't have a name, then format should do exactly that. Like this:

require('mini.tabline').setup({
  format = function(buf_id, label)
    if vim.api.nvim_buf_get_name(buf_id) == '' then return ' [No_name] ' end
    return ' ' .. label .. ' '
  end,
  tabpage_section = 'right',
})

For a more customized labels for unnamed buffers (like scratch and quickfix buffers, for example), you can check vim.bo[buf_id].buftype (see :h 'buftype' for possible values).

@Dupond
Copy link
Author

Dupond commented Feb 8, 2025

OK, thank you for your answer! Is it possible to combine this with the code in https://github.com/echasnovski/mini.tabline/blob/main/doc/mini-tabline.txt to add a + suffix for modified buffers? I mean this code:

function(buf_id, label)
    local suffix = vim.bo[buf_id].modified and '+ ' or ''
    return MiniTabline.default_format(buf_id, label) .. suffix
end

I initially thought about that, but 4 extra cells doesn't look like a huge issue. Certainly not worth adding a new config entry for.

That's not what I meant, but I think I've edited my answer too late for you to be able to see it:

There's also that "Tab" is an English word... It's "Onglet" in french :) But, well, I understand it's not in your goals... Without adding an option, I think a simple #/# format (without the "Tab" word) would still be better.

@echasnovski
Copy link
Owner

OK, thank you for your answer! Is it possible to combine this with the code in https://github.com/echasnovski/mini.tabline/blob/main/doc/mini-tabline.txt to add a + suffix for modified buffers? I mean this code:

Yes, it is possible. Replace the return statement with the code from the help page. Or just compute the suffix and append it manually.

That's not what I meant, but I think I've edited my answer too late for you to be able to see it:

There's also that "Tab" is an English word... It's "Onglet" in french :) But, well, I understand it's not in your goals... Without adding an option, I think a simple #/# format (without the "Tab" word) would still be better.

Yes, I've read that. I don't think the plain x/y format is informative enough. I didn't take into account different languages, though. Mostly because "Tab" is a shorter version of what is used in the built-in help for "tabpage", so this should be universal enough name.

@Dupond
Copy link
Author

Dupond commented Feb 8, 2025

Sorry, I don't know how to code :( Would it be:

return ' ' .. label .. suffix .. ' '

or:

return ' ' .. MiniTabline.default_format(buf_id, label) .. suffix .. ' '

And should I edit this line:

if vim.api.nvim_buf_get_name(buf_id) == '' then return ' [No_name] ' end

Maybe:

if vim.api.nvim_buf_get_name(buf_id) == '' then return ' [No_name] ' .. suffix end

Mostly because "Tab" is a shorter version of what is used in the built-in help for "tabpage", so this should be universal enough name.

OK I find it confusing, but you're the developer :)

@echasnovski
Copy link
Owner

Sorry, I don't know how to code :(

My genuine suggestion would be to have at least the basic understanding of Lua language and programming. I think Learn X in Y minutes for Lua is generally enough for basic understanding. There are also built-in resources for that: :h lua-concepts and :h lua-guide are oriented towards new users.

Without that basic understanding I am afraid there will be much less joy for you in using modern Neovim in general (not only customizing 'mini.nvim').

Would it be:

It would be something like this:

require('mini.tabline').setup({
  format = function(buf_id, label)
    if vim.api.nvim_buf_get_name(buf_id) == '' then return ' [No_name] ' end
    local suffix = vim.bo[buf_id].modified and '+ ' or ''
    return ' ' .. label .. ' ' .. suffix
  end,
  tabpage_section = 'right',
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.tabline
Projects
None yet
Development

No branches or pull requests

3 participants