Skip to content

Commit 564aafa

Browse files
Merge branch 'nvim-lualine:master' into master
2 parents 7c4f39b + f4f791f commit 564aafa

File tree

8 files changed

+96
-89
lines changed

8 files changed

+96
-89
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ require('lualine').setup {
139139
},
140140
ignore_focus = {},
141141
always_divide_middle = true,
142+
always_show_tabline = true,
142143
globalstatus = false,
143144
refresh = {
144-
statusline = 1000,
145-
tabline = 1000,
146-
winbar = 1000,
145+
statusline = 100,
146+
tabline = 100,
147+
winbar = 100,
147148
}
148149
},
149150
sections = {
@@ -378,14 +379,18 @@ options = {
378379
-- can't take over the entire statusline even
379380
-- if neither of 'x', 'y' or 'z' are present.
380381

382+
always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
383+
-- then tabline will always show. If set to false, then tabline will be displayed
384+
-- only when there are more than 1 tab. (see :h showtabline)
385+
381386
globalstatus = false, -- enable global statusline (have a single statusline
382387
-- at bottom of neovim instead of one for every window).
383388
-- This feature is only available in neovim 0.7 and higher.
384389

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

391396
-- Also you can force lualine's refresh by calling refresh function

doc/lualine.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ For more information, check out `:help lua-heredoc`.
124124
},
125125
ignore_focus = {},
126126
always_divide_middle = true,
127+
always_show_tabline = true,
127128
globalstatus = false,
128129
refresh = {
129-
statusline = 1000,
130-
tabline = 1000,
131-
winbar = 1000,
130+
statusline = 100,
131+
tabline = 100,
132+
winbar = 100,
132133
}
133134
},
134135
sections = {
@@ -393,14 +394,18 @@ in component.
393394
-- can't take over the entire statusline even
394395
-- if neither of 'x', 'y' or 'z' are present.
395396
397+
always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
398+
-- then tabline will always show. If set to false, then tabline will be displayed
399+
-- only when there are more than 1 tab. (see :h showtabline)
400+
396401
globalstatus = false, -- enable global statusline (have a single statusline
397402
-- at bottom of neovim instead of one for every window).
398403
-- This feature is only available in neovim 0.7 and higher.
399404
400405
refresh = { -- sets how often lualine should refresh it's contents (in ms)
401-
statusline = 1000, -- The refresh option sets minimum time that lualine tries
402-
tabline = 1000, -- to maintain between refresh. It's not guarantied if situation
403-
winbar = 1000 -- arises that lualine needs to refresh itself before this time
406+
statusline = 100, -- The refresh option sets minimum time that lualine tries
407+
tabline = 100, -- to maintain between refresh. It's not guarantied if situation
408+
winbar = 100 -- arises that lualine needs to refresh itself before this time
404409
-- it'll do it.
405410
406411
-- Also you can force lualine's refresh by calling refresh function

examples/evil_lualine.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ ins_left {
159159
-- Lsp server name .
160160
function()
161161
local msg = 'No Active Lsp'
162-
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
163-
local clients = vim.lsp.get_active_clients()
162+
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 })
163+
local clients = vim.lsp.get_clients()
164164
if next(clients) == nil then
165165
return msg
166166
end

lua/lualine.lua

+25-66
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ local timers = {
2525
local last_focus = {}
2626
local refresh_real_curwin
2727

28-
-- The events on which lualine redraws itself
29-
local default_refresh_events =
30-
'WinEnter,BufEnter,BufWritePost,SessionLoadPost,FileChangedShellPost,VimResized,Filetype,CursorMoved,CursorMovedI,ModeChanged'
3128
-- Helper for apply_transitional_separators()
3229
--- finds first applied highlight group after str_checked in status
3330
---@param status string : unprocessed statusline string
@@ -312,7 +309,7 @@ end
312309
---@class LualineRefreshOpts
313310
---@field scope LualineRefreshOptsKind
314311
---@field place LualineRefreshOptsPlace[]
315-
---@field trigger 'autocmd'|'autocmd_redired'|'timer'|'unknown'
312+
---@field trigger 'timer' | 'init' |'unknown'
316313
--- Refresh contents of lualine
317314
---@param opts LualineRefreshOpts
318315
local function refresh(opts)
@@ -325,36 +322,6 @@ local function refresh(opts)
325322
trigger = 'unknown',
326323
})
327324

