modules/filetype: add extra filetype detect

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-17 15:02:56 +03:00
parent 4f8b523579
commit e5f2d7236a
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2

View file

@ -1,6 +1,17 @@
{ config, lib, ... }: { config, lib, ... }:
let cfg = config.filetype; in let
cfg = config.filetype;
mkFiletypeDetect = ft: pattern: {
"filetype-detect-${ft}" = {
event = [ "BufNewFile" "BufRead" ];
inherit pattern;
command = "setfiletype ${ft}";
};
};
in
{ {
options.filetype = with lib; with types; { options.filetype = with lib; with types; {
enable = mkOption { enable = mkOption {
@ -40,7 +51,7 @@ let cfg = config.filetype; in
}; };
ignore = mkOption { ignore = mkOption {
type = uniq (listOf str); type = extCommas;
default = [ "Z" "gz" "bz2" "zip" "tgz" ]; default = [ "Z" "gz" "bz2" "zip" "tgz" ];
description = '' description = ''
To avoid that certain files are being inspected, the g:ft_ignore_pat variable To avoid that certain files are being inspected, the g:ft_ignore_pat variable
@ -49,10 +60,16 @@ let cfg = config.filetype; in
`:help filetype-ignore` `:help filetype-ignore`
''; '';
}; };
extraIgnore = mkOption { extraIgnore = mkOption {
type = uniq (listOf str); type = extCommas;
default = [ ]; default = [ ];
}; };
detect = mkOption {
type = attrsOf extCommas;
default = { };
};
}; };
config = { config = {
@ -62,6 +79,8 @@ let cfg = config.filetype; in
); );
vim.g.ft_ignore_pat = "\\\\.(${lib.concatStringsSep "|" (cfg.ignore ++ cfg.extraIgnore)})$"; vim.g.ft_ignore_pat = "\\\\.(${lib.concatStringsSep "|" (cfg.ignore ++ cfg.extraIgnore)})$";
vim.augroup = lib.mkIf (cfg.detect != { }) (lib.mapAttrsToList mkFiletypeDetect cfg.detect);
}; };
} }