vim-patch:9.1.1892: Not possible to know once Vim is done with sourcing vimrc (#36429)

Problem:   A plugin does not know when startup scripts were already
           triggered. This is useful to determine if a function is
           called inside vimrc or after (like when sourcing 'plugin/'
           files).
Solution:  Add the v:vim_did_init variable (Evgeni Chasnovski)

closes: vim/vim#18668

294bce21ee

Nvim has two more steps between sourcing startup scripts and loading
plugins. Set this variable after these two steps.

Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
This commit is contained in:
zeertzjq
2025-11-02 18:07:33 +08:00
committed by GitHub
parent 02cd564896
commit 003b429a86
10 changed files with 76 additions and 20 deletions

View File

@@ -22,9 +22,7 @@ endfunc
" 2. packages
" 3. plugins in after directories
func Test_after_comes_later()
if !has('packages')
return
endif
CheckFeature packages
let before =<< trim [CODE]
set nocp viminfo+=nviminfo
set guioptions+=M
@@ -46,14 +44,14 @@ func Test_after_comes_later()
quit
[CODE]
call mkdir('Xhere/plugin', 'p')
call mkdir('Xhere/plugin', 'pR')
call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
call mkdir('Xanother/plugin', 'p')
call mkdir('Xanother/plugin', 'pR')
call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
call mkdir('Xdir/after/plugin', 'p')
call mkdir('Xdir/after/plugin', 'pR')
call writefile(['let g:sequence .= "after "'], 'Xdir/after/plugin/later.vim')
if RunVim(before, after, '')
@@ -75,15 +73,40 @@ func Test_after_comes_later()
call delete('Xtestout')
call delete('Xsequence')
call delete('Xhere', 'rf')
call delete('Xanother', 'rf')
call delete('Xdir', 'rf')
endfunc
func Test_vim_did_init()
let before =<< trim [CODE]
set nocp viminfo+=nviminfo
set guioptions+=M
set loadplugins
set rtp=Xhere
set nomore
[CODE]
let after =<< trim [CODE]
redir! > Xtestout
echo g:var_vimrc
echo g:var_plugin
redir END
quit
[CODE]
call writefile(['let g:var_vimrc=v:vim_did_init'], 'Xvimrc', 'D')
call mkdir('Xhere/plugin', 'pR')
call writefile(['let g:var_plugin=v:vim_did_init'], 'Xhere/plugin/here.vim')
if RunVim(before, after, '-u Xvimrc')
let lines = readfile('Xtestout')
call assert_equal('0', lines[1])
call assert_equal('1', lines[2])
endif
call delete('Xtestout')
endfunc
func Test_pack_in_rtp_when_plugins_run()
if !has('packages')
return
endif
CheckFeature packages
let before =<< trim [CODE]
set nocp viminfo+=nviminfo
set guioptions+=M