328-
-- updating statusline in autocommands context seems to trigger 100 different bugs
329-
-- lets just defer it to a timer context and update there
330-
-- Since updating stl in command mode doesn't take effect
331-
-- refresh ModeChanged command in autocmd context as exception.
332-
-- workaround for
333-
-- https://github.com/neovim/neovim/issues/15300
334-
-- https://github.com/neovim/neovim/issues/19464
335-
-- https://github.com/nvim-lualine/lualine.nvim/issues/753
336-
-- https://github.com/nvim-lualine/lualine.nvim/issues/751
337-
-- https://github.com/nvim-lualine/lualine.nvim/issues/755
338-
-- https://github.com/neovim/neovim/issues/19472
339-
-- https://github.com/nvim-lualine/lualine.nvim/issues/791
340-
if
341-
opts.trigger == 'autocmd'
342-
and vim.v.event.new_mode ~= 'c'
343-
-- scheduling in op-pending mode seems to call the callback forever.
344-
-- so this is restricted in op-pending mode.
345-
-- https://github.com/neovim/neovim/issues/22263
346-
-- https://github.com/nvim-lualine/lualine.nvim/issues/967
347-
-- note this breaks mode component while switching to op-pending mode
348-
and not vim.tbl_contains({ 'no', 'nov', 'noV' }, vim.v.event.new_mode)
349-
and not vim.tbl_contains({ 'no', 'nov', 'noV' }, vim.v.event.old_mode)
350-
then
351-
opts.trigger = 'autocmd_redired'
352-
vim.schedule(function()
353-
M.refresh(opts)
354-
end)
355-
return
356-
end
357-
358325
local wins = {}
359326
local old_actual_curwin = vim.g.actual_curwin
360327

