Mercurial > vim
changeset 13444:9f06f7aca74c v8.0.1596
patch 8.0.1596: no autocommand specifically for opening a terminal window
commit https://github.com/vim/vim/commit/b852c3e64d319d6ec47dd780c8654ae095e1d8c2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 11 16:55:36 2018 +0100
patch 8.0.1596: no autocommand specifically for opening a terminal window
Problem: No autocommand specifically for opening a terminal window.
Solution: Add TerminalOpen. (?, closes https://github.com/vim/vim/issues/2484)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 11 Mar 2018 17:00:08 +0100 |
parents | b8e5a0ebfcbd |
children | bc3a1b4f9de3 |
files | runtime/doc/autocmd.txt src/fileio.c src/terminal.c src/testdir/test_terminal.vim src/version.c src/vim.h |
diffstat | 6 files changed, 58 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -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' 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|
--- a/src/fileio.c +++ b/src/fileio.c @@ -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},
--- a/src/terminal.c +++ b/src/terminal.c @@ -38,45 +38,36 @@ * 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 *o term_close_buffer(curbuf, old_curbuf); return NULL; } + + apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, curbuf); return newbuf; }
--- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -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
--- a/src/version.c +++ b/src/version.c @@ -767,6 +767,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1596, +/**/ 1595, /**/ 1594,
--- 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 */ };