vim-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)

c917da4b3e
This commit is contained in:
rover 2017-01-08 21:05:41 +08:00
parent 888cdce3aa
commit c2344f3d31
5 changed files with 53 additions and 13 deletions

View File

@ -294,6 +294,7 @@ 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
|WinEnter| after entering another window
|WinLeave| before leaving a window
|TabEnter| after entering another tab page

View File

@ -89,6 +89,7 @@ return {
'VimLeave', -- before exiting Vim
'VimLeavePre', -- before exiting Vim and writing ShaDa file
'VimResized', -- after Vim window was resized
'WinNew', -- when entering a new window
'WinEnter', -- after entering a window
'WinLeave', -- before leaving a window
},

View File

@ -82,6 +82,36 @@ function Test_autocmd_bufunload_with_tabnext()
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
func s:AddAnAutocmd()
augroup vimBarTest
au BufReadCmd * echo 'hello'

View File

@ -365,7 +365,7 @@ static int included_patches[] = {
// 2078 NA
// 2077,
// 2076,
// 2075,
2075,
// 2074,
// 2073 NA
// 2072,

View File

@ -973,11 +973,12 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
/*
* make the new window the current window
*/
win_enter(wp, false);
if (flags & WSP_VERT)
win_enter_ext(wp, false, false, true, true, true);
if (flags & WSP_VERT) {
p_wiw = i;
else
} else {
p_wh = i;
}
return OK;
}
@ -2014,10 +2015,11 @@ int win_close(win_T *win, int free_buf)
}
if (close_curwin) {
win_enter_ext(wp, false, TRUE, TRUE, TRUE);
if (other_buffer)
/* careful: after this wp and win may be invalid! */
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
win_enter_ext(wp, false, true, false, true, true);
if (other_buffer) {
// careful: after this wp and win may be invalid!
apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
}
}
/*
@ -3045,8 +3047,9 @@ int win_new_tabpage(int after, char_u *filename)
redraw_all_later(CLEAR);
apply_autocmds(EVENT_TABNEW, filename, filename, false, curbuf);
apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf);
apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
apply_autocmds(EVENT_TABNEW, filename, filename, false, curbuf);
apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf);
return OK;
@ -3204,8 +3207,8 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
/* 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);
win_enter_ext(tp->tp_curwin, false, true, false,
trigger_enter_autocmds, trigger_leave_autocmds);
prevwin = next_prevwin;
last_status(FALSE); /* status line may appear or disappear */
@ -3546,7 +3549,7 @@ end:
*/
void win_enter(win_T *wp, bool undo_sync)
{
win_enter_ext(wp, undo_sync, FALSE, TRUE, TRUE);
win_enter_ext(wp, undo_sync, false, false, true, true);
}
/*
@ -3554,7 +3557,9 @@ void win_enter(win_T *wp, bool undo_sync)
* Can be called with "curwin_invalid" TRUE, which means that curwin has just
* been closed and isn't valid.
*/
static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int trigger_enter_autocmds, int trigger_leave_autocmds)
static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
int trigger_new_autocmds, int trigger_enter_autocmds,
int trigger_leave_autocmds)
{
int other_buffer = FALSE;
@ -3630,6 +3635,9 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri
shorten_fnames(TRUE);
}
if (trigger_new_autocmds) {
apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf);
}
if (trigger_enter_autocmds) {
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
if (other_buffer)