diff options
author | rover <pathfinder2013@126.com> | 2017-01-08 21:05:41 +0800 |
---|---|---|
committer | rover <pathfinder2013@126.com> | 2017-01-08 22:46:08 +0800 |
commit | c2344f3d31fe6a006027dbf88873ee0916b73028 (patch) | |
tree | 00c08ee4d4a79beebe324e0da25c8caa1533d8b0 /src | |
parent | 888cdce3aa70c5800916b0d54ab40e8ac01d704a (diff) | |
download | rneovim-c2344f3d31fe6a006027dbf88873ee0916b73028.tar.gz rneovim-c2344f3d31fe6a006027dbf88873ee0916b73028.tar.bz2 rneovim-c2344f3d31fe6a006027dbf88873ee0916b73028.zip |
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)
https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/auevents.lua | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 30 | ||||
-rw-r--r-- | src/nvim/version.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 32 |
4 files changed, 52 insertions, 13 deletions
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 8d891effae..b405928577 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -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 }, diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 8ead589871..5777ebcddc 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -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' diff --git a/src/nvim/version.c b/src/nvim/version.c index f644b9f39b..f1ea69c30e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -365,7 +365,7 @@ static int included_patches[] = { // 2078 NA // 2077, // 2076, - // 2075, + 2075, // 2074, // 2073 NA // 2072, diff --git a/src/nvim/window.c b/src/nvim/window.c index 00229ccca9..301dc93026 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -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) |