From 1022eae16162fb6263295b696ba6d53d867e5268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Sat, 21 Jan 2023 18:09:58 +0100 Subject: [PATCH] modules/highlights: added a wrapper around vim.fn.matchadd (#123) * modules/highlights: added a wrapper around vim.fn.matchadd * modules/highlights: fix mkIf Co-authored-by: Pedro Alves --- modules/highlights.nix | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/highlights.nix b/modules/highlights.nix index 0f5fc1f0c0..0c6c473aa9 100644 --- a/modules/highlights.nix +++ b/modules/highlights.nix @@ -15,10 +15,21 @@ with lib; }; ''; }; + + match = mkOption { + type = types.attrsOf types.str; + default = { }; + description = "Define match groups"; + example = '' + match = { + ExtraWhitespace = '\\s\\+$'; + }; + ''; + }; }; - config = mkIf (config.highlight != { }) { - extraConfigLuaPost = '' + config = mkIf (config.highlight != { } || config.matches != { }) { + extraConfigLuaPost = (optionalString (config.highlight != { }) '' -- Highlight groups {{ do local highlights = ${helpers.toLuaObject config.highlight} @@ -28,6 +39,18 @@ with lib; end end -- }} - ''; + '') ++ + (optionalString (config.matches != { }) '' + -- Match groups {{ + do + local match = ${helpers.toLuaObject config.match} + + for k,v in pairs(match) do + vim.fn.matchadd(k, v) + end + end + -- }} + ''); }; } +