Skip to content

Commit

Permalink
modules/highlights: add highlightOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman authored and GaetanLepage committed Feb 11, 2024
1 parent b57fb15 commit 30bc345
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
64 changes: 50 additions & 14 deletions modules/highlights.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ with lib; {
highlight = mkOption {
type = types.attrsOf helpers.nixvimTypes.highlight;
default = {};
description = "Define highlight groups.";
description = "Define new highlight groups";
example = ''
highlight = {
MacchiatoRed.fg = "#ed8796";
};
'';
};

highlightOverride = mkOption {
type = types.attrsOf helpers.nixvimTypes.highlight;
default = {};
description = "Define highlight groups to override existing highlight";
example = ''
highlight = {
Comment.fg = "#ff0000";
Expand All @@ -31,27 +42,52 @@ with lib; {

config = {
extraConfigLuaPre =
(optionalString (config.highlight != {}) ''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
(optionalString (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)
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
end
-- }}
'')
+ (optionalString (config.match != {}) ''
-- Match groups {{
-- }}
'')
+ (optionalString (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
-- }}
'');
-- }}
'');

extraConfigLuaPost =
optionalString (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
-- }}
'';
};
}
5 changes: 5 additions & 0 deletions tests/test-sources/modules/highlight.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
example = {
options.termguicolors = true;

highlight = {
MacchiatoRed.fg = "#ed8796";
};

highlightOverride = {
Normal.fg = "#ff0000";

# With raw
Expand Down

0 comments on commit 30bc345

Please sign in to comment.