diff --git a/configuration.nix b/configuration.nix index 2602a811..d3bfaa33 100644 --- a/configuration.nix +++ b/configuration.nix @@ -49,7 +49,12 @@ isMaximal: { enableExtraDiagnostics = true; # Languages that will be supported in default and maximal configurations. - nix.enable = true; + nix = { + enable = true; + tabstop = 8; + softtabstop = 8; + shiftwidth = 8; + }; markdown.enable = true; # Languages that are enabled in the maximal configuration. diff --git a/flake.nix b/flake.nix index ba817494..2e6be161 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,7 @@ flake = { lib = { inherit (lib) nvim; + inherit (lib) generators; inherit (lib.nvim) neovimConfiguration; }; diff --git a/lib/languages.nix b/lib/languages.nix index 899d9ea8..f1f2dcd3 100644 --- a/lib/languages.nix +++ b/lib/languages.nix @@ -4,6 +4,7 @@ inherit (lib.types) listOf bool str submodule attrsOf anything either nullOr uniq; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) luaInline; + inherit (lib.generators) mkLuaInline; in { # TODO: remove diagnosticsToLua = { @@ -77,4 +78,26 @@ in { }; }; }; + + # maybe put generic function to set indent for provided langs + # Then we can just call it with the lib arg + + setLanguageIndent = {language, tabstop, softtabstop, shiftwidth}: { + vim.autocmds = [ + { + desc = "Sets indent for nix files"; + event = [ "FileType" ]; + pattern = [ language ]; + callback = mkLuaInline '' + function() + ${if tabstop != null then "vim.bo.tabstop = " + toString tabstop else ""} + ${if softtabstop != null then "vim.bo.softtabstop = " + toString softtabstop else ""} + ${if shiftwidth != null then "vim.bo.shiftwidth = " + toString shiftwidth else ""} + end + ''; + once = true; + } + ]; + }; + } diff --git a/modules/plugins/languages/markdown.nix b/modules/plugins/languages/markdown.nix index a2634e6d..2cc2238e 100644 --- a/modules/plugins/languages/markdown.nix +++ b/modules/plugins/languages/markdown.nix @@ -13,6 +13,7 @@ inherit (lib.nvim.types) diagnostics mkGrammarOption mkPluginSetupOption deprecatedSingleOrListOf; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.languages) setLanguageIndent; inherit (lib.trivial) warn; cfg = config.vim.languages.markdown; @@ -218,5 +219,8 @@ in { cfg.extraDiagnostics.types); }; }) + + # todo + ]); } diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 0dc5b357..33624668 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -4,14 +4,15 @@ lib, ... }: let - inherit (builtins) attrNames; + inherit (builtins) attrNames toString; inherit (lib) concatStringsSep; inherit (lib.meta) getExe; inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; + inherit (lib.types) enum int nullOr; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.languages) setLanguageIndent; cfg = config.vim.languages.nix; @@ -106,6 +107,24 @@ in { inherit defaultDiagnosticsProvider; }; }; + + tabstop = mkOption { + description = "Sets the tabstop size in spaces for .nix files"; + type = nullOr int; + default = null; + }; + + softtabstop = mkOption { + description = "Sets the softtabstop size in spaces for .nix files"; + type = nullOr int; + default = null; + }; + + shiftwidth = mkOption { + description = "Sets the shiftwidth in spaces for .nix files"; + type = nullOr int; + default = null; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -160,5 +179,13 @@ in { cfg.extraDiagnostics.types); }; }) + + (setLanguageIndent { + language = "nix"; + tabstop = cfg.tabstop; + softtabstop = cfg.softtabstop; + shiftwidth = cfg.shiftwidth; + }) + ]); }