chore: autogen (vimdocs+formating)

This commit is contained in:
shadmansaleh 2022-07-22 13:30:37 +00:00 committed by github-actions[bot]
parent 53aa3d82d9
commit d7386bbab3
6 changed files with 197 additions and 101 deletions

View File

@ -105,9 +105,17 @@ For more information, check out `:help lua-heredoc`.
theme = 'auto', theme = 'auto',
component_separators = { left = '', right = ''}, component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''}, section_separators = { left = '', right = ''},
disabled_filetypes = {}, disabled_filetypes = {
statusline = {},
winbar = {},
},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false, globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
}, },
sections = { sections = {
lualine_a = {'mode'}, lualine_a = {'mode'},
@ -126,6 +134,8 @@ For more information, check out `:help lua-heredoc`.
lualine_z = {} lualine_z = {}
}, },
tabline = {}, tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {} extensions = {}
} }
< <
@ -346,13 +356,28 @@ in component.
theme = 'auto', -- lualine theme theme = 'auto', -- lualine theme
component_separators = { left = '', right = '' }, component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = {}, -- Filetypes to disable lualine for. disabled_filetypes = { -- Filetypes to disable lualine for.
statusline = {}, -- only ignores the ft for statusline.
winbar = {}, -- only ignores the ft for winbar.
},
always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c' always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c'
-- can't take over the entire statusline even -- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present. -- if neither of 'x', 'y' or 'z' are present.
globalstatus = false, -- enable global statusline (have a single statusline globalstatus = false, -- enable global statusline (have a single statusline
-- at bottom of neovim instead of one for every window). -- at bottom of neovim instead of one for every window).
-- This feature is only available in neovim 0.7 and higher. -- This feature is only available in neovim 0.7 and higher.
refresh = { -- sets how often lualine should refreash 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
-- it'll do it.
-- Also you can force lualine's refresh by calling refresh function
-- like require('lualine').refresh()
}
} }
< <
@ -718,6 +743,38 @@ more traditional tabline/bufferline.
< <
WINBAR ~
From neovim-0.8 you can customize your winbar with lualine. Winbar
configuration is similar to statusline.
>
winbar = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {},
lualine_y = {},
lualine_z = {}
}
inactive_winbar = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {},
lualine_y = {},
lualine_z = {}
}
<
Just like statusline you can separately specify winbar for active and inactive
windows. Any lualine component can be placed in winbar. All kinds of custom
components supported in statusline are also suported for winbar too. In general
You can treat winbar as another lualine statusline that just appears on top of
windows instead of at bottom.
*lualine-Buffers* *lualine-Buffers*
Buffers Shows currently open buffers. Like Buffers Shows currently open buffers. Like

View File

