patch 7.4.2077
Problem:    Cannot update 'tabline' when a tab was closed.
Solution:   Add the TabClosed autocmd event. (partly by Felipe Morales)
diff --git a/src/fileio.c b/src/fileio.c
index 0a84576..ea01b76 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7707,6 +7707,7 @@
     {"SwapExists",	EVENT_SWAPEXISTS},
     {"Syntax",		EVENT_SYNTAX},
     {"TabNew",		EVENT_TABNEW},
+    {"TabClosed",	EVENT_TABCLOSED},
     {"TabEnter",	EVENT_TABENTER},
     {"TabLeave",	EVENT_TABLEAVE},
     {"TermChanged",	EVENT_TERMCHANGED},
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 14254a7..580c42f 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -87,6 +87,7 @@
     au WinEnter * call add(g:record, 'WinEnter') 
     au WinLeave * call add(g:record, 'WinLeave') 
     au TabNew * call add(g:record, 'TabNew')
+    au TabClosed * call add(g:record, 'TabClosed')
     au TabEnter * call add(g:record, 'TabEnter')
     au TabLeave * call add(g:record, 'TabLeave')
   augroup END
@@ -99,10 +100,21 @@
   call assert_equal([
 	\ 'WinLeave', 'WinNew', 'WinEnter',
 	\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
-	\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
+	\ 'WinLeave', 'TabLeave', 'TabClosed', 'WinEnter', 'TabEnter',
 	\ 'WinLeave', 'WinEnter'
 	\ ], g:record)
 
+  let g:record = []
+  tabnew somefile
+  tabnext
+  bwipe somefile
+
+  call assert_equal([
+	\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
+	\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
+	\ 'TabClosed'
+	\ ], g:record)
+
   augroup testing
     au!
   augroup END
diff --git a/src/version.c b/src/version.c
index 6f1d53a..892894a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2077,
+/**/
     2076,
 /**/
     2075,
diff --git a/src/vim.h b/src/vim.h
index d9a60dd..488f270 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1331,6 +1331,7 @@
     EVENT_TABENTER,		/* after entering a tab page */
     EVENT_TABLEAVE,		/* before leaving a tab page */
     EVENT_TABNEW,		/* when entering a new tab page */
+    EVENT_TABCLOSED,		/* after closing a 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 bf650f8..4fbe6ca 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2095,6 +2095,9 @@
     win_T	*wp;
     tabpage_T   *tp, *nexttp;
     int		h = tabline_height();
+#ifdef FEAT_AUTOCMD
+    int		count = tabpage_index(NULL);
+#endif
 
     ++RedrawingDisabled;
 
@@ -2138,6 +2141,11 @@
 
     --RedrawingDisabled;
 
+#ifdef FEAT_AUTOCMD
+    if (count != tabpage_index(NULL))
+	apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
+#endif
+
     redraw_tabline = TRUE;
     if (h != tabline_height())
 	shell_new_rows();
@@ -2220,6 +2228,7 @@
 	/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
 	 * that now. */
 #ifdef FEAT_AUTOCMD
+	apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);
 	apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
 	apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
 	if (old_curbuf != curbuf)