]> granicus.if.org Git - vim/commitdiff
patch 8.1.2219: no autocommand for open window with terminal v8.1.2219
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Oct 2019 14:21:40 +0000 (16:21 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Oct 2019 14:21:40 +0000 (16:21 +0200)
Problem:    No autocommand for open window with terminal.
Solution:   Add TerminalWinOpen. (Christian Brabandt)

runtime/doc/autocmd.txt
src/autocmd.c
src/terminal.c
src/testdir/test_terminal.vim
src/version.c
src/vim.h

index 95618e659fcd0ce09ecaa5526767273defced5bb..cfadd9ef608bc6a524c8903e8b57f1cb925e9cd7 100644 (file)
@@ -268,7 +268,6 @@ Name                        triggered by ~
 |BufCreate|            just after adding a buffer to the buffer list
 |BufDelete|            before deleting a buffer from the buffer list
 |BufWipeout|           before completely deleting a buffer
-|TerminalOpen|         after a terminal buffer was created
 
 |BufFilePre|           before changing the name of the current buffer
 |BufFilePost|          after changing the name of the current buffer
@@ -302,6 +301,10 @@ Name                       triggered by ~
 |VimLeavePre|          before exiting Vim, before writing the viminfo file
 |VimLeave|             before exiting Vim, after writing the viminfo file
 
+       Terminal
+|TerminalOpen|         after a terminal buffer was created
+|TerminalWinOpen|      after a terminal buffer was created in a new window
+
        Various
 |FileChangedShell|     Vim notices that a file changed since editing started
 |FileChangedShellPost| After handling a file changed since editing started
@@ -1081,6 +1084,12 @@ TerminalOpen                     Just after a terminal buffer was created, with
                                `:terminal` or |term_start()|. This event is
                                triggered even if the buffer is created
                                without a window, with the ++hidden option.
+                                                       *TerminalWinOpen*
+TerminalWinOpen                        Just after a terminal buffer was created, with
+                               `:terminal` or |term_start()|. This event is
+                               triggered only if the buffer is created
+                               with a window.  Can be used to set window
+                               local options for the terminal window.
                                                        *TermResponse*
 TermResponse                   After the response to |t_RV| is received from
                                the terminal.  The value of |v:termresponse|
index 3f87e931cd5d5a90c60661d1087ef1d27d6a11e8..6ed2971bbbf3d3753874389cb6d34ca60deb3bcb 100644 (file)
@@ -174,6 +174,7 @@ static struct event_name
     {"TabLeave",       EVENT_TABLEAVE},
     {"TermChanged",    EVENT_TERMCHANGED},
     {"TerminalOpen",   EVENT_TERMINALOPEN},
+    {"TerminalWinOpen", EVENT_TERMINALWINOPEN},
     {"TermResponse",   EVENT_TERMRESPONSE},
     {"TextChanged",    EVENT_TEXTCHANGED},
     {"TextChangedI",   EVENT_TEXTCHANGEDI},
index b50198ca5ae6d739585cad278d95303de353dbb1..13e32eb5d10ef2bdb14dc96b736b8064d1a805ac 100644 (file)
@@ -690,6 +690,8 @@ term_start(
     }
 
     apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
+    if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM))
+       apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf);
     return newbuf;
 }
 
index f506a39f68d9b414f3c9987cff568b261bea2dae..212a15f3146f31bd4f16b1f91a81db8461440820 100644 (file)
@@ -68,6 +68,23 @@ func Test_terminal_basic()
   unlet g:job
 endfunc
 
+func Test_terminal_TerminalWinOpen()
+  au TerminalWinOpen * let b:done = 'yes'
+  let buf = Run_shell_in_terminal({})
+  call assert_equal('yes', b:done)
+  call StopShellInTerminal(buf)
+  " closing window wipes out the terminal buffer with the finished job
+  close
+
+  if has("unix")
+    terminal ++hidden ++open sleep 1
+    sleep 1
+    call assert_fails("echo b:done", 'E121:')
+  endif
+
+  au! TerminalWinOpen
+endfunc
+
 func Test_terminal_make_change()
   let buf = Run_shell_in_terminal({})
   call StopShellInTerminal(buf)
index af2930252227b880ad027d795ecb4725873009a0..345fc7ae0938140cde6b35bed60b379d6b0dfd09 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2219,
 /**/
     2218,
 /**/
index 43eecf09078ce7733dcac9f730a052a5e6e0ca18..917dbfa7245c20231d47315b0fc687dafab00e7c 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1341,6 +1341,7 @@ enum auto_event
     EVENT_TABNEW,              // when entering a new tab page
     EVENT_TERMCHANGED,         // after changing 'term'
     EVENT_TERMINALOPEN,                // after a terminal buffer was created
+    EVENT_TERMINALWINOPEN,     // after a terminal buffer was created and entering its window
     EVENT_TERMRESPONSE,                // after setting "v:termresponse"
     EVENT_TEXTCHANGED,         // text was modified not in Insert mode
     EVENT_TEXTCHANGEDI,         // text was modified in Insert mode