-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
which-key.nix
266 lines (243 loc) · 8.21 KB
/
which-key.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{
lib,
helpers,
pkgs,
config,
...
}:
with lib;
{
options.plugins.which-key = {
enable = mkEnableOption "which-key.nvim, a plugin that popup with possible key bindings of the command you started typing";
package = helpers.mkPluginPackageOption "which-key-nvim" pkgs.vimPlugins.which-key-nvim;
registrations = mkOption {
type = with types; attrsOf anything;
default = { };
description = "Manually register the description of mappings.";
example = {
"<leader>p" = "Find git files with telescope";
};
};
plugins = {
marks = helpers.defaultNullOpts.mkBool true "shows a list of your marks on ' and `";
registers = helpers.defaultNullOpts.mkBool true ''shows your registers on " in NORMAL or <C-r> in INSERT mode'';
spelling = {
enabled = helpers.defaultNullOpts.mkBool true "enabling this will show WhichKey when pressing z= to select spelling suggestions";
suggestions = helpers.defaultNullOpts.mkInt 20 "how many suggestions should be shown in the list?";
};
presets = {
operators = helpers.defaultNullOpts.mkBool true "adds help for operators like d, y, ...";
motions = helpers.defaultNullOpts.mkBool true "adds help for motions";
textObjects = helpers.defaultNullOpts.mkBool true "help for text objects triggered after entering an operator";
windows = helpers.defaultNullOpts.mkBool true "default bindings on <c-w>";
nav = helpers.defaultNullOpts.mkBool true "misc bindings to work with windows";
z = helpers.defaultNullOpts.mkBool true "bindings for folds, spelling and others prefixed with z";
g = helpers.defaultNullOpts.mkBool true "bindings for prefixed with g";
};
};
operators = helpers.defaultNullOpts.mkAttrsOf types.str { gc = "Comments"; } ''
add operators that will trigger motion and text object completion
to enable all native operators, set the preset / operators plugin above
'';
keyLabels = helpers.defaultNullOpts.mkAttrsOf types.str { } ''
override the label used to display some keys. It doesn't effect WK in any other way.
'';
motions = {
count = helpers.defaultNullOpts.mkBool true "";
};
icons = {
breadcrumb = helpers.defaultNullOpts.mkStr "»" "symbol used in the command line area that shows your active key combo";
separator = helpers.defaultNullOpts.mkStr "➜" "symbol used between a key and it's label";
group = helpers.defaultNullOpts.mkStr "+" "symbol prepended to a group";
};
popupMappings = {
scrollDown = helpers.defaultNullOpts.mkStr "<c-d>" "binding to scroll down inside the popup";
scrollUp = helpers.defaultNullOpts.mkStr "<c-u>" "binding to scroll up inside the popup";
};
window =
let
spacingOptions = types.submodule {
options =
genAttrs
[
"top"
"right"
"bottom"
"left"
]
(
n:
mkOption {
type = types.ints.unsigned;
description = "Spacing at the ${n}.";
}
);
};
in
{
border = helpers.defaultNullOpts.mkBorder "none" "which-key" "";
position = helpers.defaultNullOpts.mkEnumFirstDefault [
"bottom"
"top"
] "";
margin = helpers.defaultNullOpts.mkNullable spacingOptions {
top = 1;
right = 0;
bottom = 1;
left = 0;
} "extra window margin";
padding = helpers.defaultNullOpts.mkNullable spacingOptions {
top = 1;
right = 2;
bottom = 1;
left = 2;
} "extra window padding";
winblend = helpers.defaultNullOpts.mkNullable (types.ints.between 0
100
) 0 "0 for fully opaque and 100 for fully transparent";
};
layout =
let
rangeOption = types.submodule {
options = {
min = mkOption {
type = types.int;
description = "Minimum size.";
};
max = mkOption {
type = types.int;
description = "Maximum size.";
};
};
};
in
{
height = helpers.defaultNullOpts.mkNullable rangeOption {
min = 4;
max = 25;
} "min and max height of the columns";
width = helpers.defaultNullOpts.mkNullable rangeOption {
min = 20;
max = 50;
} "min and max width of the columns";
spacing = helpers.defaultNullOpts.mkInt 3 "spacing between columns";
align = helpers.defaultNullOpts.mkEnumFirstDefault [
"left"
"center"
"right"
] "";
};
ignoreMissing = helpers.defaultNullOpts.mkBool false "enable this to hide mappings for which you didn't specify a label";
hidden = helpers.defaultNullOpts.mkListOf types.str [
"<silent>"
"<cmd>"
"<Cmd>"
"<CR>"
"^:"
"^ "
"^call "
"^lua "
] "hide mapping boilerplate";
showHelp = helpers.defaultNullOpts.mkBool true "show a help message in the command line for using WhichKey";
showKeys = helpers.defaultNullOpts.mkBool true "show the currently pressed key and its label as a message in the command line";
triggers = helpers.defaultNullOpts.mkNullable (
with types; either (enum [ "auto" ]) (listOf str)
) "auto" "automatically setup triggers, or specify a list manually";
triggersNoWait =
helpers.defaultNullOpts.mkListOf types.str
[
"`"
"'"
"g`"
"g'"
"\""
"<c-r>"
"z="
]
''
list of triggers, where WhichKey should not wait for timeoutlen and show immediately
'';
triggersBlackList =
helpers.defaultNullOpts.mkAttrsOf (types.listOf types.str)
{
i = [
"j"
"k"
];
v = [
"j"
"k"
];
}
''
list of mode / prefixes that should never be hooked by WhichKey
this is mostly relevant for keymaps that start with a native binding
'';
disable = {
buftypes = helpers.defaultNullOpts.mkListOf types.str [ ] "Disabled by default for Telescope";
filetypes = helpers.defaultNullOpts.mkListOf types.str [ ] "";
};
};
config =
let
cfg = config.plugins.which-key;
setupOptions = {
plugins = {
inherit (cfg.plugins) marks registers spelling;
presets = {
inherit (cfg.plugins.presets) operators motions;
text_objects = cfg.plugins.presets.textObjects;
inherit (cfg.plugins.presets)
windows
nav
z
g
;
};
};
inherit (cfg) operators;
key_labels = cfg.keyLabels;
inherit (cfg) motions icons;
popup_mappings = {
scroll_down = cfg.popupMappings.scrollDown;
scroll_up = cfg.popupMappings.scrollUp;
};
window =
let
mkSpacing =
opt:
helpers.ifNonNull' opt [
opt.top
opt.right
opt.bottom
opt.top
];
in
{
inherit (cfg.window) border position;
margin = mkSpacing cfg.window.margin;
padding = mkSpacing cfg.window.padding;
inherit (cfg.window) winblend;
};
inherit (cfg) layout;
ignore_missing = cfg.ignoreMissing;
inherit (cfg) hidden;
show_help = cfg.showHelp;
show_keys = cfg.showKeys;
inherit (cfg) triggers;
triggers_nowait = cfg.triggersNoWait;
triggers_blacklist = cfg.triggersBlackList;
inherit (cfg) disable;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua =
''
require("which-key").setup(${helpers.toLuaObject setupOptions})
''
+ (optionalString (cfg.registrations != { }) ''
require("which-key").register(${helpers.toLuaObject cfg.registrations})
'');
};
}