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, ... }:
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; {
enable = mkOption {
@ -40,7 +51,7 @@ let cfg = config.filetype; in
};
ignore = mkOption {
type = uniq (listOf str);
type = extCommas;
default = [ "Z" "gz" "bz2" "zip" "tgz" ];
description = ''
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`
'';
};
extraIgnore = mkOption {
type = uniq (listOf str);
type = extCommas;
default = [ ];
};
detect = mkOption {
type = attrsOf extCommas;
default = { };
};
};
config = {
@ -62,6 +79,8 @@ let cfg = config.filetype; in
);
vim.g.ft_ignore_pat = "\\\\.(${lib.concatStringsSep "|" (cfg.ignore ++ cfg.extraIgnore)})$";
vim.augroup = lib.mkIf (cfg.detect != { }) (lib.mapAttrsToList mkFiletypeDetect cfg.detect);
};
}