Skip to content

Commit f2a991a

Browse files
committed
plugins/colorizer: rename, switch to mkNeovimPlugin
1 parent 4b5364a commit f2a991a

File tree

4 files changed

+313
-204
lines changed

4 files changed

+313
-204
lines changed

plugins/by-name/colorizer/default.nix

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
{
2+
lib,
3+
...
4+
}:
5+
let
6+
inherit (lib.nixvim) defaultNullOpts;
7+
inherit (lib) types;
8+
in
9+
lib.nixvim.neovim-plugin.mkNeovimPlugin {
10+
name = "colorizer";
11+
originalName = "nvim-colorizer.lua";
12+
package = "nvim-colorizer-lua";
13+
14+
maintainers = [ lib.maintainers.GaetanLepage ];
15+
16+
# TODO introduced 2024-07-06: remove after 25.05
17+
imports =
18+
let
19+
oldPluginPath = [
20+
"plugins"
21+
"nvim-colorizer"
22+
];
23+
newPluginPath = [
24+
"plugins"
25+
"colorizer"
26+
];
27+
28+
optionsToRename = [
29+
"RGB"
30+
"RRGGBB"
31+
"names"
32+
"RRGGBBAA"
33+
"AARRGGBB"
34+
"rgb_fn"
35+
"hsl_fn"
36+
"tailwind"
37+
"sass"
38+
"virtualtext"
39+
"virtualtext_inline"
40+
"virtualtext_mode"
41+
"always_update"
42+
];
43+
44+
renameOption =
45+
optionName:
46+
lib.mkRenamedOptionModule
47+
(
48+
oldPluginPath
49+
++ [
50+
"userDefaultOptions"
51+
optionName
52+
]
53+
)
54+
(
55+
newPluginPath
56+
++ [
57+
"settings"
58+
"user_default_options"
59+
optionName
60+
]
61+
);
62+
in
63+
map renameOption optionsToRename
64+
++
65+
lib.mapAttrsToList
66+
(
67+
oldOptionName: newPath:
68+
lib.mkRenamedOptionModule (oldPluginPath ++ [ oldOptionName ]) (newPluginPath ++ newPath)
69+
)
70+
{
71+
enable = [ "enable" ];
72+
package = [ "package" ];
73+
fileTypes = [
74+
"settings"
75+
"filetypes"
76+
];
77+
bufTypes = [
78+
"settings"
79+
"bufTypes"
80+
];
81+
};
82+
83+
settingsOptions =
84+
let
85+
colorizerOptions = {
86+
names = defaultNullOpts.mkBool true ''
87+
Whether to highlight name codes like `Blue` or `blue`.
88+
'';
89+
90+
RGB = defaultNullOpts.mkBool true ''
91+
Whether to highlight `#RGB` hex codes.
92+
'';
93+
94+
RRGGBB = defaultNullOpts.mkBool true ''
95+
Whether to highlight `#RRGGBB` hex codes.
96+
'';
97+
98+
RRGGBBAA = defaultNullOpts.mkBool false ''
99+
Whether to highlight `#RRGGBBAA` hex codes.
100+
'';
101+
102+
AARRGGBB = defaultNullOpts.mkBool false ''
103+
Whether to highlight `0xAARRGGBB` hex codes.
104+
'';
105+
106+
rgb_fn = defaultNullOpts.mkBool false ''
107+
Whether to highlight CSS `rgb()` and `rgba()` functions.
108+
'';
109+
110+
hsl_fn = defaultNullOpts.mkBool false ''
111+
Whether to highlight CSS `hsl()` and `hsla()` functions.
112+
'';
113+
114+
css = defaultNullOpts.mkBool false ''
115+
Enable all CSS features: `rgb_fn`, `hsl_fn`, `names`, `RGB`, `RRGGBB`.
116+
'';
117+
118+
css_fn = defaultNullOpts.mkBool false ''
119+
Enable all CSS *functions*: `rgb_fn`, `hsl_fn`.
120+
'';
121+
122+
mode =
123+
defaultNullOpts.mkEnum
124+
[
125+
"foreground"
126+
"background"
127+
"virtualtext"
128+
]
129+
"background"
130+
''
131+
Set the display mode.
132+
'';
133+
134+
tailwind =
135+
defaultNullOpts.mkNullable
136+
(
137+
with types;
138+
either bool (enum [
139+
"normal"
140+
"lsp"
141+
"both"
142+
])
143+
)
144+
false
145+
''
146+
Enable tailwind colors.
147+
It can be a boolean, `"normal"`, `"lsp"` or `"both"`.
148+
`true` is same as `"normal"`.
149+
'';
150+
151+
sass = {
152+
enable = defaultNullOpts.mkBool false ''
153+
Enable sass colors.
154+
'';
155+
156+
parsers = defaultNullOpts.mkListOf types.str [ "css" ] ''
157+
Parsers can contain values used in `user_default_options`.
158+
'';
159+
};
160+
161+
virtualtext = defaultNullOpts.mkStr "■" ''
162+
Virtualtext character to use.
163+
'';
164+
165+
virtualtext_inline = defaultNullOpts.mkBool false ''
166+
Display virtualtext inline with color.
167+
'';
168+
169+
virtualtext_mode = defaultNullOpts.mkEnum [ "background" "foreground" ] "foreground" ''
170+
Virtualtext highlight mode.
171+
'';
172+
173+
always_update = defaultNullOpts.mkBool false ''
174+
Update color values even if buffer is not focused.
175+
Example use: `cmp_menu`, `cmp_docs`.
176+
'';
177+
};
178+
in
179+
{
180+
filetypes = defaultNullOpts.mkNullable' {
181+
type =
182+
with types;
183+
either (attrsOf (
184+
either str (submodule {
185+
freeformType = attrsOf anything;
186+
options = colorizerOptions;
187+
})
188+
)) (listOf str);
189+
pluginDefault = [ ];
190+
description = ''
191+
Per-filetype options.
192+
'';
193+
example = {
194+
__unkeyed-1 = "css";
195+
__unkeyed-2 = "javascript";
196+
html = {
197+
mode = "background";
198+
};
199+
};
200+
};
201+
202+
user_default_options = colorizerOptions;
203+
204+
buftypes = defaultNullOpts.mkNullable' {
205+
type =
206+
with types;
207+
either (attrsOf (
208+
either str (submodule {
209+
freeformType = attrsOf anything;
210+
options = colorizerOptions;
211+
})
212+
)) (listOf str);
213+
pluginDefault = [ ];
214+
description = ''
215+
Per-buftype options.
216+
Buftype value is fetched by `vim.bo.buftype`.
217+
'';
218+
example = [
219+
"*"
220+
"!prompt"
221+
"!popup"
222+
];
223+
};
224+
225+
user_commands = defaultNullOpts.mkNullable' {
226+
type = with types; either bool (listOf str);
227+
pluginDefault = true;
228+
description = ''
229+
Enable all or some usercommands.
230+
'';
231+
};
232+
};
233+
234+
settingsExample = {
235+
filetypes = {
236+
__unkeyed-1 = "*";
237+
__unkeyed-2 = "!vim";
238+
css.rgb_fn = true;
239+
html.names = false;
240+
};
241+
user_default_options = {
242+
mode = "virtualtext";
243+
names = false;
244+
virtualtext = "■ ";
245+
};
246+
user_commands = [
247+
"ColorizerToggle"
248+
"ColorizerReloadAllBuffers"
249+
];
250+
};
251+
}

0 commit comments

Comments
 (0)