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