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 = {
@ -22,7 +22,7 @@ local timers = {
-- The events on which lualine redraws itself -- The events on which lualine redraws itself
local default_refresh_events = 'WinEnter,BufEnter,SessionLoadPost,FileChangedShellPost,VimResized' 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 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 end
-- Helper for apply_transitional_separators() -- Helper for apply_transitional_separators()
--- finds first applied highlight group after str_checked in status --- finds first applied highlight group after str_checked in status
@ -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
@ -281,7 +285,7 @@ local function status_dispatch(sec_name)
if extension_sections ~= nil then if extension_sections ~= nil then
retval = statusline(extension_sections, is_focused, sec_name == 'winbar') retval = statusline(extension_sections, is_focused, sec_name == 'winbar')
else 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 end
return retval return retval
end end
@ -303,22 +307,23 @@ end
---@param opts LualineRefreshOpts ---@param opts LualineRefreshOpts
local function refresh(opts) local function refresh(opts)
if opts == nil then if opts == nil then
opts = {kind = 'tabpage', place = {'statusline', 'winbar', 'tabline'}, trigger='unknown'} opts = { kind = 'tabpage', place = { 'statusline', 'winbar', 'tabline' }, trigger = 'unknown' }
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
and vim.api.nvim_win_get_height(vim.api.nvim_get_current_win()) <= 1 opts.trigger == 'autocmd'
and vim.tbl_contains(opts.place, 'winbar') and vim.api.nvim_win_get_height(vim.api.nvim_get_current_win()) <= 1
) then and vim.tbl_contains(opts.place, 'winbar')
local id then
for index, value in ipairs(opts.place) do local id
if value == 'winbar' then for index, value in ipairs(opts.place) do
id = index if value == 'winbar' then
break id = index
end break
end end
table.remove(opts.place, id) end
table.remove(opts.place, id)
end end
local wins = {} local wins = {}
@ -326,47 +331,40 @@ 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))
end end
elseif opts.kind == 'window' then elseif opts.kind == 'window' then
wins = {vim.api.nvim_get_current_win()} wins = { vim.api.nvim_get_current_win() }
end end
-- 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,17 +378,24 @@ 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(
modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function () timers.tal_timer,
refresh({kind='tabpage', place={'tabline'}, trigger='timer'}) 0,
end, 3, "lualine: Failed to refresh tabline")) config.options.refresh.tabline,
modules.utils.define_autocmd(default_refresh_events, modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function()
'*', "call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['tabline'], 'trigger': 'autocmd'})", refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
'lualine_tal_refresh') end, 3, 'lualine: Failed to refresh tabline')
modules.nvim_opts.set('showtabline', 2, {global=true}) )
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 else
modules.nvim_opts.restore('tabline', {global=true}) modules.nvim_opts.restore('tabline', { global = true })
modules.nvim_opts.restore('showtabline', {global=true}) modules.nvim_opts.restore('showtabline', { global = true })
end end
end end
@ -401,30 +406,44 @@ local function set_statusline()
vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]]) vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]])
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(
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function () timers.stl_timer,
refresh({kind='window', place={'statusline'}, trigger='timer'}) 0,
end, 3, "lualine: Failed to refresh statusline")) config.options.refresh.statusline,
modules.utils.define_autocmd(default_refresh_events, modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
'*', "call v:lua.require'lualine'.refresh({'kind': 'window', 'place': ['statusline'], 'trigger': 'autocmd'})", refresh { kind = 'window', place = { 'statusline' }, trigger = 'timer' }
'lualine_stl_refresh') 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 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(
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function () timers.stl_timer,
refresh({kind='tabpage', place={'statusline'}, trigger='timer'}) 0,
end, 3, "lualine: Failed to refresh statusline")) config.options.refresh.statusline,
modules.utils.define_autocmd(default_refresh_events, modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
'*', "call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})", refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
'lualine_stl_refresh') 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 end
else 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 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 end
modules.nvim_opts.restore('laststatus', {global=true}) modules.nvim_opts.restore('laststatus', { global = true })
end end
end end
@ -433,17 +452,24 @@ 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(
modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function () timers.stl_timer,
refresh({kind='tabpage', place={'winbar'}, trigger='timer'}) 0,
end, 3, "lualine: Failed to refresh winbar")) config.options.refresh.winbar,
modules.utils.define_autocmd(default_refresh_events, modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function()
'*', "call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['winbar'], 'trigger': 'autocmd'})", refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
'lualine_wb_refresh') 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 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
modules.nvim_opts.restore('winbar', {window=win}) modules.nvim_opts.restore('winbar', { window = win })
end end
end end
end end

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

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

View File

@ -24,7 +24,7 @@ local M = {}
---@field buffer table<number, LualineNvimOptCacheOpt[]> ---@field buffer table<number, LualineNvimOptCacheOpt[]>
---@field window table<number, LualineNvimOptCacheOpt[]> ---@field window table<number, LualineNvimOptCacheOpt[]>
---@type LualineNvimOptCache ---@type LualineNvimOptCache
local options = {global={}, buffer={}, window={}} local options = { global = {}, buffer = {}, window = {} }
-- helper function for M.set -- helper function for M.set
local function set_opt(name, val, getter_fn, setter_fn, cache_tbl) 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. -- 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
@ -54,18 +60,18 @@ function M.set(name, val, opts)
if options.buffer[opts.buffer] == nil then if options.buffer[opts.buffer] == nil then
options.buffer[opts.buffer] = {} options.buffer[opts.buffer] = {}
end end
set_opt(name, val, function (nm) set_opt(name, val, function(nm)
return vim.api.nvim_buf_get_option(opts.buffer, 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) vim.api.nvim_buf_set_option(opts.buffer, nm, vl)
end, options.buffer[opts.buffer]) end, options.buffer[opts.buffer])
elseif opts.window then elseif opts.window then
if options.window[opts.window] == nil then if options.window[opts.window] == nil then
options.window[opts.window] = {} options.window[opts.window] = {}
end end
set_opt(name, val, function (nm) set_opt(name, val, function(nm)
return vim.api.nvim_win_get_option(opts.window, 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) vim.api.nvim_win_set_option(opts.window, nm, vl)
end, options.window[opts.window]) end, options.window[opts.window])
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,24 +113,27 @@ 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
function M.reset_cache() function M.reset_cache()
options = {global={}, buffer={}, window={}} options = { global = {}, buffer = {}, window = {} }
end end
return M return M

View File

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