vim-patch:7.4.1658

Problem:    A plugin does not know when VimEnter autocommands were already
            triggered.
Solution:   Add the v:vim_did_enter variable.

1473551a44
This commit is contained in:
James McCoy 2016-11-14 10:19:06 -05:00
parent 4539d867d4
commit 9d2985ecba
9 changed files with 31 additions and 2 deletions

View File

@ -940,7 +940,15 @@ VimEnter After doing all the startup stuff, including
loading vimrc files, executing the "-c cmd"
arguments, creating all windows and loading
the buffers in them.
*VimLeave*
Just before this event is triggered the
|v:vim_did_enter| variable is set, so that you
can do: >
if v:vim_did_enter
call s:init()
else
au VimEnter * call s:init()
endif
< *VimLeave*
VimLeave Before exiting Vim, just after writing the
.shada file. Executed only once, like
VimLeavePre.

View File

@ -1765,6 +1765,10 @@ v:version Version number of Vim: Major version number times 100 plus
version 5.0 and 5.1 may have a patch 123, but these are
completely different.
*v:vim_did_enter* *vim_did_enter-variable*
v:vim_did_enter Zero until most of startup is done. It is set to one just
before |VimEnter| autocommands are triggered.
*v:warningmsg* *warningmsg-variable*
v:warningmsg Last given warning message. It's allowed to set this variable.

View File

@ -384,6 +384,7 @@ static struct vimvar {
VV(VV_NULL, "null", VAR_SPECIAL, VV_RO),
VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO),
VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO),
VV(VV_VIM_DID_ENTER, "vim_did_enter", VAR_NUMBER, VV_RO),
};
#undef VV

View File

@ -124,6 +124,7 @@ typedef enum {
VV_NULL,
VV__NULL_LIST, // List with NULL value. For test purposes only.
VV__NULL_DICT, // Dictionary with NULL value. For test purposes only.
VV_VIM_DID_ENTER,
} VimVarIndex;
/// All recognized msgpack types

View File

@ -511,6 +511,7 @@ int main(int argc, char **argv)
if (p_im)
need_start_insertmode = TRUE;
set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("VimEnter autocommands");

View File

@ -2,6 +2,7 @@
" This makes testing go faster, since Vim doesn't need to restart.
source test_assign.vim
source test_autocmd.vim
source test_cursor_func.vim
source test_ex_undo.vim
source test_expr.vim

View File

@ -0,0 +1,8 @@
" Tests for autocommands
func Test_vim_did_enter()
call assert_false(v:vim_did_enter)
" This script will never reach the main loop, can't check if v:vim_did_enter
" becomes one.
endfunc

View File

@ -786,7 +786,7 @@ static int included_patches[] = {
// 1661 NA
// 1660,
// 1659 NA
// 1658,
1658,
// 1657 NA
// 1656,
// 1655 NA

View File

@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
describe('autocmds:', function()
@ -28,4 +29,8 @@ describe('autocmds:', function()
command('tabnew')
assert.same(expected, eval('g:foo'))
end)
it('v:vim_did_enter is 1 after VimEnter', function()
eq(1, eval('v:vim_did_enter'))
end)
end)