From e5f2d7236aec2dac2f6f1669aaaca1f2e58cc249 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 17 May 2024 15:02:56 +0300 Subject: [PATCH] modules/filetype: add extra filetype detect --- modules/filetype.nix | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/modules/filetype.nix b/modules/filetype.nix index 945167e..bbc36af 100644 --- a/modules/filetype.nix +++ b/modules/filetype.nix @@ -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); }; }