nvf/modules/neovim/init/highlight.nix

120 lines
3.3 KiB
Nix
Raw Normal View History

2025-01-19 17:01:43 +00:00
{
config,
lib,
...
}: let
2025-01-19 18:36:32 +00:00
inherit (lib.options) mkOption;
2025-01-19 17:11:12 +00:00
inherit (lib.types) nullOr attrsOf listOf submodule bool ints str enum;
2025-01-19 18:36:32 +00:00
inherit (lib.strings) hasPrefix concatLines;
2025-01-19 17:01:43 +00:00
inherit (lib.attrsets) mapAttrsToList;
2025-01-19 18:36:32 +00:00
inherit (lib.nvim.dag) entryBetween;
2025-01-19 17:01:43 +00:00
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.types) hexColor;
mkColorOption = target:
mkOption {
type = nullOr hexColor;
default = null;
2025-01-19 18:36:32 +00:00
example = "#ebdbb2";
2025-01-19 17:01:43 +00:00
description = ''
The ${target} color to use. Written as color name or hex "#RRGGBB".
'';
};
mkBoolOption = name:
mkOption {
type = nullOr bool;
default = null;
example = false;
2025-01-19 18:36:32 +00:00
description = "Whether to enable ${name}";
2025-01-19 17:01:43 +00:00
};
cfg = config.vim.highlight;
in {
options.vim.highlight = mkOption {
type = attrsOf (submodule {
# See :h nvim_set_hl
options = {
bg = mkColorOption "background";
fg = mkColorOption "foreground";
sp = mkColorOption "special";
blend = mkOption {
type = nullOr (ints.between 0 100);
default = null;
description = "Blend as an integer between 0 and 100";
};
bold = mkBoolOption "bold";
standout = mkBoolOption "standout";
underline = mkBoolOption "underline";
undercurl = mkBoolOption "undercurl";
underdouble = mkBoolOption "underdouble";
underdotted = mkBoolOption "underdotted";
underdashed = mkBoolOption "underdashed";
strikethrough = mkBoolOption "strikethrough";
italic = mkBoolOption "italic";
reverse = mkBoolOption "reverse";
nocombine = mkBoolOption "nocombine";
link = mkOption {
type = nullOr str;
default = null;
description = "The name of another highlight group to link to";
};
default = mkOption {
type = nullOr bool;
default = null;
description = "Don't override existing definition";
};
ctermfg = mkOption {
type = nullOr str;
default = null;
description = "The cterm foreground color to use";
};
ctermbg = mkOption {
type = nullOr str;
default = null;
description = "The cterm background color to use";
};
cterm = mkOption {
2025-01-19 17:11:12 +00:00
type = nullOr (listOf (enum [
"bold"
"underline"
"undercurl"
"underdouble"
"underdotted"
"underdashed"
"strikethrough"
"reverse"
"inverse"
"italic"
"standout"
"altfont"
"nocombine"
"NONE"
]));
2025-01-19 17:01:43 +00:00
default = null;
description = "The cterm arguments to use. See :h highlight-args";
};
force = mkBoolOption "force update";
};
});
default = {};
2025-01-20 13:16:45 +00:00
example = {
SignColumn = {
bg = "#282828";
};
};
2025-01-19 18:36:32 +00:00
description = "Custom highlights to apply";
2025-01-19 17:01:43 +00:00
};
config = {
vim.luaConfigRC.highlight = let
highlights =
mapAttrsToList (
name: value: ''vim.api.nvim_set_hl(0, ${toLuaObject name}, ${toLuaObject value})''
)
cfg;
in
2025-01-19 18:36:32 +00:00
entryBetween ["lazyConfigs" "pluginConfigs" "extraPluginConfigs"] ["theme"] (concatLines highlights);
2025-01-19 17:01:43 +00:00
};
}