Merge pull request #4296 from mhinz/fix-termclose

Make TermClose event return the associated buffer
This commit is contained in:
Justin M. Keyes
2016-02-21 02:04:13 -05:00
3 changed files with 22 additions and 2 deletions

View File

@@ -22199,7 +22199,6 @@ static void on_process_exit(Process *proc, int status, void *d)
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) {

View File

@@ -288,8 +288,9 @@ void terminal_close(Terminal *term, char *msg)
term->forward_mouse = false;
term->closed = true;
if (!msg || exiting) {
buf_T *buf = handle_get_buffer(term->buf_handle);
if (!msg || exiting) {
// If no msg was given, this was called by close_buffer(buffer.c). Or if
// exiting, we must inform the buffer the terminal no longer exists so that
// close_buffer() doesn't call this again.
@@ -304,6 +305,10 @@ void terminal_close(Terminal *term, char *msg)
} else {
terminal_receive(term, msg, strlen(msg));
}
if (buf) {
apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, buf);
}
}
void terminal_resize(Terminal *term, uint16_t width, uint16_t height)

View File

@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear, execute, feed, nvim, nvim_dir = helpers.clear,
helpers.execute, helpers.feed, helpers.nvim, helpers.nvim_dir
local eval, eq = helpers.eval, helpers.eq
describe('TermClose event', function()
local screen
@@ -25,4 +26,19 @@ describe('TermClose event', function()
TermClose works! |
]])
end)
it('reports the correct <abuf>', function()
execute('set hidden')
execute('autocmd TermClose * let g:abuf = expand("<abuf>")')
execute('edit foo')
execute('edit bar')
eq(2, eval('bufnr("%")'))
execute('terminal')
feed('<c-\\><c-n>')
eq(3, eval('bufnr("%")'))
execute('buffer 1')
eq(1, eval('bufnr("%")'))
execute('3bdelete!')
eq('3', eval('g:abuf'))
end)
end)