Skip to content

Commit

Permalink
Merge branch 'nvim-lualine:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cartercanedy authored Dec 20, 2024
2 parents aa8f68b + 2a5bae9 commit ef759fa
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 85 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ require('lualine').setup {
},
ignore_focus = {},
always_divide_middle = true,
always_show_tabline = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
statusline = 100,
tabline = 100,
winbar = 100,
}
},
sections = {
Expand Down Expand Up @@ -378,14 +379,18 @@ options = {
-- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present.

always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
-- then tabline will always show. If set to false, then tabline will be displayed
-- only when there are more than 1 tab. (see :h showtabline)

globalstatus = false, -- enable global statusline (have a single statusline
-- at bottom of neovim instead of one for every window).
-- This feature is only available in neovim 0.7 and higher.

refresh = { -- sets how often lualine should refresh it's contents (in ms)
statusline = 1000, -- The refresh option sets minimum time that lualine tries
tabline = 1000, -- to maintain between refresh. It's not guarantied if situation
winbar = 1000 -- arises that lualine needs to refresh itself before this time
statusline = 100, -- The refresh option sets minimum time that lualine tries
tabline = 100, -- to maintain between refresh. It's not guarantied if situation
winbar = 100 -- arises that lualine needs to refresh itself before this time
-- it'll do it.

-- Also you can force lualine's refresh by calling refresh function
Expand Down
17 changes: 11 additions & 6 deletions doc/lualine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ For more information, check out `:help lua-heredoc`.
},
ignore_focus = {},
always_divide_middle = true,
always_show_tabline = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
statusline = 100,
tabline = 100,
winbar = 100,
}
},
sections = {
Expand Down Expand Up @@ -393,14 +394,18 @@ in component.
-- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present.
always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
-- then tabline will always show. If set to false, then tabline will be displayed
-- only when there are more than 1 tab. (see :h showtabline)
globalstatus = false, -- enable global statusline (have a single statusline
-- at bottom of neovim instead of one for every window).
-- This feature is only available in neovim 0.7 and higher.
refresh = { -- sets how often lualine should refresh it's contents (in ms)
statusline = 1000, -- The refresh option sets minimum time that lualine tries
tabline = 1000, -- to maintain between refresh. It's not guarantied if situation
winbar = 1000 -- arises that lualine needs to refresh itself before this time
statusline = 100, -- The refresh option sets minimum time that lualine tries
tabline = 100, -- to maintain between refresh. It's not guarantied if situation
winbar = 100 -- arises that lualine needs to refresh itself before this time
-- it'll do it.
-- Also you can force lualine's refresh by calling refresh function
Expand Down
4 changes: 2 additions & 2 deletions examples/evil_lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ ins_left {
-- Lsp server name .
function()
local msg = 'No Active Lsp'
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 })
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
Expand Down
83 changes: 21 additions & 62 deletions lua/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ local timers = {
local last_focus = {}
local refresh_real_curwin

-- The events on which lualine redraws itself
local default_refresh_events =
'WinEnter,BufEnter,BufWritePost,SessionLoadPost,FileChangedShellPost,VimResized,Filetype,CursorMoved,CursorMovedI,ModeChanged'
-- Helper for apply_transitional_separators()
--- finds first applied highlight group after str_checked in status
---@param status string : unprocessed statusline string
Expand Down Expand Up @@ -312,7 +309,7 @@ end
---@class LualineRefreshOpts
---@field scope LualineRefreshOptsKind
---@field place LualineRefreshOptsPlace[]
---@field trigger 'autocmd'|'autocmd_redired'|'timer'|'unknown'
---@field trigger 'timer' | 'init' |'unknown'
--- Refresh contents of lualine
---@param opts LualineRefreshOpts
local function refresh(opts)
Expand All @@ -325,36 +322,6 @@ local function refresh(opts)
trigger = 'unknown',
})

-- updating statusline in autocommands context seems to trigger 100 different bugs
-- lets just defer it to a timer context and update there
-- Since updating stl in command mode doesn't take effect
-- refresh ModeChanged command in autocmd context as exception.
-- workaround for
-- https://github.com/neovim/neovim/issues/15300
-- https://github.com/neovim/neovim/issues/19464
-- https://github.com/nvim-lualine/lualine.nvim/issues/753
-- https://github.com/nvim-lualine/lualine.nvim/issues/751
-- https://github.com/nvim-lualine/lualine.nvim/issues/755
-- https://github.com/neovim/neovim/issues/19472
-- https://github.com/nvim-lualine/lualine.nvim/issues/791
if
opts.trigger == 'autocmd'
and vim.v.event.new_mode ~= 'c'
-- scheduling in op-pending mode seems to call the callback forever.
-- so this is restricted in op-pending mode.
-- https://github.com/neovim/neovim/issues/22263
-- https://github.com/nvim-lualine/lualine.nvim/issues/967
-- note this breaks mode component while switching to op-pending mode
and not vim.tbl_contains({ 'no', 'nov', 'noV' }, vim.v.event.new_mode)
and not vim.tbl_contains({ 'no', 'nov', 'noV' }, vim.v.event.old_mode)
then
opts.trigger = 'autocmd_redired'
vim.schedule(function()
M.refresh(opts)
end)
return
end

local wins = {}
local old_actual_curwin = vim.g.actual_curwin

