]> granicus.if.org Git - vim/commitdiff
patch 7.4.1658 v7.4.1658
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Mar 2016 20:00:08 +0000 (21:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Mar 2016 20:00:08 +0000 (21:00 +0100)
Problem:    A plugin does not know when VimEnter autocommands were already
            triggered.
Solution:   Add the v:vim_did_enter variable.

runtime/doc/autocmd.txt
runtime/doc/eval.txt
src/eval.c
src/main.c
src/testdir/test_alot.vim
src/testdir/test_autocmd.vim [new file with mode: 0644]
src/version.c
src/vim.h

index 4de5b16194de47dfaf7a87dbbd4517fecf687464..5d502f12368107c95ff3c59192dff329922d5ed6 100644 (file)
@@ -918,7 +918,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
                                .viminfo file.  Executed only once, like
                                VimLeavePre.
index 642f0ad768ef9018ced38921790a8126616d853c..e1744812580c78fca3470a2ac12b2482df53abba 100644 (file)
@@ -1762,6 +1762,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.
 
index 06f3585b30a23040255a1bdbcc6a241f0da0c327..c1046955b7353ff619c36c2bbd44c09dfa4f4db6 100644 (file)
@@ -372,6 +372,7 @@ static struct vimvar
     {VV_NAME("true",            VAR_SPECIAL), VV_RO},
     {VV_NAME("null",            VAR_SPECIAL), VV_RO},
     {VV_NAME("none",            VAR_SPECIAL), VV_RO},
+    {VV_NAME("vim_did_enter",   VAR_NUMBER), VV_RO},
 };
 
 /* shorthand */
index 35c940f6ab41a1d9ca89b2be752f5cf4734bc855..91ef66db6fcbade4218001dec56f6b72ebad05f4 100644 (file)
@@ -969,6 +969,9 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
     if (p_im)
        need_start_insertmode = TRUE;
 
+#ifdef FEAT_EVAL
+    set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
+#endif
 #ifdef FEAT_AUTOCMD
     apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
     TIME_MSG("VimEnter autocommands");
index fcf358b5347e9846f15a5ad96a0d84acff7b3654..06309982acb9ae5fe42752904cbe279db235dcab 100644 (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_delete.vim
 source test_ex_undo.vim
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
new file mode 100644 (file)
index 0000000..12c9848
--- /dev/null
@@ -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
index 6459356cec09bd0fc56ec4bbadc1884f36d7a233..62e66ab1f65b080f073df27b7411c4960398ba87 100644 (file)
@@ -748,6 +748,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1658,
 /**/
     1657,
 /**/
index a7443e9a1dd200aa136388c51a6310ae0ab09041..a2dc079613470a63f9f6d45ce16be33ce3e26b2c 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1869,7 +1869,8 @@ typedef int sock_T;
 #define VV_TRUE                64
 #define VV_NULL                65
 #define VV_NONE                66
-#define VV_LEN         67      /* number of v: vars */
+#define VV_VIM_DID_ENTER 67
+#define VV_LEN         68      /* number of v: vars */
 
 /* used for v_number in VAR_SPECIAL */
 #define VVAL_FALSE     0L