Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
flake = {
lib = {
inherit (lib) nvim;
inherit (lib) generators;
inherit (lib.nvim) neovimConfiguration;
};

Expand Down
23 changes: 23 additions & 0 deletions lib/languages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
];
};

}
4 changes: 4 additions & 0 deletions modules/plugins/languages/markdown.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,5 +206,8 @@ in {
cfg.extraDiagnostics.types);
};
})

# todo

]);
}
31 changes: 29 additions & 2 deletions modules/plugins/languages/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -160,5 +179,13 @@ in {
cfg.extraDiagnostics.types);
};
})

(setLanguageIndent {
language = "nix";
tabstop = cfg.tabstop;
softtabstop = cfg.softtabstop;
shiftwidth = cfg.shiftwidth;
})

]);
}