akinsho / bufferline.nvim

A snazzy bufferline for Neovim
GNU General Public License v3.0
3.46k stars 195 forks source link

feat(ui): pass formatter opts to icon fetcher as well #944

Open ofseed opened 2 months ago

ofseed commented 2 months ago

When a user customized the name by name_formatter, they would customize the icon too. I think it should be better to make them have the same arguments, but considering changing the arguments would be a breaking change, I recommend adding all the name_formatter properties to get_element_icon.

In my usage, I use the tab mode of bufferline, I don't want bufferline to show the name of buffers which has a special buftype when there is a normal buffer that exists in the tabpage.

akinsho commented 2 months ago

Hi @ofseed,

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

ofseed commented 2 months ago

When using tab mode, there's buffers in name_formatter, but there's no equivalent for get_element_icon. We can only get information about the currently active buffer

ofseed commented 2 months ago

My usage:

mode = "tabs",
name_formatter = function(args)
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
      end
    end
  end
end,
get_element_icon = function(args)
  local loaded, devicons = pcall(require, "nvim-web-devicons")
  if not loaded then
    return ""
  end
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return devicons.get_icon(
          vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t"),
          nil,
          { default = true }
        )
      end
    end
  end
end,
ofseed commented 2 months ago

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

@akinsho I mean they should be able to, because there's no extra information like buffers opened in the tab in current API, we chan only get current active file's filetype for path, even cannot get it's bufnr

ofseed commented 2 months ago

@akinsho I have already provided explanations for your questions. Could you please review them again?

akinsho commented 2 months ago

@ofseed this will have to wait till I have free time

ofseed commented 2 months ago

I just wanted to avoid the message getting lost in the notifications. Thank you.