function plugin_config:bufferline()
local tab_group = {}
local tabpagenr = vim.fn['tabpagenr'];
local bufnr = vim.fn['bufnr']
local buflisted = vim.fn['buflisted']
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = '*',
callback = function ()
local tabId = tabpagenr()
local buf = bufnr()
if tab_group[tabId] then
for _, v in ipairs(tab_group[tabId]) do
if v == buf then
return
end
end
table.insert(tab_group[tabId], buf)
else
tab_group[tabId] = { buf }
end
end
})
vim.api.nvim_create_autocmd({ "BufDelete" }, {
pattern = '*',
callback = function ()
local tabId = tabpagenr()
if tab_group[tabId] then
local new_tab_group = {}
for k, tab_list in ipairs(tab_group) do
local list = {}
for _, v in ipairs(tab_list) do
if buflisted(v) > 0 then
table.insert(list, v)
end
end
if #list ~= 0 then
new_tab_group[k] = list
end
end
tab_group = new_tab_group
end
end
})
require('bufferline').setup{
options = {
enforce_regular_tabs = false,
diagnostics = "coc",
diagnostics_update_in_insert = true,
diagnostics_indicator = function(count, level)
local icon = level:match("error") and " " or " "
return " " .. icon .. count
end,
numbers = function(opts)
return string.format(' %s/%s', vim.fn['tabpagenr'](), opts.ordinal)
end,
offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
text_align = "left"
},
{
filetype = "coc-explorer",
text = function()
return vim.fn.getcwd()
end,
highlight = "Directory",
text_align = "left"
},
{
filetype = 'vista',
text = function()
return vim.fn.getcwd()
end,
highlight = "Tags",
text_align = "right"
}
},
separator_style = "slant",
custom_filter = function (buf_number)
if string.match(vim.fn['bufname'](buf_number), "^term://") then
return false
end
local tabId = tabpagenr()
if tab_group[tabId] then
for _, p in ipairs(tab_group[tabId]) do
if p == buf_number then
return true
end
end
end
return false
end
}
};
end