I recorded info of terminal buffers in a dict, and want remove bufnr of closed ones.
Can you tell me how to start a terminal such that call a function on exit, eg,
func! myterm#remove(bufnr):
call remove(s:terms, a:bufnr)
endfunc
I recorded info of terminal buffers in a dict, and want remove bufnr of closed ones.
Can you tell me how to start a terminal such that call a function on exit, eg,
func! myterm#remove(bufnr):
call remove(s:terms, a:bufnr)
endfunc
The solution is using job-exit_cb handler, (see :help job-exit_cb)
A working example is
func! g:Exit_cb(job, exit_code)
echo term_getjob(2)
let pid = matchstr(a:job, '^\%(process \)\zs\d\+')
echom "job " . pid . " finished with exit_code " . a:exit_code
endfunc
call term_start('bash', {'exit_cb': function('g:Exit_cb')})
Run above code, then close the newly created terminal, you will see something like below
job 61392 finished with exit_code 0
be echoed at the bottom, you can also verify with :mess command. (since `:echom is used)
term_start()and use thecallbackoptions for this specific use case. – Christian Brabandt Nov 27 '19 at 11:38