@@ -463,24 +430,22 @@ end
463430
local function set_tabline(hide)
464431
vim.loop.timer_stop(timers.tal_timer)
465432
timers.halt_tal_refresh = true
466-
vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]])
467433
if not hide and next(config.tabline) ~= nil then
468434
vim.loop.timer_start(
469435
timers.tal_timer,
470436
0,
471437
config.options.refresh.tabline,
472438
modules.utils.timer_call(timers.tal_timer, 'lualine_tal_refresh', function()
473-
refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
439+
refresh { scope = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
474440
end, 3, 'lualine: Failed to refresh tabline')
475441
)
476-
modules.utils.define_autocmd(
477-
default_refresh_events,
478-
'*',
479-
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['tabline'], 'trigger': 'autocmd'})",
480-
'lualine_tal_refresh'
481-
)
482-
modules.nvim_opts.set('showtabline', 2, { global = true })
442+
modules.nvim_opts.set('showtabline', config.options.always_show_tabline and 2 or 1, { global = true })
483443
timers.halt_tal_refresh = false
444+
vim.schedule(function()
445+
-- imediately refresh upon load
446+
-- schedule needed so stuff like filetype detect can run first
447+
refresh { scope = 'tabpage', place = { 'tabline' }, trigger = 'init' }
448+
end)
484449
else
485450
modules.nvim_opts.restore('tabline', { global = true })
486451
modules.nvim_opts.restore('showtabline', { global = true })
@@ -493,7 +458,6 @@ end
493458
local function set_statusline(hide)
494459
vim.loop.timer_stop(timers.stl_timer)
495460
timers.halt_stl_refresh = true
496-
vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]])
497461
if not hide and (next(config.sections) ~= nil or next(config.inactive_sections) ~= nil) then
498462
if vim.go.statusline == '' then
499463
modules.nvim_opts.set('statusline', '%#Normal#', { global = true })
@@ -505,33 +469,30 @@ local function set_statusline(hide)
505469
0,
506470
config.options.refresh.statusline,
507471
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
508-
refresh { kind = 'window', place = { 'statusline' }, trigger = 'timer' }
472+
refresh { scope = 'window', place = { 'statusline' }, trigger = 'timer' }
509473
end, 3, 'lualine: Failed to refresh statusline')
510474
)
511-
modules.utils.define_autocmd(
512-
default_refresh_events,
513-
'*',
514-
"call v:lua.require'lualine'.refresh({'kind': 'window', 'place': ['statusline'], 'trigger': 'autocmd'})",
515-
'lualine_stl_refresh'
516-
)
517475
else
518476
modules.nvim_opts.set('laststatus', 2, { global = true })
519477
vim.loop.timer_start(
520478
timers.stl_timer,
521479
0,
522480
config.options.refresh.statusline,
523481
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
524-
refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
482+
refresh { scope = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
525483
end, 3, 'lualine: Failed to refresh statusline')
526484
)
527-
modules.utils.define_autocmd(
528-
default_refresh_events,
529-
'*',
530-
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})",
531-
'lualine_stl_refresh'
532-
)
533485
end
534486
timers.halt_stl_refresh = false
487+
vim.schedule(function()
488+
-- imediately refresh upon load
489+
-- schedule needed so stuff like filetype detect can run first
490+
if config.options.globalstatus then
491+
refresh { scope = 'window', place = { 'statusline' }, trigger = 'init' }
492+
else
493+
refresh { scope = 'tabpage', place = { 'statusline' }, trigger = 'init' }
494+
end
495+
end)
535496
else
536497
modules.nvim_opts.restore('statusline', { global = true })
537498
for _, win in ipairs(vim.api.nvim_list_wins()) do
@@ -546,23 +507,21 @@ end
546507
local function set_winbar(hide)
547508
vim.loop.timer_stop(timers.wb_timer)
548509
timers.halt_wb_refresh = true
549-
vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]])
550510
if not hide and (next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil) then
551511
vim.loop.timer_start(
552512
timers.wb_timer,
553513
0,
554514
config.options.refresh.winbar,
555515
modules.utils.timer_call(timers.wb_timer, 'lualine_wb_refresh', function()
556-
refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
516+
refresh { scope = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
557517
end, 3, 'lualine: Failed to refresh winbar')
558518
)
559-
modules.utils.define_autocmd(
560-
default_refresh_events,
561-
'*',
562-
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['winbar'], 'trigger': 'autocmd'})",
563-
'lualine_wb_refresh'
564-
)
565519
timers.halt_wb_refresh = false
520+
vim.schedule(function()
521+
-- imediately refresh upon load.
522+
-- schedule needed so stuff like filetype detect can run first
523+
refresh { scope = 'tabpage', place = { 'winbar' }, trigger = 'init' }
524+
end)
566525
elseif vim.fn.has('nvim-0.8') == 1 then
567526
modules.nvim_opts.restore('winbar', { global = true })
568527
for _, win in ipairs(vim.api.nvim_list_wins()) do

