1

Update preferences

This commit is contained in:
Alex Yatskov 2024-04-29 20:33:02 -07:00
parent 0778dbca64
commit e8dcbc6da4
2 changed files with 20 additions and 28 deletions

View File

@ -1,4 +1,4 @@
local configs = { local opt_curr = {
default = { default = {
brace_last_indent = false, brace_last_indent = false,
brace_last_wrap = true, brace_last_wrap = true,
@ -17,46 +17,38 @@ local configs = {
} }
} }
local function set(opts, filetypes) local function setup(opt)
if opts then for file_type, file_opt in pairs(opt) do
if type(filetypes) == 'string' then local file_opt_curr = opt_curr[file_type]
filetypes = {filetypes} if not file_opt_curr then
elseif not filetypes then file_opt_curr = {}
filetypes = {'default'} opt_curr[file_type] = file_opt_curr
end end
for _, filetype in ipairs(filetypes) do for param_name, param_value in pairs(file_opt) do
local config = configs[filetype] file_opt_curr[param_name] = param_value
if not config then
config = {}
configs[filetype] = config
end
for key, value in pairs(opts) do
config[key] = value
end
end end
end end
end end
local function get() local function get()
local file_config = configs[vim.bo.filetype] local file_opt_curr = opt_curr[vim.bo.filetype]
local config = {} local file_opt = {}
for key, value in pairs(configs.default) do for param_name, param_value in pairs(opt_curr.default) do
config[key] = value file_opt[param_name] = param_value
if file_config then if file_opt_curr then
local file_value = file_config[key] param_value = file_opt_curr[param_name]
if file_value ~= nil then if param_value ~= nil then
config[key] = file_config[key] file_opt[param_name] = param_value
end end
end end
end end
return config return file_opt
end end
return { return {
set = set, setup = setup,
get = get, get = get,
} }

View File

@ -10,5 +10,5 @@ end
return { return {
reflow = reflow, reflow = reflow,
setup = config.set, setup = config.setup,
} }