mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-22 00:48:58 +02:00
modules/options: refactoring
This commit is contained in:
parent
02149dbb01
commit
a7144cfbf7
1 changed files with 58 additions and 57 deletions
|
@ -4,78 +4,79 @@
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib; {
|
with lib; let
|
||||||
|
optionsAttrs = {
|
||||||
options = {
|
options = {
|
||||||
options = mkOption {
|
prettyName = "options";
|
||||||
type = types.attrsOf types.anything;
|
luaVariableName = "options";
|
||||||
default = {};
|
luaApi = "opt";
|
||||||
description = "The configuration options, e.g. line numbers";
|
description = "The configuration options, e.g. line numbers";
|
||||||
};
|
};
|
||||||
|
|
||||||
globalOptions = mkOption {
|
globalOptions = {
|
||||||
type = types.attrsOf types.anything;
|
prettyName = "global options";
|
||||||
default = {};
|
luaVariableName = "global_options";
|
||||||
|
luaApi = "opt_global";
|
||||||
description = "The configuration global options";
|
description = "The configuration global options";
|
||||||
};
|
};
|
||||||
|
|
||||||
localOptions = mkOption {
|
localOptions = {
|
||||||
type = types.attrsOf types.anything;
|
prettyName = "local options";
|
||||||
default = {};
|
luaVariableName = "local_options";
|
||||||
|
luaApi = "opt_local";
|
||||||
description = "The configuration local options";
|
description = "The configuration local options";
|
||||||
};
|
};
|
||||||
|
|
||||||
globals = mkOption {
|
globals = {
|
||||||
type = types.attrsOf types.anything;
|
prettyName = "globals";
|
||||||
default = {};
|
luaVariableName = "globals";
|
||||||
|
luaApi = "g";
|
||||||
description = "Global variables";
|
description = "Global variables";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
in {
|
||||||
|
options =
|
||||||
|
mapAttrs
|
||||||
|
(
|
||||||
|
_: {description, ...}:
|
||||||
|
mkOption {
|
||||||
|
type = with types; attrsOf anything;
|
||||||
|
default = {};
|
||||||
|
inherit description;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
optionsAttrs;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
extraConfigLuaPre =
|
extraConfigLuaPre =
|
||||||
optionalString (config.globals != {}) ''
|
concatLines
|
||||||
-- Set up globals {{{
|
(
|
||||||
|
mapAttrsToList
|
||||||
|
(
|
||||||
|
optionName: {
|
||||||
|
prettyName,
|
||||||
|
luaVariableName,
|
||||||
|
luaApi,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
varName = "nixvim_${luaVariableName}";
|
||||||
|
optionDefinitions = config.${optionName};
|
||||||
|
in
|
||||||
|
optionalString
|
||||||
|
(optionDefinitions != {})
|
||||||
|
''
|
||||||
|
-- Set up ${prettyName} {{{
|
||||||
do
|
do
|
||||||
local nixvim_globals = ${helpers.toLuaObject config.globals}
|
local ${varName} = ${helpers.toLuaObject optionDefinitions}
|
||||||
|
|
||||||
for k,v in pairs(nixvim_globals) do
|
for k,v in pairs(${varName}) do
|
||||||
vim.g[k] = v
|
vim.${luaApi}[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
''
|
''
|
||||||
+ optionalString (config.options != {}) ''
|
)
|
||||||
-- Set up options {{{
|
optionsAttrs
|
||||||
do
|
);
|
||||||
local nixvim_options = ${helpers.toLuaObject config.options}
|
|
||||||
|
|
||||||
for k,v in pairs(nixvim_options) do
|
|
||||||
vim.opt[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- }}}
|
|
||||||
''
|
|
||||||
+ optionalString (config.localOptions != {}) ''
|
|
||||||
-- Set up local options {{{
|
|
||||||
do
|
|
||||||
local nixvim_local_options = ${helpers.toLuaObject config.localOptions}
|
|
||||||
|
|
||||||
for k,v in pairs(nixvim_local_options) do
|
|
||||||
vim.opt_local[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- }}}
|
|
||||||
''
|
|
||||||
+ optionalString (config.globalOptions != {}) ''
|
|
||||||
-- Set up global options {{{
|
|
||||||
do
|
|
||||||
local nixvim_global_options = ${helpers.toLuaObject config.globalOptions}
|
|
||||||
|
|
||||||
for k,v in pairs(nixvim_global_options) do
|
|
||||||
vim.opt_global[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- }}}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue