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

@ -9,8 +9,4 @@ end, 0)
require("core.packer").bootstrap() require("core.packer").bootstrap()
require "plugins" require "plugins"
local user_conf, _ = pcall(require, "custom") pcall(require, "custom")
if user_conf then
require "custom"
end

View file

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

View file

@ -114,7 +114,7 @@ M.tabufline = function()
callback = function() callback = function()
if #vim.fn.getbufinfo { buflisted = 1 } >= 2 then if #vim.fn.getbufinfo { buflisted = 1 } >= 2 then
vim.opt.showtabline = 2 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" vim.api.nvim_del_augroup_by_name "TabuflineLazyLoad"
end end
end, end,

View file

@ -195,8 +195,20 @@ M.packer_sync = function(...)
end end
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() M.tabuflineNext = function()
local bufs = vim.t.bufs or {} local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then if api.nvim_get_current_buf() == v then
@ -207,7 +219,7 @@ M.tabuflineNext = function()
end end
M.tabuflinePrev = function() M.tabuflinePrev = function()
local bufs = vim.t.bufs or {} local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then if api.nvim_get_current_buf() == v then

View file

@ -9,6 +9,7 @@ require("base46").load_highlight "nvimtree"
local options = { local options = {
filters = { filters = {
dotfiles = false, dotfiles = false,
exclude = { vim.fn.stdpath "config" .. "/lua/custom" },
}, },
disable_netrw = true, disable_netrw = true,
hijack_netrw = true, hijack_netrw = true,

View file

@ -74,20 +74,24 @@ local function bufferlist()
local buffers = "" local buffers = ""
for _, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr for _, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t") or " No Name " if api.nvim_buf_is_loaded(nr) then
local close_btn = "%" .. nr .. "@TbKillBuf@ %X" local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t")
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X" or " No Name "
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
-- color close btn for focused / hidden buffers -- color close btn for focused / hidden buffers
if nr == api.nvim_get_current_buf() then if nr == api.nvim_get_current_buf() then
close_btn = (vim.bo[0].modified and "%#TbLineBufOnModified# ") or ("%#TbLineBufOnClose#" .. close_btn) close_btn = (vim.bo[0].modified and "%#TbLineBufOnModified# ") or ("%#TbLineBufOnClose#" .. close_btn)
name = "%#TbLineBufOn#" .. name .. close_btn name = "%#TbLineBufOn#" .. name .. close_btn
else else
close_btn = (vim.bo[nr].modified and "%#TbBufLineBufOffModified# ") or ("%#TbLineBufOffClose#" .. close_btn) close_btn = (vim.bo[nr].modified and "%#TbBufLineBufOffModified# ")
name = "%#TbLineBufOff#" .. name .. close_btn or ("%#TbLineBufOffClose#" .. close_btn)
name = "%#TbLineBufOff#" .. name .. close_btn
end
buffers = buffers .. name
end end
buffers = buffers .. name
end end
return buffers .. "%#TblineFill#" .. "%=" -- buffers + empty space return buffers .. "%#TblineFill#" .. "%=" -- buffers + empty space