From cb17aecf83c5b8dfc5168ef768a541f9817f989f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 10 Jun 2024 18:49:45 +0800 Subject: [PATCH] fix(statusline): fix display current tag --- autoload/SpaceVim/autocmds.vim | 1 + lua/spacevim/plugin/statusline.lua | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim index 591bd69a9..a6b4742e5 100644 --- a/autoload/SpaceVim/autocmds.vim +++ b/autoload/SpaceVim/autocmds.vim @@ -59,6 +59,7 @@ if has('nvim-0.10.0') endtry call SpaceVim#logger#info('finished loading local conf') endif + let g:_spacevim_after_vimenter = 1 endfunction function! SpaceVim#autocmds#init() abort lua require('spacevim.autocmds').init() diff --git a/lua/spacevim/plugin/statusline.lua b/lua/spacevim/plugin/statusline.lua index 5475a8c53..d581fb138 100644 --- a/lua/spacevim/plugin/statusline.lua +++ b/lua/spacevim/plugin/statusline.lua @@ -283,10 +283,23 @@ local function check_mode() end local function current_tag() - return M._current_tag() + return '%{ v:lua.require("spacevim.plugin.statusline")._current_tag() }' end -function M._current_tag() end +function M._current_tag() + + local tag = '' + pcall(function() + -- current tag should be show only after vimenter + -- @fixme this make sure tagbar has been loaded + -- because when first run tagbar, it needs long time. + -- and also there no syntax highlight when first time open file. + if vim.g._spacevim_after_vimenter == 1 and vim.g.spacevim_enable_statusline_tag == 1 and vim.g.loaded_tagbar == 1 then + tag = vim.fn['tagbar#currenttag']('%s ', '') + end + end) + return tag +end local function active() local lsec = {} @@ -324,7 +337,7 @@ local function active() end end local fname = buffer_name() - local tab = current_tag() + local tag = current_tag() local winwidth = vim.fn.winwidth(vim.fn.winnr()) if vim.o.laststatus == 3 then winwidth = vim.o.columns @@ -335,7 +348,7 @@ local function active() lsep, rsep, fname, - tab, + tag, 'SpaceVim_statusline_a', 'SpaceVim_statusline_b', 'SpaceVim_statusline_c',