modules/highlights: add highlightOverride

This commit is contained in:
Austin Horstman 2024-02-08 21:33:56 -06:00 committed by Gaétan Lepage
parent b57fb15344
commit 30bc345dee
2 changed files with 55 additions and 14 deletions

View file

@ -9,7 +9,18 @@ with lib; {
highlight = mkOption { highlight = mkOption {
type = types.attrsOf helpers.nixvimTypes.highlight; type = types.attrsOf helpers.nixvimTypes.highlight;
default = {}; 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 = '' example = ''
highlight = { highlight = {
Comment.fg = "#ff0000"; Comment.fg = "#ff0000";
@ -31,7 +42,11 @@ with lib; {
config = { config = {
extraConfigLuaPre = extraConfigLuaPre =
(optionalString (config.highlight != {}) '' (optionalString (config.highlight != {})
/*
lua
*/
''
-- Highlight groups {{ -- Highlight groups {{
do do
local highlights = ${helpers.toLuaObject config.highlight} local highlights = ${helpers.toLuaObject config.highlight}
@ -42,7 +57,11 @@ with lib; {
end end
-- }} -- }}
'') '')
+ (optionalString (config.match != {}) '' + (optionalString (config.match != {})
/*
lua
*/
''
-- Match groups {{ -- Match groups {{
do do
local match = ${helpers.toLuaObject config.match} local match = ${helpers.toLuaObject config.match}
@ -53,5 +72,22 @@ with lib; {
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
-- }}
'';
}; };
} }

View file

@ -1,7 +1,12 @@
{ {
example = { example = {
options.termguicolors = true; options.termguicolors = true;
highlight = { highlight = {
MacchiatoRed.fg = "#ed8796";
};
highlightOverride = {
Normal.fg = "#ff0000"; Normal.fg = "#ff0000";
# With raw # With raw