mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #1717 'TabNew, TabNewEntered, TabClosed'
This commit is contained in:
commit
662b7227b5
@ -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
|
||||
|
@ -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*
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
36
test/functional/autocmd/tabclose_spec.lua
Normal file
36
test/functional/autocmd/tabclose_spec.lua
Normal file
@ -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)
|
||||
|
24
test/functional/autocmd/tabnew_spec.lua
Normal file
24
test/functional/autocmd/tabnew_spec.lua
Normal file
@ -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)
|
24
test/functional/autocmd/tabnewentered_spec.lua
Normal file
24
test/functional/autocmd/tabnewentered_spec.lua
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user