summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/pack.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-11-13 15:49:13 +0200
committerEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-11-16 22:19:10 +0200
commita39171f5327e44162aebd17f16d4cb7ffddef1df (patch)
tree9b7d8d3e180e62192928555acd6a4b89078fb9cc /runtime/lua/vim/pack.lua
parente4e6605943665c2f7b3bb9f7e2b065188935bd33 (diff)
fix(pack)!: make default `opts.load` in `add()` to work inside 'plugin/'
Problem: Plain `vim.pack.add()` calls (with default `opts.load`) does not fully work if called inside 'plugin/' runtime directory. In particular, 'plugin/' files of newly added plugins are not sourced. This is because `opts.load` is `false` during the whole startup, which means `:packadd!` is used (modify 'runtimepath' but not force source newly added 'plugin/' files). This use case is common due to users organizing their config as separate files in '~/.config/nvim/plugin/'. Solution: Use newly added `v:vim_did_init` to decide default `opts.load` value instead of `v:vim_did_enter`.
Diffstat (limited to 'runtime/lua/vim/pack.lua')
-rw-r--r--runtime/lua/vim/pack.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
index 6180f23db5..265a366d48 100644
--- a/runtime/lua/vim/pack.lua
+++ b/runtime/lua/vim/pack.lua
@@ -743,8 +743,9 @@ local function pack_add(plug, load)
-- NOTE: The `:packadd` specifically seems to not handle spaces in dir name
vim.cmd.packadd({ vim.fn.escape(plug.spec.name, ' '), bang = not load, magic = { file = false } })
- -- Execute 'after/' scripts if not during startup (when they will be sourced
- -- automatically), as `:packadd` only sources plain 'plugin/' files.
+ -- The `:packadd` only sources plain 'plugin/' files. Execute 'after/' scripts
+ -- if not during startup (when they will be sourced later, even if
+ -- `vim.pack.add` is inside user's 'plugin/')
-- See https://github.com/vim/vim/issues/15584
-- Deliberately do so after executing all currently known 'plugin/' files.
if vim.v.vim_did_enter == 1 and load then
@@ -760,7 +761,7 @@ end
--- @inlinedoc
--- Load `plugin/` files and `ftdetect/` scripts. If `false`, works like `:packadd!`.
--- If function, called with plugin data and is fully responsible for loading plugin.
---- Default `false` during startup and `true` afterwards.
+--- Default `false` during |init.lua| sourcing and `true` afterwards.
--- @field load? boolean|fun(plug_data: {spec: vim.pack.Spec, path: string})
---
--- @field confirm? boolean Whether to ask user to confirm initial install. Default `true`.
@@ -788,7 +789,7 @@ end
--- @param opts? vim.pack.keyset.add
function M.add(specs, opts)
vim.validate('specs', specs, vim.islist, false, 'list')
- opts = vim.tbl_extend('force', { load = vim.v.vim_did_enter == 1, confirm = true }, opts or {})
+ opts = vim.tbl_extend('force', { load = vim.v.vim_did_init == 1, confirm = true }, opts or {})
vim.validate('opts', opts, 'table')
local plug_dir = get_plug_dir()