Skip to content

Commit 1473551

Browse files
committed
patch 7.4.1658
Problem: A plugin does not know when VimEnter autocommands were already triggered. Solution: Add the v:vim_did_enter variable.
1 parent 8fdd721 commit 1473551

8 files changed

Lines changed: 30 additions & 2 deletions

File tree

runtime/doc/autocmd.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,15 @@ VimEnter After doing all the startup stuff, including
918918
loading .vimrc files, executing the "-c cmd"
919919
arguments, creating all windows and loading
920920
the buffers in them.
921-
*VimLeave*
921+
Just before this event is triggered the
922+
|v:vim_did_enter| variable is set, so that you
923+
can do: >
924+
if v:vim_did_enter
925+
call s:init()
926+
else
927+
au VimEnter * call s:init()
928+
endif
929+
< *VimLeave*
922930
VimLeave Before exiting Vim, just after writing the
923931
.viminfo file. Executed only once, like
924932
VimLeavePre.

runtime/doc/eval.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,10 @@ v:version Version number of Vim: Major version number times 100 plus
17621762
version 5.0 and 5.1 may have a patch 123, but these are
17631763
completely different.
17641764

1765+
*v:vim_did_enter* *vim_did_enter-variable*
1766+
v:vim_did_enter Zero until most of startup is done. It is set to one just
1767+
before |VimEnter| autocommands are triggered.
1768+
17651769
*v:warningmsg* *warningmsg-variable*
17661770
v:warningmsg Last given warning message. It's allowed to set this variable.
17671771

src/eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ static struct vimvar
372372
{VV_NAME("true", VAR_SPECIAL), VV_RO},
373373
{VV_NAME("null", VAR_SPECIAL), VV_RO},
374374
{VV_NAME("none", VAR_SPECIAL), VV_RO},
375+
{VV_NAME("vim_did_enter", VAR_NUMBER), VV_RO},
375376
};
376377

377378
/* shorthand */

src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,9 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
969969
if (p_im)
970970
need_start_insertmode = TRUE;
971971

972+
#ifdef FEAT_EVAL
973+
set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
974+
#endif
972975
#ifdef FEAT_AUTOCMD
973976
apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
974977
TIME_MSG("VimEnter autocommands");

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
" This makes testing go faster, since Vim doesn't need to restart.
33

44
source test_assign.vim
5+
source test_autocmd.vim
56
source test_cursor_func.vim
67
source test_delete.vim
78
source test_ex_undo.vim

src/testdir/test_autocmd.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
" Tests for autocommands
2+
3+
func Test_vim_did_enter()
4+
call assert_false(v:vim_did_enter)
5+
6+
" This script will never reach the main loop, can't check if v:vim_did_enter
7+
" becomes one.
8+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1658,
751753
/**/
752754
1657,
753755
/**/

src/vim.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,8 @@ typedef int sock_T;
18691869
#define VV_TRUE 64
18701870
#define VV_NULL 65
18711871
#define VV_NONE 66
1872-
#define VV_LEN 67 /* number of v: vars */
1872+
#define VV_VIM_DID_ENTER 67
1873+
#define VV_LEN 68 /* number of v: vars */
18731874

18741875
/* used for v_number in VAR_SPECIAL */
18751876
#define VVAL_FALSE 0L

0 commit comments

Comments
 (0)