mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
filetype: Add a module to wrap vim.filetype.add (#277)
This commit is contained in:
parent
58b6c74e2f
commit
cbae935d89
2 changed files with 81 additions and 0 deletions
40
modules/filetype.nix
Normal file
40
modules/filetype.nix
Normal file
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
} @ args:
|
||||
with lib; let
|
||||
helpers = import ../lib/helpers.nix args;
|
||||
filetypeDefinition = helpers.mkNullOrOption (types.attrsOf (
|
||||
types.oneOf [
|
||||
# Raw filetype
|
||||
types.str
|
||||
# Function to set the filetype
|
||||
helpers.rawType
|
||||
# ["filetype" {priority = xx;}]
|
||||
(types.listOf (types.either types.str (types.submodule {
|
||||
options = {
|
||||
priority = mkOption {
|
||||
type = types.int;
|
||||
};
|
||||
};
|
||||
})))
|
||||
]
|
||||
));
|
||||
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 = helpers.mkIfNonNull' config.filetype ''
|
||||
vim.filetype.add(${helpers.toLuaObject config.filetype})
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue