Skip to content

Commit 12c11d5

Browse files
committed
patch 7.4.2077
Problem: Cannot update 'tabline' when a tab was closed. Solution: Add the TabClosed autocmd event. (partly by Felipe Morales)
1 parent 4f0383b commit 12c11d5

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

runtime/doc/autocmd.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*autocmd.txt* For Vim version 7.4. Last change: 2016 Jun 09
1+
*autocmd.txt* For Vim version 7.4. Last change: 2016 Jul 19
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -294,7 +294,8 @@ Name triggered by ~
294294
|CursorMovedI| the cursor was moved in Insert mode
295295

296296
|WinNew| after creating a new window
297-
|TabNew| after creating a new window
297+
|TabNew| after creating a new tab page
298+
|TabClosed| after closing a tab page
298299
|WinEnter| after entering another window
299300
|WinLeave| before leaving a window
300301
|TabEnter| after entering another tab page
@@ -311,9 +312,6 @@ Name triggered by ~
311312
|TextChanged| after a change was made to the text in Normal mode
312313
|TextChangedI| after a change was made to the text in Insert mode
313314

314-
|TextChanged| after a change was made to the text in Normal mode
315-
|TextChangedI| after a change was made to the text in Insert mode
316-
317315
|ColorScheme| after loading a color scheme
318316

319317
|RemoteReply| a reply from a server Vim was received
@@ -879,6 +877,8 @@ Syntax When the 'syntax' option has been set. The
879877
where this option was set, and <amatch> for
880878
the new value of 'syntax'.
881879
See |:syn-on|.
880+
*TabClosed*
881+
TabClosed After closing a tab page.
882882
*TabEnter*
883883
TabEnter Just after entering a tab page. |tab-page|
884884
After triggering the WinEnter and before
@@ -976,6 +976,11 @@ WinLeave Before leaving a window. If the window to be
976976
WinLeave autocommands (but not for ":new").
977977
Not used for ":qa" or ":q" when exiting Vim.
978978

979+
*WinNew*
980+
WinNew When a new window was created. Not done for
981+
the fist window, when Vim has just started.
982+
Before a WinEnter event.
983+
979984
==============================================================================
980985
6. Patterns *autocmd-patterns* *{pat}*
981986

src/fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7707,6 +7707,7 @@ static struct event_name
77077707
{"SwapExists", EVENT_SWAPEXISTS},
77087708
{"Syntax", EVENT_SYNTAX},
77097709
{"TabNew", EVENT_TABNEW},
7710+
{"TabClosed", EVENT_TABCLOSED},
77107711
{"TabEnter", EVENT_TABENTER},
77117712
{"TabLeave", EVENT_TABLEAVE},
77127713
{"TermChanged", EVENT_TERMCHANGED},

src/testdir/test_autocmd.vim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func Test_win_tab_autocmd()
8787
au WinEnter * call add(g:record, 'WinEnter')
8888
au WinLeave * call add(g:record, 'WinLeave')
8989
au TabNew * call add(g:record, 'TabNew')
90+
au TabClosed * call add(g:record, 'TabClosed')
9091
au TabEnter * call add(g:record, 'TabEnter')
9192
au TabLeave * call add(g:record, 'TabLeave')
9293
augroup END
@@ -99,10 +100,21 @@ func Test_win_tab_autocmd()
99100
call assert_equal([
100101
\ 'WinLeave', 'WinNew', 'WinEnter',
101102
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
102-
\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
103+
\ 'WinLeave', 'TabLeave', 'TabClosed', 'WinEnter', 'TabEnter',
103104
\ 'WinLeave', 'WinEnter'
104105
\ ], g:record)
105106

107+
let g:record = []
108+
tabnew somefile
109+
tabnext
110+
bwipe somefile
111+
112+
call assert_equal([
113+
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
114+
\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
115+
\ 'TabClosed'
116+
\ ], g:record)
117+
106118
augroup testing
107119
au!
108120
augroup END

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static char *(features[]) =
758758

759759
static int included_patches[] =
760760
{ /* Add new patch number below this line */
761+
/**/
762+
2077,
761763
/**/
762764
2076,
763765
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ enum auto_event
13311331
EVENT_TABENTER, /* after entering a tab page */
13321332
EVENT_TABLEAVE, /* before leaving a tab page */
13331333
EVENT_TABNEW, /* when entering a new tab page */
1334+
EVENT_TABCLOSED, /* after closing a tab page */
13341335
EVENT_SHELLCMDPOST, /* after ":!cmd" */
13351336
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
13361337
EVENT_TEXTCHANGED, /* text was modified */

src/window.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,9 @@ close_windows(
20952095
win_T *wp;
20962096
tabpage_T *tp, *nexttp;
20972097
int h = tabline_height();
2098+
#ifdef FEAT_AUTOCMD
2099+
int count = tabpage_index(NULL);
2100+
#endif
20982101

20992102
++RedrawingDisabled;
21002103

@@ -2138,6 +2141,11 @@ close_windows(
21382141

21392142
--RedrawingDisabled;
21402143

2144+
#ifdef FEAT_AUTOCMD
2145+
if (count != tabpage_index(NULL))
2146+
apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
2147+
#endif
2148+
21412149
redraw_tabline = TRUE;
21422150
if (h != tabline_height())
21432151
shell_new_rows();
@@ -2220,6 +2228,7 @@ close_last_window_tabpage(
22202228
/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
22212229
* that now. */
22222230
#ifdef FEAT_AUTOCMD
2231+
apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
22232232
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
22242233
apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
22252234
if (old_curbuf != curbuf)

0 commit comments

Comments
 (0)