refactor: option names

This commit is contained in:
Folke Lemaitre 2024-07-15 15:13:07 +02:00
parent 4d9407dc22
commit 24918c2565
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 14 additions and 22 deletions

View file

@ -74,28 +74,20 @@ function M.format(buf)
return ret
end
---@param values? {[1]:any, [2]:any}
function M.option(option, values)
---@param opts? {values?: {[1]:any, [2]:any}, name?: string}
function M.option(option, opts)
opts = opts or {}
local name = opts.name or option
local on = opts.values and opts.values[2] or true
local off = opts.values and opts.values[1] or false
---@type lazyvim.Toggle
local ret = {
name = option,
name = name,
get = function()
if values then
return vim.opt_local[option]:get() == values[2]
end
return vim.opt_local[option]:get()
return vim.opt_local[option]:get() == on
end,
set = function(state)
if values then
if state then
vim.opt_local[option] = values[2]
else
vim.opt_local[option] = values[1]
end
else
---@diagnostic disable-next-line: no-unknown
vim.opt_local[option] = state
end
vim.opt_local[option] = state and on or off
end,
}
return ret