lua/lualine/config.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ local config = {
1818
},
1919
ignore_focus = {},
2020
always_divide_middle = true,
21+
always_show_tabline = true,
2122
globalstatus = vim.go.laststatus == 3,
2223
refresh = {
23-
statusline = 1000,
24-
tabline = 1000,
25-
winbar = 1000,
24+
statusline = 100,
25+
tabline = 100,
26+
winbar = 100,
2627
},
2728
},
2829
sections = {

lua/lualine/utils/loader.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ local function load_theme(theme_name)
220220
end
221221
local n_files = #files
222222
if n_files == 0 then
223-
-- No match found
224-
error(path .. ' Not found')
223+
-- No match found on runtimepath. Fall back to package.path
224+
local file =
225+
assert(package.searchpath('lualine.themes.' .. theme_name, package.path), 'Theme ' .. theme_name .. ' not found')
226+
retval = dofile(file)
225227
elseif n_files == 1 then
226228
-- when only one is found run that and return it's return value
227229
retval = dofile(files[1])

lua/lualine/utils/nvim_opts.lua

+32
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,33 @@ local function set_opt(name, val, getter_fn, setter_fn, cache_tbl)
4141
if cache_tbl[name] == nil then
4242
cache_tbl[name] = {}
4343
end
44+
4445
if cache_tbl[name].set ~= cur then
4546
if type(cur) ~= 'string' or not cur:find('lualine') then
4647
cache_tbl[name].prev = cur
4748
end
4849
end
4950
cache_tbl[name].set = val
5051
setter_fn(name, val)
52+
53+
-- Mitigation for https://github.com/nvim-lualine/lualine.nvim/issues/1323
54+
-- when redrawstatus is ran and winbar usues some eval syntax %{} for some
55+
-- odd reason nvim renders the winbar in statusline first then actual statusline
56+
-- replaces it. Also it doesn't happen on top window. Might be some bug in
57+
-- neovims rendering. Also it doesn't seem to happend with laststatus=2 or
58+
-- global status turned off in lualine. lualines rendering might be at fault
59+
-- too. but we should never be evaluating an externally set winbar so that
60+
-- doen't make much sense either.
61+
-- Tested: nvim v0.9.5
62+
-- TODO: Needs further investigation.
63+
if vim.api.nvim_get_mode().mode == 'c' then
64+
if name == 'statusline' or name == 'winbar' then
65+
vim.cmd('redrawstatus')
66+
end
67+
if name == 'tabline' then
68+
vim.cmd('redrawtabline')
69+
end
70+
end
5171
end
5272

5373
-- set a option value
@@ -63,17 +83,29 @@ function M.set(name, val, opts)
6383
options.buffer[opts.buffer] = {}
6484
end
6585
set_opt(name, val, function(nm)
86+
if not vim.tbl_contains(vim.api.nvim_list_bufs(), opts.buffer) then
87+
return nil
88+
end
6689
return vim.api.nvim_buf_get_option(opts.buffer, nm)
6790
end, function(nm, vl)
91+
if not vim.tbl_contains(vim.api.nvim_list_bufs(), opts.buffer) then
92+
return nil
93+
end
6894
vim.api.nvim_buf_set_option(opts.buffer, nm, vl)
6995
end, options.buffer[opts.buffer])
7096
elseif opts.window then
7197
if options.window[opts.window] == nil then
7298
options.window[opts.window] = {}
7399
end
74100
set_opt(name, val, function(nm)
101+
if not vim.tbl_contains(vim.api.nvim_list_wins(), opts.window) then
102+
return nil
103+
end
75104
return vim.api.nvim_win_get_option(opts.window, nm)
76105
end, function(nm, vl)
106+
if not vim.tbl_contains(vim.api.nvim_list_wins(), opts.window) then
107+
return nil
108+
end
77109
vim.api.nvim_win_set_option(opts.window, nm, vl)
78110
end, options.window[opts.window])
79111
end

tests/spec/lualine_spec.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ describe('Lualine', function()
2121
},
2222
ignore_focus = {},
2323
always_divide_middle = true,
24+
always_show_tabline = true,
2425
globalstatus = false,
2526
refresh = {
26-
statusline = 1000,
27-
tabline = 1000,
28-
winbar = 1000,
27+
statusline = 100,
28+
tabline = 100,
29+
winbar = 100,
2930
},
3031
},
3132
sections = {
@@ -388,7 +389,9 @@ describe('Lualine', function()
388389
conf.inactive_sections = {}
389390
require('lualine').setup(conf)
390391
require('lualine').statusline()
391-
eq('%#Normal#', vim.go.statusline)
392+
393+
-- TODO: check why this test fails because of debounce
394+
-- eq('%#Normal#', vim.go.statusline)
392395

393396
tabline:expect([===[
394397
highlights = {

0 commit comments

Comments
 (0)