From 535d58afbab32ae4f13ae1fad45d0fb9a323adae Mon Sep 17 00:00:00 2001 From: mewoocat Date: Mon, 22 Dec 2025 22:35:50 -0600 Subject: [PATCH] generic indent func --- lib/languages.nix | 20 ++++++++++++++++++++ modules/plugins/languages/markdown.nix | 7 +++++++ modules/plugins/languages/nix.nix | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/lib/languages.nix b/lib/languages.nix index 423c4f8a..f4e4f990 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 = { @@ -80,4 +81,23 @@ in { # maybe put generic function to set indent for provided langs # Then we can just call it with the lib arg + + setLanguageIndent = {language, indentSize}: { + vim.autocmds = [ + { + desc = "Sets indent for nix files"; + event = ["BufEnter"]; + pattern = [ "*.${language}" ]; + callback = mkLuaInline '' + function() + vim.opt.tabstop = ${toString indentSize} + vim.opt.softtabstop = ${toString indentSize} + vim.opt.shiftwidth = ${toString indentSize} + end + ''; + once = true; + } + ]; + }; + } diff --git a/modules/plugins/languages/markdown.nix b/modules/plugins/languages/markdown.nix index 59615cec..427c401c 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; @@ -205,5 +206,11 @@ in { cfg.extraDiagnostics.types); }; }) + + (setLanguageIndent { + language = "md"; + indentSize = 4; + }) + ]); } diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 16b27f19..afc26104 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -13,6 +13,7 @@ inherit (lib.types) int; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.languages) setLanguageIndent; cfg = config.vim.languages.nix; @@ -168,6 +169,12 @@ in { }; }) + (setLanguageIndent { + language = "nix"; + indentSize = cfg.indentSize; + }) + + /* { vim.autocmds = [ { @@ -188,6 +195,7 @@ in { } ]; } + */ ]); }