summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-19 22:31:36 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-19 22:31:36 +0200
commitc917da4b3e8801a255dbefea8e4ed19c1c716dd8 (patch)
tree4c4ca7b3b658f666aa781e2f9e51e9dafc57f6d6
parent0a0f641b9841189ba4180758109d04d0a26e50e3 (diff)
patch 7.4.2075v7.4.2075
Problem: No autocommand event to initialize a window or tab page. Solution: Add WinNew and TabNew events. (partly by Felipe Morales)
-rw-r--r--runtime/doc/autocmd.txt9
-rw-r--r--src/fileio.c2
-rw-r--r--src/testdir/test_autocmd.vim30
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h4
-rw-r--r--src/window.c15
6 files changed, 56 insertions, 6 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index d33d6f28b5..c924af32dd 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -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
diff --git a/src/fileio.c b/src/fileio.c
index e9dca0c0a1..0a84576e57 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -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},
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 187d8d2a2c..14254a7fad 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index a5f33b1811..cb8fed64fc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2075,
+/**/
2074,
/**/
2073,
diff --git a/src/vim.h b/src/vim.h
index c6e29a0ab2..d9a60dd6b5 100644
--- 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 */
diff --git a/src/window.c b/src/window.c
index b9e75d6dfc..bf650f84b9 100644
--- a/src/window.c
+++ b/src/window.c
@@ -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);