-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
spectre.nix
274 lines (235 loc) · 7.48 KB
/
spectre.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
267
268
269
270
271
272
273
274
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
name = "spectre";
originalName = "nvim-spectre";
defaultPackage = pkgs.vimPlugins.nvim-spectre;
maintainers = [ maintainers.GaetanLepage ];
description = ''
You may want to set the package for your find/replace tool(s) like shown below:
```nix
plugins.spectre.findPackage = pkgs.rg;
plugins.spectre.replacePackage = pkgs.gnused;
```
'';
settingsOptions =
let
mkEngineOption =
type:
helpers.mkNullOrOption
(
with types;
attrsOf (submodule {
options = {
cmd = mkOption {
type = types.str;
description = "Executable to run.";
};
args = helpers.defaultNullOpts.mkListOf types.str [ ] ''
List of arguments to provide to the engine.
'';
options = helpers.defaultNullOpts.mkAttrsOf (types.submodule {
options = {
value = mkOption {
type = types.str;
example = "-i";
description = "The option flag.";
};
icon = mkOption {
type = types.str;
example = "[I]";
description = "The option icon.";
};
desc = helpers.mkNullOrStr ''
The description for this option.
'';
};
}) { } "The options for this engine.";
};
})
)
''
Definition of the ${type} engines.
default: see [here](https://github.com/nvim-pack/nvim-spectre/blob/master/lua/spectre/config.lua)
'';
in
{
color_devicons = helpers.defaultNullOpts.mkBool true ''
Whether to enable color devicons.
'';
open_cmd = helpers.defaultNullOpts.mkStr "vnew" ''
The open command.
'';
live_update = helpers.defaultNullOpts.mkBool false ''
Auto execute search again when you write to any file in vim.
'';
lnum_for_results = helpers.defaultNullOpts.mkBool false ''
Show line number for search/replace results.
'';
line_sep_start = helpers.defaultNullOpts.mkStr "┌──────────────────────────────────────────────────────" "Start of the line separator";
result_padding = helpers.defaultNullOpts.mkStr "│ " ''
Result padding string.
'';
line_sep = helpers.defaultNullOpts.mkStr "└──────────────────────────────────────────────────────" "Line separator.";
highlight = helpers.defaultNullOpts.mkAttrsOf types.str {
headers = "SpectreHeader";
ui = "SpectreBody";
filename = "SpectreFile";
filedirectory = "SpectreDir";
search = "SpectreSearch";
border = "SpectreBorder";
replace = "SpectreReplace";
} "Highlight groups.";
mapping =
helpers.mkNullOrOption
(
with types;
attrsOf (submodule {
options = {
map = mkOption {
type = types.str;
description = "Keyboard shortcut.";
};
cmd = mkOption {
type = types.str;
description = "Command to run.";
example = "<cmd>lua require('spectre').tab()<cr>";
};
desc = helpers.mkNullOrStr ''
Description for this mapping.
'';
};
})
)
''
Keymaps declaration.
default: see [here](https://github.com/nvim-pack/nvim-spectre/blob/master/lua/spectre/config.lua)
'';
find_engine = mkEngineOption "find";
replace_engine = mkEngineOption "replace";
default = {
find = {
cmd = helpers.defaultNullOpts.mkStr "rg" ''
Which find engine to use. Pick one from the `find_engine` list.
'';
options = helpers.defaultNullOpts.mkListOf types.str [ "ignore-case" ] ''
Options to use for this engine.
'';
};
replace = {
cmd = helpers.defaultNullOpts.mkStr "rg" ''
Which find engine to use. Pick one from the `replace_engine` list.
'';
options = helpers.defaultNullOpts.mkListOf types.str [ ] ''
Options to use for this engine.
'';
};
};
replace_vim_cmd = helpers.defaultNullOpts.mkStr "cdo" ''
The replace command to use within vim.
'';
is_open_target_win = helpers.defaultNullOpts.mkBool true ''
Open file on opener window.
'';
is_insert_mode = helpers.defaultNullOpts.mkBool false ''
Start open panel in insert mode.
'';
is_block_ui_break = helpers.defaultNullOpts.mkBool false ''
Mapping backspace and enter key to avoid ui break.
'';
};
settingsExample = {
live_update = true;
is_insert_mode = false;
find_engine = {
rg = {
cmd = "rg";
args = [
"--color=never"
"--no-heading"
"--with-filename"
"--line-number"
"--column"
];
options = {
ignore-case = {
value = "--ignore-case";
icon = "[I]";
desc = "ignore case";
};
hidden = {
value = "--hidden";
desc = "hidden file";
icon = "[H]";
};
line = {
value = "-x";
icon = "[L]";
desc = "match in line";
};
word = {
value = "-w";
icon = "[W]";
desc = "match in word";
};
};
};
};
default = {
find = {
cmd = "rg";
options = [
"word"
"hidden"
];
};
replace = {
cmd = "sed";
};
};
};
extraOptions =
let
userCommandSettings = config.plugins.spectre.settings.default;
findPackages = {
rg = pkgs.ripgrep;
};
replacePackages = {
sed = pkgs.gnused;
inherit (pkgs) sd;
};
# `toString` will turn `null` into `"null"` to allow for the attrs indexation.
findDefaultPackage = findPackages.${toString userCommandSettings.find.cmd} or null;
replaceDefaultPackage = replacePackages.${toString userCommandSettings.replace.cmd} or null;
in
{
findPackage = helpers.mkPackageOption {
default = findDefaultPackage;
description = ''
Which package to install for the find command.
Defaults to `pkgs.$\{settings.default.find.cmd}`.
Set to `null` to prevent the installation.
'';
};
replacePackage = helpers.mkPackageOption {
default = replaceDefaultPackage;
description = ''
Which package to install for the find command.
Defaults to `pkgs.$\{settings.default.replace.cmd}`.
Set to `null` to prevent the installation.
'';
};
};
extraConfig = cfg: {
extraPackages = [
cfg.findPackage
cfg.replacePackage
];
};
}