From 58021beb1c952c55feb693c1469dd9e9c9c9e7a5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 22 Mar 2025 15:01:51 +0100 Subject: [PATCH 1/5] lazy: fix incomplete event type --- 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 5d67aa59..eb1f5cdf 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -126,7 +126,7 @@ }; event = mkOption { - type = nullOr (oneOf [str (listOf str) lznEvent]); + type = nullOr (oneOf [str lznEvent (listOf (either str lznEvent))]); default = null; description = "Lazy-load on event"; }; From e2d10e8fb20c8a366a23bcd97535ecd3b3b940c8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 22 Mar 2025 15:02:13 +0100 Subject: [PATCH 2/5] lazy: create LazyFile user event --- 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 3468d5ec..c1bd8829 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -134,6 +134,15 @@ in { startPlugins = ["lz-n" "lzn-auto-require"]; optPlugins = pluginPackages; + augroups = [{name = "nvf_lazy_file_hooks";}]; + autocmds = [ + { + event = ["BufReadPost" "BufNewFile" "BufWritePre"]; + group = "nvf_lazy_file_hooks"; + command = "doautocmd User LazyFile"; + once = true; + } + ]; lazy.builtLazyConfig = '' require('lz.n').load(${toLuaObject lznSpecs}) From c639cf50646abc67f87231654c49d749c8b16135 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 22 Mar 2025 15:02:40 +0100 Subject: [PATCH 3/5] copilot: load on LazyFile --- modules/plugins/assistant/copilot/config.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 37da046f..525fe3bd 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -37,6 +37,12 @@ in { inherit (cfg) setupOpts; after = mkIf cfg.cmp.enable "require('copilot_cmp').setup()"; + event = [ + { + event = "User"; + pattern = "LazyFile"; + } + ]; cmd = ["Copilot" "CopilotAuth" "CopilotDetach" "CopilotPanel" "CopilotStop"]; keys = [ (mkLuaKeymap ["n"] cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion" {}) From 5f99c7f4e5cd7db5a3d0ef3e56b0beb75411f93a Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 22 Mar 2025 15:07:27 +0100 Subject: [PATCH 4/5] docs: update release notes --- docs/release-notes/rl-0.8.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index c84ef199..e1c1f38f 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -89,6 +89,7 @@ [blink.cmp]: https://github.com/saghen/blink.cmp - Add [blink.cmp] support. +- Add `LazyFile` user event. [diniamo](https://github.com/diniamo): @@ -244,8 +245,8 @@ syncing of nvim shell environment with direnv's. - Add [blink.cmp] source options and some default-disabled sources. - Add [blink.cmp] option to add - [friendly-snippets](https://github.com/rafamadriz/friendly-snippets) - so blink.cmp can source snippets from it. + [friendly-snippets](https://github.com/rafamadriz/friendly-snippets) so + blink.cmp can source snippets from it. - Fix [blink.cmp] breaking when built-in sources were modified. [TheColorman](https://github.com/TheColorman): From d105f699219954d973a9f56c60b1be120b67fde4 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 22 Mar 2025 15:13:44 +0100 Subject: [PATCH 5/5] docs: mention LazyFile --- .../configuring/custom-plugins/lazy-method.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/manual/configuring/custom-plugins/lazy-method.md b/docs/manual/configuring/custom-plugins/lazy-method.md index c6fd7106..ae766535 100644 --- a/docs/manual/configuring/custom-plugins/lazy-method.md +++ b/docs/manual/configuring/custom-plugins/lazy-method.md @@ -38,3 +38,22 @@ As of version **0.7**, we exposed an API for configuring lazy-loaded plugins via }; } ``` + +## LazyFile event {#sec-lazyfile-event} + +You can use the `LazyFile` user event to load a plugin when a file is opened: + +```nix +{ + config.vim.lazy.plugins = { + "aerial.nvim" = { + package = pkgs.vimPlugins.aerial-nvim; + event = [{event = "User"; pattern = "LazyFile";}]; + # ... + }; + }; +} +``` + +You can consider `LazyFile` as an alias to +`["BufReadPost" "BufNewFile" "BufWritePre"]`