@ -10,7 +10,7 @@ local modules = lualine_require.lazy_require {
utils = 'lualine.utils.utils', utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices', utils_notices = 'lualine.utils.notices',
config_module = 'lualine.config', config_module = 'lualine.config',
nvim_opts = 'lualine.utils.nvim_opts' nvim_opts = 'lualine.utils.nvim_opts',
} }
local config -- Stores currently applied config local config -- Stores currently applied config
local timers = { local timers = {
@ -272,8 +272,12 @@ local function status_dispatch(sec_name)
local retval local retval
local current_ft = vim.bo.filetype local current_ft = vim.bo.filetype
local is_focused = focused ~= nil and focused or modules.utils.is_focused() local is_focused = focused ~= nil and focused or modules.utils.is_focused()
if vim.tbl_contains(config.options.disabled_filetypes[(sec_name == 'sections' and 'statusline' or sec_name)], if
current_ft) then vim.tbl_contains(
config.options.disabled_filetypes[(sec_name == 'sections' and 'statusline' or sec_name)],
current_ft
)
then
-- disable on specific filetypes -- disable on specific filetypes
return '' return ''
end end
@ -307,10 +311,11 @@ local function refresh(opts)
end end
-- workaround for https://github.com/neovim/neovim/issues/19464 -- workaround for https://github.com/neovim/neovim/issues/19464
if (opts.trigger == 'autocmd' if
opts.trigger == 'autocmd'
and vim.api.nvim_win_get_height(vim.api.nvim_get_current_win()) <= 1 and vim.api.nvim_win_get_height(vim.api.nvim_get_current_win()) <= 1
and vim.tbl_contains(opts.place, 'winbar') and vim.tbl_contains(opts.place, 'winbar')
) then then
local id local id
for index, value in ipairs(opts.place) do for index, value in ipairs(opts.place) do
if value == 'winbar' then if value == 'winbar' then
@ -326,15 +331,13 @@ local function refresh(opts)
vim.g.actual_curwin = vim.api.nvim_get_current_win() vim.g.actual_curwin = vim.api.nvim_get_current_win()
-- gather which windows needs update -- gather which windows needs update
if opts.kind == 'all' then if opts.kind == 'all' then
if vim.tbl_contains(opts.place, 'statusline') if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function(win) wins = vim.tbl_filter(function(win)
return vim.fn.win_gettype(win) ~= 'popup' return vim.fn.win_gettype(win) ~= 'popup'
end, vim.api.nvim_list_wins()) end, vim.api.nvim_list_wins())
end end
elseif opts.kind == 'tabpage' then elseif opts.kind == 'tabpage' then
if vim.tbl_contains(opts.place, 'statusline') if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function(win) wins = vim.tbl_filter(function(win)
return vim.fn.win_gettype(win) ~= 'popup' return vim.fn.win_gettype(win) ~= 'popup'
end, vim.api.nvim_tabpage_list_wins(0)) end, vim.api.nvim_tabpage_list_wins(0))
@ -346,27 +349,22 @@ local function refresh(opts)
-- update them -- update them
if vim.tbl_contains(opts.place, 'statusline') then if vim.tbl_contains(opts.place, 'statusline') then
for _, win in ipairs(wins) do for _, win in ipairs(wins) do
modules.nvim_opts.set('statusline', modules.nvim_opts.set('statusline', vim.api.nvim_win_call(win, M.statusline), { window = win })
vim.api.nvim_win_call(win, M.statusline), {window=win})
end end
end end
if vim.tbl_contains(opts.place, 'winbar') then if vim.tbl_contains(opts.place, 'winbar') then
for _, win in ipairs(wins) do for _, win in ipairs(wins) do
if vim.api.nvim_win_get_height(win) > 1 then if vim.api.nvim_win_get_height(win) > 1 then
modules.nvim_opts.set('winbar', modules.nvim_opts.set('winbar', vim.api.nvim_win_call(win, M.winbar), { window = win })
vim.api.nvim_win_call(win, M.winbar), {window=win})
end end
end end
end end
if vim.tbl_contains(opts.place, 'tabline') then if vim.tbl_contains(opts.place, 'tabline') then
modules.nvim_opts.set('tabline', modules.nvim_opts.set('tabline', vim.api.nvim_win_call(vim.api.nvim_get_current_win(), tabline), { global = true })
vim.api.nvim_win_call(vim.api.nvim_get_current_win(), tabline),
{global=true})
end end
-- call redraw -- call redraw
if vim.tbl_contains(opts.place, 'statusline') if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
or vim.tbl_contains(opts.place, 'winbar') then
vim.cmd('redrawstatus') vim.cmd('redrawstatus')
elseif vim.tbl_contains(opts.place, 'tabline') then elseif vim.tbl_contains(opts.place, 'tabline') then
vim.cmd('redrawtabline') vim.cmd('redrawtabline')
@ -380,13 +378,20 @@ local function set_tabline()
vim.loop.timer_stop(timers.tal_timer) vim.loop.timer_stop(timers.tal_timer)
vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]]) vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]])
if next(config.tabline) ~= nil then if next(config.tabline) ~= nil then
vim.loop.timer_start(timers.tal_timer, 0, config.options.refresh.tabline, vim.loop.timer_start(
timers.tal_timer,
0,
config.options.refresh.tabline,
modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function() modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function()
refresh({kind='tabpage', place={'tabline'}, trigger='timer'}) refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
end, 3, "lualine: Failed to refresh tabline")) 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'})", modules.utils.define_autocmd(
'lualine_tal_refresh') 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', 2, { global = true })
else else
modules.nvim_opts.restore('tabline', { global = true }) modules.nvim_opts.restore('tabline', { global = true })
@ -402,22 +407,36 @@ local function set_statusline()
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
if config.options.globalstatus then if config.options.globalstatus then
modules.nvim_opts.set('laststatus', 3, { global = true }) modules.nvim_opts.set('laststatus', 3, { global = true })
vim.loop.timer_start(timers.stl_timer, 0, config.options.refresh.statusline, vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function() modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
refresh({kind='window', place={'statusline'}, trigger='timer'}) refresh { kind = 'window', place = { 'statusline' }, trigger = 'timer' }
end, 3, "lualine: Failed to refresh statusline")) 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'})", modules.utils.define_autocmd(
'lualine_stl_refresh') default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'window', 'place': ['statusline'], 'trigger': 'autocmd'})",
'lualine_stl_refresh'
)
else else
modules.nvim_opts.set('laststatus', 2, { global = true }) modules.nvim_opts.set('laststatus', 2, { global = true })
vim.loop.timer_start(timers.stl_timer, 0, config.options.refresh.statusline, vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function() modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
refresh({kind='tabpage', place={'statusline'}, trigger='timer'}) refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
end, 3, "lualine: Failed to refresh statusline")) 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'})", modules.utils.define_autocmd(
'lualine_stl_refresh') default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})",
'lualine_stl_refresh'
)
end end
else else
modules.nvim_opts.restore('statusline', { global = true }) modules.nvim_opts.restore('statusline', { global = true })
@ -433,13 +452,20 @@ local function set_winbar()
vim.loop.timer_stop(timers.wb_timer) vim.loop.timer_stop(timers.wb_timer)
vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]]) vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]])
if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then
vim.loop.timer_start(timers.stl_timer, 0, config.options.refresh.winbar, vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.winbar,
modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function() modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function()
refresh({kind='tabpage', place={'winbar'}, trigger='timer'}) refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
end, 3, "lualine: Failed to refresh winbar")) 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'})", modules.utils.define_autocmd(
'lualine_wb_refresh') default_refresh_events,
'*',
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['winbar'], 'trigger': 'autocmd'})",
'lualine_wb_refresh'
)
elseif vim.fn.has('nvim-0.8') == 1 then elseif vim.fn.has('nvim-0.8') == 1 then
modules.nvim_opts.restore('winbar', { global = true }) modules.nvim_opts.restore('winbar', { global = true })
for _, win in ipairs(vim.api.nvim_list_wins()) do for _, win in ipairs(vim.api.nvim_list_wins()) do

