modules/filetype: add extra filetype detect
This commit is contained in:
parent
4f8b523579
commit
e5f2d7236a
1 changed files with 22 additions and 3 deletions
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue