Skip to content

Commit 28ed4df

Browse files
committed
patch 8.1.2219: no autocommand for open window with terminal
Problem: No autocommand for open window with terminal. Solution: Add TerminalWinOpen. (Christian Brabandt)
1 parent 453c192 commit 28ed4df

6 files changed

Lines changed: 33 additions & 1 deletion

File tree

runtime/doc/autocmd.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ Name triggered by ~
268268
|BufCreate| just after adding a buffer to the buffer list
269269
|BufDelete| before deleting a buffer from the buffer list
270270
|BufWipeout| before completely deleting a buffer
271-
|TerminalOpen| after a terminal buffer was created
272271

273272
|BufFilePre| before changing the name of the current buffer
274273
|BufFilePost| after changing the name of the current buffer
@@ -302,6 +301,10 @@ Name triggered by ~
302301
|VimLeavePre| before exiting Vim, before writing the viminfo file
303302
|VimLeave| before exiting Vim, after writing the viminfo file
304303

304+
Terminal
305+
|TerminalOpen| after a terminal buffer was created
306+
|TerminalWinOpen| after a terminal buffer was created in a new window
307+
305308
Various
306309
|FileChangedShell| Vim notices that a file changed since editing started
307310
|FileChangedShellPost| After handling a file changed since editing started
@@ -1081,6 +1084,12 @@ TerminalOpen Just after a terminal buffer was created, with
10811084
`:terminal` or |term_start()|. This event is
10821085
triggered even if the buffer is created
10831086
without a window, with the ++hidden option.
1087+
*TerminalWinOpen*
1088+
TerminalWinOpen Just after a terminal buffer was created, with
1089+
`:terminal` or |term_start()|. This event is
1090+
triggered only if the buffer is created
1091+
with a window. Can be used to set window
1092+
local options for the terminal window.
10841093
*TermResponse*
10851094
TermResponse After the response to |t_RV| is received from
10861095
the terminal. The value of |v:termresponse|

src/autocmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static struct event_name
174174
{"TabLeave", EVENT_TABLEAVE},
175175
{"TermChanged", EVENT_TERMCHANGED},
176176
{"TerminalOpen", EVENT_TERMINALOPEN},
177+
{"TerminalWinOpen", EVENT_TERMINALWINOPEN},
177178
{"TermResponse", EVENT_TERMRESPONSE},
178179
{"TextChanged", EVENT_TEXTCHANGED},
179180
{"TextChangedI", EVENT_TEXTCHANGEDI},

src/terminal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ term_start(
690690
}
691691

692692
apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
693+
if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM))
694+
apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf);
693695
return newbuf;
694696
}
695697

src/testdir/test_terminal.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ func Test_terminal_basic()
6868
unlet g:job
6969
endfunc
7070

71+
func Test_terminal_TerminalWinOpen()
72+
au TerminalWinOpen * let b:done = 'yes'
73+
let buf = Run_shell_in_terminal({})
74+
call assert_equal('yes', b:done)
75+
call StopShellInTerminal(buf)
76+
" closing window wipes out the terminal buffer with the finished job
77+
close
78+
79+
if has("unix")
80+
terminal ++hidden ++open sleep 1
81+
sleep 1
82+
call assert_fails("echo b:done", 'E121:')
83+
endif
84+
85+
au! TerminalWinOpen
86+
endfunc
87+
7188
func Test_terminal_make_change()
7289
let buf = Run_shell_in_terminal({})
7390
call StopShellInTerminal(buf)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2219,
744746
/**/
745747
2218,
746748
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ enum auto_event
13411341
EVENT_TABNEW, // when entering a new tab page
13421342
EVENT_TERMCHANGED, // after changing 'term'
13431343
EVENT_TERMINALOPEN, // after a terminal buffer was created
1344+
EVENT_TERMINALWINOPEN, // after a terminal buffer was created and entering its window
13441345
EVENT_TERMRESPONSE, // after setting "v:termresponse"
13451346
EVENT_TEXTCHANGED, // text was modified not in Insert mode
13461347
EVENT_TEXTCHANGEDI, // text was modified in Insert mode

0 commit comments

Comments
 (0)