fix tabufline crash when formatting buf | (#1265)

This commit is contained in:
siduck 2022-06-26 06:24:52 +05:30
parent 876295ec02
commit 62b9c09f44
6 changed files with 35 additions and 22 deletions

View file

@ -39,7 +39,7 @@ autocmd("BufEnter", {
vim.t.bufs = vim.api.nvim_list_bufs()
-- thx to https://github.com/ii14 & stores buffer per tab -> table
autocmd({ "BufAdd" }, {
autocmd("BufAdd", {
callback = function(args)
if vim.t.bufs == nil then
vim.t.bufs = { args.buf }
@ -76,5 +76,5 @@ if require("core.utils").load_config().ui.tabufline_lazyloaded then
require("core.lazy_load").tabufline()
else
vim.opt.showtabline = 2
vim.opt.tabline = "%!v:lua.require('ui.tabline').run()"
vim.opt.tabline = "%!v:lua.require'ui.tabline'.run()"
end

View file

@ -114,7 +114,7 @@ M.tabufline = function()
callback = function()
if #vim.fn.getbufinfo { buflisted = 1 } >= 2 then
vim.opt.showtabline = 2
vim.opt.tabline = "%!v:lua.require('ui.tabline').run()"
vim.opt.tabline = "%!v:lua.require'ui.tabline'.run()"
vim.api.nvim_del_augroup_by_name "TabuflineLazyLoad"
end
end,

View file

@ -195,8 +195,20 @@ M.packer_sync = function(...)
end
end
M.bufilter = function()
local bufs = vim.t.bufs
for i = #bufs, 1, -1 do
if not vim.api.nvim_buf_is_loaded(bufs[i]) then
table.remove(bufs, i)
end
end
return bufs
end
M.tabuflineNext = function()
local bufs = vim.t.bufs or {}
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
@ -207,7 +219,7 @@ M.tabuflineNext = function()
end
M.tabuflinePrev = function()
local bufs = vim.t.bufs or {}
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then