forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiletype.nix
63 lines (57 loc) · 1.75 KB
/
filetype.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
{
lib,
helpers,
config,
...
}:
let
inherit (lib) types;
cfg = config.filetype;
filetypeDefinition = helpers.mkNullOrOption (
with types;
attrsOf (oneOf [
# Raw filetype
str
# Function to set the filetype
helpers.nixvimTypes.rawLua
# ["filetype" {priority = xx;}]
(listOf (
either str (submodule {
options = {
priority = lib.mkOption {
type = ints.unsigned;
description = ''
Filename patterns can specify an optional priority to resolve cases when a file path
matches multiple patterns.
Higher priorities are matched first.
When omitted, the priority defaults to 0.
A pattern can contain environment variables of the form `"''${SOME_VAR}"` that will
be automatically expanded.
If the environment variable is not set, the pattern won't be matched.
'';
};
};
})
))
])
);
in
{
options.filetype =
helpers.mkCompositeOption
''
Define additional filetypes. The values can either be a literal filetype or a function
taking the filepath and the buffer number.
For more information check `:h vim.filetype.add()`
''
{
extension = filetypeDefinition "set filetypes matching the file extension";
filename = filetypeDefinition "set filetypes matching the file name (or path)";
pattern = filetypeDefinition "set filetypes matching the specified pattern";
};
config.extraConfigLua =
lib.mkIf (cfg != null && (builtins.any (v: v != null) (builtins.attrValues cfg)))
''
vim.filetype.add(${helpers.toLuaObject cfg})
'';
}