Update option parsing code
This commit is contained in:
parent
1df9315390
commit
6b63f79b2d
@ -1,56 +1,53 @@
|
|||||||
local options_current = {
|
local options_current = {
|
||||||
default = {
|
|
||||||
auto_reload = false,
|
auto_reload = false,
|
||||||
brace_last_indent = false,
|
brace_last_indent = false,
|
||||||
brace_last_wrap = true,
|
brace_last_wrap = true,
|
||||||
brace_pad = false,
|
brace_pad = false,
|
||||||
comma_last = {['{'] = true, ['['] = true},
|
comma_last = {['{'] = true},
|
||||||
comma_prefix = false,
|
comma_prefix = false,
|
||||||
comma_prefix_indent = false,
|
comma_prefix_indent = false,
|
||||||
},
|
by_filetype = {
|
||||||
go = {
|
go = {comma_last = true},
|
||||||
comma_last = true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function setup(opt)
|
local function merge_table(target, source)
|
||||||
for file_type, file_options in pairs(opt) do
|
for key, value in pairs(source) do
|
||||||
local file_options_current = options_current[file_type]
|
if type(target[key]) == 'table' then
|
||||||
if not file_options_current then
|
merge_table(target[key], value)
|
||||||
file_options_current = {}
|
else
|
||||||
options_current[file_type] = file_options_current
|
target[key] = value
|
||||||
end
|
|
||||||
|
|
||||||
for param_name, param_value in pairs(file_options) do
|
|
||||||
file_options_current[param_name] = param_value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function query(param_name, pairing)
|
local function query_with_pairing(value, pairing)
|
||||||
local default_param_value = options_current.default[param_name]
|
if type(value) == 'table' and pairing then
|
||||||
local param_value = default_param_value
|
local sub_value = value[pairing.open]
|
||||||
|
if sub_value == nil then
|
||||||
local file_options_current = options_current[vim.bo.filetype]
|
value = value['*']
|
||||||
if file_options_current then
|
else
|
||||||
param_value = file_options_current[param_name]
|
value = sub_value
|
||||||
if param_value == nil then
|
|
||||||
param_value = default_param_value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(param_value) == 'table' then
|
return value
|
||||||
param_value = param_value[pairing.open]
|
end
|
||||||
if param_value == nil then
|
|
||||||
param_value = default_param_value
|
local function setup(options)
|
||||||
|
merge_table(options_current, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function query(name, pairing)
|
||||||
|
local options_current_by_filetype = options_current.by_filetype[vim.bo.filetype]
|
||||||
|
if options_current_by_filetype then
|
||||||
|
local value = query_with_pairing(options_current_by_filetype[name], pairing)
|
||||||
|
if value ~= nil then
|
||||||
|
return value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(param_value) == 'table' then
|
return query_with_pairing(options_current[name], pairing)
|
||||||
param_value = param_value[pairing.open]
|
|
||||||
end
|
|
||||||
|
|
||||||
return param_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user