mirror of
https://github.com/vim/vim.git
synced 2025-11-13 22:54:27 -05:00
patch 9.1.1892: Not possible to know once Vim is done with sourcing vimrc
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: #18668
Signed-off-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
fe71c56d8f
commit
294bce21ee
@@ -1,4 +1,4 @@
|
||||
*eval.txt* For Vim version 9.1. Last change: 2025 Oct 26
|
||||
*eval.txt* For Vim version 9.1. Last change: 2025 Nov 01
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -2988,6 +2988,10 @@ v:versionlong Like v:version, but also including the patchlevel in the last
|
||||
v:vim_did_enter Zero until most of startup is done. It is set to one just
|
||||
before |VimEnter| autocommands are triggered.
|
||||
|
||||
*v:vim_did_init* *vim_did_init-variable*
|
||||
v:vim_did_init Zero until initialization is done. It is set to one just
|
||||
after |vimrc| is sourced and before |load-plugins|.
|
||||
|
||||
*v:warningmsg* *warningmsg-variable*
|
||||
v:warningmsg Last given warning message. It's allowed to set this
|
||||
variable.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
*repeat.txt* For Vim version 9.1. Last change: 2025 Oct 13
|
||||
*repeat.txt* For Vim version 9.1. Last change: 2025 Nov 01
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -328,6 +328,12 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
|
||||
you will need to write `filetype plugin indent on`
|
||||
AFTER all `packadd!` commands.
|
||||
|
||||
To programmatically decide if `!` is needed during
|
||||
startup, check |v:vim_did_init|: use `!` if 0 (to not
|
||||
duplicate |load-plugins| step), no `!` otherwise (to
|
||||
force load plugin files as otherwise they won't be
|
||||
loaded automatically).
|
||||
|
||||
Also see |pack-add|.
|
||||
{only available when compiled with |+eval|}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
*starting.txt* For Vim version 9.1. Last change: 2025 Oct 12
|
||||
*starting.txt* For Vim version 9.1. Last change: 2025 Nov 01
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -843,6 +843,9 @@ accordingly. Vim proceeds in this order:
|
||||
If Vim was started in Ex mode with the "-s" argument, all following
|
||||
initializations until 4. are skipped. Only the "-u" option is
|
||||
interpreted.
|
||||
|
||||
The |v:vim_did_init| variable is set to 1 after this step is finished.
|
||||
|
||||
*evim.vim*
|
||||
a. If Vim was started as |evim| or |eview| or with the |-y| argument, the
|
||||
script $VIMRUNTIME/evim.vim will be loaded.
|
||||
|
||||
@@ -11360,6 +11360,7 @@ v:var eval.txt /*v:var*
|
||||
v:version eval.txt /*v:version*
|
||||
v:versionlong eval.txt /*v:versionlong*
|
||||
v:vim_did_enter eval.txt /*v:vim_did_enter*
|
||||
v:vim_did_init eval.txt /*v:vim_did_init*
|
||||
v:warningmsg eval.txt /*v:warningmsg*
|
||||
v:wayland_display eval.txt /*v:wayland_display*
|
||||
v:windowid eval.txt /*v:windowid*
|
||||
@@ -11634,6 +11635,7 @@ vim: options.txt /*vim:*
|
||||
vim_announce intro.txt /*vim_announce*
|
||||
vim_dev intro.txt /*vim_dev*
|
||||
vim_did_enter-variable eval.txt /*vim_did_enter-variable*
|
||||
vim_did_init-variable eval.txt /*vim_did_init-variable*
|
||||
vim_mac intro.txt /*vim_mac*
|
||||
vim_starting builtin.txt /*vim_starting*
|
||||
vim_use intro.txt /*vim_use*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
*version9.txt* For Vim version 9.1. Last change: 2025 Oct 26
|
||||
*version9.txt* For Vim version 9.1. Last change: 2025 Nov 01
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -41908,6 +41908,7 @@ Vim Variables: ~
|
||||
|v:termda1| The escape sequence returned for the primary device
|
||||
attribute query (DA1).
|
||||
|v:termosc| The most recent received OSC response.
|
||||
|v:vim_did_init| Set once Vim finishes startup initialization.
|
||||
|v:wayland_display| The name of the Wayland display Vim is connected to.
|
||||
|
||||
Vim Arguments: ~
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
" Language: Vim script
|
||||
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
|
||||
" Doug Kearns <dougkearns@gmail.com>
|
||||
" Last Change: 2025 Oct 27
|
||||
" Last Change: 2025 Nov 01
|
||||
" Former Maintainer: Charles E. Campbell
|
||||
|
||||
" DO NOT CHANGE DIRECTLY.
|
||||
@@ -166,7 +166,7 @@ syn keyword vimFuncName contained win_execute win_findbuf win_getid win_gettype
|
||||
" Predefined variable names {{{2
|
||||
" GEN_SYN_VIM: vimVarName, START_STR='syn keyword vimVimVarName contained', END_STR=''
|
||||
syn keyword vimVimVarName contained count count1 prevcount errmsg warningmsg statusmsg shell_error this_session version lnum termresponse fname lang lc_time ctype charconvert_from charconvert_to fname_in fname_out fname_new fname_diff cmdarg foldstart foldend folddashes foldlevel progname servername dying exception throwpoint register cmdbang insertmode val key profiling fcs_reason fcs_choice beval_bufnr beval_winnr beval_winid beval_lnum beval_col beval_text scrollstart swapname swapchoice swapcommand char mouse_win mouse_winid mouse_lnum mouse_col operator searchforward hlsearch oldfiles windowid progpath completed_item option_new option_old option_oldlocal option_oldglobal option_command option_type errors false true none null numbermax numbermin numbersize
|
||||
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc
|
||||
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc vim_did_init
|
||||
|
||||
"--- syntax here and above generated by runtime/syntax/generator/gen_syntax_vim.vim ---
|
||||
|
||||
|
||||
@@ -167,6 +167,7 @@ static struct vimvar
|
||||
{VV_NAME("clipmethod", VAR_STRING), NULL, VV_RO},
|
||||
{VV_NAME("termda1", VAR_STRING), NULL, VV_RO},
|
||||
{VV_NAME("termosc", VAR_STRING), NULL, VV_RO},
|
||||
{VV_NAME("vim_did_init", VAR_NUMBER), NULL, VV_RO},
|
||||
};
|
||||
|
||||
// shorthand
|
||||
|
||||
@@ -433,6 +433,10 @@ main
|
||||
// Source startup scripts.
|
||||
source_startup_scripts(¶ms);
|
||||
|
||||
#ifdef FEAT_EVAL
|
||||
set_vim_var_nr(VV_VIM_DID_INIT, 1L);
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_MZSCHEME
|
||||
/*
|
||||
* Newer version of MzScheme (Racket) require earlier (trampolined)
|
||||
|
||||
@@ -71,6 +71,36 @@ func Test_after_comes_later()
|
||||
call delete('Xsequence')
|
||||
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()
|
||||
CheckFeature packages
|
||||
let before =<< trim [CODE]
|
||||
|
||||
@@ -729,6 +729,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1892,
|
||||
/**/
|
||||
1891,
|
||||
/**/
|
||||
|
||||
@@ -2256,7 +2256,8 @@ typedef int sock_T;
|
||||
#define VV_CLIPMETHOD 113
|
||||
#define VV_TERMDA1 114
|
||||
#define VV_TERMOSC 115
|
||||
#define VV_LEN 116 // number of v: vars
|
||||
#define VV_VIM_DID_INIT 116
|
||||
#define VV_LEN 117 // number of v: vars
|
||||
|
||||
// used for v_number in VAR_BOOL and VAR_SPECIAL
|
||||
#define VVAL_FALSE 0L // VAR_BOOL
|
||||
|
||||
Reference in New Issue
Block a user