]> granicus.if.org Git - vim/commitdiff
patch 8.0.1596: no autocommand specifically for opening a terminal window v8.0.1596
authorBram Moolenaar <Bram@vim.org>
Sun, 11 Mar 2018 15:55:36 +0000 (16:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 11 Mar 2018 15:55:36 +0000 (16:55 +0100)
Problem:    No autocommand specifically for opening a terminal window.
Solution:   Add TerminalOpen. (?, closes #2484)

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

index e08a7cbba33e045409b8b2c134ebb9157fc923c4..678fb378f76fd4b05e37ba4f1779410fe7f0788d 100644 (file)
@@ -257,6 +257,7 @@ 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
@@ -328,6 +329,10 @@ Name                       triggered by ~
 |CmdlineEnter|         after the cursor moves to the command line
 |CmdlineLeave|         before the cursor leaves the command line
 
+|CmdlineChanged|       after a change was made to the command-line text
+|CmdlineEnter|         after the cursor moves to the command line
+|CmdlineLeave|         before the cursor leaves the command line
+
 |InsertEnter|          starting Insert mode
 |InsertChange|         when typing <Insert> while in Insert or Replace mode
 |InsertLeave|          when leaving Insert mode
@@ -968,6 +973,11 @@ TermChanged                        After the value of 'term' has changed.  Useful
                                for re-loading the syntax file to update the
                                colors, fonts and other terminal-dependent
                                settings.  Executed for all loaded buffers.
+                                                       *TerminalOpen*
+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.
                                                        *TermResponse*
 TermResponse                   After the response to |t_RV| is received from
                                the terminal.  The value of |v:termresponse|
index 8331c08ab313dbe0f0d83a5b45e523331194450e..05c3df50bc4e0cd6c7db776c0ccf15a3f1ec0a2f 100644 (file)
@@ -7773,6 +7773,7 @@ static struct event_name
     {"TabEnter",       EVENT_TABENTER},
     {"TabLeave",       EVENT_TABLEAVE},
     {"TermChanged",    EVENT_TERMCHANGED},
+    {"TerminalOpen",   EVENT_TERMINALOPEN},
     {"TermResponse",   EVENT_TERMRESPONSE},
     {"TextChanged",    EVENT_TEXTCHANGED},
     {"TextChangedI",   EVENT_TEXTCHANGEDI},
index cc83055175fa4ca471d1dfcad12c6f707a486c66..7a80636ad09836c823d46cc1e339e70d7d244e8e 100644 (file)
  * in tl_scrollback are no longer used.
  *
  * TODO:
- * - Add a flag to kill the job when Vim is exiting.  Useful when it's showing
- *   a logfile.  Or send keys there to make it quit: "exit\r" for a shell.
+ * - if the job in the terminal does not support the mouse, we can use the
+ *   mouse in the Terminal window for copy/paste and scrolling.
  * - When using 'termguicolors' still use the 16 ANSI colors as-is.  Helps for
+ * - In the GUI use a terminal emulator for :!cmd.  Make the height the same as
+ *   the window and position it higher up when it gets filled, so it looks like
+ *   the text scrolls up.
+ * - implement term_setsize()
+ * - Copy text in the vterm to the Vim buffer once in a while, so that
+ *   completion works.
  * - Adding WinBar to terminal window doesn't display, text isn't shifted down.
  *   a job that uses 16 colors while Vim is using > 256.
  * - in GUI vertical split causes problems.  Cursor is flickering. (Hirohito
  *   Higashi, 2017 Sep 19)
- * - Trigger TerminalOpen event?  #2422  patch in #2484
  * - after resizing windows overlap. (Boris Staletic, #2164)
  * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
  *   is disabled.
- * - if the job in the terminal does not support the mouse, we can use the
- *   mouse in the Terminal window for copy/paste and scrolling.
  * - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
- * - When closing gvim with an active terminal buffer, the dialog suggests
- *   saving the buffer.  Should say something else. (Manas Thakur, #2215)
- *   Also: #2223
  * - Termdebug does not work when Vim build with mzscheme.  gdb hangs.
  * - MS-Windows GUI: WinBar has  tearoff item
  * - MS-Windows GUI: still need to type a key after shell exits?  #1924
  * - After executing a shell command the status line isn't redraw.
- * - implement term_setsize()
  * - add test for giving error for invalid 'termsize' value.
  * - support minimal size when 'termsize' is "rows*cols".
  * - support minimal size when 'termsize' is empty?
  * - GUI: when using tabs, focus in terminal, click on tab does not work.
- * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save
- *   changes to "!shell".
- *   (justrajdeep, 2017 Aug 22)
  * - Redrawing is slow with Athena and Motif.  Also other GUI? (Ramel Eshed)
  * - For the GUI fill termios with default values, perhaps like pangoterm:
  *   http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
  * - when 'encoding' is not utf-8, or the job is using another encoding, setup
  *   conversions.
- * - In the GUI use a terminal emulator for :!cmd.  Make the height the same as
- *   the window and position it higher up when it gets filled, so it looks like
- *   the text scrolls up.
- * - Copy text in the vterm to the Vim buffer once in a while, so that
- *   completion works.
  * - add an optional limit for the scrollback size.  When reaching it remove
  *   10% at the start.
  */
@@ -582,6 +573,8 @@ term_start(typval_T *argvar, jobopt_T *opt, int without_job, int forceit)
        term_close_buffer(curbuf, old_curbuf);
        return NULL;
     }
+
+    apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, curbuf);
     return newbuf;
 }
 
index 0178e3b8886e0cf34da91eedf41cf5f0a2647429..d8e40d1c3e496f7e863c9a1fc789d956577f53ec 100644 (file)
@@ -908,3 +908,37 @@ func Test_terminal_qall_prompt()
   " close the terminal window where Vim was running
   quit
 endfunc
+
+func Test_terminalopen_autocmd()
+  augroup repro
+    au!
+    au TerminalOpen * let s:called += 1
+  augroup END
+
+  let s:called = 0
+
+  " Open a terminal window with :terminal
+  terminal
+  call assert_equal(1, s:called)
+  bwipe!
+
+  " Open a terminal window with term_start()
+  call term_start(&shell)
+  call assert_equal(2, s:called)
+  bwipe!
+
+  " Open a hidden terminal buffer with :terminal
+  terminal ++hidden
+  call assert_equal(3, s:called)
+  for buf in term_list()
+    exe buf . "bwipe!"
+  endfor
+
+  " Open a hidden terminal buffer with term_start()
+  let buf = term_start(&shell, {'hidden': 1})
+  call assert_equal(4, s:called)
+  exe buf . "bwipe!"
+
+  unlet s:called
+  au! repro
+endfunction
index 4f1c001193305b7db6201e90d7035c633cba7932..a6ca13296fa43ea591962344818356a74f6a3b03 100644 (file)
@@ -766,6 +766,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1596,
 /**/
     1595,
 /**/
index 3b458a027e047e27aeaca01d734ebf4082372aaf..86948b03f8760ba8efd7cb689458d6b905f14318 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1346,6 +1346,7 @@ enum auto_event
     EVENT_CMDUNDEFINED,                /* command undefined */
     EVENT_OPTIONSET,           /* option was set */
     EVENT_TEXTYANKPOST,                /* after some text was yanked */
+    EVENT_TERMINALOPEN,                /* after a terminal buffer was created */
     NUM_EVENTS                 /* MUST be the last one */
 };