2023-03-24 11:14:12 +01:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
2023-03-24 11:14:12 +01:00
|
|
|
...
|
2023-11-06 15:04:08 +01:00
|
|
|
}:
|
2023-03-24 11:14:12 +01:00
|
|
|
let
|
2024-08-30 14:37:41 -05:00
|
|
|
inherit (lib) types;
|
|
|
|
|
2024-07-21 11:15:45 +03:00
|
|
|
cfg = config.filetype;
|
|
|
|
|
2023-12-09 20:34:24 +01:00
|
|
|
filetypeDefinition = helpers.mkNullOrOption (
|
|
|
|
with types;
|
|
|
|
attrsOf (oneOf [
|
|
|
|
# Raw filetype
|
|
|
|
str
|
|
|
|
# Function to set the filetype
|
2024-09-27 08:07:20 +01:00
|
|
|
rawLua
|
2023-12-09 20:34:24 +01:00
|
|
|
# ["filetype" {priority = xx;}]
|
|
|
|
(listOf (
|
|
|
|
either str (submodule {
|
|
|
|
options = {
|
2024-08-30 14:37:41 -05:00
|
|
|
priority = lib.mkOption {
|
2024-06-09 23:04:27 +02:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2023-12-09 20:34:24 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
))
|
|
|
|
])
|
|
|
|
);
|
2023-03-24 11:14:12 +01:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2024-07-21 11:15:45 +03:00
|
|
|
config.extraConfigLua =
|
|
|
|
lib.mkIf (cfg != null && (builtins.any (v: v != null) (builtins.attrValues cfg)))
|
|
|
|
''
|
2024-12-15 20:32:14 +01:00
|
|
|
vim.filetype.add(${lib.nixvim.toLuaObject cfg})
|
2024-07-21 11:15:45 +03:00
|
|
|
'';
|
2023-03-24 11:14:12 +01:00
|
|
|
}
|