From 5a54ea433342ac26709577c04641a6ffc2994738 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 1 Apr 2021 20:01:54 -0400 Subject: [PATCH] Handle race condition closing job stdin This race condition is there for any key press, but it's greatly exaggerated by Vim's default one second timeout on Escape. This delay also disqualifies Escape as the official interface to this feature, but leave it as a DWIM alternative to CTRL-D for now. Closes https://github.com/tpope/vim-fugitive/issues/1722 --- autoload/fugitive.vim | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 041c160..5d9e063 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2566,6 +2566,19 @@ function! s:RunSend(job, str) abort endtry endfunction +function! s:RunCloseIn(job) abort + try + if type(a:job) ==# type(0) + call chanclose(a:job, 'stdin') + else + call ch_close_in(a:job) + endif + return 1 + catch /^Vim\%((\a\+)\)\=:E90[06]:/ + return 0 + endtry +endfunction + function! s:RunEcho(tmp) abort if !has_key(a:tmp, 'echo') return @@ -2605,12 +2618,7 @@ function! s:RunWait(state, tmp, job, ...) abort let c = type(c) == type(0) ? nr2char(c) : c if c ==# "\" || c ==# "\" let a:state.closed_in = 1 - if type(a:job) ==# type(0) - call chanclose(a:job, 'stdin') - else - call ch_close_in(a:job) - endif - let can_pedit = exists('*setbufline') + let can_pedit = s:RunCloseIn(a:job) && exists('*setbufline') for winnr in range(1, winnr('$')) if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified') let can_pedit = 0