]> granicus.if.org Git - vim/commitdiff
patch 7.4.2075 v7.4.2075
authorBram Moolenaar <Bram@vim.org>
Tue, 19 Jul 2016 20:31:36 +0000 (22:31 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Jul 2016 20:31:36 +0000 (22:31 +0200)
Problem:    No autocommand event to initialize a window or tab page.
Solution:   Add WinNew and TabNew events. (partly by Felipe Morales)

runtime/doc/autocmd.txt
src/fileio.c
src/testdir/test_autocmd.vim
src/version.c
src/vim.h
src/window.c

index d33d6f28b541f70b1037b66f7145ca1374629f08..c924af32ddeb1b5d5ecc90fa343b0a0b13cae7d0 100644 (file)
@@ -293,6 +293,8 @@ Name                        triggered by ~
 |CursorMoved|          the cursor was moved in Normal mode
 |CursorMovedI|         the cursor was moved in Insert mode
 
+|WinNew|               after creating a new window
+|TabNew|               after creating a new window
 |WinEnter|             after entering another window
 |WinLeave|             before leaving a window
 |TabEnter|             after entering another tab page
@@ -309,6 +311,9 @@ Name                        triggered by ~
 |TextChanged|          after a change was made to the text in Normal mode
 |TextChangedI|         after a change was made to the text in Insert mode
 
+|TextChanged|          after a change was made to the text in Normal mode
+|TextChangedI|         after a change was made to the text in Insert mode
+
 |ColorScheme|          after loading a color scheme
 
 |RemoteReply|          a reply from a server Vim was received
@@ -882,6 +887,10 @@ TabEnter                   Just after entering a tab page. |tab-page|
 TabLeave                       Just before leaving a tab page. |tab-page|
                                A WinLeave event will have been triggered
                                first.
+                                                       *TabNew*
+TabNew                         When a tab page was created. |tab-page|
+                               A WinEnter event will have been triggered
+                               first, TabEnter follows.
                                                        *TermChanged*
 TermChanged                    After the value of 'term' has changed.  Useful
                                for re-loading the syntax file to update the
index e9dca0c0a11b54977ba040a8d436bb533c9437b5..0a84576e576e7f83a1a472ea639c8e2b78ead6ef 100644 (file)
@@ -7706,6 +7706,7 @@ static struct event_name
     {"StdinReadPre",   EVENT_STDINREADPRE},
     {"SwapExists",     EVENT_SWAPEXISTS},
     {"Syntax",         EVENT_SYNTAX},
+    {"TabNew",         EVENT_TABNEW},
     {"TabEnter",       EVENT_TABENTER},
     {"TabLeave",       EVENT_TABLEAVE},
     {"TermChanged",    EVENT_TERMCHANGED},
@@ -7716,6 +7717,7 @@ static struct event_name
     {"VimEnter",       EVENT_VIMENTER},
     {"VimLeave",       EVENT_VIMLEAVE},
     {"VimLeavePre",    EVENT_VIMLEAVEPRE},
+    {"WinNew",         EVENT_WINNEW},
     {"WinEnter",       EVENT_WINENTER},
     {"WinLeave",       EVENT_WINLEAVE},
     {"VimResized",     EVENT_VIMRESIZED},
index 187d8d2a2cdc202fb51fab6fa35c34a4bfe643a1..14254a7fad6e0b39858467b57c1463b9fa99a06c 100644 (file)
@@ -78,3 +78,33 @@ function Test_autocmd_bufunload_with_tabnext()
   tablast
   quit
 endfunc
+
+func Test_win_tab_autocmd()
+  let g:record = []
+
+  augroup testing
+    au WinNew * call add(g:record, 'WinNew')
+    au WinEnter * call add(g:record, 'WinEnter') 
+    au WinLeave * call add(g:record, 'WinLeave') 
+    au TabNew * call add(g:record, 'TabNew')
+    au TabEnter * call add(g:record, 'TabEnter')
+    au TabLeave * call add(g:record, 'TabLeave')
+  augroup END
+
+  split
+  tabnew
+  close
+  close
+
+  call assert_equal([
+       \ 'WinLeave', 'WinNew', 'WinEnter',
+       \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
+       \ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
+       \ 'WinLeave', 'WinEnter'
+       \ ], g:record)
+
+  augroup testing
+    au!
+  augroup END
+  unlet g:record
+endfunc
index a5f33b18115c50e3820dd85150bf7f47224d472b..cb8fed64fc44a4aaa31339475243fcea4a7c60d5 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2075,
 /**/
     2074,
 /**/
index c6e29a0ab21f4a7d41c4238024440f372502542b..d9a60dd6b535517dfeef02ead47b9300d4190e2a 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1315,6 +1315,7 @@ enum auto_event
     EVENT_VIMRESIZED,          /* after Vim window was resized */
     EVENT_WINENTER,            /* after entering a window */
     EVENT_WINLEAVE,            /* before leaving a window */
+    EVENT_WINNEW,              /* when entering a new window */
     EVENT_ENCODINGCHANGED,     /* after changing the 'encoding' option */
     EVENT_INSERTCHARPRE,       /* before inserting a char */
     EVENT_CURSORHOLD,          /* cursor in same position for a while */
@@ -1327,8 +1328,9 @@ enum auto_event
     EVENT_SPELLFILEMISSING,    /* spell file missing */
     EVENT_CURSORMOVED,         /* cursor was moved */
     EVENT_CURSORMOVEDI,                /* cursor was moved in Insert mode */
-    EVENT_TABLEAVE,            /* before leaving a tab page */
     EVENT_TABENTER,            /* after entering a tab page */
+    EVENT_TABLEAVE,            /* before leaving a tab page */
+    EVENT_TABNEW,              /* when entering a new tab page */
     EVENT_SHELLCMDPOST,                /* after ":!cmd" */
     EVENT_SHELLFILTERPOST,     /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
     EVENT_TEXTCHANGED,         /* text was modified */
index b9e75d6dfcfad3a9147595597012061996f8a773..bf650f84b9b48d6acdde639c741a9f6f763ae828 100644 (file)
@@ -45,7 +45,7 @@ static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds);
 static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds);
 static void frame_fix_height(win_T *wp);
 static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
