nix-community.nixvim/modules/highlights.nix
Stanislav Asunkin 9317537848 modules: avoid setting empty strings to extraConfig* options
Problem:  Some modules are setting empty strings to extraConfig* options
          with the intention to not generate any config. But empty
          strings are also values, so they are still concatenated in the
          final value of extraConfig* options. This results in a
          multiple empty strings in extraConfigs.

Solution: Avoid using optionalString when setting values to extraConfig*
          options. Use mkIf instead.

          This commit also fixes mkIf condition in autocmd module.

          `mkNeovimPlugin` is a special case. To avoid evaluating
          caller's arguments mkMerge/optionalAttrs pattern is used
          instead.
2024-07-22 23:18:53 +02:00

86 lines
1.9 KiB
Nix

{
lib,
helpers,
config,
...
}:
with lib;
{
options = {
highlight = mkOption {
type = types.attrsOf helpers.nixvimTypes.highlight;
default = { };
description = "Define new highlight groups";
example = {
MacchiatoRed.fg = "#ed8796";
};
};
highlightOverride = mkOption {
type = types.attrsOf helpers.nixvimTypes.highlight;
default = { };
description = "Define highlight groups to override existing highlight";
example = {
Comment.fg = "#ff0000";
};
};
match = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Define match groups";
example = {
ExtraWhitespace = "\\s\\+$";
};
};
};
config = mkMerge [
{
extraConfigLuaPre =
mkIf (config.highlight != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
-- }}
'';
extraConfigLuaPost =
mkIf (config.highlightOverride != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlightOverride}
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
-- }}
'';
}
{
extraConfigLuaPre =
mkIf (config.match != { })
# lua
''
-- Match groups {{
do
local match = ${helpers.toLuaObject config.match}
for k,v in pairs(match) do
vim.fn.matchadd(k, v)
end
end
-- }}
'';
}
];
}