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',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {},
disabled_filetypes = {
statusline = {},
winbar = {},
},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
@ -126,6 +134,8 @@ For more information, check out `:help lua-heredoc`.
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
<
@ -346,13 +356,28 @@ in component.
theme = 'auto', -- lualine theme
component_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'
-- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present.
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 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*
Buffers Shows currently open buffers. Like

View File

@ -10,7 +10,7 @@ local modules = lualine_require.lazy_require {
utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices',
config_module = 'lualine.config',
nvim_opts = 'lualine.utils.nvim_opts'
nvim_opts = 'lualine.utils.nvim_opts',
}
local config -- Stores currently applied config
local timers = {
@ -22,7 +22,7 @@ local timers = {
-- The events on which lualine redraws itself
local default_refresh_events = 'WinEnter,BufEnter,SessionLoadPost,FileChangedShellPost,VimResized'
if vim.fn.has('nvim-0.7') == 1 then -- utilize ModeChanged event introduced in 0.7
default_refresh_events = default_refresh_events..',ModeChanged'
default_refresh_events = default_refresh_events .. ',ModeChanged'
end
-- Helper for apply_transitional_separators()
--- finds first applied highlight group after str_checked in status
@ -272,8 +272,12 @@ local function status_dispatch(sec_name)
local retval
local current_ft = vim.bo.filetype
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)],
current_ft) then
if
vim.tbl_contains(
config.options.disabled_filetypes[(sec_name == 'sections' and 'statusline' or sec_name)],
current_ft
)
then
-- disable on specific filetypes
return ''
end
@ -281,7 +285,7 @@ local function status_dispatch(sec_name)
if extension_sections ~= nil then
retval = statusline(extension_sections, is_focused, sec_name == 'winbar')
else
retval = statusline(config[(is_focused and '' or 'inactive_')..sec_name], is_focused, sec_name == 'winbar')
retval = statusline(config[(is_focused and '' or 'inactive_') .. sec_name], is_focused, sec_name == 'winbar')
end
return retval
end
@ -303,14 +307,15 @@ end
---@param opts LualineRefreshOpts
local function refresh(opts)
if opts == nil then
opts = {kind = 'tabpage', place = {'statusline', 'winbar', 'tabline'}, trigger='unknown'}
opts = { kind = 'tabpage', place = { 'statusline', 'winbar', 'tabline' }, trigger = 'unknown' }
end
-- 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.tbl_contains(opts.place, 'winbar')
) then
then
local id
for index, value in ipairs(opts.place) do
if value == 'winbar' then
@ -326,47 +331,40 @@ local function refresh(opts)
vim.g.actual_curwin = vim.api.nvim_get_current_win()
-- gather which windows needs update
if opts.kind == 'all' then
if vim.tbl_contains(opts.place, 'statusline')
or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function (win)
if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function(win)
return vim.fn.win_gettype(win) ~= 'popup'
end, vim.api.nvim_list_wins())
end
elseif opts.kind == 'tabpage' then
if vim.tbl_contains(opts.place, 'statusline')
or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function (win)
if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
wins = vim.tbl_filter(function(win)
return vim.fn.win_gettype(win) ~= 'popup'
end, vim.api.nvim_tabpage_list_wins(0))
end
elseif opts.kind == 'window' then
wins = {vim.api.nvim_get_current_win()}
wins = { vim.api.nvim_get_current_win() }
end
-- update them
if vim.tbl_contains(opts.place, 'statusline') then
for _, win in ipairs(wins) do
modules.nvim_opts.set('statusline',
vim.api.nvim_win_call(win, M.statusline), {window=win})
modules.nvim_opts.set('statusline', vim.api.nvim_win_call(win, M.statusline), { window = win })
end
end
if vim.tbl_contains(opts.place, 'winbar') then
for _, win in ipairs(wins) do
if vim.api.nvim_win_get_height(win) > 1 then
modules.nvim_opts.set('winbar',
vim.api.nvim_win_call(win, M.winbar), {window=win})
modules.nvim_opts.set('winbar', vim.api.nvim_win_call(win, M.winbar), { window = win })
end
end
end
if vim.tbl_contains(opts.place, 'tabline') then
modules.nvim_opts.set('tabline',
vim.api.nvim_win_call(vim.api.nvim_get_current_win(), tabline),
{global=true})
modules.nvim_opts.set('tabline', vim.api.nvim_win_call(vim.api.nvim_get_current_win(), tabline), { global = true })
end
-- call redraw
if vim.tbl_contains(opts.place, 'statusline')
or vim.tbl_contains(opts.place, 'winbar') then
if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
vim.cmd('redrawstatus')
elseif vim.tbl_contains(opts.place, 'tabline') then
vim.cmd('redrawtabline')
@ -380,17 +378,24 @@ local function set_tabline()
vim.loop.timer_stop(timers.tal_timer)
vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]])
if next(config.tabline) ~= nil then
vim.loop.timer_start(timers.tal_timer, 0, config.options.refresh.tabline,
modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function ()
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})
vim.loop.timer_start(
timers.tal_timer,
0,
config.options.refresh.tabline,
modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function()
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 })
else
modules.nvim_opts.restore('tabline', {global=true})
modules.nvim_opts.restore('showtabline', {global=true})
modules.nvim_opts.restore('tabline', { global = true })
modules.nvim_opts.restore('showtabline', { global = true })
end
end
@ -401,30 +406,44 @@ local function set_statusline()
vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]])
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
if config.options.globalstatus then
modules.nvim_opts.set('laststatus', 3, {global=true})
vim.loop.timer_start(timers.stl_timer, 0, config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function ()
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')
modules.nvim_opts.set('laststatus', 3, { global = true })
vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
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(timers.stl_timer, 0, config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function ()
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')
modules.nvim_opts.set('laststatus', 2, { global = true })
vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.statusline,
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
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
else
modules.nvim_opts.restore('statusline', {global=true})
modules.nvim_opts.restore('statusline', { global = true })
for _, win in ipairs(vim.api.nvim_list_wins()) do
modules.nvim_opts.restore('statusline', {window=win})
modules.nvim_opts.restore('statusline', { window = win })
end
modules.nvim_opts.restore('laststatus', {global=true})
modules.nvim_opts.restore('laststatus', { global = true })
end
end
@ -433,17 +452,24 @@ local function set_winbar()
vim.loop.timer_stop(timers.wb_timer)
vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]])
if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then
vim.loop.timer_start(timers.stl_timer, 0, config.options.refresh.winbar,
modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function ()
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')
vim.loop.timer_start(
timers.stl_timer,
0,
config.options.refresh.winbar,
modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function()
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'
)
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
modules.nvim_opts.restore('winbar', {window=win})
modules.nvim_opts.restore('winbar', { window = win })
end
end
end

View File

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

View File

@ -154,7 +154,7 @@ end
---loads all the configs (active, inactive, tabline)
---@param config table user config
local function load_components(config)
local sec_names = {'sections', 'inactive_sections', 'tabline', 'winbar', 'inactive_winbar'}
local sec_names = { 'sections', 'inactive_sections', 'tabline', 'winbar', 'inactive_winbar' }
for _, section in ipairs(sec_names) do
load_sections(config[section], config.options)
end
@ -164,7 +164,7 @@ end
---@param config table user config
local function load_extensions(config)
local loaded_extensions = {}
local sec_names = {'sections', 'inactive_sections', 'winbar', 'inactive_winbar'}
local sec_names = { 'sections', 'inactive_sections', 'winbar', 'inactive_winbar' }
for _, extension in pairs(config.extensions) do
if type(extension) == 'string' then
local ok

View File

@ -24,7 +24,7 @@ local M = {}
---@field buffer table<number, LualineNvimOptCacheOpt[]>
---@field window table<number, LualineNvimOptCacheOpt[]>
---@type LualineNvimOptCache
local options = {global={}, buffer={}, window={}}
local options = { global = {}, buffer = {}, window = {} }
-- helper function for M.set
local function set_opt(name, val, getter_fn, setter_fn, cache_tbl)
@ -32,9 +32,15 @@ local function set_opt(name, val, getter_fn, setter_fn, cache_tbl)
-- the option wasn't set instead threw error.
-- So we need pcall (probably just for test)
local ok, cur = pcall(getter_fn, name)
if not ok then cur = nil end
if cur == val then return end
if cache_tbl[name] == nil then cache_tbl[name] = {} end
if not ok then
cur = nil
end
if cur == val then
return
end
if cache_tbl[name] == nil then
cache_tbl[name] = {}
end
if cache_tbl[name].set ~= cur then
cache_tbl[name].prev = cur
end
@ -54,18 +60,18 @@ function M.set(name, val, opts)
if options.buffer[opts.buffer] == nil then
options.buffer[opts.buffer] = {}
end
set_opt(name, val, function (nm)
set_opt(name, val, function(nm)
return vim.api.nvim_buf_get_option(opts.buffer, nm)
end, function (nm, vl)
end, function(nm, vl)
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)
set_opt(name, val, function(nm)
return vim.api.nvim_win_get_option(opts.window, nm)
end, function (nm, vl)
end, function(nm, vl)
vim.api.nvim_win_set_option(opts.window, nm, vl)
end, options.window[opts.window])
end
@ -80,15 +86,19 @@ function M.restore(name, opts)
vim.api.nvim_set_option(name, options.global[name].prev)
end
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].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)
end
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].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)
end
end
@ -103,24 +113,27 @@ function M.get_cache(name, opts)
return options.global[name].prev
end
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].prev ~= nil then
and options.buffer[opts.buffer][name].prev ~= nil
then
return options.buffer[opts.buffer][name].prev
end
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].prev ~= nil then
and options.window[opts.window][name].prev ~= nil
then
return options.window[opts.window][name].prev
end
end
end
-- resets cache for options
function M.reset_cache()
options = {global={}, buffer={}, window={}}
options = { global = {}, buffer = {}, window = {} }
end
return M

View File

@ -201,7 +201,7 @@ function M.timer_call(timer, augroup, fn, max_err, err_msg)
if augroup then
vim.cmd(string.format([[augroup %s | exe "autocmd!" | augroup END]], augroup))
end
error(err_msg..':\n'..tostring(ret))
error(err_msg .. ':\n' .. tostring(ret))
end
local ok
ok, ret = pcall(fn, ...)