Don't use autocmd's to select active/inactive statusline
This commit is contained in:
@@ -162,25 +162,14 @@ function _G.statusline_inactive()
|
|||||||
return line
|
return line
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Setup autocmds to set the statusline per buffer.
|
-- Pick the active or inactive variant for the window currently being drawn.
|
||||||
local group = vim.api.nvim_create_augroup('statusline', { clear = true })
|
function _G.statusline_render()
|
||||||
-- Dynamically update the current buffer mode and color changes using %! to
|
if vim.api.nvim_get_current_win() == tonumber(vim.g.actual_curwin or '-1') then
|
||||||
-- call a function which is always evaluated on statusline update.
|
return _G.statusline_active()
|
||||||
vim.api.nvim_create_autocmd({ 'BufEnter', 'WinEnter', 'BufWinEnter' }, {
|
end
|
||||||
pattern = '*',
|
return _G.statusline_inactive()
|
||||||
group = group,
|
|
||||||
callback = function()
|
|
||||||
vim.cmd.setlocal("statusline=%{%v:lua.statusline_active()%}")
|
|
||||||
end
|
end
|
||||||
})
|
|
||||||
|
|
||||||
-- Statically set the statusline when leaving the buffer.
|
vim.o.statusline = '%{%v:lua.statusline_render()%}'
|
||||||
vim.api.nvim_create_autocmd({ 'BufLeave', 'WinLeave' }, {
|
|
||||||
pattern = '*',
|
|
||||||
group = group,
|
|
||||||
callback = function()
|
|
||||||
vim.cmd.setlocal("statusline=%{%v:lua.statusline_inactive()%}")
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
return statusline
|
return statusline
|
||||||
|
|||||||
Reference in New Issue
Block a user