fix(pack): update add() to have default load=false during startup

Problem: the `load=true` in `vim.pack.add()` means that `:packadd` is
  executed even during startup. This leads to force source of 'plugin/',
  which breaks the intended loading order (`:h load-plugins`) and
  results into sourcing them twice. This also makes it ignore
  `--noplugin` argument.

  Using `:packadd!` during startup is more appropriate, while `:packadd`
  afterwards is still more favorable to actually force 'plugin/' source
  (as there is no pre-defined mechanism that will load them later).

Solution: have `load=false` default during startup, `true` - afterwards.
This commit is contained in:
Evgeni Chasnovski
2025-08-09 15:33:33 +03:00
parent e3913c0fc2
commit b337c6e0fc
3 changed files with 46 additions and 3 deletions

View File

@@ -669,7 +669,9 @@ end
--- @class vim.pack.keyset.add
--- @inlinedoc
--- @field load? boolean Load `plugin/` files and `ftdetect/` scripts. If `false`, works like `:packadd!`. Default `true`.
--- Load `plugin/` files and `ftdetect/` scripts. If `false`, works like `:packadd!`.
--- Default `false` during startup and `true` afterwards.
--- @field load? boolean
--- Add plugin to current session
---
@@ -693,7 +695,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 = true }, opts or {})
opts = vim.tbl_extend('force', { load = vim.v.vim_did_enter == 1 }, opts or {})
vim.validate('opts', opts, 'table')
--- @type vim.pack.Plug[]