feat: improved smartcolumn freeform

This commit is contained in:
NotAShelf 2023-06-04 17:36:01 +03:00
parent 2cfeb22764
commit 86fec8646d
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
4 changed files with 32 additions and 15 deletions

View file

@ -185,6 +185,7 @@ inputs: let
nix = 110; nix = 110;
ruby = 120; ruby = 120;
java = 130; java = 130;
go = [90 130];
}; };
}; };
colorizer.enable = true; colorizer.enable = true;

View file

@ -12,21 +12,29 @@
then "nil" then "nil"
else "'${value}'"; else "'${value}'";
# Helper function to convert an attribute name to a Lua table key expToLua = exp:
attrToKey = name: name; if builtins.isList exp
then listToLuaTable exp
else if builtins.isAttrs exp
then attrsetToLuaTable exp
else ("\"" + builtins.toJSON exp + "\"");
listToLuaTable = list:
"{ " + (builtins.concatStringsSep ", " (map expToLua list)) + " }";
# Function to convert a Nix attrset to a Lua table
attrsetToLuaTable = attrset: attrsetToLuaTable = attrset:
"{ " "{ "
+ ( + (
builtins.concatStringsSep ", " builtins.concatStringsSep ", "
(builtins.attrValues ( (
builtins.mapAttrs ( lib.mapAttrsToList (
name: value: name: value:
attrToKey name + " = " + ("\"" + builtins.toJSON value + "\"") name
+ " = "
+ (expToLua value)
) )
attrset attrset
)) )
) )
+ " }"; + " }";
} }

View file

@ -17,13 +17,21 @@ with builtins; {
}; };
columnAt = { columnAt = {
# TODO: the current implementation only allows for options such as { ruby = "120", java = "120" }
# whereas the lua config would allow { ruby = "120", java = { "180", "200"} }, this needs to be fixed in the custom lib
languages = lib.mkOption { languages = lib.mkOption {
description = "The position at which smart column should be displayed for each individual buffer type"; description = "The position at which smart column should be displayed for each individual buffer type";
type = lib.types.submodule { type = lib.types.submodule {
freeformType = with lib.types; attrsOf int; freeformType = with lib.types; attrsOf (either int (listOf int));
}; };
example = lib.literalExpression ''
vim.ui.smartcolumn.columnAt.languages = {
nix = 110;
ruby = 120;
java = 130;
go = [90 130];
};
'';
}; };
}; };
}; };