View File

@ -14,7 +14,7 @@ local config = {
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = { disabled_filetypes = {
statusline = {}, statusline = {},
winbar = {} winbar = {},
}, },
always_divide_middle = true, always_divide_middle = true,
globalstatus = vim.go.laststatus == 3, globalstatus = vim.go.laststatus == 3,
@ -22,7 +22,7 @@ local config = {
statusline = 1000, statusline = 1000,
tabline = 1000, tabline = 1000,
winbar = 1000, winbar = 1000,
} },
}, },
sections = { sections = {
lualine_a = { 'mode' }, lualine_a = { 'mode' },
@ -62,7 +62,9 @@ end
---@param disabled_filetypes table ---@param disabled_filetypes table
---@return table ---@return table
local function fix_disabled_filetypes(disabled_filetypes) local function fix_disabled_filetypes(disabled_filetypes)
if disabled_filetypes == nil then return end if disabled_filetypes == nil then
return
end
if disabled_filetypes.statusline == nil then if disabled_filetypes.statusline == nil then
disabled_filetypes.statusline = {} disabled_filetypes.statusline = {}
end end
@ -102,9 +104,7 @@ local function apply_configuration(config_table)
config_table.options.globalstatus = false config_table.options.globalstatus = false
end end
if vim.fn.has('nvim-0.8') == 0 and (next(config_table.winbar or {}) or next(config_table.inactive_winbar or {})) then if vim.fn.has('nvim-0.8') == 0 and (next(config_table.winbar or {}) or next(config_table.inactive_winbar or {})) then
modules.utils_notices.add_notice( modules.utils_notices.add_notice('### winbar\nSorry `winbar can only be used in neovim 0.8 or higher.\n')
'### winbar\nSorry `winbar can only be used in neovim 0.8 or higher.\n'
)
config_table.winbar = {} config_table.winbar = {}
config_table.inactive_winbar = {} config_table.inactive_winbar = {}
end end

View File

@ -32,9 +32,15 @@ local function set_opt(name, val, getter_fn, setter_fn, cache_tbl)
-- the option wasn't set instead threw error. -- the option wasn't set instead threw error.
-- So we need pcall (probably just for test) -- So we need pcall (probably just for test)
local ok, cur = pcall(getter_fn, name) local ok, cur = pcall(getter_fn, name)
if not ok then cur = nil end if not ok then
if cur == val then return end cur = nil
if cache_tbl[name] == nil then cache_tbl[name] = {} end end
if cur == val then
return
end
if cache_tbl[name] == nil then
cache_tbl[name] = {}
end
if cache_tbl[name].set ~= cur then if cache_tbl[name].set ~= cur then
cache_tbl[name].prev = cur cache_tbl[name].prev = cur
end end
@ -80,15 +86,19 @@ function M.restore(name, opts)
vim.api.nvim_set_option(name, options.global[name].prev) vim.api.nvim_set_option(name, options.global[name].prev)
end end
elseif opts.buffer then elseif opts.buffer then
if options.buffer[opts.buffer] ~= nil if
options.buffer[opts.buffer] ~= nil
and options.buffer[opts.buffer][name] ~= nil and options.buffer[opts.buffer][name] ~= nil
and options.buffer[opts.buffer][name].prev ~= nil then and options.buffer[opts.buffer][name].prev ~= nil
then
vim.api.nvim_buf_set_option(opts.buffer, name, options.buffer[opts.buffer][name].prev) vim.api.nvim_buf_set_option(opts.buffer, name, options.buffer[opts.buffer][name].prev)
end end
elseif opts.window then elseif opts.window then
if options.window[opts.window] ~= nil if
options.window[opts.window] ~= nil
and options.window[opts.window][name] ~= nil and options.window[opts.window][name] ~= nil
and options.window[opts.window][name].prev ~= nil then and options.window[opts.window][name].prev ~= nil
then
vim.api.nvim_win_set_option(opts.window, name, options.window[opts.window][name].prev) vim.api.nvim_win_set_option(opts.window, name, options.window[opts.window][name].prev)
end end
end end
@ -103,19 +113,22 @@ function M.get_cache(name, opts)
return options.global[name].prev return options.global[name].prev
end end
elseif opts.buffer then elseif opts.buffer then
if options.buffer[opts.buffer] ~= nil if
options.buffer[opts.buffer] ~= nil
and options.buffer[opts.buffer][name] ~= nil and options.buffer[opts.buffer][name] ~= nil
and options.buffer[opts.buffer][name].prev ~= nil then and options.buffer[opts.buffer][name].prev ~= nil
then
return options.buffer[opts.buffer][name].prev return options.buffer[opts.buffer][name].prev
end end
elseif opts.window then elseif opts.window then
if options.window[opts.window] ~= nil if
options.window[opts.window] ~= nil
and options.window[opts.window][name] ~= nil and options.window[opts.window][name] ~= nil
and options.window[opts.window][name].prev ~= nil then and options.window[opts.window][name].prev ~= nil
then
return options.window[opts.window][name].prev return options.window[opts.window][name].prev
end end
end end
end end
-- resets cache for options -- resets cache for options