From b8c8dc2484156d8f6f0cbb1dd1db0a1da3bd5503 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:16:44 +0200 Subject: [PATCH 01/39] maps: allow same key on multiple mode --- modules/neovim/mappings/config.nix | 70 +++++++++++++++++++---------- modules/neovim/mappings/options.nix | 36 ++++++++------- modules/wrapper/rc/config.nix | 45 +++++-------------- 3 files changed, 78 insertions(+), 73 deletions(-) diff --git a/modules/neovim/mappings/config.nix b/modules/neovim/mappings/config.nix index 365e124..b7e274b 100644 --- a/modules/neovim/mappings/config.nix +++ b/modules/neovim/mappings/config.nix @@ -3,32 +3,56 @@ lib, ... }: let - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkMerge; + inherit (builtins) mapAttrs; + + processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})]; cfg = config.vim; in { config = { - vim.maps = mkIf cfg.disableArrows { - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - }; + vim.keymaps = mkMerge [ + (mkIf cfg.disableArrows { + "" = [ + { + mode = ["n" "i"]; + action = ""; + noremap = false; + } + ]; + "" = [ + { + mode = ["n" "i"]; + action = ""; + noremap = false; + } + ]; + "" = [ + { + mode = ["n" "i"]; + action = ""; + noremap = false; + } + ]; + "" = [ + { + mode = ["n" "i"]; + action = ""; + noremap = false; + } + ]; + }) + (mapAttrs (_key: processLegacyMap "n") cfg.maps.normal) + (mapAttrs (_key: processLegacyMap "i") cfg.maps.insert) + (mapAttrs (_key: processLegacyMap "s") cfg.maps.select) + (mapAttrs (_key: processLegacyMap "v") cfg.maps.visual) + (mapAttrs (_key: processLegacyMap "t") cfg.maps.terminal) + (mapAttrs (_key: processLegacyMap "nvo") cfg.maps.normalVisualOp) + (mapAttrs (_key: processLegacyMap "nx") cfg.maps.visualOnly) + (mapAttrs (_key: processLegacyMap "o") cfg.maps.operator) + (mapAttrs (_key: processLegacyMap "ic") cfg.maps.insertCommand) + (mapAttrs (_key: processLegacyMap "l") cfg.maps.lang) + (mapAttrs (_key: processLegacyMap "c") cfg.maps.command) + ]; }; } diff --git a/modules/neovim/mappings/options.nix b/modules/neovim/mappings/options.nix index f422991..e16b787 100644 --- a/modules/neovim/mappings/options.nix +++ b/modules/neovim/mappings/options.nix @@ -38,6 +38,7 @@ See `:help map-modes` for a list of modes. ''; + example = ''"nvc" for normal, visual and command mode''; }; }; }; @@ -55,25 +56,10 @@ }; in { options.vim = { - maps = mkOption { + keymaps = mkOption { type = submodule { - freeformType = attrsOf mapType; - options = { - normal = mapOptions "normal"; - insert = mapOptions "insert"; - select = mapOptions "select"; - visual = mapOptions "visual and select"; - terminal = mapOptions "terminal"; - normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')"; - - visualOnly = mapOptions "visual only"; - operator = mapOptions "operator-pending"; - insertCommand = mapOptions "insert and command-line"; - lang = mapOptions "insert, command-line and lang-arg"; - command = mapOptions "command-line"; - }; + freeformType = attrsOf (listOf mapType); }; - default = {}; description = "Custom keybindings."; example = '' maps = { @@ -84,6 +70,22 @@ in { }; # Same as nnoremap m make }; ''; + default = {}; + }; + + maps = { + normal = mapOptions "normal"; + insert = mapOptions "insert"; + select = mapOptions "select"; + visual = mapOptions "visual and select"; + terminal = mapOptions "terminal"; + normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')"; + + visualOnly = mapOptions "visual only"; + operator = mapOptions "operator-pending"; + insertCommand = mapOptions "insert and command-line"; + lang = mapOptions "insert, command-line and lang-arg"; + command = mapOptions "command-line"; }; }; } diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index b3fd2e4..549c3fd 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -5,8 +5,8 @@ }: let inherit (builtins) map mapAttrs filter removeAttrs attrNames; inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList; - inherit (lib.strings) concatLines concatMapStringsSep; - inherit (lib.trivial) showWarnings; + inherit (lib.strings) concatLines concatMapStringsSep optionalString; + inherit (lib.trivial) showWarnings pipe; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere; inherit (lib.nvim.lua) toLuaObject; @@ -40,40 +40,19 @@ in { inherit (keymap) desc silent nowait script expr unique noremap; }; - toLuaKeymap = { - name, - value, - }: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})"; - - 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"]; - }; + toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})"; 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; + pipe + # attrsOf (listOf mapOption) + cfg.keymaps + [ + (mapAttrsToList (key: binds: + concatLines (map (toLuaKeymap key) binds))) + concatLines + ]; - keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull maps))); + keymaps = maps; in { vim = { luaConfigRC = { From fd4ddbdd39e34b0f07fc94768f66bacfbb56d050 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:04:32 +0200 Subject: [PATCH 02/39] maps: fix bad mode names --- modules/neovim/mappings/config.nix | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/neovim/mappings/config.nix b/modules/neovim/mappings/config.nix index b7e274b..a620e37 100644 --- a/modules/neovim/mappings/config.nix +++ b/modules/neovim/mappings/config.nix @@ -42,17 +42,17 @@ in { } ]; }) - (mapAttrs (_key: processLegacyMap "n") cfg.maps.normal) - (mapAttrs (_key: processLegacyMap "i") cfg.maps.insert) - (mapAttrs (_key: processLegacyMap "s") cfg.maps.select) - (mapAttrs (_key: processLegacyMap "v") cfg.maps.visual) - (mapAttrs (_key: processLegacyMap "t") cfg.maps.terminal) - (mapAttrs (_key: processLegacyMap "nvo") cfg.maps.normalVisualOp) - (mapAttrs (_key: processLegacyMap "nx") cfg.maps.visualOnly) - (mapAttrs (_key: processLegacyMap "o") cfg.maps.operator) - (mapAttrs (_key: processLegacyMap "ic") cfg.maps.insertCommand) - (mapAttrs (_key: processLegacyMap "l") cfg.maps.lang) - (mapAttrs (_key: processLegacyMap "c") cfg.maps.command) + (mapAttrs (_key: processLegacyMap ["n"]) cfg.maps.normal) + (mapAttrs (_key: processLegacyMap ["i"]) cfg.maps.insert) + (mapAttrs (_key: processLegacyMap ["s"]) cfg.maps.select) + (mapAttrs (_key: processLegacyMap ["v"]) cfg.maps.visual) + (mapAttrs (_key: processLegacyMap ["t"]) cfg.maps.terminal) + (mapAttrs (_key: processLegacyMap ["n" "v" "o"]) cfg.maps.normalVisualOp) + (mapAttrs (_key: processLegacyMap ["n" "x"]) cfg.maps.visualOnly) + (mapAttrs (_key: processLegacyMap ["o"]) cfg.maps.operator) + (mapAttrs (_key: processLegacyMap ["i" "c"]) cfg.maps.insertCommand) + (mapAttrs (_key: processLegacyMap ["l"]) cfg.maps.lang) + (mapAttrs (_key: processLegacyMap ["c"]) cfg.maps.command) ]; }; } From 7b00ab4fa37642efa8b8c1c2d4b9fbfc7248eef8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:55:55 +0200 Subject: [PATCH 03/39] remove unused From b89c311d9574d59204c18e2d1c9bf7e1e0e18521 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:02:03 +0200 Subject: [PATCH 04/39] maps: fix missing description From 57afef83217eb9ab1e12c28806a2b8d960883188 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:10:43 +0200 Subject: [PATCH 05/39] flake: add lz.n plugin --- flake.lock | 17 +++++++++++++++++ flake.nix | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/flake.lock b/flake.lock index 1851eb7..4644afe 100644 --- a/flake.lock +++ b/flake.lock @@ -843,6 +843,22 @@ "type": "github" } }, + "plugin-lz-n": { + "flake": false, + "locked": { + "lastModified": 1719248596, + "narHash": "sha256-GBDmumQ0XYxawPdUncI6fW413MMSjGl6TwCQTexUpnE=", + "owner": "nvim-neorocks", + "repo": "lz.n", + "rev": "24f9fe1024c936d9fa6a5607b73a4ae1958c9d77", + "type": "github" + }, + "original": { + "owner": "nvim-neorocks", + "repo": "lz.n", + "type": "github" + } + }, "plugin-mind-nvim": { "flake": false, "locked": { @@ -1872,6 +1888,7 @@ "plugin-lspkind": "plugin-lspkind", "plugin-lspsaga": "plugin-lspsaga", "plugin-lualine": "plugin-lualine", + "plugin-lz-n": "plugin-lz-n", "plugin-mind-nvim": "plugin-mind-nvim", "plugin-minimap-vim": "plugin-minimap-vim", "plugin-modes-nvim": "plugin-modes-nvim", diff --git a/flake.nix b/flake.nix index c00e9b8..131c21d 100644 --- a/flake.nix +++ b/flake.nix @@ -102,6 +102,12 @@ }; ## Plugins + # Lazy loading + plugin-lz-n = { + url = "github:nvim-neorocks/lz.n"; + flake = false; + }; + # LSP plugins plugin-nvim-lspconfig = { url = "github:neovim/nvim-lspconfig"; From d0134752829ace685e6c99c60440c6dd81abaa08 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:16:49 +0200 Subject: [PATCH 06/39] add lazy module skeleton --- modules/modules.nix | 1 + modules/wrapper/lazy/config.nix | 14 ++++++++++++++ modules/wrapper/lazy/default.nix | 6 ++++++ modules/wrapper/lazy/lazy.nix | 15 +++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 modules/wrapper/lazy/config.nix create mode 100644 modules/wrapper/lazy/default.nix create mode 100644 modules/wrapper/lazy/lazy.nix diff --git a/modules/modules.nix b/modules/modules.nix index a00cea6..a995754 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -50,6 +50,7 @@ wrapper = map (p: ./wrapper + "/${p}") [ "build" "rc" + "lazy" "warnings" ]; diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix new file mode 100644 index 0000000..53df6ae --- /dev/null +++ b/modules/wrapper/lazy/config.nix @@ -0,0 +1,14 @@ +{ + lib, + config, + ... +}: let + inherit (lib.modules) mkIf; + cfg = config.vim.lazy; +in { + config.vim = mkIf cfg.enable { + startPlugins = ["lz-n"]; + + # optPlugins = + }; +} diff --git a/modules/wrapper/lazy/default.nix b/modules/wrapper/lazy/default.nix new file mode 100644 index 0000000..fa40127 --- /dev/null +++ b/modules/wrapper/lazy/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./lazy.nix + ./config.nix + ]; +} diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix new file mode 100644 index 0000000..0b11ab1 --- /dev/null +++ b/modules/wrapper/lazy/lazy.nix @@ -0,0 +1,15 @@ +{lib, ...}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) enum; +in { + options.vim.lazy = { + enable = mkEnableOption "plugin lazy-loading" // {default = true;}; + loader = mkOption { + description = "Lazy loader to use"; + type = enum ["lz.n"]; + default = "lz.n"; + }; + + # plugins = mkOption {}; + }; +} From ccc871047ce08680de3c44fc51ed792b415be2cc Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:47:33 +0200 Subject: [PATCH 07/39] lib: add basic lz.n plugin spec type --- lib/types/plugins.nix | 81 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index c0e89d6..b590ed5 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -6,8 +6,7 @@ inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.strings) hasPrefix removePrefix; - inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr; - + inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf; # Get the names of all flake inputs that start with the given prefix. fromInputs = { inputs, @@ -51,8 +50,79 @@ }; }; }; + + luaInline = lib.mkOptionType { + name = "luaInline"; + check = x: lib.nvim.lua.isLuaInline x; + }; + + lznPluginType = submodule { + options = { + ## Should probably infer from the actual plugin somehow + ## In general this is the name passed to packadd, so the dir name of the plugin + # name = mkOption { + # type= str; + # } + + package = pluginType; + + before = mkOption { + type = nullOr luaInline; + description = "Code to run before plugin is loaded"; + default = null; + }; + + after = mkOption { + type = nullOr luaInline; + description = "Code to run after plugin is loaded"; + default = null; + }; + + event = mkOption { + description = "Lazy-load on event"; + default = "null"; + type = let + event = submodule { + options = { + event = mkOption { + type = nullOr (either str (listOf str)); + description = "Exact event name"; + example = "BufEnter"; + }; + pattern = mkOption { + type = nullOr (either str (listOf str)); + description = "Event pattern"; + example = "BufEnter *.lua"; + }; + }; + }; + in + oneOf [str (listOf str) event]; + }; + + cmd = mkOption { + description = "Lazy-load on command"; + default = null; + type = nullOr (either str (listOf str)); + }; + + ft = mkOption { + description = "Lazy-load on filetype"; + default = null; + type = nullOr (either str (listOf str)); + }; + + keys = mkOption { + description = "Lazy-load on key mapping"; + default = null; + type = nullOr (either str (listOf str)); # TODO: support lz.n.KeysSpec + }; + + # TODO: enabled, beforeAll, colorscheme, priority, load + }; + }; in { - inherit extraPluginType fromInputs pluginType; + inherit extraPluginType fromInputs pluginType luaInline lznPluginType; pluginsOpt = { description, @@ -64,11 +134,6 @@ in { type = pluginsType; }; - luaInline = lib.mkOptionType { - name = "luaInline"; - check = x: lib.nvim.lua.isLuaInline x; - }; - /* opts is a attrset of options, example: ``` From 0fac19afee33c34cc19206512ae9f08d63226861 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:28:10 +0200 Subject: [PATCH 08/39] lz.n: add basic lazy.plugins option --- modules/wrapper/lazy/lazy.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index 0b11ab1..90ae055 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -1,6 +1,7 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) enum; + inherit (lib.nvim.types) lznPluginTableType; in { options.vim.lazy = { enable = mkEnableOption "plugin lazy-loading" // {default = true;}; @@ -10,6 +11,19 @@ in { default = "lz.n"; }; - # plugins = mkOption {}; + plugins = mkOption { + default = {}; + type = lznPluginTableType; + description = "list of plugins to lazy load"; + example = '' + { + toggleterm-nvim = { + package = "toggleterm-nvim"; + after = "require('toggleterm').setup{}"; + cmd = ["ToggleTerm"]; + }; + } + ''; + }; }; } From 2d797ead5d4e1e3e3a4c5d53f76226d8f75c44f2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:28:18 +0200 Subject: [PATCH 09/39] lz.n: load lz.n --- modules/wrapper/lazy/config.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 53df6ae..a2bd73a 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,12 +3,26 @@ config, ... }: let + inherit (builtins) toJSON; inherit (lib.modules) mkIf; + inherit (lib.attrsets) mapAttrsToList; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lazy; + + toLznSpec = name: plugin: + (removeAttrs plugin ["package"]) + // {__HACK = mkLuaInline "nil, [1] = ${toJSON name}";}; + lznSpecs = mapAttrsToList toLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable { startPlugins = ["lz-n"]; - # optPlugins = + optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; + + luaConfigRC.lzn-load = entryAnywhere '' + require('lz.n').load(${toLuaObject lznSpecs}) + ''; }; } From de82d9b2c857b4bd9638f114abd5addb8b3e0236 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:52:42 +0200 Subject: [PATCH 10/39] lib: export lznPluginType --- lib/types/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/types/default.nix b/lib/types/default.nix index 928bbae..98c64cc 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -9,7 +9,7 @@ typesCustom = import ./custom.nix {inherit lib;}; in { inherit (typesDag) dagOf; - inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType; + inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType lznPluginType; inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesCustom) anythingConcatLists char; } From a0006ca4861b000fac0641cb6acbdbcf869fcd25 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:40:11 +0200 Subject: [PATCH 11/39] lib: add lznPluginTableType --- lib/types/default.nix | 2 +- lib/types/plugins.nix | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/types/default.nix b/lib/types/default.nix index 98c64cc..170667d 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -9,7 +9,7 @@ typesCustom = import ./custom.nix {inherit lib;}; in { inherit (typesDag) dagOf; - inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType lznPluginType; + inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType lznPluginType lznPluginTableType; inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesCustom) anythingConcatLists char; } diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index b590ed5..fd8e8bb 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -56,6 +56,7 @@ check = x: lib.nvim.lua.isLuaInline x; }; + lznPluginTableType = attrsOf lznPluginType; lznPluginType = submodule { options = { ## Should probably infer from the actual plugin somehow @@ -64,7 +65,9 @@ # type= str; # } - package = pluginType; + package = mkOption { + type = pluginType; + }; before = mkOption { type = nullOr luaInline; @@ -80,7 +83,7 @@ event = mkOption { description = "Lazy-load on event"; - default = "null"; + default = null; type = let event = submodule { options = { @@ -97,7 +100,7 @@ }; }; in - oneOf [str (listOf str) event]; + nullOr (oneOf [str (listOf str) event]); }; cmd = mkOption { @@ -122,7 +125,7 @@ }; }; in { - inherit extraPluginType fromInputs pluginType luaInline lznPluginType; + inherit extraPluginType fromInputs pluginType luaInline lznPluginType lznPluginTableType; pluginsOpt = { description, From dc79db2e892cee0b86ef995d78b7a0cda12865f9 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:40:26 +0200 Subject: [PATCH 12/39] flake: update lz.n --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 4644afe..263a5c2 100644 --- a/flake.lock +++ b/flake.lock @@ -846,11 +846,11 @@ "plugin-lz-n": { "flake": false, "locked": { - "lastModified": 1719248596, - "narHash": "sha256-GBDmumQ0XYxawPdUncI6fW413MMSjGl6TwCQTexUpnE=", + "lastModified": 1719989949, + "narHash": "sha256-oHwmlLgdJJDz5+gs1KLAa2MHQAadM/JYmHGfep9yl28=", "owner": "nvim-neorocks", "repo": "lz.n", - "rev": "24f9fe1024c936d9fa6a5607b73a4ae1958c9d77", + "rev": "4c790ba2c3789f580aa019712bbe3112f85e73a0", "type": "github" }, "original": { From e6c15ed881646f514300304e88a25db217341851 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:39:53 +0200 Subject: [PATCH 13/39] wrap lazy init code in function --- modules/wrapper/lazy/lazy.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index 90ae055..151c087 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -19,7 +19,7 @@ in { { toggleterm-nvim = { package = "toggleterm-nvim"; - after = "require('toggleterm').setup{}"; + after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end"; cmd = ["ToggleTerm"]; }; } From 29278001750e9c3711466bcb01a00b31c41f2390 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:00:41 +0200 Subject: [PATCH 14/39] switch to other hacky array-table syntax --- modules/wrapper/lazy/config.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index a2bd73a..749a320 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,18 +3,16 @@ config, ... }: let - inherit (builtins) toJSON; inherit (lib.modules) mkIf; inherit (lib.attrsets) mapAttrsToList; - inherit (lib.generators) mkLuaInline; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lazy; - toLznSpec = name: plugin: + toLuaLznSpec = name: plugin: (removeAttrs plugin ["package"]) - // {__HACK = mkLuaInline "nil, [1] = ${toJSON name}";}; - lznSpecs = mapAttrsToList toLznSpec cfg.plugins; + // {"@1" = name;}; + lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable { startPlugins = ["lz-n"]; From 6feafdc2920c2cb2d19d3d74b9cf215352fcced8 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:36:49 +0200 Subject: [PATCH 15/39] fix: broken optPlugins --- modules/default.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index 1ae3b03..8a436d5 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -69,10 +69,7 @@ inputs: { # built (or "normalized") plugins that are modified builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; - builtOptPlugins = map (package: { - plugin = package; - optional = true; - }) (buildConfigPlugins vimOptions.optPlugins); + builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins); # additional Lua and Python3 packages, mapped to their respective functions # to conform to the format mnw expects. end user should From 140a2ed660282273c3a4a24121673f447143d5d2 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:52:47 +0200 Subject: [PATCH 16/39] lazy: add setupOpts support --- lib/types/plugins.nix | 17 +++++++++++++++++ modules/wrapper/lazy/config.nix | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index fd8e8bb..ca5c614 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -65,10 +65,27 @@ # type= str; # } + # Non-lz.n options + package = mkOption { type = pluginType; + description = "Plugin package"; }; + setupModule = mkOption { + type = nullOr str; + description = "Lua module to run setup function on."; + default = null; + }; + + setupOpts = mkOption { + type = submodule {freeformType = attrsOf anything;}; + description = "Options to pass to the setup function"; + default = {}; + }; + + # lz.n options + before = mkOption { type = nullOr luaInline; description = "Code to run before plugin is loaded"; diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 749a320..5e25939 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,15 +3,29 @@ config, ... }: let + inherit (builtins) toJSON; inherit (lib.modules) mkIf; inherit (lib.attrsets) mapAttrsToList; + inherit (lib.generators) mkLuaInline; + inherit (lib.strings) optionalString; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lazy; - toLuaLznSpec = name: plugin: - (removeAttrs plugin ["package"]) - // {"@1" = name;}; + toLuaLznSpec = name: spec: + (removeAttrs spec ["package" "setupModule" "setupOpts"]) + // { + "@1" = name; + after = mkLuaInline '' + function() + ${ + optionalString (spec.setupModule != null) + "require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" + } + ${optionalString (spec.after != null) spec.after} + end + ''; + }; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable { From 5708487de75c0d9718acebea46e0f8e8eb379b38 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:23:53 +0200 Subject: [PATCH 17/39] nvim-tree: use lazy --- modules/plugins/filetree/nvimtree/config.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index b97b1e4..f1e75b5 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -16,8 +16,6 @@ inherit (self.options.vim.filetree.nvimTree) mappings; in { config = mkIf cfg.enable { - vim.startPlugins = ["nvim-tree-lua"]; - vim.maps.normal = mkMerge [ (mkBinding cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) (mkBinding cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) @@ -29,6 +27,17 @@ in { "t" = "+NvimTree"; }; + vim.lazy = { + plugins = { + nvim-tree-lua = { + package = "nvim-tree-lua"; + setupModule = "nvim-tree"; + inherit (cfg) setupOpts; + cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; + }; + }; + }; + vim.pluginRC.nvimtreelua = entryAnywhere '' ${ optionalString cfg.setupOpts.disable_netrw '' @@ -38,8 +47,6 @@ in { '' } - require'nvim-tree'.setup(${toLuaObject cfg.setupOpts}) - ${ optionalString cfg.openOnSetup '' -- autostart behaviour From bf858feb1141e75076b5087a5ff129350eba5a83 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Thu, 1 Aug 2024 22:33:51 +0200 Subject: [PATCH 18/39] lib: add lz.n KeySpec --- lib/types/plugins.nix | 62 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index ca5c614..7e65abc 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.strings) hasPrefix removePrefix; - inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf; + inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool; # Get the names of all flake inputs that start with the given prefix. fromInputs = { inputs, @@ -56,6 +56,64 @@ check = x: lib.nvim.lua.isLuaInline x; }; + lznKeysSpec = submodule { + apply = x: + x + // { + "@1" = x.lhs; + "@2" = x.rhs; + }; + + options = { + desc = mkOption { + description = "Description of the key map"; + type = nullOr str; + default = null; + }; + + noremap = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + expr = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + nowait = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + ft = mkOption { + description = "TBD"; + type = nullOr (listOf str); + default = null; + }; + + lhs = mkOption { + type = str; + description = "Key to bind to"; + }; + + rhs = mkOption { + type = nullOr str; + default = null; + description = "Action to trigger"; + }; + + mode = mkOption { + description = "Modes to bind in"; + type = listOf str; + default = ["n"]; + }; + }; + }; + lznPluginTableType = attrsOf lznPluginType; lznPluginType = submodule { options = { @@ -135,7 +193,7 @@ keys = mkOption { description = "Lazy-load on key mapping"; default = null; - type = nullOr (either str (listOf str)); # TODO: support lz.n.KeysSpec + type = nullOr (oneOf [str (listOf str) lznKeysSpec]); # TODO: support lz.n.KeysSpec }; # TODO: enabled, beforeAll, colorscheme, priority, load From 86bb6fffdf9eee24f66cdc29155df4a5dcac846f Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:10:20 +0200 Subject: [PATCH 19/39] lib: fix lz.n map type --- lib/types/plugins.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 7e65abc..c993f1d 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -109,7 +109,7 @@ mode = mkOption { description = "Modes to bind in"; type = listOf str; - default = ["n"]; + default = ["n" "x" "s" "o"]; }; }; }; @@ -193,7 +193,7 @@ keys = mkOption { description = "Lazy-load on key mapping"; default = null; - type = nullOr (oneOf [str (listOf str) lznKeysSpec]); # TODO: support lz.n.KeysSpec + type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); # TODO: support lz.n.KeysSpec }; # TODO: enabled, beforeAll, colorscheme, priority, load From d5b6923f5afe7b0cea0c01c1f9416139184f1fa0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:45:29 +0200 Subject: [PATCH 20/39] remove unused --- lib/types/plugins.nix | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index c993f1d..7fa7448 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -57,13 +57,6 @@ }; lznKeysSpec = submodule { - apply = x: - x - // { - "@1" = x.lhs; - "@2" = x.rhs; - }; - options = { desc = mkOption { description = "Description of the key map"; From 74bc4f843d5644994b70dd785ed16f2c6e3223fd Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:45:48 +0200 Subject: [PATCH 21/39] lz.n: process key maps --- modules/wrapper/lazy/config.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 5e25939..645dfb9 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -12,8 +12,23 @@ inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lazy; + toLuzLznKeySpec = { + desc, + noremap, + expr, + nowait, + ft, + lhs, + rhs, + mode, + }: { + "@1" = lhs; + "@2" = rhs; + inherit desc noremap expr nowait ft mode; + }; + toLuaLznSpec = name: spec: - (removeAttrs spec ["package" "setupModule" "setupOpts"]) + (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) // { "@1" = name; after = mkLuaInline '' @@ -25,6 +40,7 @@ ${optionalString (spec.after != null) spec.after} end ''; + keys = map toLuzLznKeySpec spec.keys; }; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { From 7350769edf932f2cfaabde63df64c2ece23383d2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:38:42 +0200 Subject: [PATCH 22/39] lib: add lznKeySpec example --- lib/types/plugins.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 7fa7448..f328aae 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -186,7 +186,12 @@ keys = mkOption { description = "Lazy-load on key mapping"; default = null; - type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); # TODO: support lz.n.KeysSpec + type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); + example = '' + keys = [ + {lhs = "s"; rhs = ":NvimTreeToggle"; desc = "Toggle NvimTree"} + ] + ''; }; # TODO: enabled, beforeAll, colorscheme, priority, load From d5bc0ce4f95a512e1fc9e611e7fcbe431bdff1af Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:01:34 +0200 Subject: [PATCH 23/39] lz.n: missing type check --- modules/wrapper/lazy/config.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 645dfb9..5ce308b 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,7 +3,7 @@ config, ... }: let - inherit (builtins) toJSON; + inherit (builtins) toJSON typeOf head length; inherit (lib.modules) mkIf; inherit (lib.attrsets) mapAttrsToList; inherit (lib.generators) mkLuaInline; @@ -40,7 +40,10 @@ ${optionalString (spec.after != null) spec.after} end ''; - keys = map toLuzLznKeySpec spec.keys; + keys = + if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set" + then map toLuzLznKeySpec spec.keys + else spec.keys; }; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { From acbc2ecfa0cfbf77970200dc8b7a34f4b27bd60c Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:05:33 +0200 Subject: [PATCH 24/39] lib: change lz.n spec "inlineLua" types to str --- lib/types/plugins.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index f328aae..84bf78a 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -138,14 +138,14 @@ # lz.n options before = mkOption { - type = nullOr luaInline; - description = "Code to run before plugin is loaded"; + type = nullOr str; + description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; default = null; }; after = mkOption { - type = nullOr luaInline; - description = "Code to run after plugin is loaded"; + type = nullOr str; + description = "Lua code to run after plugin is loaded. This will be wrapped in a function."; default = null; }; From ed88e796a6f522f72889c2e711d8fe1c56da5e36 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:41:41 +0200 Subject: [PATCH 25/39] lib: add mkLznBinding --- lib/binds.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/binds.nix b/lib/binds.nix index 8c9e9a6..ae16d73 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -67,6 +67,10 @@ mkLuaBinding binding.value action binding.description; pushDownDefault = attr: mapAttrs (_: mkDefault) attr; + + mkLznBinding = mode: lhs: rhs: desc: { + inherit mode lhs rhs desc; + }; }; in binds From 346950ad7afb5cfb92694c372873b0aa47482924 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:46:05 +0200 Subject: [PATCH 26/39] nvim-tree: move to lz.n keymaps --- modules/plugins/filetree/nvimtree/config.nix | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index f1e75b5..9e9d4e3 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -4,11 +4,11 @@ pkgs, ... }: let + inherit (builtins) filter; inherit (lib.strings) optionalString; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkBinding; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkLznBinding; inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.binds) pushDownDefault; cfg = config.vim.filetree.nvimTree; @@ -16,13 +16,6 @@ inherit (self.options.vim.filetree.nvimTree) mappings; in { config = mkIf cfg.enable { - vim.maps.normal = mkMerge [ - (mkBinding cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) - (mkBinding cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) - (mkBinding cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) - (mkBinding cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) - ]; - vim.binds.whichKey.register = pushDownDefault { "t" = "+NvimTree"; }; @@ -34,6 +27,13 @@ in { setupModule = "nvim-tree"; inherit (cfg) setupOpts; cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; + + keys = filter ({lhs, ...}: lhs != null) [ + (mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) + (mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) + (mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) + (mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) + ]; }; }; }; From 290cfebec5ecff3bc55956cf2981ff70f10eca61 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:59:41 +0200 Subject: [PATCH 27/39] nvim-tree: load nvim-tree if openOnSetup --- modules/plugins/filetree/nvimtree/config.nix | 1 + modules/wrapper/lazy/config.nix | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index 9e9d4e3..47a85d6 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -49,6 +49,7 @@ in { ${ optionalString cfg.openOnSetup '' + require('lz.n').trigger_load("nvim-tree-lua") -- autostart behaviour -- Open on startup has been deprecated -- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 5ce308b..b1afb5b 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -9,7 +9,7 @@ inherit (lib.generators) mkLuaInline; inherit (lib.strings) optionalString; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.dag) entryBefore; cfg = config.vim.lazy; toLuzLznKeySpec = { @@ -52,7 +52,7 @@ in { optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; - luaConfigRC.lzn-load = entryAnywhere '' + luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] '' require('lz.n').load(${toLuaObject lznSpecs}) ''; }; From 6497644e6d03376c4e718b72eb78c7bc09b19280 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:18:25 +0200 Subject: [PATCH 28/39] lib: add mkLznBinding --- lib/binds.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/binds.nix b/lib/binds.nix index ae16d73..61fec95 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -71,6 +71,24 @@ mkLznBinding = mode: lhs: rhs: desc: { inherit mode lhs rhs desc; }; + + # Usage: + # + # ``` + # vim.lazy.plugins = { + # telescope = { + # # ... + # keys = builtins.filter ({lhs, ...}: lhs != null) [ + # mkSetLznBinding mapping ":Telescope" + # ]; + # } + # } + # ``` + mkSetLznBinding = binding: action: { + lhs = binding.value; + rhs = action; + desc = binding.description; + }; }; in binds From afec78de264b2971ae751f024dc5347050c2db96 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:46:52 +0200 Subject: [PATCH 29/39] lz.n: wrap lua code in function --- modules/wrapper/lazy/config.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index b1afb5b..38be892 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -31,6 +31,15 @@ (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) // { "@1" = name; + before = + if spec.before != null + then + mkLuaInline '' + function() + ${spec.before} + end + '' + else null; after = mkLuaInline '' function() ${ From 645574073ab79d5f1847449bb238e4360512c796 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:48:13 +0200 Subject: [PATCH 30/39] lz.n: generate less code --- modules/wrapper/lazy/config.nix | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 38be892..b3fdb7d 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -40,15 +40,21 @@ end '' else null; - after = mkLuaInline '' - function() - ${ - optionalString (spec.setupModule != null) - "require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" - } - ${optionalString (spec.after != null) spec.after} - end - ''; + + after = + if spec.setupModule == null && spec.after == null + then null + else + mkLuaInline '' + function() + ${ + optionalString (spec.setupModule != null) + "require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" + } + ${optionalString (spec.after != null) spec.after} + end + ''; + keys = if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set" then map toLuzLznKeySpec spec.keys From aeabcb80e0777dfec99d30f00eaf6f0a888852f2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:21:32 +0200 Subject: [PATCH 31/39] flake: add plugin lzn-auto-require --- flake.lock | 17 +++++++++++++++++ flake.nix | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/flake.lock b/flake.lock index 263a5c2..634a707 100644 --- a/flake.lock +++ b/flake.lock @@ -859,6 +859,22 @@ "type": "github" } }, + "plugin-lzn-auto-require": { + "flake": false, + "locked": { + "lastModified": 1722716302, + "narHash": "sha256-YehBjQ4m3i0yEnts7HhWW78N6g40hblfcl94d7l9aN4=", + "owner": "horriblename", + "repo": "lzn-auto-require", + "rev": "57567c9db26a3b5b143ae91f35143c34706e8881", + "type": "github" + }, + "original": { + "owner": "horriblename", + "repo": "lzn-auto-require", + "type": "github" + } + }, "plugin-mind-nvim": { "flake": false, "locked": { @@ -1889,6 +1905,7 @@ "plugin-lspsaga": "plugin-lspsaga", "plugin-lualine": "plugin-lualine", "plugin-lz-n": "plugin-lz-n", + "plugin-lzn-auto-require": "plugin-lzn-auto-require", "plugin-mind-nvim": "plugin-mind-nvim", "plugin-minimap-vim": "plugin-minimap-vim", "plugin-modes-nvim": "plugin-modes-nvim", diff --git a/flake.nix b/flake.nix index 131c21d..8468bd2 100644 --- a/flake.nix +++ b/flake.nix @@ -108,6 +108,11 @@ flake = false; }; + plugin-lzn-auto-require = { + url = "github:horriblename/lzn-auto-require"; + flake = false; + }; + # LSP plugins plugin-nvim-lspconfig = { url = "github:neovim/nvim-lspconfig"; From eeb54209e211dc71f7e7ca906507d54ab3c12884 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:28:51 +0200 Subject: [PATCH 32/39] wrapper: use lzn-auto-require loader --- modules/wrapper/rc/config.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index 549c3fd..67731fa 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -3,8 +3,8 @@ lib, ... }: let - inherit (builtins) map mapAttrs filter removeAttrs attrNames; - inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList; + inherit (builtins) map mapAttrs filter; + inherit (lib.attrsets) mapAttrsToList filterAttrs; inherit (lib.strings) concatLines concatMapStringsSep optionalString; inherit (lib.trivial) showWarnings pipe; inherit (lib.generators) mkLuaInline; @@ -61,6 +61,8 @@ in { pluginConfigs = entryAfter ["theme"] pluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; mappings = entryAfter ["extraPluginConfigs"] keymaps; + # FIXME: put this somewhere less stupid + footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require.loader').register_loader()"); }; builtLuaConfigRC = let From 767407a7d421ee886c0c87ba32a3a89ba53bf97b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:33:09 +0200 Subject: [PATCH 33/39] lib: add mkSetLuaBinding --- lib/binds.nix | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/binds.nix b/lib/binds.nix index 61fec95..f8f915e 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -3,6 +3,7 @@ inherit (lib.modules) mkIf mkDefault; inherit (lib.types) nullOr str; inherit (lib.attrsets) isAttrs mapAttrs; + inherit (lib.generators) mkLuaInline; binds = rec { mkLuaBinding = key: action: desc: @@ -72,23 +73,17 @@ inherit mode lhs rhs desc; }; - # Usage: - # - # ``` - # vim.lazy.plugins = { - # telescope = { - # # ... - # keys = builtins.filter ({lhs, ...}: lhs != null) [ - # mkSetLznBinding mapping ":Telescope" - # ]; - # } - # } - # ``` mkSetLznBinding = binding: action: { lhs = binding.value; rhs = action; desc = binding.description; }; + + mkSetLuaLznBinding = binding: action: { + lhs = binding.value; + rhs = mkLuaInline "function() ${action} end"; + desc = binding.description; + }; }; in binds From b7d9febe254c401f13b0ad7a4040b37958abf857 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 3 Aug 2024 22:46:06 +0200 Subject: [PATCH 34/39] fixup! wrapper: use lzn-auto-require loader --- modules/wrapper/lazy/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index b3fdb7d..7baefa4 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -63,7 +63,7 @@ lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable { - startPlugins = ["lz-n"]; + startPlugins = ["lz-n" "lzn-auto-require"]; optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; From 97aa39bc02b174bd0f234f31540a302551541dec Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sun, 4 Aug 2024 02:23:30 +0200 Subject: [PATCH 35/39] flake: update lzn-auto-require --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 634a707..2d56f9f 100644 --- a/flake.lock +++ b/flake.lock @@ -862,11 +862,11 @@ "plugin-lzn-auto-require": { "flake": false, "locked": { - "lastModified": 1722716302, - "narHash": "sha256-YehBjQ4m3i0yEnts7HhWW78N6g40hblfcl94d7l9aN4=", + "lastModified": 1722727896, + "narHash": "sha256-h7Dx3zBkUYamQY6lcuQrwAMgBpPqskLnA6WsbefHzMU=", "owner": "horriblename", "repo": "lzn-auto-require", - "rev": "57567c9db26a3b5b143ae91f35143c34706e8881", + "rev": "c6b47e148a1ff9709e802f68c2c8b558a9a8de9b", "type": "github" }, "original": { From 2e2a34f9ac785da4fe7e369e80c389ff99a40838 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sun, 4 Aug 2024 02:24:10 +0200 Subject: [PATCH 36/39] lib: allow luaInline in lz.n map action --- lib/types/plugins.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 84bf78a..d6dc79a 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -94,9 +94,9 @@ }; rhs = mkOption { - type = nullOr str; + type = nullOr (either str luaInline); default = null; - description = "Action to trigger"; + description = "Action to trigger. luaInline code will be wrapped in a function."; }; mode = mkOption { From 5136fc4bd120f964393b4341c2443835b8c541d1 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sun, 4 Aug 2024 02:27:59 +0200 Subject: [PATCH 37/39] add TODO --- lib/types/plugins.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index d6dc79a..86f6101 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -96,6 +96,7 @@ rhs = mkOption { type = nullOr (either str luaInline); default = null; + # FIXME: use a separate flag to indicate lua instead of luaInline description = "Action to trigger. luaInline code will be wrapped in a function."; }; From c0bfe6bb38563749948338d7559481c78c1e3948 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:19:12 +0200 Subject: [PATCH 38/39] lz.n: add missing PluginSpec options --- lib/types/plugins.nix | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 86f6101..d83c48f 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.strings) hasPrefix removePrefix; - inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool; + inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int; # Get the names of all flake inputs that start with the given prefix. fromInputs = { inputs, @@ -138,6 +138,18 @@ # lz.n options + enabled = mkOption { + type = nullOr (either bool str); + description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; + default = null; + }; + + beforeAll = mkOption { + type = nullOr str; + description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; + default = null; + }; + before = mkOption { type = nullOr str; description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; @@ -195,7 +207,27 @@ ''; }; - # TODO: enabled, beforeAll, colorscheme, priority, load + colorscheme = mkOption { + description = "Lazy-load on colorscheme."; + type = nullOr (either str (listOf str)); + default = null; + }; + + priority = mkOption { + type = nullOr int; + description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; + default = null; + }; + + load = mkOption { + type = nullOr str; + default = null; + description = '' + Lua code to override the `vim.g.lz_n.load()` function for a single plugin. + + This will be wrapped in a function + ''; + }; }; }; in { From c5c7d46e35201b279c6f933034c0d611113bed1e Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:43:03 +0200 Subject: [PATCH 39/39] flake: update lzn-auto-require --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 2d56f9f..56d380b 100644 --- a/flake.lock +++ b/flake.lock @@ -862,11 +862,11 @@ "plugin-lzn-auto-require": { "flake": false, "locked": { - "lastModified": 1722727896, - "narHash": "sha256-h7Dx3zBkUYamQY6lcuQrwAMgBpPqskLnA6WsbefHzMU=", + "lastModified": 1723928740, + "narHash": "sha256-CMWy+btqUaXUWSO4jZYDfBcNiYMFyRb8jtIdi072WP8=", "owner": "horriblename", "repo": "lzn-auto-require", - "rev": "c6b47e148a1ff9709e802f68c2c8b558a9a8de9b", + "rev": "1b9f6527e32bf196ce239f7a8b9a54d342605511", "type": "github" }, "original": {