-static void win_enter_ext(win_T *wp, int undo_sync, int no_curwin, int trigger_enter_autocmds, int trigger_leave_autocmds);
+static void win_enter_ext(win_T *wp, int undo_sync, int no_curwin, int trigger_new_autocmds, int trigger_enter_autocmds, int trigger_leave_autocmds);
 static void win_free(win_T *wp, tabpage_T *tp);
 static void frame_append(frame_T *after, frame_T *frp);
 static void frame_insert(frame_T *before, frame_T *frp);
@@ -1259,7 +1259,7 @@ win_split_ins(
     /*
      * make the new window the current window
      */
-    win_enter(wp, FALSE);
+    win_enter_ext(wp, FALSE, FALSE, TRUE, TRUE, TRUE);
     if (flags & WSP_VERT)
        p_wiw = i;
     else
@@ -2416,7 +2416,7 @@ win_close(win_T *win, int free_buf)
        win_comp_pos();
     if (close_curwin)
     {
-       win_enter_ext(wp, FALSE, TRUE, TRUE, TRUE);
+       win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE);
 #ifdef FEAT_AUTOCMD
        if (other_buffer)
            /* careful: after this wp and win may be invalid! */
@@ -3629,7 +3629,9 @@ win_new_tabpage(int after)
 
        redraw_all_later(CLEAR);
 #ifdef FEAT_AUTOCMD
+       apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
        apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
+       apply_autocmds(EVENT_TABNEW, NULL, NULL, FALSE, curbuf);
        apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
 #endif
        return OK;
@@ -3808,7 +3810,7 @@ enter_tabpage(
     /* We would like doing the TabEnter event first, but we don't have a
      * valid current window yet, which may break some commands.
      * This triggers autocommands, thus may make "tp" invalid. */
-    win_enter_ext(tp->tp_curwin, FALSE, TRUE,
+    win_enter_ext(tp->tp_curwin, FALSE, TRUE, FALSE,
                              trigger_enter_autocmds, trigger_leave_autocmds);
     prevwin = next_prevwin;
 
@@ -4242,7 +4244,7 @@ end:
     void
 win_enter(win_T *wp, int undo_sync)
 {
-    win_enter_ext(wp, undo_sync, FALSE, TRUE, TRUE);
+    win_enter_ext(wp, undo_sync, FALSE, FALSE, TRUE, TRUE);
 }
 
 /*
@@ -4255,6 +4257,7 @@ win_enter_ext(
     win_T      *wp,
     int                undo_sync,
     int                curwin_invalid,
+    int                trigger_new_autocmds UNUSED,
     int                trigger_enter_autocmds UNUSED,
     int                trigger_leave_autocmds UNUSED)
 {
@@ -4340,6 +4343,8 @@ win_enter_ext(
     }
 
 #ifdef FEAT_AUTOCMD
+    if (trigger_new_autocmds)
+       apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
     if (trigger_enter_autocmds)
     {
        apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);