Expand Down Expand Up @@ -463,7 +430,6 @@ end
local function set_tabline(hide)
vim.loop.timer_stop(timers.tal_timer)
timers.halt_tal_refresh = true
vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]])
if not hide and next(config.tabline) ~= nil then
vim.loop.timer_start(
timers.tal_timer,
Expand All @@ -473,14 +439,13 @@ local function set_tabline(hide)
refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
end, 3, 'lualine: Failed to refresh tabline')
)
modules.utils.define_autocmd(
default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['tabline'], 'trigger': 'autocmd'})",
'lualine_tal_refresh'
)
modules.nvim_opts.set('showtabline', 2, { global = true })
modules.nvim_opts.set('showtabline', config.options.always_show_tabline and 2 or 1, { global = true })
timers.halt_tal_refresh = false
vim.schedule(function()
-- imediately refresh upon load
-- schedule needed so stuff like filetype detect can run first
refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'init' }
end)
else
modules.nvim_opts.restore('tabline', { global = true })
modules.nvim_opts.restore('showtabline', { global = true })
Expand All @@ -493,7 +458,6 @@ end
local function set_statusline(hide)
vim.loop.timer_stop(timers.stl_timer)
timers.halt_stl_refresh = true
vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]])
if not hide and (next(config.sections) ~= nil or next(config.inactive_sections) ~= nil) then
if vim.go.statusline == '' then
modules.nvim_opts.set('statusline', '%#Normal#', { global = true })
Expand All @@ -508,12 +472,6 @@ local function set_statusline(hide)
refresh { kind = 'window', place = { 'statusline' }, trigger = 'timer' }
end, 3, 'lualine: Failed to refresh statusline')
)
modules.utils.define_autocmd(
default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'window', 'place': ['statusline'], 'trigger': 'autocmd'})",
'lualine_stl_refresh'
)
else
modules.nvim_opts.set('laststatus', 2, { global = true })
vim.loop.timer_start(
Expand All @@ -524,14 +482,17 @@ local function set_statusline(hide)
refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
end, 3, 'lualine: Failed to refresh statusline')
)
modules.utils.define_autocmd(
default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})",
'lualine_stl_refresh'
)
end
timers.halt_stl_refresh = false
vim.schedule(function()
-- imediately refresh upon load
-- schedule needed so stuff like filetype detect can run first
if config.options.globalstatus then
refresh { kind = 'window', place = { 'statusline' }, trigger = 'init' }
else
refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'init' }
end
end)
else
modules.nvim_opts.restore('statusline', { global = true })
for _, win in ipairs(vim.api.nvim_list_wins()) do
Expand All @@ -546,7 +507,6 @@ end
local function set_winbar(hide)
vim.loop.timer_stop(timers.wb_timer)
timers.halt_wb_refresh = true
vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]])
if not hide and (next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil) then
vim.loop.timer_start(
timers.wb_timer,
Expand All @@ -556,13 +516,12 @@ local function set_winbar(hide)
refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
end, 3, 'lualine: Failed to refresh winbar')
)
modules.utils.define_autocmd(
default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['winbar'], 'trigger': 'autocmd'})",
'lualine_wb_refresh'
)
timers.halt_wb_refresh = false
vim.schedule(function()
-- imediately refresh upon load.
-- schedule needed so stuff like filetype detect can run first
refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'init' }
end)
elseif vim.fn.has('nvim-0.8') == 1 then
modules.nvim_opts.restore('winbar', { global = true })
for _, win in ipairs(vim.api.nvim_list_wins()) do
Expand Down
7 changes: 4 additions & 3 deletions lua/lualine/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ local config = {
},
ignore_focus = {},
always_divide_middle = true,
always_show_tabline = true,
globalstatus = vim.go.laststatus == 3,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
statusline = 100,
tabline = 100,
winbar = 100,
},
},
sections = {
Expand Down
6 changes: 4 additions & 2 deletions lua/lualine/utils/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@ local function load_theme(theme_name)
end
local n_files = #files
if n_files == 0 then
-- No match found
error(path .. ' Not found')
-- No match found on runtimepath. Fall back to package.path
local file =
assert(package.searchpath('lualine.themes.' .. theme_name, package.path), 'Theme ' .. theme_name .. ' not found')
retval = dofile(file)
elseif n_files == 1 then
-- when only one is found run that and return it's return value
retval = dofile(files[1])
Expand Down
32 changes: 32 additions & 0 deletions lua/lualine/utils/nvim_opts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,33 @@ local function set_opt(name, val, getter_fn, setter_fn, cache_tbl)
if cache_tbl[name] == nil then
cache_tbl[name] = {}
end

if cache_tbl[name].set ~= cur then
if type(cur) ~= 'string' or not cur:find('lualine') then
cache_tbl[name].prev = cur
end
end
cache_tbl[name].set = val
setter_fn(name, val)

-- Mitigation for https://github.com/nvim-lualine/lualine.nvim/issues/1323
-- when redrawstatus is ran and winbar usues some eval syntax %{} for some
-- odd reason nvim renders the winbar in statusline first then actual statusline
-- replaces it. Also it doesn't happen on top window. Might be some bug in
-- neovims rendering. Also it doesn't seem to happend with laststatus=2 or
-- global status turned off in lualine. lualines rendering might be at fault
-- too. but we should never be evaluating an externally set winbar so that
-- doen't make much sense either.
-- Tested: nvim v0.9.5
-- TODO: Needs further investigation.
if vim.api.nvim_get_mode().mode == 'c' then
if name == 'statusline' or name == 'winbar' then
vim.cmd('redrawstatus')
end
if name == 'tabline' then
vim.cmd('redrawtabline')
end
end
end

-- set a option value
Expand All @@ -63,17 +83,29 @@ function M.set(name, val, opts)
options.buffer[opts.buffer] = {}
end
set_opt(name, val, function(nm)
if not vim.tbl_contains(vim.api.nvim_list_bufs(), opts.buffer) then
return nil
end
return vim.api.nvim_buf_get_option(opts.buffer, nm)
end, function(nm, vl)
if not vim.tbl_contains(vim.api.nvim_list_bufs(), opts.buffer) then
return nil
end
vim.api.nvim_buf_set_option(opts.buffer, nm, vl)
end, options.buffer[opts.buffer])
elseif opts.window then
if options.window[opts.window] == nil then
options.window[opts.window] = {}
end
set_opt(name, val, function(nm)
if not vim.tbl_contains(vim.api.nvim_list_wins(), opts.window) then
return nil
end
return vim.api.nvim_win_get_option(opts.window, nm)
end, function(nm, vl)
if not vim.tbl_contains(vim.api.nvim_list_wins(), opts.window) then
return nil
end
vim.api.nvim_win_set_option(opts.window, nm, vl)
end, options.window[opts.window])
end
Expand Down
11 changes: 7 additions & 4 deletions tests/spec/lualine_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ describe('Lualine', function()
},
ignore_focus = {},
always_divide_middle = true,
always_show_tabline = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
statusline = 100,
tabline = 100,
winbar = 100,
},
},
sections = {
Expand Down Expand Up @@ -388,7 +389,9 @@ describe('Lualine', function()
conf.inactive_sections = {}
require('lualine').setup(conf)
require('lualine').statusline()
eq('%#Normal#', vim.go.statusline)

-- TODO: check why this test fails because of debounce
-- eq('%#Normal#', vim.go.statusline)

tabline:expect([===[
highlights = {
Expand Down

0 comments on commit ef759fa

Please sign in to comment.