2024-04-20 23:10:06 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2024-08-12 22:27:05 +00:00
|
|
|
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
|
|
|
|
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
|
2024-07-20 08:30:48 +00:00
|
|
|
inherit (lib.strings) concatLines concatMapStringsSep;
|
2024-04-20 23:10:06 +00:00
|
|
|
inherit (lib.trivial) showWarnings;
|
|
|
|
inherit (lib.generators) mkLuaInline;
|
2024-07-20 08:30:48 +00:00
|
|
|
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
|
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-04-20 23:10:06 +00:00
|
|
|
|
|
|
|
cfg = config.vim;
|
|
|
|
in {
|
|
|
|
config = let
|
2024-08-12 00:07:45 +00:00
|
|
|
filterNonNull = filterAttrs (_: value: value != null);
|
2024-04-20 23:10:06 +00:00
|
|
|
globalsScript =
|
2024-08-12 00:08:53 +00:00
|
|
|
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}")
|
2024-04-20 23:10:06 +00:00
|
|
|
(filterNonNull cfg.globals);
|
|
|
|
|
2024-07-20 08:30:48 +00:00
|
|
|
extraPluginConfigs = resolveDag {
|
|
|
|
name = "extra plugin configs";
|
|
|
|
dag = mapAttrs (_: value: entryAfter value.after value.setup) cfg.extraPlugins;
|
|
|
|
mapResult = result: concatLines (map mkLuarcSection result);
|
|
|
|
};
|
|
|
|
|
|
|
|
pluginConfigs = resolveDag {
|
|
|
|
name = "plugin configs";
|
|
|
|
dag = cfg.pluginRC;
|
|
|
|
mapResult = result: concatLines (map mkLuarcSection result);
|
|
|
|
};
|
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
getAction = keymap:
|
|
|
|
if keymap.lua
|
|
|
|
then mkLuaInline keymap.action
|
|
|
|
else keymap.action;
|
|
|
|
|
|
|
|
getOpts = keymap: {
|
2024-08-17 11:08:47 +00:00
|
|
|
inherit (keymap) desc silent nowait script expr unique noremap;
|
2024-08-12 00:07:45 +00:00
|
|
|
};
|
2024-04-20 23:10:06 +00:00
|
|
|
|
2024-08-12 00:07:45 +00:00
|
|
|
toLuaKeymap = {
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
|
2024-04-20 23:10:06 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
namedModes = {
|
|
|
|
"normal" = ["n"];
|
|
|
|
"insert" = ["i"];
|
|
|
|
"select" = ["s"];
|
|
|
|
"visual" = ["v"];
|
|
|
|
"terminal" = ["t"];
|
|
|
|
"normalVisualOp" = ["n" "v" "o"];
|
|
|
|
"visualOnly" = ["n" "x"];
|
|
|
|
"operator" = ["o"];
|
|
|
|
"insertCommand" = ["i" "c"];
|
|
|
|
"lang" = ["l"];
|
|
|
|
"command" = ["c"];
|
|
|
|
};
|
2024-04-20 23:10:06 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
maps =
|
|
|
|
removeAttrs cfg.maps (attrNames namedModes)
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normal;}) cfg.maps.normal
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insert;}) cfg.maps.insert
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.select;}) cfg.maps.select
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visual;}) cfg.maps.visual
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.terminal;}) cfg.maps.terminal
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normalVisualOp;}) cfg.maps.normalVisualOp
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visualOnly;}) cfg.maps.visualOnly
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.operator;}) cfg.maps.operator
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insertCommand;}) cfg.maps.insertCommand
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.lang;}) cfg.maps.lang
|
|
|
|
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.command;}) cfg.maps.command;
|
|
|
|
|
|
|
|
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull maps)));
|
2024-04-20 23:10:06 +00:00
|
|
|
in {
|
|
|
|
vim = {
|
2024-07-20 08:30:48 +00:00
|
|
|
luaConfigRC = {
|
2024-07-08 21:57:58 +00:00
|
|
|
globalsScript = entryAnywhere (concatLines globalsScript);
|
2024-07-20 08:30:48 +00:00
|
|
|
# basic, theme
|
|
|
|
pluginConfigs = entryAfter ["theme"] pluginConfigs;
|
|
|
|
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
|
2024-08-12 00:07:45 +00:00
|
|
|
mappings = entryAfter ["extraPluginConfigs"] keymaps;
|
2024-04-20 23:10:06 +00:00
|
|
|
};
|
|
|
|
|
2024-07-20 08:30:48 +00:00
|
|
|
builtLuaConfigRC = let
|
2024-04-20 23:10:06 +00:00
|
|
|
# Catch assertions and warnings
|
|
|
|
# and throw for each failed assertion. If no assertions are found, show warnings.
|
|
|
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
|
|
|
baseSystemAssertWarn =
|
|
|
|
if failedAssertions != []
|
2024-07-08 21:57:58 +00:00
|
|
|
then throw "\nFailed assertions:\n${concatMapStringsSep "\n" (x: "- ${x}") failedAssertions}"
|
2024-04-20 23:10:06 +00:00
|
|
|
else showWarnings config.warnings;
|
|
|
|
|
2024-07-20 08:30:48 +00:00
|
|
|
luaConfig = resolveDag {
|
|
|
|
name = "lua config script";
|
|
|
|
dag = cfg.luaConfigRC;
|
|
|
|
mapResult = result:
|
|
|
|
concatLines [
|
|
|
|
cfg.luaConfigPre
|
|
|
|
(concatMapStringsSep "\n" mkLuarcSection result)
|
|
|
|
cfg.luaConfigPost
|
|
|
|
];
|
2024-04-20 23:10:06 +00:00
|
|
|
};
|
|
|
|
in
|
2024-07-20 08:30:48 +00:00
|
|
|
baseSystemAssertWarn luaConfig;
|
2024-04-20 23:10:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|