1
argonaut.nvim/lua/argonaut/options.lua

57 lines
1.3 KiB
Lua
Raw Normal View History

2024-12-30 20:31:50 -08:00
local options_current = {
2025-01-19 11:38:03 -08:00
auto_reload = false,
brace_last_indent = false,
brace_last_wrap = true,
brace_pad = false,
comma_last = {['{'] = true},
comma_prefix = false,
comma_prefix_indent = false,
by_filetype = {
go = {comma_last = true},
2024-12-30 20:31:50 -08:00
},
}
2025-01-19 11:38:03 -08:00
local function merge_table(target, source)
for key, value in pairs(source) do
if type(target[key]) == 'table' then
merge_table(target[key], value)
else
target[key] = value
2024-12-30 20:31:50 -08:00
end
end
end
2025-01-19 11:38:03 -08:00
local function query_with_pairing(value, pairing)
if type(value) == 'table' and pairing then
local sub_value = value[pairing.open]
if sub_value == nil then
value = value['*']
else
value = sub_value
2024-12-30 20:31:50 -08:00
end
end
2025-01-19 11:38:03 -08:00
return value
end
2024-12-30 20:31:50 -08:00
2025-01-19 11:38:03 -08:00
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
2024-12-30 20:31:50 -08:00
end
2025-01-19 11:38:03 -08:00
return query_with_pairing(options_current[name], pairing)
2024-12-30 20:31:50 -08:00
end
return {
setup = setup,
query = query,
}