aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Morales <hel.sheep@gmail.com>2014-12-22 02:05:22 -0300
committerJustin M. Keyes <justinkz@gmail.com>2015-02-16 23:24:30 -0500
commit817be96be535a8aecc24a72f51fe2d6743ed4a24 (patch)
tree89d896fc8bb6e6f47db50d6f5a2361a2c35b5ab8
parent0429857689ba98356bc80d01ebd540fe861e8db2 (diff)
downloadrneovim-817be96be535a8aecc24a72f51fe2d6743ed4a24.tar.gz
rneovim-817be96be535a8aecc24a72f51fe2d6743ed4a24.tar.bz2
rneovim-817be96be535a8aecc24a72f51fe2d6743ed4a24.zip
Add TabNew event
TabNew triggers when entering a new tab page, but not when entering an already created one.
-rw-r--r--runtime/doc/autocmd.txt5
-rw-r--r--runtime/doc/tabpage.txt3
-rw-r--r--runtime/syntax/vim.vim2
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/fileio.c1
-rw-r--r--src/nvim/fileio.h1
-rw-r--r--test/functional/autocmd/tabnew_spec.lua24
7 files changed, 37 insertions, 1 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 85384519e6..c86a244a5e 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -296,6 +296,7 @@ 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
|CmdwinEnter| after entering the command-line window
|CmdwinLeave| before leaving the command-line window
@@ -859,6 +860,10 @@ 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.
+
*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..d9f3c85921 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 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..9d2285acb5 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -5715,6 +5715,8 @@ 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);
+ entering_new_tab = true;
do_exedit(eap, old_curwin);
/* set the alternate buffer for the window we came from */
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index dd6e5ace3f..c8944fffe4 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5247,6 +5247,7 @@ static struct event_name {
{"Syntax", EVENT_SYNTAX},
{"TabEnter", EVENT_TABENTER},
{"TabLeave", EVENT_TABLEAVE},
+ {"TabNew", EVENT_TABNEW},
{"TermChanged", EVENT_TERMCHANGED},
{"TermResponse", EVENT_TERMRESPONSE},
{"TextChanged", EVENT_TEXTCHANGED},
diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h
index 29bd1307f6..134759577c 100644
--- a/src/nvim/fileio.h
+++ b/src/nvim/fileio.h
@@ -95,6 +95,7 @@ typedef enum auto_event {
EVENT_CURSORMOVEDI, /* cursor was moved in Insert mode */
EVENT_TABLEAVE, /* before leaving a tab page */
EVENT_TABENTER, /* after entering a tab page */
+ EVENT_TABNEW, /* when creating 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/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)