Hi all,
at https://groups.google.com/forum/#!topic/vim_dev/Qnmdv7OLh_g/discussion I
proposed a new TabNew event. This is a followup to that, adding:
- a new TabNewEntered event which gets triggered after the first buffer in the
new tab is entered. This is equivalent to using a t: variable, but is more
straightforward:
au! BufEnter * if !exists('t:new_tab') | let t:new_tab = 1 | doautocmd
User TabNew | endif
au! User TabNew :echom "new tab"
turns into
au! TabNewEntered * echom "new tab"
- a TabClosed event which gets triggered after a tab is closed.
TabClosed uses the closed tab page number as <afile>, so we can trigger the
event when a specific tab page is closed.
Bram asked it it was possible to add WinEnter events too, and I think it is,
but I haven't been able to take the time to implement that, so for now I'm
limiting myself to this.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# User Felipe Morales <[email protected]>
# Date 1422816945 10800
# Sun Feb 01 15:55:45 2015 -0300
# Node ID 2d7886ce7b75c4900846bfc5c8dad4e5b4013859
# Parent 84171683fd6681984b88b7b70d0d3e6a317ac169
Add TabNew and TabNewEntered events
diff -r 84171683fd66 -r 2d7886ce7b75 runtime/doc/autocmd.txt
--- a/runtime/doc/autocmd.txt Tue Jan 27 22:52:15 2015 +0100
+++ b/runtime/doc/autocmd.txt Sun Feb 01 15:55:45 2015 -0300
@@ -295,6 +295,8 @@
|WinEnter| after entering another window
|WinLeave| before leaving a window
|TabEnter| after entering another tab page
+|TabNew| when creating a new tab page
+|TabNewEntered| after entering a new tab page
|TabLeave| before leaving a tab page
|CmdwinEnter| after entering the command-line window
|CmdwinLeave| before leaving the command-line window
@@ -849,6 +851,12 @@
TabEnter Just after entering a tab page. |tab-page|
After triggering the WinEnter and before
triggering the BufEnter event.
+ *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.
*TabLeave*
TabLeave Just before leaving a tab page. |tab-page|
A WinLeave event will have been triggered
diff -r 84171683fd66 -r 2d7886ce7b75 runtime/syntax/vim.vim
--- a/runtime/syntax/vim.vim Tue Jan 27 22:52:15 2015 +0100
+++ b/runtime/syntax/vim.vim Sun Feb 01 15:55:45 2015 -0300
@@ -63,7 +63,7 @@
" 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 CmdUndefined 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 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 CmdUndefined 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 MenuPopup QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SessionLoadPost ShellCmdPost ShellFilterPost SourceCmd SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabEnter TabNew TabNewEntered TabLeave 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 -r 84171683fd66 -r 2d7886ce7b75 src/ex_docmd.c
--- a/src/ex_docmd.c Tue Jan 27 22:52:15 2015 +0100
+++ b/src/ex_docmd.c Sun Feb 01 15:55:45 2015 -0300
@@ -8052,7 +8052,13 @@
: eap->addr_count == 0 ? 0
: (int)eap->line2 + 1) != FAIL)
{
+#ifdef FEAT_AUTOCMD
+ apply_autocmds(EVENT_TABNEW, eap->arg, eap->arg, FALSE, curbuf);
+#endif
do_exedit(eap, old_curwin);
+#ifdef FEAT_AUTOCMD
+ apply_autocmds(EVENT_TABNEWENTERED, NULL, NULL, FALSE; curbuf);
+#endif
/* set the alternate buffer for the window we came from */
if (curwin != old_curwin
diff -r 84171683fd66 -r 2d7886ce7b75 src/fileio.c
--- a/src/fileio.c Tue Jan 27 22:52:15 2015 +0100
+++ b/src/fileio.c Sun Feb 01 15:55:45 2015 -0300
@@ -7701,6 +7701,8 @@
{"SwapExists", EVENT_SWAPEXISTS},
{"Syntax", EVENT_SYNTAX},
{"TabEnter", EVENT_TABENTER},
+ {"TabNew", EVENT_TABNEW},
+ {"TabNewEntered", EVENT_TABNEWENTERED},
{"TabLeave", EVENT_TABLEAVE},
{"TermChanged", EVENT_TERMCHANGED},
{"TermResponse", EVENT_TERMRESPONSE},
diff -r 84171683fd66 -r 2d7886ce7b75 src/vim.h
--- a/src/vim.h Tue Jan 27 22:52:15 2015 +0100
+++ b/src/vim.h Sun Feb 01 15:55:45 2015 -0300
@@ -1325,6 +1325,8 @@
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 page */
+ EVENT_TABNEWENTERED /* after entering a new tab page */
EVENT_SHELLCMDPOST, /* after ":!cmd" */
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
EVENT_TEXTCHANGED, /* text was modified */
# HG changeset patch
# User Felipe Morales <[email protected]>
# Date 1422814547 10800
# Sun Feb 01 15:15:47 2015 -0300
# Node ID e404f41a5272cfaadd3aabaab665ba0db75b9b67
# Parent 84171683fd6681984b88b7b70d0d3e6a317ac169
Add TabClosed event
diff -r 84171683fd66 -r e404f41a5272 runtime/doc/autocmd.txt
--- a/runtime/doc/autocmd.txt Tue Jan 27 22:52:15 2015 +0100
+++ b/runtime/doc/autocmd.txt Sun Feb 01 15:15:47 2015 -0300
@@ -296,6 +296,7 @@
|WinLeave| before leaving a window
|TabEnter| after entering another tab page
|TabLeave| before leaving a tab page
+|TabClosed| after closing a tab page
|CmdwinEnter| after entering the command-line window
|CmdwinLeave| before leaving the command-line window
@@ -853,6 +854,9 @@
TabLeave Just before leaving a tab page. |tab-page|
A WinLeave event will have been triggered
first.
+ *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 -r 84171683fd66 -r e404f41a5272 src/ex_docmd.c
--- a/src/ex_docmd.c Tue Jan 27 22:52:15 2015 +0100
+++ b/src/ex_docmd.c Sun Feb 01 15:15:47 2015 -0300
@@ -7363,11 +7363,17 @@
int done = 0;
win_T *wp;
int h = tabline_height();
+#ifdef FEAT_AUTOCMD
+ char_u prev_idx[NUMBUFLEN];
+#endif
/* Limit to 1000 windows, autocommands may add a window while we close
* one. OK, so I'm paranoid... */
while (++done < 1000)
{
+#ifdef FEAT_AUTOCMD
+ sprintf((char *)prev_idx, "%i", tabpage_index(tp));
+#endif
wp = tp->tp_firstwin;
ex_win_close(forceit, wp, tp);
@@ -7376,6 +7382,9 @@
if (!valid_tabpage(tp) || tp->tp_firstwin == wp)
break;
}
+#ifdef FEAT_AUTOCMD
+ apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf);
+#endif
redraw_tabline = TRUE;
if (h != tabline_height())
diff -r 84171683fd66 -r e404f41a5272 src/fileio.c
--- a/src/fileio.c Tue Jan 27 22:52:15 2015 +0100
+++ b/src/fileio.c Sun Feb 01 15:15:47 2015 -0300
@@ -7700,6 +7700,7 @@
{"StdinReadPre", EVENT_STDINREADPRE},
{"SwapExists", EVENT_SWAPEXISTS},
{"Syntax", EVENT_SYNTAX},
+ {"TabClosed", EVENT_TABCLOSED},
{"TabEnter", EVENT_TABENTER},
{"TabLeave", EVENT_TABLEAVE},
{"TermChanged", EVENT_TERMCHANGED},
@@ -9370,7 +9371,8 @@
|| event == EVENT_SPELLFILEMISSING
|| event == EVENT_QUICKFIXCMDPRE
|| event == EVENT_COLORSCHEME
- || event == EVENT_QUICKFIXCMDPOST)
+ || event == EVENT_QUICKFIXCMDPOST
+ || event == EVENT_TABCLOSED)
fname = vim_strsave(fname);
else
fname = FullName_save(fname, FALSE);
diff -r 84171683fd66 -r e404f41a5272 src/vim.h
--- a/src/vim.h Tue Jan 27 22:52:15 2015 +0100
+++ b/src/vim.h Sun Feb 01 15:15:47 2015 -0300
@@ -1323,6 +1323,7 @@
EVENT_SPELLFILEMISSING, /* spell file missing */
EVENT_CURSORMOVED, /* cursor was moved */
EVENT_CURSORMOVEDI, /* cursor was moved in Insert mode */
+ EVENT_TABCLOSED, /* after closing a tab page */
EVENT_TABLEAVE, /* before leaving a tab page */
EVENT_TABENTER, /* after entering a tab page */
EVENT_SHELLCMDPOST, /* after ":!cmd" */
diff -r 84171683fd66 -r e404f41a5272 src/window.c
--- a/src/window.c Tue Jan 27 22:52:15 2015 +0100
+++ b/src/window.c Sun Feb 01 15:15:47 2015 -0300
@@ -2310,6 +2310,9 @@
/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
* that now. */
#ifdef FEAT_AUTOCMD
+ 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)