Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight: init #571

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/rl-0.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- `mini.trailspace`
- `mini.visits`
- Add [fzf-lua](https://github.com/ibhagwan/fzf-lua) in `vim.fzf-lua`
- Add options to define highlights under [](#opt-vim.highlight)

[kaktu5](https://github.com/kaktu5):

Expand Down
1 change: 1 addition & 0 deletions modules/neovim/init/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
imports = [
./basic.nix
./debug.nix
./highlight.nix
./spellcheck.nix
];
}
119 changes: 119 additions & 0 deletions modules/neovim/init/highlight.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
config,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.types) nullOr attrsOf listOf submodule bool ints str enum;
inherit (lib.strings) hasPrefix concatLines;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.nvim.dag) entryBetween;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.types) hexColor;

mkColorOption = target:
mkOption {
type = nullOr hexColor;
default = null;
example = "#ebdbb2";
description = ''
The ${target} color to use. Written as color name or hex "#RRGGBB".
'';
};

mkBoolOption = name:
mkOption {
type = nullOr bool;
default = null;
example = false;
description = "Whether to enable ${name}";
};
Comment on lines +14 to +30
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but these may be better suited for the extended lib.


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";
Comment on lines +46 to +56
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapAttrs (_: mkBoolOption) can probably handle this with less repetition of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        // builtins.listToAttrs (map (option:
          nameValuePair option (mkOption {
            type = nullOr bool;
            default = null;
            example = false;
            description = "Whether to enable ${option}";
          })) [
          "bold"
          "standout"
          "underline"
          "undercurl"
          "underdotted"
          "underdashed"
          "strikethrough"
          "italic"
          "reverse"
          "nocombine"
          "force"
        ]);

Something like this? I don't really like that code, i think it looked better with repetition of mkBoolOption

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapAttrs (_: mkBoolOption) {
  bold = "bold";
  standout = "standout";
  underline = "underline";
  undercurl =  "undercurl";
  underdouble = "underdouble";
  underdotted = "underdotted";
  underdashed = "underdashed";
  strikethrough =  "strikethrough";
  italic = "italic";
  reverse =  "reverse";
  nocombine =  "nocombine";
}

would do it if I'm not mistaken. But you can keep the current method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that the code looks better with the repetition, and the two alternatives only introduce unneeded complexity and makes the code harder to read, even when there is slightly more repetition.

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 {
type = nullOr (listOf (enum [
"bold"
"underline"
"undercurl"
"underdouble"
"underdotted"
"underdashed"
"strikethrough"
"reverse"
"inverse"
"italic"
"standout"
"altfont"
"nocombine"
"NONE"
]));
default = null;
description = "The cterm arguments to use. See ':h highlight-args'";
};
force = mkBoolOption "force update";
};
});
default = {};
example = {
SignColumn = {
bg = "#282828";
};
};
description = "Custom highlights to apply";
};

config = {
vim.luaConfigRC.highlight = let
highlights =
mapAttrsToList (
name: value: ''vim.api.nvim_set_hl(0, ${toLuaObject name}, ${toLuaObject value})''
)
cfg;
in
entryBetween ["lazyConfigs" "pluginConfigs" "extraPluginConfigs"] ["theme"] (concatLines highlights);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @horriblename on this. I'm not actually sure where lazyConfigs is located in the DAG system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it based on the code in modules/wrapper/rc/config.nix, where those three are listed as after each other.

};
}
Loading