fix tabufline crash when formatting buf | (#1265)
This commit is contained in:
parent
876295ec02
commit
62b9c09f44
6
init.lua
6
init.lua
|
@ -9,8 +9,4 @@ end, 0)
|
|||
require("core.packer").bootstrap()
|
||||
require "plugins"
|
||||
|
||||
local user_conf, _ = pcall(require, "custom")
|
||||
|
||||
if user_conf then
|
||||
require "custom"
|
||||
end
|
||||
pcall(require, "custom")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,6 +9,7 @@ require("base46").load_highlight "nvimtree"
|
|||
local options = {
|
||||
filters = {
|
||||
dotfiles = false,
|
||||
exclude = { vim.fn.stdpath "config" .. "/lua/custom" },
|
||||
},
|
||||
disable_netrw = true,
|
||||
hijack_netrw = true,
|
||||
|
|
|
@ -74,7 +74,9 @@ local function bufferlist()
|
|||
local buffers = ""
|
||||
|
||||
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 name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t")
|
||||
or " No Name "
|
||||
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
||||
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
||||
|
||||
|
@ -83,12 +85,14 @@ local function bufferlist()
|
|||
close_btn = (vim.bo[0].modified and "%#TbLineBufOnModified# ") or ("%#TbLineBufOnClose#" .. close_btn)
|
||||
name = "%#TbLineBufOn#" .. name .. close_btn
|
||||
else
|
||||
close_btn = (vim.bo[nr].modified and "%#TbBufLineBufOffModified# ") or ("%#TbLineBufOffClose#" .. close_btn)
|
||||
close_btn = (vim.bo[nr].modified and "%#TbBufLineBufOffModified# ")
|
||||
or ("%#TbLineBufOffClose#" .. close_btn)
|
||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||
end
|
||||
|
||||
buffers = buffers .. name
|
||||
end
|
||||
end
|
||||
|
||||
return buffers .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue