-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
bufferline.nix
320 lines (251 loc) · 10 KB
/
bufferline.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.bufferline;
highlightOptions = {
fill = "fill";
background = "background";
tab = "tab";
tab_selected = "tabSelected";
tab_separator = "tabSeparator";
tab_separator_selected = "tabSeparatorSelected";
tab_close = "tabClose";
close_button = "closeButton";
close_button_visible = "closeButtonVisible";
close_button_selected = "closeButtonSelected";
buffer_visible = "bufferVisible";
buffer_selected = "bufferSelected";
numbers = "numbers";
numbers_visible = "numbersVisible";
numbers_selected = "numbersSelected";
diagnostic = "diagnostic";
diagnostic_visible = "diagnosticVisible";
diagnostic_selected = "diagnosticSelected";
hint = "hint";
hint_visible = "hintVisible";
hint_selected = "hintSelected";
hint_diagnostic = "hintDiagnostic";
hint_diagnostic_visible = "hintDiagnosticVisible";
hint_diagnostic_selected = "hintDiagnosticSelected";
info = "info";
info_visible = "infoVisible";
info_selected = "infoSelected";
info_diagnostic = "infoDiagnostic";
info_diagnostic_visible = "infoDiagnosticVisible";
info_diagnostic_selected = "infoDiagnosticSelected";
warning = "warning";
warning_visible = "warningVisible";
warning_selected = "warningSelected";
warning_diagnostic = "warningDiagnostic";
warning_diagnostic_visible = "warningDiagnosticVisible";
warning_diagnostic_selected = "warningDiagnosticSelected";
error = "error";
error_visible = "errorVisible";
error_selected = "errorSelected";
error_diagnostic = "errorDiagnostic";
error_diagnostic_visible = "errorDiagnosticVisible";
error_diagnostic_selected = "errorDiagnosticSelected";
modified = "modified";
modified_visible = "modifiedVisible";
modified_selected = "modifiedSelected";
duplicate = "duplicate";
duplicate_visible = "duplicateVisible";
duplicate_selected = "duplicateSelected";
separator = "separator";
separator_visible = "separatorVisible";
separator_selected = "separatorSelected";
indicator_visible = "indicatorVisible";
indicator_selected = "indicatorSelected";
pick = "pick";
pick_visible = "pickVisible";
pick_selected = "pickSelected";
offset_separator = "offsetSeparator";
trunc_marker = "trunkMarker";
};
in
{
options = {
plugins.bufferline = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "bufferline";
package = helpers.mkPluginPackageOption "bufferline" pkgs.vimPlugins.bufferline-nvim;
mode = helpers.defaultNullOpts.mkEnumFirstDefault [
"buffers"
"tabs"
] "mode";
themable = helpers.defaultNullOpts.mkBool true "Whether or not bufferline highlights can be overridden externally";
numbers =
helpers.defaultNullOpts.mkNullable
(
with types;
either (enum [
"none"
"ordinal"
"buffer_id"
"both"
]) helpers.nixvimTypes.rawLua
)
"none"
''
Customize the styling of numbers.
Either one of "none" "ordinal" "buffer_id" "both" or a lua function:
```
function({ ordinal, id, lower, raise }): string
```
'';
bufferCloseIcon = helpers.defaultNullOpts.mkStr "" "The close icon for each buffer.";
modifiedIcon = helpers.defaultNullOpts.mkStr "●" "The icon indicating a buffer was modified.";
closeIcon = helpers.defaultNullOpts.mkStr "" "The close icon.";
closeCommand = helpers.defaultNullOpts.mkStr "bdelete! %d" "Command or function run when closing a buffer.";
leftMouseCommand = helpers.defaultNullOpts.mkStr "buffer %d" "Command or function run when clicking on a buffer.";
rightMouseCommand = helpers.defaultNullOpts.mkStr "bdelete! %d" "Command or function run when right clicking on a buffer.";
middleMouseCommand = helpers.defaultNullOpts.mkStr null "Command or function run when middle clicking on a buffer.";
indicator = {
icon = helpers.defaultNullOpts.mkStr "▎" "icon";
style = helpers.defaultNullOpts.mkEnumFirstDefault [
"icon"
"underline"
] "style";
};
leftTruncMarker = helpers.defaultNullOpts.mkStr "" "left trunc marker";
rightTruncMarker = helpers.defaultNullOpts.mkStr "" "right trunc marker";
separatorStyle = helpers.defaultNullOpts.mkEnum [
"slant"
"padded_slant"
"slope"
"padded_slope"
"thick"
"thin"
] "thin" "Separator style";
nameFormatter = helpers.defaultNullOpts.mkLuaFn null ''
A lua function that can be used to modify the buffer's label.
The argument 'buf' containing a name, path and bufnr is supplied.
'';
truncateNames = helpers.defaultNullOpts.mkBool true "Whether to truncate names.";
tabSize = helpers.defaultNullOpts.mkInt 18 "Size of the tabs";
maxNameLength = helpers.defaultNullOpts.mkInt 18 "Max length of a buffer name.";
colorIcons = helpers.defaultNullOpts.mkBool true "Enable color icons.";
showBufferIcons = helpers.defaultNullOpts.mkBool true "Show buffer icons";
showBufferCloseIcons = helpers.defaultNullOpts.mkBool true "Show buffer close icons";
getElementIcon = helpers.defaultNullOpts.mkLuaFn null ''
Lua function returning an element icon.
```
fun(opts: IconFetcherOpts): string?, string?
```
'';
showCloseIcon = helpers.defaultNullOpts.mkBool true "Whether to show the close icon.";
showTabIndicators = helpers.defaultNullOpts.mkBool true "Whether to show the tab indicators.";
showDuplicatePrefix = helpers.defaultNullOpts.mkBool true "Whether to show the prefix of duplicated files.";
enforceRegularTabs = helpers.defaultNullOpts.mkBool false "Whether to enforce regular tabs.";
alwaysShowBufferline = helpers.defaultNullOpts.mkBool true "Whether to always show the bufferline.";
persistBufferSort = helpers.defaultNullOpts.mkBool true "Whether to make the buffer sort persistent.";
maxPrefixLength = helpers.defaultNullOpts.mkInt 15 "Maximum prefix length";
sortBy = helpers.defaultNullOpts.mkStr "id" "sort by";
diagnostics = helpers.defaultNullOpts.mkNullable (
with types;
either bool (enum [
"nvim_lsp"
"coc"
])
) false "diagnostics";
diagnosticsIndicator = helpers.defaultNullOpts.mkLuaFn null "Either `null` or a function that returns the diagnostics indicator.";
diagnosticsUpdateInInsert = helpers.defaultNullOpts.mkBool true "Whether diagnostics should update in insert mode";
offsets = helpers.defaultNullOpts.mkNullable (types.listOf types.attrs) null "offsets";
groups = {
items = helpers.defaultNullOpts.mkListOf types.attrs [ ] "List of groups.";
options = {
toggleHiddenOnEnter = helpers.defaultNullOpts.mkBool true "Re-open hidden groups on bufenter.";
};
};
hover = {
enabled = mkEnableOption "hover";
reveal = helpers.defaultNullOpts.mkListOf types.str [ ] "reveal";
delay = helpers.defaultNullOpts.mkInt 200 "delay";
};
debug = {
logging = helpers.defaultNullOpts.mkBool false "Whether to enable logging";
};
customFilter = helpers.defaultNullOpts.mkLuaFn null ''
```
fun(buf: number, bufnums: number[]): boolean
```
'';
highlights = genAttrs (attrValues highlightOptions) (
name:
helpers.mkNullOrOption helpers.nixvimTypes.highlight ''
Highlight group definition for ${name}.
''
);
};
};
config =
let
setupOptions = with cfg; {
options = {
inherit mode themable numbers;
buffer_close_icon = bufferCloseIcon;
modified_icon = modifiedIcon;
close_icon = closeIcon;
close_command = closeCommand;
left_mouse_command = leftMouseCommand;
right_mouse_command = rightMouseCommand;
middle_mouse_command = middleMouseCommand;
inherit indicator;
left_trunc_marker = leftTruncMarker;
right_trunc_marker = rightTruncMarker;
separator_style = separatorStyle;
name_formatter = nameFormatter;
truncate_names = truncateNames;
tab_size = tabSize;
max_name_length = maxNameLength;
color_icons = colorIcons;
show_buffer_icons = showBufferIcons;
show_buffer_close_icons = showBufferCloseIcons;
get_element_icon = getElementIcon;
show_close_icon = showCloseIcon;
show_tab_indicators = showTabIndicators;
show_duplicate_prefix = showDuplicatePrefix;
enforce_regular_tabs = enforceRegularTabs;
always_show_bufferline = alwaysShowBufferline;
persist_buffer_sort = persistBufferSort;
max_prefix_length = maxPrefixLength;
sort_by = sortBy;
inherit diagnostics;
diagnostics_indicator = diagnosticsIndicator;
diagnostics_update_in_insert = diagnosticsUpdateInInsert;
inherit offsets;
groups = {
inherit (groups) items;
options = {
toggle_hidden_on_enter = groups.options.toggleHiddenOnEnter;
};
};
hover = {
inherit (hover) enabled reveal delay;
};
debug = {
inherit (debug) logging;
};
custom_filter = customFilter;
} // cfg.extraOptions;
highlights = mapAttrs (
pluginOptionName: nixvimOptionName: cfg.highlights.${nixvimOptionName}
) highlightOptions;
};
in
mkIf cfg.enable {
extraPlugins = with pkgs.vimPlugins; [
cfg.package
nvim-web-devicons
];
opts.termguicolors = true;
extraConfigLua = ''
require('bufferline').setup${helpers.toLuaObject setupOptions}
'';
};
}