nix-community.nixvim/modules/options.nix

83 lines
1.8 KiB
Nix
Raw Normal View History

{
lib,
helpers,
config,
...
}:
2023-12-28 11:14:57 +01:00
with lib; let
optionsAttrs = {
options = {
prettyName = "options";
luaVariableName = "options";
luaApi = "opt";
2023-12-29 10:30:47 +01:00
description = "The configuration options, e.g. line numbers (`vim.opt.*`)";
};
2023-12-28 11:14:57 +01:00
globalOptions = {
prettyName = "global options";
luaVariableName = "global_options";
luaApi = "opt_global";
2023-12-29 10:30:47 +01:00
description = "The configuration global options (`vim.opt_global.*`)";
};
2023-12-28 11:14:57 +01:00
localOptions = {
prettyName = "local options";
luaVariableName = "local_options";
luaApi = "opt_local";
2023-12-29 10:30:47 +01:00
description = "The configuration local options (`vim.opt_local.*`)";
};
2023-12-28 11:14:57 +01:00
globals = {
prettyName = "globals";
luaVariableName = "globals";
luaApi = "g";
2023-12-29 10:30:47 +01:00
description = "Global variables (`vim.g.*`)";
};
};
2023-12-28 11:14:57 +01:00
in {
options =
mapAttrs
(
_: {description, ...}:
mkOption {
type = with types; attrsOf anything;
default = {};
inherit description;
}
)
optionsAttrs;
config = {
extraConfigLuaPre =
2023-12-28 11:14:57 +01:00
concatLines
(
mapAttrsToList
(
optionName: {
prettyName,
luaVariableName,
luaApi,
...
}: let
varName = "nixvim_${luaVariableName}";
optionDefinitions = config.${optionName};
in
optionalString
(optionDefinitions != {})
''
-- Set up ${prettyName} {{{
do
local ${varName} = ${helpers.toLuaObject optionDefinitions}
2023-12-28 11:14:57 +01:00
for k,v in pairs(${varName}) do
vim.${luaApi}[k] = v
end
end
-- }}}
''
)
optionsAttrs
);
};
}