From a36880be2217814b7034f05eb0f402e8183befc9 Mon Sep 17 00:00:00 2001 From: Linwei Date: Sat, 30 May 2020 16:51:45 +0800 Subject: [PATCH] Prevent temporary window creation on Windows (#611) Co-authored-by: skywind3000 Co-authored-by: Caleb Maclennan --- autoload/tagbar.vim | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 0f67dea..565fc2b 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -2871,6 +2871,39 @@ function! s:EscapeCtagsCmd(ctags_bin, args, ...) abort return ctags_cmd endfunction +" run shell command in a proper way: prevent temporary window creation +function! s:run_system(cmd, version) abort + if has('win32') && !has('nvim') && a:version > 0 && (has('python3') || has('python2')) + if a:version == 3 && has('python3') + let pyx = 'py3 ' + let python_eval = 'py3eval' + elseif a:version == 2 && has('python2') + let pyx = 'py2 ' + let python_eval = 'pyeval' + else + let pyx = 'pyx ' + let python_eval = 'pyxeval' + endif + let l:pc = 0 + exec pyx . 'import subprocess, vim' + exec pyx . '__argv = {"args":vim.eval("a:cmd"), "shell":True}' + exec pyx . '__argv["stdout"] = subprocess.PIPE' + exec pyx . '__argv["stderr"] = subprocess.STDOUT' + exec pyx . '__pp = subprocess.Popen(**__argv)' + exec pyx . '__return_text = __pp.stdout.read()' + exec pyx . '__pp.stdout.close()' + exec pyx . '__return_code = __pp.wait()' + exec 'let l:hr = '. python_eval .'("__return_text")' + exec 'let l:pc = '. python_eval .'("__return_code")' + let s:shell_error = l:pc + return l:hr + endif + let hr = system(a:cmd) + let s:shell_error = v:shell_error + return hr +endfunction + + " s:ExecuteCtags() {{{2 " Execute ctags with necessary shell settings " Partially based on the discussion at @@ -2908,7 +2941,8 @@ function! s:ExecuteCtags(ctags_cmd) abort call tagbar#debug#log('Exit code: ' . v:shell_error) redraw! else - silent let ctags_output = system(a:ctags_cmd) + let py_version = get(g:, 'tagbar_python', 1) + silent let ctags_output = s:run_system(a:ctags_cmd, py_version) endif if &shell =~? 'cmd\.exe'