From 202ea7570d4c7701cd676c2a64e7b87ee6b7cd7f 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 01/36] remove unused --- modules/neovim/mappings/options.nix | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/modules/neovim/mappings/options.nix b/modules/neovim/mappings/options.nix index 522079e..f422991 100644 --- a/modules/neovim/mappings/options.nix +++ b/modules/neovim/mappings/options.nix @@ -44,23 +44,7 @@ # legacy stuff mapOption = submodule { - options = - mapConfigOptions - // { - action = mkOption { - type = str; - description = "The action to execute."; - }; - - lua = mkOption { - type = bool; - description = '' - If true, `action` is considered to be lua code. - Thus, it will not be wrapped in `""`. - ''; - default = false; - }; - }; + options = mapConfigOptions; }; mapOptions = mode: From 6d654ce4cd5ed01a660b3651f061f76d679c19bc 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 02/36] maps: fix missing description --- modules/wrapper/rc/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index f4c100d..b3fd2e4 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -37,7 +37,7 @@ in { else keymap.action; getOpts = keymap: { - inherit (keymap) silent nowait script expr unique noremap; + inherit (keymap) desc silent nowait script expr unique noremap; }; toLuaKeymap = { From ad8ce463f1154ca0fbbf8eaa5f1096dcb52fe101 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:10:43 +0200 Subject: [PATCH 03/36] 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 b409800b2fecf68d8d8b2ceed8d5a125139f012e Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:16:49 +0200 Subject: [PATCH 04/36] 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 b1a1aaba4629740781afbd1c1dc7aa2e191e8e59 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching Date: Tue, 25 Jun 2024 17:47:33 +0200 Subject: [PATCH 05/36] 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 44681a4cb5ed49ae58a7c8c4e6852cdcd829bccf 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 06/36] 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 0d452bcaf7e03b142535a39e202cd5573d782255 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 07/36] 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 8f92dd2dc12f55873958cd49d05994ecfceda83c 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 08/36] 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 8a0ffcb69f294ee1c1890ebe1739d740ae7e8531 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 09/36] 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 4a8c83130d2495f978fca0c5f4097e6abfec07e7 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 10/36] 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 7aef3392fda76d8171a8bbd1971edb3cf762f4cb 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 11/36] 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 dee9fa0d61778734d4b60a826b608e2f9da0ea41 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 12/36] 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 e07ff4029be3ba82c265a54d4567ac13cf8e62ef 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 13/36] 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 1e83f6f50b9a7fdde0940dcf070b2f96f63c35c9 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 14/36] 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 3763d71124920e90b3568ff6f19f0e135c1e75c6 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 15/36] 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 1b661bacfd6a6f15d94234e7a26bd565ad337ded 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 16/36] 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 320d05aff293439c4417c9179d6865a2a9f2fa0f 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 17/36] 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 980c80f0b8493f0e866491dd506f1fc77cef22c6 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 18/36] 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 fc63d2e0a12a70d015ef132bf384295928cdfbec 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 19/36] 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 3fbef8cdb4e45be56664c2ed395c882c1d2ed93c 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 20/36] 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 ad5b928830f04e5b3654daf6aa5a19cccc716194 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 21/36] 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 8195ad5cc9f8fee32d4212995b14387040ddeb37 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 22/36] 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 be6e41e876a1b6e60397c5e93f88ff38ad5c7f17 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 23/36] 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 7260efac666c85493bbc5a08b8ba908deab7bf69 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 24/36] 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 98bfd74de3f328e2dd02ffeb36c7caf66b257c7b 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 25/36] 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 a6568e64dd9240658993822b713aeb8a08154eeb 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 26/36] 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 c80f303b0ff6bc95368230ce2bcd59edf717e988 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 27/36] 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 61dc161ef7f7fa2c92c13aecc5870f2cb55eb41d 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 28/36] 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 ff214eb491d3516bb2bec4c2620d1109a26f2e6b 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 29/36] 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 6b94991888054267a20313348ad2bc744e9ad194 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 30/36] wrapper: use lzn-auto-require loader --- modules/wrapper/rc/config.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index b3fd2e4..b82d840 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -5,7 +5,7 @@ }: let inherit (builtins) map mapAttrs filter removeAttrs attrNames; inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList; - inherit (lib.strings) concatLines concatMapStringsSep; + inherit (lib.strings) concatLines concatMapStringsSep optionalString; inherit (lib.trivial) showWarnings; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere; @@ -82,6 +82,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 60b0c630a7de77b39243dbe612238503979b5b78 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 31/36] 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 29f9e3f168347b8cc534c7aa67d97dacf0e0d3ed 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 32/36] 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 4dcce2341047d792e1ea46bfefcbdb1cfa32bdbf 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 33/36] 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 745d539732ec4a1ab6ab9db89de2b4836a34506c 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 34/36] 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 c331e3303ef0977bcec20cbc74a57bcd9b99adf8 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 35/36] 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 83fd1b5c7a89029813b3ff01068c691a6b6113b4 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 36/36] 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..27f3fec 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 = 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 {