diff options
-rw-r--r-- | BACKERS.md | 2 | ||||
-rw-r--r-- | runtime/doc/autocmd.txt | 3 | ||||
-rw-r--r-- | runtime/doc/nvim_terminal_emulator.txt | 2 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 4 | ||||
-rw-r--r-- | runtime/doc/windows.txt | 2 | ||||
-rw-r--r-- | src/nvim/auevents.lua | 8 | ||||
-rw-r--r-- | src/nvim/eval.c | 6 | ||||
-rw-r--r-- | src/nvim/memory.c | 2 | ||||
-rw-r--r-- | src/nvim/normal.c | 10 | ||||
-rw-r--r-- | src/nvim/terminal.h | 9 | ||||
-rw-r--r-- | src/nvim/version.c | 66 | ||||
-rw-r--r-- | test/functional/autocmd/termclose_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 2 |
15 files changed, 128 insertions, 24 deletions
diff --git a/BACKERS.md b/BACKERS.md index 10c6f42f27..6cfcb0b407 100644 --- a/BACKERS.md +++ b/BACKERS.md @@ -104,7 +104,7 @@ Thank you to everyone who backed our [Bountysource fundraiser](https://www.bount - Michael Ulm www.mulm.at - Mikael Jansson http://mikaelj.se - Mikkel Høgh http://mikkel.hoegh.org/ -- Ming Liu http://www.codingupfengshui.io +- Ming Liu http://ming.codes - Holger Peters http://www.holger-peters.de - Alexander Myshov http://myshov.com/ - Darren Cheng http://sanguinerane.com/ diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 7b53bd64ca..a0ed91c95d 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -251,6 +251,7 @@ Name triggered by ~ |SwapExists| detected an existing swap file |TermOpen| when a terminal buffer is starting +|TermClose| when a terminal buffer ends Options |FileType| when the 'filetype' option has been set @@ -871,6 +872,8 @@ 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. + {Nvim} *TermClose* +TermClose When a terminal buffer ends. {Nvim} *TermOpen* TermOpen When a terminal buffer is starting. This can be used to configure the terminal emulator by diff --git a/runtime/doc/nvim_terminal_emulator.txt b/runtime/doc/nvim_terminal_emulator.txt index 701c6dc274..6ef3aaebaa 100644 --- a/runtime/doc/nvim_terminal_emulator.txt +++ b/runtime/doc/nvim_terminal_emulator.txt @@ -105,6 +105,8 @@ The configuration variables are only processed when the terminal starts, which is why it needs to be done with the |TermOpen| autocmd or setting global variables before the terminal is started. +There is also a corresponding |TermClose| event. + The terminal cursor can be highlighted via |hl-TermCursor| and |hl-TermCursorNC|. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 976890f7d7..6cbc2aef59 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -24,7 +24,7 @@ these differences. - Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing configuration. - Use `$XDG_CONFIG_HOME/nvim` instead of `.vim` to store configuration files. -- Use `$XDG_DATA_HOME/shada/main.shada` instead of `.viminfo` for persistent +- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent session information. ============================================================================== @@ -143,6 +143,8 @@ Events: |TabNew| |TabNewEntered| |TabClosed| + |TermOpen| + |TermClose| Highlight groups: |hl-EndOfBuffer| diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index 0e83c1fc89..c009bec66e 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -1006,7 +1006,7 @@ list of buffers. |unlisted-buffer| - buffers with 'modifiable' off = readonly buffers a active buffers - u unloaded buffers (overrides the "!") + u unlisted buffers (overrides the "!") h hidden buffers x buffers with a read error % current buffer diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 3d8a75febd..7624dd2303 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -77,8 +77,9 @@ return { 'TabNew', -- when creating a new tab 'TabNewEntered', -- after entering a new tab 'TermChanged', -- after changing 'term' - 'TermResponse', -- after setting "v:termresponse" + 'TermClose', -- after the processs exits 'TermOpen', -- after opening a terminal buffer + 'TermResponse', -- after setting "v:termresponse" 'TextChanged', -- text was modified 'TextChangedI', -- text was modified in Insert mode 'User', -- user defined autocommand @@ -98,9 +99,10 @@ return { -- List of neovim-specific events or aliases for the purpose of generating -- syntax file neovim_specific = { + TabClosed=true, TabNew=true, TabNewEntered=true, - TabClosed=true, - TermEnter=true, + TermClose=true, + TermOpen=true, }, } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e1fa76c526..9581b81456 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21781,8 +21781,10 @@ static void on_process_exit(Process *proc, int status, void *d) TerminalJobData *data = d; if (data->term && !data->exited) { data->exited = true; - terminal_close(data->term, - _("\r\n[Program exited, press any key to close]")); + char msg[22]; + snprintf(msg, sizeof msg, "\r\n[Process exited %d]", proc->status); + terminal_close(data->term, msg); + apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, curbuf); } if (data->status_ptr) { diff --git a/src/nvim/memory.c b/src/nvim/memory.c index d25dc7c941..6d386f3599 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -42,8 +42,6 @@ void try_to_free_memory(void) clear_sb_text(); // Try to save all buffers and release as many blocks as possible mf_release_all(); - // cleanup recursive lists/dicts - garbage_collect(); trying_to_free = false; } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index fce3558e9f..d6bc416c91 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -7701,6 +7701,16 @@ static void nv_open(cmdarg_T *cap) // Handle an arbitrary event in normal mode static void nv_event(cmdarg_T *cap) { + // Garbage collection should have been executed before blocking for events in + // the `os_inchar` in `state_enter`, but we also disable it here in case the + // `os_inchar` branch was not executed(!queue_empty(loop.events), which could + // have `may_garbage_collect` set to true in `normal_check`). + // + // That is because here we may run code that calls `os_inchar` + // later(`f_confirm` or `get_keystroke` for example), but in these cases it is + // not safe to perform garbage collection because there could be unreferenced + // lists or dicts being used. + may_garbage_collect = false; queue_process_events(loop.events); cap->retval |= CA_COMMAND_BUSY; // don't call edit() now } diff --git a/src/nvim/terminal.h b/src/nvim/terminal.h index 6e0b062fbd..25e609fb68 100644 --- a/src/nvim/terminal.h +++ b/src/nvim/terminal.h @@ -18,15 +18,6 @@ typedef struct { terminal_close_cb close_cb; } TerminalOptions; -#define TERMINAL_OPTIONS_INIT ((TerminalOptions) { \ - .data = NULL, \ - .width = 80, \ - .height = 24, \ - .write_cb = NULL, \ - .resize_cb = NULL, \ - .close_cb = NULL \ - }) - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "terminal.h.generated.h" #endif diff --git a/src/nvim/version.c b/src/nvim/version.c index 45b36e7d99..f5e43878e4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -74,6 +74,72 @@ static char *features[] = { // clang-format off static int included_patches[] = { + 916, + // 915, + // 914, + // 913, + // 912, + // 911, + // 910, + // 909, + // 908, + // 907, + // 906, + // 905, + // 904, + // 903, + // 902, + // 901, + // 900, + // 899, + // 898, + // 897, + // 896, + // 895, + // 894, + // 893, + // 892, + // 891, + // 890, + // 889, + // 888, + // 887, + // 886, + // 885, + // 884, + // 883, + // 882, + // 881, + // 880, + // 879, + // 878, + // 877, + // 876, + // 875, + // 874, + // 873, + // 872, + // 871, + // 870, + // 869, + // 868, + // 867, + // 866, + // 865, + // 864, + // 863, + // 862, + // 861, + // 860, + // 859, + // 858, + // 857, + // 856, + // 855, + // 854, + // 853, + // 852, + // 851, // 850, 849, // 848, diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua new file mode 100644 index 0000000000..265d857a42 --- /dev/null +++ b/test/functional/autocmd/termclose_spec.lua @@ -0,0 +1,28 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') + +local clear, eval, execute, feed, nvim, nvim_dir = helpers.clear, helpers.eval, +helpers.execute, helpers.feed, helpers.nvim, helpers.nvim_dir +local wait = helpers.wait + +describe('TermClose event', function() + before_each(function() + clear() + nvim('set_option', 'shell', nvim_dir .. '/shell-test') + nvim('set_option', 'shellcmdflag', 'EXE') + screen = Screen.new(20, 4) + screen:attach(false) + end) + + it('works as expected', function() + execute('autocmd TermClose * echomsg "TermClose works!"') + execute('terminal') + feed('<c-\\><c-n>') + screen:expect([[ + ready $ | + [Process exited 0] | + ^ | + TermClose works! | + ]]) + end) +end) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 3855cf4b65..611ba55793 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -22,7 +22,7 @@ describe(':terminal', function() wait() screen:expect([[ ready $ | - [Program exited, press any key to close] | + [Process exited 0] | | | | @@ -37,7 +37,7 @@ describe(':terminal', function() screen:expect([[ ready $ echo hi | | - [Program exited, press any key to close] | + [Process exited 0] | | | | @@ -51,7 +51,7 @@ describe(':terminal', function() screen:expect([[ ready $ echo 'hello' \ "world" | | - [Program exited, press any key to close] | + [Process exited 0] | | | | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 87cc9a8266..4b56698520 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -340,7 +340,7 @@ describe('terminal prints more lines than the screen height and exits', function line8 | line9 | | - [Program exited, press any key to close] | + [Process exited 0] | -- TERMINAL -- | ]]) feed('<cr>') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 0c4b80fdd2..ba0c531c7e 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -167,7 +167,7 @@ describe('tui with non-tty file descriptors', function() :q | abc | | - [Program exited, press any key to close] | + [Process exited 0] | | -- TERMINAL -- | ]]) |