aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Morales <hel.sheep@gmail.com>2015-01-05 01:03:22 -0300
committerJustin M. Keyes <justinkz@gmail.com>2015-02-16 23:24:31 -0500
commit3ffc5d81c34cfdd535573a50790690c88e4324bb (patch)
treeaa35b1fcb2e89f4f11976edb4e32b315f746e168
parent66d94869a0f01902d93597eae4244f9a64db82fc (diff)
downloadrneovim-3ffc5d81c34cfdd535573a50790690c88e4324bb.tar.gz
rneovim-3ffc5d81c34cfdd535573a50790690c88e4324bb.tar.bz2
rneovim-3ffc5d81c34cfdd535573a50790690c88e4324bb.zip
Add TabClosed event
TabClosed is triggered when a tab page closes.
-rw-r--r--runtime/doc/autocmd.txt4
-rw-r--r--runtime/syntax/vim.vim2
-rw-r--r--src/nvim/ex_docmd.c3
-rw-r--r--src/nvim/fileio.c4
-rw-r--r--src/nvim/fileio.h1
-rw-r--r--src/nvim/window.c3
-rw-r--r--test/functional/autocmd/tabclose_spec.lua36
7 files changed, 51 insertions, 2 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 9d645d435d..6a9e4f025d 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -298,6 +298,7 @@ Name triggered by ~
|TabLeave| before leaving a tab page
|TabNew| when creating a new tab page
|TabNewEntered| after entering a new tab page
+|TabClosed| after closing a tab page
|CmdwinEnter| after entering the command-line window
|CmdwinLeave| before leaving the command-line window
@@ -867,6 +868,9 @@ TabNew When creating a new tab page. |tab-page|
*TabNewEntered*
TabNewEntered After entering a new tab page. |tab-page|
After BufEnter.
+ *TabClosed*
+TabClosed After closing a tab page. <afile> can be used
+ for the tab page number.
*TermChanged*
TermChanged After the value of 'term' has changed. Useful
for re-loading the syntax file to update the
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index 7d6a4b91a5..6da23a40fa 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -76,7 +76,7 @@ syn keyword vimErrSetting contained hardtabs ht w1200 w300 w9600
" AutoCmd Events {{{2
syn case ignore
-syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CompleteDone CursorHold CursorHoldI CursorMoved CursorMovedI EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave JobActivity MenuPopup QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SessionLoadPost ShellCmdPost ShellFilterPost SourceCmd SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabEnter TabLeave TabNew TabNewEntered TermChanged TermResponse TextChanged TextChangedI User UserGettingBored VimEnter VimLeave VimLeavePre VimResized WinEnter WinLeave
+syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CompleteDone CursorHold CursorHoldI CursorMoved CursorMovedI EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave JobActivity MenuPopup QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SessionLoadPost ShellCmdPost ShellFilterPost SourceCmd SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabEnter TabLeave TabNew TabNewEntered TabClosed TermChanged TermResponse TextChanged TextChangedI User UserGettingBored VimEnter VimLeave VimLeavePre VimResized WinEnter WinLeave
" Highlight commonly used Groupnames {{{2
syn keyword vimGroup contained Comment Constant String Character Number Boolean Float Identifier Function Statement Conditional Repeat Label Operator Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug Underlined Ignore Error Todo
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 189881be34..bf9b5c16d7 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -5328,10 +5328,12 @@ void tabpage_close_other(tabpage_T *tp, int forceit)
int done = 0;
win_T *wp;
int h = tabline_height();
+ char_u prev_idx[NUMBUFLEN];
/* Limit to 1000 windows, autocommands may add a window while we close
* one. OK, so I'm paranoid... */
while (++done < 1000) {
+ sprintf((char *)prev_idx, "%i", tabpage_index(tp));
wp = tp->tp_firstwin;
ex_win_close(forceit, wp, tp);
@@ -5340,6 +5342,7 @@ void tabpage_close_other(tabpage_T *tp, int forceit)
if (!valid_tabpage(tp) || tp->tp_firstwin == wp)
break;
}
+ apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf);
redraw_tabline = TRUE;
if (h != tabline_height())
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 6aeb36b719..762514a237 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5245,6 +5245,7 @@ static struct event_name {
{"StdinReadPre", EVENT_STDINREADPRE},
{"SwapExists", EVENT_SWAPEXISTS},
{"Syntax", EVENT_SYNTAX},
+ {"TabClosed", EVENT_TABCLOSED},
{"TabEnter", EVENT_TABENTER},
{"TabLeave", EVENT_TABLEAVE},
{"TabNew", EVENT_TABNEW},
@@ -6634,7 +6635,8 @@ apply_autocmds_group (
|| event == EVENT_QUICKFIXCMDPRE
|| event == EVENT_COLORSCHEME
|| event == EVENT_QUICKFIXCMDPOST
- || event == EVENT_JOBACTIVITY)
+ || event == EVENT_JOBACTIVITY
+ || event == EVENT_TABCLOSED)
fname = vim_strsave(fname);
else
fname = FullName_save(fname, FALSE);
diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h
index 48d96760db..7a9e2adae1 100644
--- a/src/nvim/fileio.h
+++ b/src/nvim/fileio.h
@@ -93,6 +93,7 @@ typedef enum auto_event {
EVENT_SPELLFILEMISSING, /* spell file missing */
EVENT_CURSORMOVED, /* cursor was moved */
EVENT_CURSORMOVEDI, /* cursor was moved in Insert mode */
+ EVENT_TABCLOSED, /* a tab has closed */
EVENT_TABLEAVE, /* before leaving a tab page */
EVENT_TABENTER, /* after entering a tab page */
EVENT_TABNEW, /* when creating a new tab */
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 52a1853f4b..adc6e9f1c2 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1791,6 +1791,9 @@ static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_c
}
/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
* that now. */
+ char_u prev_idx[NUMBUFLEN];
+ sprintf((char *)prev_idx, "%i", tabpage_index(prev_curtab));
+ apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf);
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
if (old_curbuf != curbuf)
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
new file mode 100644
index 0000000000..847362e3de
--- /dev/null
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -0,0 +1,36 @@
+local helpers = require('test.functional.helpers')
+local clear, nvim, buffer, curbuf, curwin, eq, neq, ok =
+ helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
+ helpers.eq, helpers.neq, helpers.ok
+
+describe('TabClosed', function()
+ describe('au TabClosed', function()
+ describe('with * as <afile>', function()
+ it('matches when closing any tab', function()
+ clear()
+ nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
+ repeat
+ nvim('command', 'tabnew')
+ until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
+ eq("\ntabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
+ eq("\ntabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
+ eq("\ntabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
+ eq("\ntabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
+ end)
+ end)
+ describe('with NR as <afile>', function()
+ it('matches when closing a tab whose index is NR', function()
+ tmp_path = nvim('eval', 'tempname()')
+ nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
+ repeat
+ nvim('command', 'tabnew')
+ until nvim('eval', 'tabpagenr()') == 5 -- current tab is now 5
+ -- sanity check, we shouldn't match on tabs with numbers other than 2
+ eq("\ntabclosed:5:5:4", nvim('command_output', 'tabclose'))
+ -- close tab page 2, current tab is now 3
+ eq("\ntabclosed:2:2:3\ntabclosed:match", nvim('command_output', '2tabclose'))
+ end)
+ end)
+ end)
+end)
+