diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 10 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 4 | ||||
-rw-r--r-- | src/nvim/eval.c | 1 | ||||
-rw-r--r-- | src/nvim/eval.h | 1 | ||||
-rw-r--r-- | src/nvim/main.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_alot.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 8 | ||||
-rw-r--r-- | src/nvim/version.c | 2 | ||||
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 5 |
9 files changed, 32 insertions, 3 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 76dd3c7d4c..4f23aee83d 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -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. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 5c704837d6..da52a8f078 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -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. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5d4241c8af..b8173c7570 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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 diff --git a/src/nvim/eval.h b/src/nvim/eval.h index d6800afd52..1ab908deb5 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -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 diff --git a/src/nvim/main.c b/src/nvim/main.c index ffd9353252..1bd622bdba 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -511,7 +511,8 @@ int main(int argc, char **argv) if (p_im) need_start_insertmode = TRUE; - apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf); + set_vim_var_nr(VV_VIM_DID_ENTER, 1L); + apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf); TIME_MSG("VimEnter autocommands"); /* When a startup script or session file setup for diff'ing and diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 87c1cd2c58..60f264fb3f 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -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 diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim new file mode 100644 index 0000000000..12c984888e --- /dev/null +++ b/src/nvim/testdir/test_autocmd.vim @@ -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 diff --git a/src/nvim/version.c b/src/nvim/version.c index a51c2b6ea9..c1459466a2 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -786,7 +786,7 @@ static int included_patches[] = { // 1661 NA // 1660, // 1659 NA - // 1658, + 1658, // 1657 NA // 1656, // 1655 NA diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 72aff58d73..162e112047 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -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) |