aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/autocmd.txt12
-rw-r--r--runtime/doc/tabpage.txt3
-rw-r--r--runtime/syntax/vim.vim2
-rw-r--r--src/nvim/ex_docmd.c5
-rw-r--r--src/nvim/fileio.c6
-rw-r--r--src/nvim/fileio.h3
-rw-r--r--src/nvim/window.c3
-rw-r--r--test/functional/autocmd/tabclose_spec.lua36
-rw-r--r--test/functional/autocmd/tabnew_spec.lua24
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua24
10 files changed, 116 insertions, 2 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 85384519e6..6a9e4f025d 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -296,6 +296,9 @@ Name triggered by ~
|WinLeave| before leaving a window
|TabEnter| after entering another tab page
|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
@@ -859,6 +862,15 @@ TabEnter Just after entering a tab page. |tab-page|
TabLeave Just before leaving a tab page. |tab-page|
A WinLeave event will have been triggered
first.
+ *TabNew*
+TabNew When creating a new tab page. |tab-page|
+ After WinEnter and before TabEnter.
+ *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/doc/tabpage.txt b/runtime/doc/tabpage.txt
index 3c7ad9fe28..dd3a031020 100644
--- a/runtime/doc/tabpage.txt
+++ b/runtime/doc/tabpage.txt
@@ -251,6 +251,9 @@ When switching to another tab page the order is:
WinEnter
BufEnter
+When entering a new tab page (|:tabnew|), TabNew is triggered before TabEnter
+and after WinEnter.
+
==============================================================================
4. Setting 'tabline' *setting-tabline*
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index 8cbc516797..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 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 7ff69a3d41..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())
@@ -5715,7 +5718,9 @@ void ex_splitview(exarg_T *eap)
if (win_new_tabpage(cmdmod.tab != 0 ? cmdmod.tab
: eap->addr_count == 0 ? 0
: (int)eap->line2 + 1) != FAIL) {
+ apply_autocmds(EVENT_TABNEW, eap->arg, eap->arg, FALSE, curbuf);
do_exedit(eap, old_curwin);
+ apply_autocmds(EVENT_TABNEWENTERED, NULL, NULL, FALSE, curbuf);
/* set the alternate buffer for the window we came from */
if (curwin != old_curwin
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index dd6e5ace3f..762514a237 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5245,8 +5245,11 @@ 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},
+ {"TabNewEntered", EVENT_TABNEWENTERED},
{"TermChanged", EVENT_TERMCHANGED},
{"TermResponse", EVENT_TERMRESPONSE},
{"TextChanged", EVENT_TEXTCHANGED},
@@ -6632,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 29bd1307f6..7a9e2adae1 100644
--- a/src/nvim/fileio.h
+++ b/src/nvim/fileio.h
@@ -93,8 +93,11 @@ 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 */
+ EVENT_TABNEWENTERED, /* after entering a new tab */
EVENT_SHELLCMDPOST, /* after ":!cmd" */
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
EVENT_TEXTCHANGED, /* text was modified */
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)
+
diff --git a/test/functional/autocmd/tabnew_spec.lua b/test/functional/autocmd/tabnew_spec.lua
new file mode 100644
index 0000000000..970ca19726
--- /dev/null
+++ b/test/functional/autocmd/tabnew_spec.lua
@@ -0,0 +1,24 @@
+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('TabNew', function()
+ describe('au TabNew', function()
+ clear()
+ describe('with * as <afile>', function()
+ it('matches when opening any new tab', function()
+ nvim('command', 'au! TabNew * echom "tabnew:".tabpagenr().":".bufnr("")')
+ eq("\ntabnew:2:1", nvim('command_output', 'tabnew'))
+ eq("\ntabnew:3:2\n\"test.x\" [New File]", nvim('command_output', 'tabnew test.x'))
+ end)
+ end)
+ describe('with FILE as <afile>', function()
+ it('matches when opening a new tab for FILE', function()
+ tmp_path = nvim('eval', 'tempname()')
+ nvim('command', 'au! TabNew '..tmp_path..' echom "tabnew:match"')
+ eq("\ntabnew:4:3\ntabnew:match\n\""..tmp_path.."\" [New File]", nvim('command_output', 'tabnew '..tmp_path))
+ end)
+ end)
+ end)
+end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
new file mode 100644
index 0000000000..f220c15ef7
--- /dev/null
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -0,0 +1,24 @@
+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('TabNewEntered', function()
+ describe('au TabNewEntered', function()
+ describe('with * as <afile>', function()
+ it('matches when entering any new tab', function()
+ clear()
+ nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
+ eq("\ntabnewentered:2:2", nvim('command_output', 'tabnew'))
+ eq("\n\"test.x2\" [New File]\ntabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
+ end)
+ end)
+ describe('with FILE as <afile>', function()
+ it('matches when opening a new tab for FILE', function()
+ tmp_path = nvim('eval', 'tempname()')
+ nvim('command', 'au! TabNewEntered '..tmp_path..' echom "tabnewentered:match"')
+ eq("\n\""..tmp_path.."\" [New File]\ntabnewentered:4:4\ntabnewentered:match", nvim('command_output', 'tabnew '..tmp_path))
+ end)
+ end)
+ end)
+end)