[vim] Don't start extra process when opening popup (#2000)

Fix #2038
pull/2042/head
ichizok 4 years ago committed by GitHub
parent e6d33f77da
commit d631c76e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -648,6 +648,7 @@ function! s:split(dict)
\ 'left': ['vertical topleft', 'vertical resize', &columns],
\ 'right': ['vertical botright', 'vertical resize', &columns] }
let ppos = s:getpos()
let is_popup = 0
try
if s:present(a:dict, 'window')
if type(a:dict.window) == type({})
@ -655,6 +656,7 @@ function! s:split(dict)
throw 'Vim 8.2.191 or later is required for pop-up window'
end
call s:popup(a:dict.window)
let is_popup = 1
else
execute 'keepalt' a:dict.window
endif
@ -672,11 +674,11 @@ function! s:split(dict)
endif
execute cmd sz.'new'
execute resz sz
return [ppos, {}]
return [ppos, {}, is_popup]
endif
endfor
endif
return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]
return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }, is_popup]
finally
setlocal winfixwidth winfixheight
endtry
@ -685,7 +687,7 @@ endfunction
function! s:execute_term(dict, command, temps) abort
let winrest = winrestcmd()
let pbuf = bufnr('')
let [ppos, winopts] = s:split(a:dict)
let [ppos, winopts, is_popup] = s:split(a:dict)
call s:use_sh()
let b:fzf = a:dict
let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
@ -752,8 +754,17 @@ function! s:execute_term(dict, command, temps) abort
if !len(&bufhidden)
setlocal bufhidden=hide
endif
let fzf.buf = term_start([&shell, &shellcmdflag, command], {'curwin': 1, 'exit_cb': function(fzf.on_exit)})
if !has('patch-8.0.1261') && !has('nvim') && !s:is_win
let term_opts = {'exit_cb': function(fzf.on_exit)}
if is_popup
let term_opts.hidden = 1
else
let term_opts.curwin = 1
endif
let fzf.buf = term_start([&shell, &shellcmdflag, command], term_opts)
if is_popup && exists('#TerminalWinOpen')
doautocmd <nomodeline> TerminalWinOpen
endif
if !has('patch-8.0.1261') && !s:is_win
call term_wait(fzf.buf, 20)
endif
endif
@ -824,23 +835,22 @@ if has('nvim')
else
function! s:create_popup(hl, opts) abort
let is_frame = has_key(a:opts, 'border')
let buf = is_frame ? '' : term_start(&shell, #{hidden: 1, term_finish: 'close'})
let id = popup_create(buf, #{
let s:popup_create = {buf -> popup_create(buf, #{
\ line: a:opts.row,
\ col: a:opts.col,
\ minwidth: a:opts.width,
\ minheight: a:opts.height,
\ zindex: 50 - is_frame,
\ })
\ })}
if is_frame
let id = s:popup_create('')
call setwinvar(id, '&wincolor', a:hl)
call setbufline(winbufnr(id), 1, a:opts.border)
execute 'autocmd BufWipeout * ++once call popup_close('..id..')'
return winbufnr(id)
else
execute 'autocmd BufWipeout * ++once call term_sendkeys('..buf..', "exit\<CR>")'
autocmd TerminalOpen * ++once call s:popup_create(str2nr(expand('<abuf>')))
endif
return winbufnr(id)
endfunction
endif

Loading…
Cancel
Save