Patch 7.4.2075
Problem: No autocommand event to initialize a window or tab page.
Solution: Add WinNew and TabNew events. (partly by Felipe Morales)
Files: src/fileio.c, src/window.c, src/vim.h,
src/testdir/test_autocmd.vim, runtime/doc/autocmd.txt
*** ../vim-7.4.2074/src/fileio.c 2016-07-16 14:46:51.127240626 +0200
--- src/fileio.c 2016-07-19 22:05:33.885908703 +0200
***************
*** 7706,7711 ****
--- 7706,7712 ----
{"StdinReadPre", EVENT_STDINREADPRE},
{"SwapExists", EVENT_SWAPEXISTS},
{"Syntax", EVENT_SYNTAX},
+ {"TabNew", EVENT_TABNEW},
{"TabEnter", EVENT_TABENTER},
{"TabLeave", EVENT_TABLEAVE},
{"TermChanged", EVENT_TERMCHANGED},
***************
*** 7716,7721 ****
--- 7717,7723 ----
{"VimEnter", EVENT_VIMENTER},
{"VimLeave", EVENT_VIMLEAVE},
{"VimLeavePre", EVENT_VIMLEAVEPRE},
+ {"WinNew", EVENT_WINNEW},
{"WinEnter", EVENT_WINENTER},
{"WinLeave", EVENT_WINLEAVE},
{"VimResized", EVENT_VIMRESIZED},
*** ../vim-7.4.2074/src/window.c 2016-07-10 22:11:11.878751222 +0200
--- src/window.c 2016-07-19 22:03:51.590949315 +0200
***************
*** 45,51 ****
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_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);
--- 45,51 ----
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_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,1265 ****
/*
* make the new window the current window
*/
! win_enter(wp, FALSE);
if (flags & WSP_VERT)
p_wiw = i;
else
--- 1259,1265 ----
/*
* make the new window the current window
*/
! win_enter_ext(wp, FALSE, FALSE, TRUE, TRUE, TRUE);
if (flags & WSP_VERT)
p_wiw = i;
else
***************
*** 2416,2422 ****
win_comp_pos();
if (close_curwin)
{
! win_enter_ext(wp, FALSE, TRUE, TRUE, TRUE);
#ifdef FEAT_AUTOCMD
if (other_buffer)
/* careful: after this wp and win may be invalid! */
--- 2416,2422 ----
win_comp_pos();
if (close_curwin)
{
! 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,3635 ****
--- 3629,3637 ----
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,3814 ****
/* 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,
trigger_enter_autocmds, trigger_leave_autocmds);
prevwin = next_prevwin;
--- 3810,3816 ----
/* 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, FALSE,
trigger_enter_autocmds, trigger_leave_autocmds);
prevwin = next_prevwin;
***************
*** 4242,4248 ****
void
win_enter(win_T *wp, int undo_sync)
{
! win_enter_ext(wp, undo_sync, FALSE, TRUE, TRUE);
}
/*
--- 4244,4250 ----
void
win_enter(win_T *wp, int undo_sync)
{
! win_enter_ext(wp, undo_sync, FALSE, FALSE, TRUE, TRUE);
}
/*
***************
*** 4255,4260 ****
--- 4257,4263 ----
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,4345 ****
--- 4343,4350 ----
}
#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);
*** ../vim-7.4.2074/src/vim.h 2016-07-19 17:25:19.082023340 +0200
--- src/vim.h 2016-07-19 22:05:03.934213386 +0200
***************
*** 1315,1320 ****
--- 1315,1321 ----
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,1334 ****
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_SHELLCMDPOST, /* after ":!cmd" */
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
EVENT_TEXTCHANGED, /* text was modified */
--- 1328,1336 ----
EVENT_SPELLFILEMISSING, /* spell file missing */
EVENT_CURSORMOVED, /* cursor was moved */
EVENT_CURSORMOVEDI, /* cursor was moved in Insert mode */
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 */
*** ../vim-7.4.2074/src/testdir/test_autocmd.vim 2016-07-09
15:20:48.688771385 +0200
--- src/testdir/test_autocmd.vim 2016-07-19 22:21:50.279933091 +0200
***************
*** 78,80 ****
--- 78,110 ----
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
*** ../vim-7.4.2074/runtime/doc/autocmd.txt 2016-03-26 20:59:48.111431615
+0100
--- runtime/doc/autocmd.txt 2016-07-19 21:55:41.775932869 +0200
***************
*** 293,298 ****
--- 293,300 ----
|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
***************
*** 306,311 ****
--- 308,316 ----
|InsertCharPre| when a character was typed in Insert mode,
before
inserting it
+ |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
***************
*** 519,524 ****
--- 524,534 ----
operator.
While recording the CursorHold event is not
triggered. |q|
+ *<CursorHold>*
+ Internally the autocommand is triggered by the
+ <CursorHold> key. In an expression mapping
+ |getchar()| may see this character.
+
Note: Interactive commands cannot be used for
this event. There is no hit-enter prompt,
the screen is updated directly (when needed).
***************
*** 865,870 ****
--- 884,893 ----
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
***************
*** 950,958 ****
--- 973,993 ----
WinLeave autocommands (but not for ":new").
Not used for ":qa" or ":q" when exiting Vim.
+ *WinNew*
+ WinNew When a new window was created. Not
done for
+ the fist window, when Vim has just started.
+ Before a WinEnter event.
+
==============================================================================
6. Patterns *autocmd-patterns* *{pat}*
+ The {pat} argument can be a comma separated list. This works as if the
+ command was given with each pattern separately. Thus this command: >
+ :autocmd BufRead *.txt,*.info set et
+ Is equivalent to: >
+ :autocmd BufRead *.txt set et
+ :autocmd BufRead *.info set et
+
The file pattern {pat} is tested for a match against the file name in one of
two ways:
1. When there is no '/' in the pattern, Vim checks for a match against only
*** ../vim-7.4.2074/src/version.c 2016-07-19 21:30:07.707499837 +0200
--- src/version.c 2016-07-19 22:25:49.073466335 +0200
***************
*** 760,761 ****
--- 760,763 ----
{ /* Add new patch number below this line */
+ /**/
+ 2075,
/**/
--
Witches prefer brooms: vacuum-cleaners need extension cords!
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.