Created
July 6, 2013 13:46
-
-
Save ichizok/5939936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCRIPT /Users/Experiment/.dotfiles/vim/bundle/vimproc.vim/autoload/vimproc.vim | |
Sourced 1 time | |
Total time: 0.004266 | |
Self time: 0.003283 | |
count total (s) self (s) | |
"============================================================================= | |
" FILE: vimproc.vim | |
" AUTHOR: Shougo Matsushita <[email protected]> (Modified) | |
" Yukihiro Nakadaira <yukihiro.nakadaira at gmail.com> (Original) | |
" Last Modified: 06 Jul 2013. | |
" License: MIT license {{{ | |
" Permission is hereby granted, free of charge, to any person obtaining | |
" a copy of this software and associated documentation files (the | |
" "Software"), to deal in the Software without restriction, including | |
" without limitation the rights to use, copy, modify, merge, publish, | |
" distribute, sublicense, and/or sell copies of the Software, and to | |
" permit persons to whom the Software is furnished to do so, subject to | |
" the following conditions: | |
" | |
" The above copyright notice and this permission notice shall be included | |
" in all copies or substantial portions of the Software. | |
" | |
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
" }}} | |
"============================================================================= | |
" Saving 'cpoptions' {{{ | |
1 0.000007 let s:save_cpo = &cpo | |
1 0.000007 set cpo&vim | |
" }}} | |
1 0.000003 function! s:print_error(string) | |
echohl Error | echomsg a:string | echohl None | |
endfunction | |
" MacVim trouble shooter {{{ | |
1 0.000355 if vimproc#util#is_mac() && !&encoding | |
1 0.000078 set encoding=utf-8 | |
1 0.000001 endif | |
"}}} | |
" Check 'encoding' "{{{ | |
1 0.000005 if &encoding =~# '^euc-jp' | |
call s:print_error('Sorry, vimproc is not supported this encoding environment.') | |
call s:print_error('You should set ''encoding'' option to "utf-8" ' | |
\ .'and set ''termencoding'' option to "euc-jp".') | |
finish | |
endif | |
"}}} | |
" Global options definition. "{{{ | |
" Set the default of g:vimproc_dll_path by judging OS "{{{ | |
1 0.000007 0.000005 if vimproc#util#is_windows() | |
if has('win64') | |
let s:vimproc_dll_basename = 'vimproc_win64.dll' | |
else | |
let s:vimproc_dll_basename = 'vimproc_win32.dll' | |
endif | |
elseif vimproc#util#is_cygwin() | |
let s:vimproc_dll_basename = 'vimproc_cygwin.dll' | |
elseif vimproc#util#is_mac() | |
1 0.000003 let s:vimproc_dll_basename = 'vimproc_mac.so' | |
1 0.000001 else | |
let s:vimproc_dll_basename = 'vimproc_unix.so' | |
endif | |
"}}} | |
1 0.000032 0.000018 call vimproc#util#set_default( | |
\ 'g:vimproc#dll_path', | |
\ expand('<sfile>:p:h') . '/' . s:vimproc_dll_basename, | |
\ 'g:vimproc_dll_path') | |
1 0.000002 unlet s:vimproc_dll_basename | |
1 0.000028 0.000015 call vimproc#util#set_default( | |
\ 'g:vimproc#password_pattern', | |
\ '\%(Enter \|[Oo]ld \|[Nn]ew \|login ' . | |
\'\|Kerberos \|CVS \|UNIX \| SMB \|LDAP \|\[sudo] ' . | |
\'\|^\|\n\|''s \)\%([Pp]assword\|[Pp]assphrase\)\>', | |
\ 'g:vimproc_password_pattern') | |
1 0.000028 0.000015 call vimproc#util#set_default( | |
\ 'g:vimproc#popen2_commands', { | |
\ 'sh' : 1, 'bash' : 1, 'zsh' : 1, 'csh' : 1, 'tcsh' : 1, | |
\ 'tmux' : 1, 'screen' : 1, 'su' : 1, | |
\ 'python' : 1, 'rhino' : 1, 'ipython' : 1, 'ipython3' : 1, 'yaourt' : 1, | |
\ }, 'g:vimproc_popen2_commands') | |
1 0.000018 0.000006 call vimproc#util#set_default( | |
\ 'g:stdinencoding', 'char') | |
1 0.000016 0.000006 call vimproc#util#set_default( | |
\ 'g:stdoutencoding', 'char') | |
1 0.000016 0.000006 call vimproc#util#set_default( | |
\ 'g:stderrencoding', 'char') | |
"}}} | |
" Constants {{{ | |
1 0.000002 let g:vimproc#SIGINT = 2 | |
1 0.000003 let g:vimproc#SIGQUIT = 3 | |
1 0.000001 let g:vimproc#SIGILL = 4 | |
1 0.000002 let g:vimproc#SIGABRT = 6 | |
1 0.000002 let g:vimproc#SIGFPE = 8 | |
1 0.000002 let g:vimproc#SIGKILL = 9 | |
1 0.000002 let g:vimproc#SIGSEGV = 11 | |
1 0.000002 let g:vimproc#SIGPIPE = 13 | |
1 0.000001 let g:vimproc#SIGALRM = 14 | |
1 0.000005 let g:vimproc#SIGTERM = 15 | |
1 0.000002 let g:vimproc#SIGUSR1 = 10 | |
1 0.000001 let g:vimproc#SIGUSR2 = 12 | |
1 0.000002 let g:vimproc#SIGCHLD = 17 | |
1 0.000002 let g:vimproc#SIGCONT = 18 | |
1 0.000002 let g:vimproc#SIGSTOP = 19 | |
1 0.000001 let g:vimproc#SIGTSTP = 20 | |
1 0.000002 let g:vimproc#SIGTTIN = 21 | |
1 0.000002 let g:vimproc#SIGTTOU = 22 | |
1 0.000002 let g:vimproc#SIGWINCH = 28 | |
" }}} | |
1 0.000044 0.000018 let g:vimproc#dll_path = | |
\ vimproc#util#iconv( | |
\ vimproc#util#substitute_path_separator(g:vimproc#dll_path), | |
\ &encoding, vimproc#util#termencoding()) | |
" Backward compatibility. | |
1 0.000003 let g:vimproc_password_pattern = g:vimproc#password_pattern | |
1 0.000040 if !filereadable(g:vimproc#dll_path) "{{{ | |
function! vimproc#get_last_status() | |
return v:shell_error | |
endfunction | |
function! vimproc#get_last_errmsg() | |
return '' | |
endfunction | |
function! vimproc#system(...) | |
return call('system', a:000) | |
endfunction | |
echoerr printf('vimproc''s DLL: "%s" is not found. | |
\ Please read :help vimproc and make it.', g:vimproc#dll_path) | |
finish | |
endif"}}} | |
1 0.000003 function! vimproc#version() "{{{ | |
return str2nr(printf('%2d%02d', 7, 1)) | |
endfunction"}}} | |
1 0.000002 function! vimproc#dll_version() "{{{ | |
let [dll_version] = s:libcall('vp_dlversion', []) | |
return str2nr(dll_version) | |
endfunction"}}} | |
"----------------------------------------------------------- | |
" API | |
1 0.000003 function! vimproc#open(filename) "{{{ | |
let filename = vimproc#util#iconv(fnamemodify(a:filename, ':p'), | |
\ &encoding, vimproc#util#termencoding()) | |
if filename =~ '^\%(https\?\|ftp\)://' | |
\ && !vimproc#host_exists(filename) | |
" URI is invalid. | |
call s:print_error('vimproc#open: URI "' . filename . '" is invalid.') | |
return | |
endif | |
" Detect desktop environment. | |
if vimproc#util#is_windows() | |
" For URI only. | |
"execute '!start rundll32 url.dll,FileProtocolHandler' filename | |
call s:libcall('vp_open', [filename]) | |
elseif has('win32unix') | |
" Cygwin. | |
call vimproc#system(['cygstart', filename]) | |
elseif executable('xdg-open') | |
" Linux. | |
call vimproc#system_bg(['xdg-open', filename]) | |
elseif exists('$KDE_FULL_SESSION') && $KDE_FULL_SESSION ==# 'true' | |
" KDE. | |
call vimproc#system_bg(['kioclient', 'exec', filename]) | |
elseif exists('$GNOME_DESKTOP_SESSION_ID') | |
" GNOME. | |
call vimproc#system_bg(['gnome-open', filename]) | |
elseif executable('exo-open') | |
" Xfce. | |
call vimproc#system_bg(['exo-open', filename]) | |
elseif vimproc#util#is_mac() && executable('open') | |
" Mac OS. | |
call vimproc#system_bg(['open', filename]) | |
else | |
" Give up. | |
call s:print_error('vimproc#open: Not supported.') | |
endif | |
endfunction"}}} | |
1 0.000003 function! vimproc#get_command_name(command, ...) "{{{ | |
let path = get(a:000, 0, $PATH) | |
let cnt = a:0 < 2 ? 1 : a:2 | |
let files = split(substitute(vimproc#util#substitute_path_separator( | |
\ vimproc#filepath#which(a:command, path)), '//', '/', 'g'), '\n') | |
if cnt < 0 | |
return files | |
endif | |
let file = get(files, 0, '') | |
if file == '' | |
throw printf( | |
\ 'vimproc#get_command_name: File "%s" is not found.', a:command) | |
endif | |
return file | |
endfunction"}}} | |
1 0.000004 function! s:system(cmdline, is_passwd, input, timeout, is_pty) "{{{ | |
if empty(a:cmdline) | |
let s:last_status = 0 | |
let s:last_errmsg = '' | |
return '' | |
endif | |
" Open pipe. | |
let subproc = (type(a:cmdline[0]) == type('')) ? vimproc#popen3(a:cmdline) : | |
\ a:is_pty ? vimproc#ptyopen(a:cmdline): | |
\ vimproc#pgroup_open(a:cmdline) | |
if a:input != '' | |
" Write input. | |
call subproc.stdin.write(a:input) | |
endif | |
if a:timeout > 0 && has('reltime') && v:version >= 702 | |
let start = reltime() | |
let timeout = a:timeout | |
else | |
let timeout = 0 | |
endif | |
if !a:is_passwd | |
call subproc.stdin.close() | |
endif | |
let output = '' | |
let s:last_errmsg = '' | |
while !subproc.stdout.eof || !subproc.stderr.eof | |
if timeout > 0 "{{{ | |
" Check timeout. | |
let end = split(reltimestr(reltime(start)))[0] * 1000 | |
if end > timeout && !subproc.stdout.eof | |
" Kill process. | |
" 15 == SIGTERM | |
try | |
call subproc.kill(15) | |
call subproc.waitpid() | |
catch | |
" Ignore error. | |
endtry | |
throw 'vimproc: vimproc#system(): Timeout.' | |
endif | |
endif"}}} | |
if !subproc.stdout.eof "{{{ | |
let out = subproc.stdout.read(1000, 0) | |
if a:is_passwd && out =~# g:vimproc_password_pattern | |
redraw | |
echo out | |
" Password input. | |
set imsearch=0 | |
let in = vimproc#util#iconv(inputsecret('Input Secret : ')."\<NL>", | |
\ &encoding, vimproc#util#termencoding()) | |
call subproc.stdin.write(in) | |
else | |
let output .= out | |
endif | |
endif"}}} | |
if !subproc.stderr.eof "{{{ | |
let out = subproc.stderr.read(1000, 0) | |
if a:is_passwd && out =~# g:vimproc_password_pattern | |
redraw | |
echo out | |
" Password input. | |
set imsearch=0 | |
let in = vimproc#util#iconv(inputsecret('Input Secret : ') . "\<NL>", | |
\ &encoding, vimproc#util#termencoding()) | |
call subproc.stdin.write(in) | |
else | |
let s:last_errmsg .= out | |
let output .= out | |
endif | |
endif"}}} | |
endwhile | |
let [cond, status] = subproc.waitpid() | |
" Newline convert. | |
if vimproc#util#is_mac() | |
let output = substitute(output, '\r\n\@!', '\n', 'g') | |
elseif has('win32') || has('win64') | |
let output = substitute(output, '\r\n', '\n', 'g') | |
endif | |
return output | |
endfunction"}}} | |
1 0.000003 function! vimproc#system(cmdline, ...) "{{{ | |
if type(a:cmdline) == type('') | |
if a:cmdline =~ '&\s*$' | |
let cmdline = substitute(a:cmdline, '&\s*$', '', '') | |
return vimproc#system_bg(cmdline) | |
endif | |
let args = vimproc#parser#parse_statements(a:cmdline) | |
for arg in args | |
let arg.statement = vimproc#parser#parse_pipe(arg.statement) | |
endfor | |
else | |
let args = [{'statement' : | |
\ [{ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | |
\ 'args' : a:cmdline }], 'condition' : 'always' }] | |
endif | |
let timeout = get(a:000, 1, 0) | |
let input = get(a:000, 0, '') | |
return s:system(args, 0, input, timeout, 0) | |
endfunction"}}} | |
1 0.000002 function! vimproc#system2(...) "{{{ | |
if empty(a:000) | |
return '' | |
endif | |
if len(a:0) > 1 | |
let args = deepcopy(a:000) | |
let args[1] = vimproc#util#iconv( | |
\ args[1], &encoding, vimproc#util#stdinencoding()) | |
else | |
let args = a:000 | |
endif | |
let output = call('vimproc#system', args) | |
" This function converts application encoding to &encoding. | |
let output = vimproc#util#iconv( | |
\ output, vimproc#util#stdoutencoding(), &encoding) | |
let s:last_errmsg = vimproc#util#iconv( | |
\ s:last_errmsg, vimproc#util#stderrencoding(), &encoding) | |
return output | |
endfunction"}}} | |
1 0.000003 function! vimproc#system_passwd(cmdline, ...) "{{{ | |
if type(a:cmdline) == type('') | |
let args = vimproc#parser#parse_pipe(a:cmdline) | |
else | |
let args = [{ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | |
\ 'args' : a:cmdline }] | |
endif | |
let timeout = a:0 >= 2 ? a:2 : 0 | |
let input = a:0 >= 1 ? a:1 : '' | |
let lang_save = $LANG | |
try | |
let $LANG = 'C' | |
return s:system(args, 1, input, timeout, 1) | |
finally | |
let $LANG = lang_save | |
endtry | |
endfunction"}}} | |
1 0.000002 function! vimproc#system_bg(cmdline) "{{{ | |
" Open pipe. | |
let subproc = vimproc#popen3(a:cmdline) | |
if empty(subproc) | |
" Not supported path error. | |
return '' | |
endif | |
" Close handles. | |
call s:close_all(subproc) | |
let s:bg_processes[subproc.pid] = subproc.pid | |
return '' | |
endfunction"}}} | |
1 0.000003 function! vimproc#system_gui(cmdline) "{{{ | |
if vimproc#util#is_windows() | |
silent execute ':!start ' . join(map(vimproc#parser#split_args(a:cmdline), '"\"".v:val."\""')) | |
return '' | |
else | |
return vimproc#system_bg(a:cmdline) | |
endif | |
endfunction"}}} | |
1 0.000003 function! vimproc#get_last_status() "{{{ | |
return s:last_status | |
endfunction"}}} | |
1 0.000002 function! vimproc#get_last_errmsg() "{{{ | |
return substitute(vimproc#util#iconv(s:last_errmsg, | |
\ vimproc#util#stderrencoding(), &encoding), '\n$', '', '') | |
endfunction"}}} | |
1 0.000002 function! vimproc#shellescape(string) "{{{ | |
return string(a:string) | |
endfunction"}}} | |
1 0.000003 function! vimproc#fopen(path, flags, ...) "{{{ | |
let mode = get(a:000, 0, 0644) | |
let fd = s:vp_file_open(a:path, a:flags, mode) | |
let proc = s:fdopen(fd, 'vp_file_close', 'vp_file_read', 'vp_file_write') | |
return proc | |
endfunction"}}} | |
1 0.000006 function! vimproc#popen2(args) "{{{ | |
let args = type(a:args) == type('') ? | |
\ vimproc#parser#split_args(a:args) : | |
\ a:args | |
return s:plineopen(2, [{ | |
\ 'args' : args, | |
\ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | |
\ }], 0) | |
endfunction"}}} | |
1 0.000003 function! vimproc#popen3(args) "{{{ | |
let args = type(a:args) == type('') ? | |
\ vimproc#parser#split_args(a:args) : | |
\ a:args | |
return s:plineopen(3, [{ | |
\ 'args' : args, | |
\ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | |
\ }], 0) | |
endfunction"}}} | |
1 0.000002 function! vimproc#plineopen2(commands, ...) "{{{ | |
let commands = type(a:commands) == type('') ? | |
\ vimproc#parser#parse_pipe(a:commands) : | |
\ a:commands | |
let is_pty = get(a:000, 0, 0) | |
return s:plineopen(2, commands, is_pty) | |
endfunction"}}} | |
1 0.000003 function! vimproc#plineopen3(commands, ...) "{{{ | |
let commands = type(a:commands) == type('') ? | |
\ vimproc#parser#parse_pipe(a:commands) : | |
\ a:commands | |
let is_pty = get(a:000, 0, 0) | |
return s:plineopen(3, commands, is_pty) | |
endfunction"}}} | |
1 0.000003 function! s:plineopen(npipe, commands, is_pty) "{{{ | |
let pid_list = [] | |
let stdin_list = [] | |
let stdout_list = [] | |
let stderr_list = [] | |
let npipe = a:npipe | |
" Open input. | |
let hstdin = (empty(a:commands) || a:commands[0].fd.stdin == '')? | |
\ 0 : vimproc#fopen(a:commands[0].fd.stdin, 'O_RDONLY').fd | |
let is_pty = !vimproc#util#is_windows() && a:is_pty | |
let cnt = 0 | |
for command in a:commands | |
if is_pty && command.fd.stdout == '' && cnt == 0 | |
\ && len(a:commands) != 1 | |
" pty_open() use pipe. | |
let hstdout = 1 | |
else | |
let mode = 'O_WRONLY | O_CREAT' | |
if command.fd.stdout =~ '^>' | |
let mode .= ' | O_APPEND' | |
let command.fd.stdout = command.fd.stdout[1:] | |
else | |
let mode .= ' | O_TRUNC' | |
endif | |
let hstdout = s:is_pseudo_device(command.fd.stdout) ? | |
\ 0 : vimproc#fopen(command.fd.stdout, mode).fd | |
endif | |
if is_pty && command.fd.stderr == '' && cnt == 0 | |
\ && len(a:commands) != 1 | |
" pty_open() use pipe. | |
let hstderr = 1 | |
else | |
let mode = 'O_WRONLY | O_CREAT' | |
if command.fd.stderr =~ '^>' | |
let mode .= ' | O_APPEND' | |
let command.fd.stderr = command.fd.stderr[1:] | |
else | |
let mode .= ' | O_TRUNC' | |
endif | |
let hstderr = s:is_pseudo_device(command.fd.stderr) ? | |
\ 0 : vimproc#fopen(command.fd.stderr, mode).fd | |
endif | |
if command.fd.stderr ==# '/dev/stdout' | |
let npipe = 2 | |
endif | |
let args = s:convert_args(command.args) | |
let command_name = fnamemodify(args[0], ':t:r') | |
let pty_npipe = cnt == 0 | |
\ && hstdin == 0 && hstdout == 0 && hstderr == 0 | |
\ && exists('g:vimproc_popen2_commands') | |
\ && get(g:vimproc_popen2_commands, command_name, 0) != 0 ? | |
\ 2 : npipe | |
if is_pty && (cnt == 0 || cnt == len(a:commands)-1) | |
" Use pty_open(). | |
let pipe = s:vp_pty_open(pty_npipe, winwidth(0)-5, winheight(0), | |
\ hstdin, hstdout, hstderr, args) | |
else | |
let pipe = s:vp_pipe_open(pty_npipe, | |
\ hstdin, hstdout, hstderr, args) | |
endif | |
if len(pipe) == 4 | |
let [pid, fd_stdin, fd_stdout, fd_stderr] = pipe | |
let stderr = s:fdopen(fd_stderr, | |
\ 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
else | |
let [pid, fd_stdin, fd_stdout] = pipe | |
let stderr = s:closed_fdopen( | |
\ 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
endif | |
call add(pid_list, pid) | |
let stdin = s:fdopen(fd_stdin, | |
\ 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
let stdin.is_pty = is_pty | |
\ && (cnt == 0 || cnt == len(a:commands)-1) | |
\ && hstdin == 0 | |
call add(stdin_list, stdin) | |
let stdout = s:fdopen(fd_stdout, | |
\ 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
let stdout.is_pty = is_pty | |
\ && (cnt == 0 || cnt == len(a:commands)-1) | |
\ && hstdout == 0 | |
call add(stdout_list, stdout) | |
let stderr.is_pty = is_pty | |
\ && (cnt == 0 || cnt == len(a:commands)-1) | |
\ && hstderr == 0 | |
call add(stderr_list, stderr) | |
let hstdin = stdout_list[-1].fd | |
let cnt += 1 | |
endfor | |
let proc = {} | |
let proc.pid_list = pid_list | |
let proc.pid = pid_list[-1] | |
let proc.stdin = s:fdopen_pipes(stdin_list, | |
\ 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
let proc.stdout = s:fdopen_pipes(stdout_list, | |
\ 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
let proc.stderr = s:fdopen_pipes(stderr_list, | |
\ 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
let proc.get_winsize = s:funcref('vp_get_winsize') | |
let proc.set_winsize = s:funcref('vp_set_winsize') | |
let proc.kill = s:funcref('vp_kill') | |
let proc.waitpid = s:funcref('vp_waitpid') | |
let proc.checkpid = s:funcref('vp_checkpid') | |
let proc.is_valid = 1 | |
let proc.is_pty = is_pty | |
if a:is_pty | |
let proc.ttyname = '' | |
let proc.get_winsize = s:funcref('vp_get_winsize') | |
let proc.set_winsize = s:funcref('vp_set_winsize') | |
endif | |
return proc | |
endfunction"}}} | |
1 0.000003 function! s:is_pseudo_device(filename) "{{{ | |
if vimproc#util#is_windows() && ( | |
\ a:filename ==# '/dev/stdin' | |
\ || a:filename ==# '/dev/stdout' | |
\ || a:filename ==# '/dev/stderr') | |
return 1 | |
endif | |
return a:filename == '' | |
\ || a:filename ==# '/dev/null' | |
\ || a:filename ==# '/dev/clip' | |
\ || a:filename ==# '/dev/quickfix' | |
endfunction"}}} | |
1 0.000003 function! vimproc#pgroup_open(statements, ...) "{{{ | |
if type(a:statements) == type('') | |
let statements = | |
\ vimproc#parser#parse_statements(a:statements) | |
for statement in statements | |
let statement.statement = | |
\ vimproc#parser#parse_pipe(statement.statement) | |
endfor | |
else | |
let statements = a:statements | |
endif | |
let is_pty = get(a:000, 0, 0) | |
let npipe = get(a:000, 1, 3) | |
return s:pgroup_open(statements, is_pty && !vimproc#util#is_windows(), npipe) | |
endfunction"}}} | |
1 0.000003 function! s:pgroup_open(statements, is_pty, npipe) "{{{ | |
let proc = {} | |
let proc.current_proc = | |
\ vimproc#plineopen{a:npipe}(a:statements[0].statement, a:is_pty) | |
let proc.pid = proc.current_proc.pid | |
let proc.pid_list = proc.current_proc.pid_list | |
let proc.condition = a:statements[0].condition | |
let proc.statements = a:statements[1:] | |
let proc.stdin = s:fdopen_pgroup(proc, proc.current_proc.stdin, | |
\ 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let proc.stdout = s:fdopen_pgroup(proc, proc.current_proc.stdout, | |
\ 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let proc.stderr = s:fdopen_pgroup(proc, proc.current_proc.stderr, | |
\ 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let proc.kill = s:funcref('vp_pgroup_kill') | |
let proc.waitpid = s:funcref('vp_pgroup_waitpid') | |
let proc.is_valid = 1 | |
let proc.is_pty = 0 | |
" echomsg expand('<sfile>') | |
" echomsg 'open:' string(map(copy(proc.current_proc.stdin.fd), 'v:val.fd')) | |
" echomsg 'open:' string(map(copy(proc.current_proc.stdout.fd), 'v:val.fd')) | |
" echomsg 'open:' string(map(copy(proc.current_proc.stderr.fd), 'v:val.fd')) | |
return proc | |
endfunction"}}} | |
1 0.000002 function! vimproc#ptyopen(commands, ...) "{{{ | |
let commands = type(a:commands) == type('') ? | |
\ vimproc#parser#parse_pipe(a:commands) : | |
\ a:commands | |
let npipe = get(a:000, 0, 3) | |
return s:plineopen(npipe, commands, !vimproc#util#is_windows()) | |
endfunction"}}} | |
1 0.000003 function! vimproc#socket_open(host, port) "{{{ | |
let fd = s:vp_socket_open(a:host, a:port) | |
return s:fdopen(fd, 'vp_socket_close', 'vp_socket_read', 'vp_socket_write') | |
endfunction"}}} | |
1 0.000002 function! vimproc#host_exists(host) "{{{ | |
let rval = s:vp_host_exists( | |
\ substitute(substitute(a:host, '^\a\+://', '', ''), '/.*$', '', '')) | |
return 0 + rval | |
endfunction"}}} | |
1 0.000003 function! vimproc#kill(pid, sig) "{{{ | |
if a:sig == 0 && vimproc#util#is_windows() | |
" Use waitpid(). | |
let [cond, status] = s:waitpid(a:pid) | |
return cond ==# 'run' | |
endif | |
try | |
let [ret] = s:libcall('vp_kill', [a:pid, a:sig]) | |
catch /kill() error:/ | |
let s:last_errmsg = v:exception | |
return 1 | |
endtry | |
return ret | |
endfunction"}}} | |
1 0.000003 function! vimproc#decode_signal(signal) "{{{ | |
if a:signal == 2 | |
return 'SIGINT' | |
elseif a:signal == 3 | |
return 'SIGQUIT' | |
elseif a:signal == 4 | |
return 'SIGILL' | |
elseif a:signal == 6 | |
return 'SIGABRT' | |
elseif a:signal == 8 | |
return 'SIGFPE' | |
elseif a:signal == 9 | |
return 'SIGKILL' | |
elseif a:signal == 11 | |
return 'SIGSEGV' | |
elseif a:signal == 13 | |
return 'SIGPIPE' | |
elseif a:signal == 14 | |
return 'SIGALRM' | |
elseif a:signal == 15 | |
return 'SIGTERM' | |
elseif a:signal == 10 | |
return 'SIGUSR1' | |
elseif a:signal == 12 | |
return 'SIGUSR2' | |
elseif a:signal == 17 | |
return 'SIGCHLD' | |
elseif a:signal == 18 | |
return 'SIGCONT' | |
elseif a:signal == 19 | |
return 'SIGSTOP' | |
elseif a:signal == 20 | |
return 'SIGTSTP' | |
elseif a:signal == 21 | |
return 'SIGTTIN' | |
elseif a:signal == 22 | |
return 'SIGTTOU' | |
else | |
return 'UNKNOWN' | |
endif | |
endfunction"}}} | |
1 0.000003 function! vimproc#write(filename, string, ...) "{{{ | |
if a:string == '' | |
return | |
endif | |
let mode = get(a:000, 0, | |
\ a:filename =~ '^>' ? 'a' : 'w') | |
let filename = a:filename =~ '^>' ? | |
\ a:filename[1:] : a:filename | |
if filename ==# '/dev/null' | |
" Nothing. | |
elseif filename ==# '/dev/clip' | |
" Write to clipboard. | |
if mode =~ 'a' | |
let @+ .= a:string | |
else | |
let @+ = a:string | |
endif | |
elseif filename ==# '/dev/quickfix' | |
" Write to quickfix. | |
let qflist = getqflist() | |
for str in split(a:string, '\n\|\r\n') | |
if str =~ '^.\+:.\+:.\+$' | |
let line = split(str[2:], ':') | |
let filename = str[:1] . line[0] | |
if len(line) >= 3 && line[1] =~ '^\d\+$' | |
call add(qflist, { | |
\ 'filename' : filename, | |
\ 'lnum' : line[1], | |
\ 'text' : join(line[2:], ':'), | |
\ }) | |
else | |
call add(qflist, { | |
\ 'text' : str, | |
\ }) | |
endif | |
endif | |
endfor | |
call setqflist(qflist) | |
else | |
" Write file. | |
let mode = 'O_WRONLY | O_CREAT' | |
if mode =~ 'a' | |
" Append mode. | |
let mode .= '| O_APPEND' | |
endif | |
let hfile = vimproc#fopen(filename, mode) | |
call hfile.write(a:string) | |
call hfile.close() | |
endif | |
endfunction"}}} | |
1 0.000003 function! vimproc#readdir(dirname) "{{{ | |
let dirname = substitute(substitute( | |
\ vimproc#util#expand(a:dirname), | |
\ '\\', '/', 'g'), '/$', '', '') | |
if dirname == '' | |
let dirname = getcwd() | |
endif | |
if !isdirectory(dirname) | |
return [] | |
endif | |
let dirname = vimproc#util#iconv(dirname, &encoding, | |
\ vimproc#util#termencoding()) | |
try | |
let files = s:libcall('vp_readdir', [dirname]) | |
catch /vp_readdir/ | |
return [] | |
endtry | |
call map(files, 'vimproc#util#iconv( | |
\ v:val, vimproc#util#termencoding(), &encoding)') | |
if vimproc#util#is_windows() | |
call map(files, 'vimproc#util#substitute_path_separator(v:val)') | |
endif | |
return files | |
endfunction"}}} | |
1 0.000003 function! vimproc#delete_trash(filename) "{{{ | |
if !vimproc#util#is_windows() | |
call s:print_error('Not implemented in this platform.') | |
return | |
endif | |
let filename = a:filename | |
if !filewritable(filename) && !isdirectory(filename) | |
return 1 | |
endif | |
" Substitute path separator to "/". | |
let filename = substitute( | |
\ fnamemodify(filename, ':p'), '/', '\\', 'g') | |
" Delete last /. | |
if filename =~ '[^:][/\\]$' | |
" Delete last /. | |
let filename = filename[: -2] | |
endif | |
" Encoding conversion. | |
let filename = vimproc#util#iconv(filename, | |
\ &encoding, vimproc#util#termencoding()) | |
let [ret] = s:libcall('vp_delete_trash', [filename]) | |
return str2nr(ret) | |
endfunction"}}} | |
1 0.000003 function! vimproc#test_readdir(dirname) "{{{ | |
let start = reltime() | |
call split(glob(a:dirname.'/*'), '\n') | |
echomsg reltimestr(reltime(start)) | |
let start = reltime() | |
call vimproc#readdir(a:dirname) | |
echomsg reltimestr(reltime(start)) | |
endfunction"}}} | |
1 0.000003 function! s:close_all(self) "{{{ | |
if has_key(a:self, 'stdin') | |
call a:self.stdin.close() | |
endif | |
if has_key(a:self, 'stdout') | |
call a:self.stdout.close() | |
endif | |
if has_key(a:self, 'stderr') | |
call a:self.stderr.close() | |
endif | |
endfunction"}}} | |
1 0.000002 function! s:close() dict "{{{ | |
if self.is_valid | |
call self.f_close() | |
endif | |
let self.is_valid = 0 | |
let self.eof = 1 | |
let self.__eof = 1 | |
endfunction"}}} | |
1 0.000003 function! s:read(...) dict "{{{ | |
if self.__eof | |
let self.eof = 1 | |
return '' | |
endif | |
let number = get(a:000, 0, -1) | |
let timeout = get(a:000, 1, s:read_timeout) | |
let [hd, eof] = self.f_read(number, timeout) | |
let self.eof = eof | |
let self.__eof = eof | |
if hd == '' | |
return '' | |
endif | |
" Note: if output string is too long, if_lua is too slow. | |
return (vimproc#util#has_lua() && len(hd) < 1024) ? | |
\ s:hd2str_lua([hd]) : s:hd2str([hd]) | |
" return s:hd2str([hd]) | |
endfunction"}}} | |
1 0.000002 function! s:read_lines(...) dict "{{{ | |
let res = self.buffer | |
while !self.eof && stridx(res, "\n") < 0 | |
let out = call(self.read, a:000, self) | |
if out == '' | |
break | |
endif | |
let res .= out | |
endwhile | |
let lines = split(res, '\r\?\n', 1) | |
if self.eof | |
let self.buffer = '' | |
return lines | |
else | |
let self.buffer = empty(lines)? '' : lines[-1] | |
let lines = lines[ : -2] | |
endif | |
let self.eof = (self.buffer != '') ? 0 : self.__eof | |
return lines | |
endfunction"}}} | |
1 0.000002 function! s:read_line(...) dict "{{{ | |
let lines = call(self.read_lines, a:000, self) | |
let self.buffer = join(lines[1:], "\n") . self.buffer | |
let self.eof = (self.buffer != '') ? 0 : self.__eof | |
return get(lines, 0, '') | |
endfunction"}}} | |
1 0.000002 function! s:write(str, ...) dict "{{{ | |
let timeout = get(a:000, 0, s:write_timeout) | |
let hd = s:str2hd(a:str) | |
return self.f_write(hd, timeout) | |
endfunction"}}} | |
1 0.000007 function! s:fdopen(fd, f_close, f_read, f_write) "{{{ | |
return { | |
\ 'fd' : a:fd, | |
\ 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', | |
\ 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), | |
\ 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), | |
\ 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'), | |
\} | |
endfunction"}}} | |
1 0.000002 function! s:closed_fdopen(f_close, f_read, f_write) "{{{ | |
return { | |
\ 'fd' : -1, | |
\ 'eof' : 1, '__eof' : 1, 'is_valid' : 0, 'buffer' : '', | |
\ 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), | |
\ 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), | |
\ 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'), | |
\} | |
endfunction"}}} | |
1 0.000003 function! s:fdopen_pty(fd_stdin, fd_stdout, f_close, f_read, f_write) "{{{ | |
return { | |
\ 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', | |
\ 'fd_stdin' : a:fd_stdin, 'fd_stdout' : a:fd_stdout, | |
\ 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), | |
\ 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), | |
\ 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'), | |
\} | |
endfunction"}}} | |
1 0.000003 function! s:fdopen_pipes(fd, f_close, f_read, f_write) "{{{ | |
return { | |
\ 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', | |
\ 'fd' : a:fd, | |
\ 'f_close' : s:funcref(a:f_close), | |
\ 'close' : s:funcref('close'), 'read' : s:funcref(a:f_read), 'write' : s:funcref(a:f_write), | |
\ 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'), | |
\} | |
endfunction"}}} | |
1 0.000004 function! s:fdopen_pgroup(proc, fd, f_close, f_read, f_write) "{{{ | |
return { | |
\ 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', | |
\ 'proc' : a:proc, 'fd' : a:fd, | |
\ 'f_close' : s:funcref(a:f_close), | |
\ 'close' : s:funcref('close'), 'read' : s:funcref(a:f_read), 'write' : s:funcref(a:f_write), | |
\ 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'), | |
\} | |
endfunction"}}} | |
1 0.000002 function! s:garbage_collect(is_force) "{{{ | |
for pid in values(s:bg_processes) | |
" Check processes. | |
try | |
let [cond, status] = s:libcall('vp_waitpid', [pid]) | |
" echomsg string([pid, cond, status]) | |
if cond !=# 'run' || a:is_force | |
if cond !=# 'exit' | |
" Kill process. | |
" 15 == SIGTERM | |
call vimproc#kill(pid, 15) | |
endif | |
if vimproc#util#is_windows() | |
call s:libcall('vp_close_handle', [pid]) | |
endif | |
call remove(s:bg_processes, pid) | |
endif | |
catch | |
" Ignore error. | |
endtry | |
endfor | |
endfunction"}}} | |
"----------------------------------------------------------- | |
" UTILS | |
1 0.000003 function! s:str2hd(str) | |
return join(map(range(len(a:str)), | |
\ 'printf("%02X", char2nr(a:str[v:val]))'), '') | |
endfunction | |
1 0.000002 function! s:hd2str(hd) | |
" a:hd is a list because to avoid copying the value. | |
return get(s:libcall('vp_decode', [a:hd[0]]), 0, '') | |
endfunction | |
1 0.000002 function! s:hd2str_lua(hd) | |
let ret = [] | |
lua << EOF | |
do | |
local ret = vim.eval('ret') | |
local hd = vim.eval('a:hd') | |
if hd[0] == nil then | |
hd[0] = '' | |
end | |
local len = string.len(hd[0]) | |
local s = '' | |
for i = 1, len, 2 do | |
s = s .. string.char(tonumber(string.sub(hd[0], i, i+1), 16)) | |
end | |
ret:add(s) | |
end | |
EOF | |
return ret[0] | |
endfunction | |
1 0.000002 function! s:str2list(str) | |
return map(range(len(a:str)), 'char2nr(a:str[v:val])') | |
endfunction | |
1 0.000002 function! s:list2str(lis) | |
return s:hd2str(s:list2hd([a:lis])) | |
endfunction | |
1 0.000002 function! s:hd2list(hd) | |
return map(split(a:hd, '..\zs'), 'str2nr(v:val, 16)') | |
endfunction | |
1 0.000002 function! s:list2hd(lis) | |
return join(map(a:lis, 'printf("%02X", v:val)'), '') | |
endfunction | |
1 0.000002 function! s:convert_args(args) "{{{ | |
if empty(a:args) | |
return [] | |
endif | |
if vimproc#util#is_windows() && !executable(a:args[0]) | |
" Search from internal commands. | |
let internal_commands = [ | |
\ 'copy', 'dir', 'echo', 'erase', 'ftype', | |
\ 'md', 'mkdir', 'move', 'path', 'rd', 'ren', 'rename', | |
\ 'rmdir', 'start', 'time', 'type', 'ver', 'vol'] | |
let index = index(internal_commands, a:args[0]) | |
if index >= 0 | |
" Use cmd.exe | |
return ['cmd', '/c', internal_commands[index]] + a:args[1:] | |
endif | |
endif | |
let command_name = vimproc#get_command_name(a:args[0]) | |
return vimproc#analyze_shebang(command_name) + a:args[1:] | |
endfunction"}}} | |
1 0.000003 function! vimproc#analyze_shebang(filename) "{{{ | |
if !filereadable(a:filename) || | |
\ getfsize(a:filename) > 100000 || | |
\ (vimproc#util#is_windows() && | |
\ '.'.fnamemodify(a:filename, ':e') !~? | |
\ '^'.substitute($PATHEXT, ';', '$\\|^', 'g').'$') | |
" Maybe a binary file. | |
return [a:filename] | |
endif | |
let lines = readfile(a:filename, '', 1) | |
if empty(lines) || lines[0] !~ '^#!.\+' | |
" Shebang not found. | |
return [a:filename] | |
endif | |
" Get shebang line. | |
let shebang = split(matchstr(lines[0], '^#!\zs.\+')) | |
" Convert command name. | |
if vimproc#util#is_windows() | |
\ && shebang[0] =~ '^/' | |
let shebang[0] = vimproc#get_command_name( | |
\ fnamemodify(shebang[0], ':t')) | |
endif | |
return shebang + [a:filename] | |
endfunction"}}} | |
"----------------------------------------------------------- | |
" LOW LEVEL API | |
1 0.000003 augroup vimproc | |
1 0.000008 autocmd VimLeave * call s:finalize() | |
1 0.000010 autocmd CursorHold,BufWritePost * call s:garbage_collect(0) | |
1 0.000001 augroup END | |
" Initialize. | |
1 0.000003 let s:lasterr = [] | |
1 0.000002 let s:read_timeout = 100 | |
1 0.000001 let s:write_timeout = 100 | |
1 0.000002 let s:bg_processes = {} | |
1 0.000014 0.000005 if vimproc#util#has_lua() | |
1 0.000003 function! s:split(str, sep) | |
let result = [] | |
lua << EOF | |
do | |
local result = vim.eval('result') | |
local str = vim.eval('a:str') | |
local sep = vim.eval('a:sep') | |
local last | |
if string.find(str, sep, 1, true) == nil then | |
result:add(str) | |
else | |
for part, pos in string.gmatch(str, | |
'(.-)' .. sep .. '()') do | |
result:add(part) | |
last = pos | |
end | |
result:add(string.sub(str, last)) | |
end | |
end | |
EOF | |
return result | |
endfunction | |
1 0.000002 else | |
function! s:split(str, sep) | |
let [result, pos] = [[], 0] | |
while 1 | |
let tmp = stridx(a:str, a:sep, pos) | |
if tmp == -1 | |
call add(result, strpart(a:str, pos)) | |
break | |
endif | |
call add(result, strpart(a:str, pos, tmp - pos)) | |
let pos = tmp + 1 | |
endwhile | |
return result | |
endfunction | |
endif | |
1 0.000003 function! s:libcall(func, args) "{{{ | |
" End Of Value | |
let EOV = "\xFF" | |
let args = empty(a:args) ? '' : (join(reverse(copy(a:args)), EOV) . EOV) | |
let stack_buf = libcall(g:vimproc#dll_path, a:func, args) | |
let result = s:split(stack_buf, EOV) | |
if !empty(result) && result[-1] != '' | |
if stack_buf[len(stack_buf) - 1] ==# EOV | |
" Note: If &encoding equals "cp932" and output ends multibyte first byte, | |
" will fail split. | |
return result | |
endif | |
let s:lasterr = result | |
let msg = vimproc#util#iconv(string(result), | |
\ vimproc#util#termencoding(), &encoding) | |
throw printf('vimproc: %s: %s', a:func, msg) | |
endif | |
return result[:-2] | |
endfunction"}}} | |
1 0.000003 function! s:SID_PREFIX() | |
if !exists('s:sid_prefix') | |
let s:sid_prefix = matchstr(expand('<sfile>'), | |
\ '<SNR>\d\+_\zeSID_PREFIX$') | |
endif | |
return s:sid_prefix | |
endfunction | |
" Get funcref. | |
1 0.000002 function! s:funcref(funcname) | |
return function(s:SID_PREFIX().a:funcname) | |
endfunction | |
1 0.000002 function! s:finalize() | |
call s:garbage_collect(1) | |
if exists('s:dll_handle') | |
call s:vp_dlclose(s:dll_handle) | |
endif | |
endfunction | |
1 0.000002 function! s:vp_dlopen(path) | |
let [handle] = s:libcall('vp_dlopen', [a:path]) | |
return handle | |
endfunction | |
1 0.000002 function! s:vp_dlclose(handle) | |
call s:libcall('vp_dlclose', [a:handle]) | |
endfunction | |
1 0.000002 function! s:vp_file_open(path, flags, mode) | |
let [fd] = s:libcall('vp_file_open', [a:path, a:flags, a:mode]) | |
return fd | |
endfunction | |
1 0.000001 function! s:vp_file_close() dict | |
if self.fd != 0 | |
call s:libcall('vp_file_close', [self.fd]) | |
let self.fd = 0 | |
endif | |
endfunction | |
1 0.000003 function! s:vp_file_read(number, timeout) dict | |
let [hd, eof] = s:libcall('vp_file_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
endfunction | |
1 0.000002 function! s:vp_file_write(hd, timeout) dict | |
let [nleft] = s:libcall('vp_file_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
endfunction | |
1 0.000002 function! s:quote_arg(arg) | |
return a:arg =~ '[ "]' ? '"' . substitute(a:arg, '"', '\\"', 'g') . '"' : a:arg | |
endfunction | |
1 0.000003 function! s:vp_pipe_open(npipe, hstdin, hstdout, hstderr, argv) "{{{ | |
if vimproc#util#is_windows() | |
let cmdline = s:quote_arg(substitute(a:argv[0], '/', '\', 'g')) | |
for arg in a:argv[1:] | |
let cmdline .= ' ' . s:quote_arg(arg) | |
endfor | |
let [pid; fdlist] = s:libcall('vp_pipe_open', | |
\ [a:npipe, a:hstdin, a:hstdout, a:hstderr, cmdline]) | |
else | |
let [pid; fdlist] = s:libcall('vp_pipe_open', | |
\ [a:npipe, a:hstdin, a:hstdout, a:hstderr, len(a:argv)] + a:argv) | |
endif | |
if a:npipe != len(fdlist) | |
call s:print_error(printf('a:npipe = %d, a:argv = %s', a:npipe, string(a:argv))) | |
call s:print_error(printf('fdlist = %s', string(fdlist))) | |
echoerr 'Bug behavior is detected!: ' . pid | |
endif | |
return [pid] + fdlist | |
endfunction"}}} | |
1 0.000002 function! s:vp_pipe_close() dict | |
" echomsg 'close:'.self.fd | |
if self.fd != 0 | |
call s:libcall('vp_pipe_close', [self.fd]) | |
let self.fd = 0 | |
endif | |
endfunction | |
1 0.000002 function! s:vp_pipes_close() dict | |
for fd in self.fd | |
try | |
call fd.close() | |
catch /vimproc: vp_pipe_close: / | |
" Ignore error. | |
endtry | |
endfor | |
endfunction | |
1 0.000002 function! s:vp_pgroup_close() dict | |
call self.fd.close() | |
endfunction | |
1 0.000001 function! s:vp_pipe_read(number, timeout) dict | |
if self.fd == 0 | |
return ['', 1] | |
endif | |
let [hd, eof] = s:libcall('vp_pipe_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
endfunction | |
1 0.000002 function! s:vp_pipe_write(hd, timeout) dict | |
if self.fd == 0 | |
return 0 | |
endif | |
let [nleft] = s:libcall('vp_pipe_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
endfunction | |
1 0.000002 function! s:read_pipes(...) dict "{{{ | |
if type(self.fd[-1]) != type({}) | |
let self.eof = 1 | |
return '' | |
endif | |
let number = get(a:000, 0, -1) | |
let timeout = get(a:000, 1, s:read_timeout) | |
let output = self.fd[-1].read(number, timeout) | |
let self.eof = self.fd[-1].eof | |
return output | |
endfunction"}}} | |
1 0.000005 function! s:write_pipes(str, ...) dict "{{{ | |
let timeout = get(a:000, 0, s:write_timeout) | |
if self.fd[0].eof | |
return 0 | |
endif | |
" Write data. | |
let nleft = self.fd[0].write(a:str, timeout) | |
let self.eof = self.fd[0].eof | |
return nleft | |
endfunction"}}} | |
1 0.000002 function! s:read_pgroup(...) dict "{{{ | |
let number = get(a:000, 0, -1) | |
let timeout = get(a:000, 1, s:read_timeout) | |
let output = '' | |
if !self.fd.eof | |
let output = self.fd.read(number, timeout) | |
endif | |
if self.proc.current_proc.stdout.eof && self.proc.current_proc.stderr.eof | |
" Get status. | |
let [cond, status] = self.proc.current_proc.waitpid() | |
if empty(self.proc.statements) | |
\ || (self.proc.condition ==# 'true' && status) | |
\ || (self.proc.condition ==# 'false' && !status) | |
let self.proc.statements = [] | |
" Caching status. | |
let self.proc.cond = cond | |
let self.proc.status = status | |
else | |
" Initialize next statement. | |
let proc = vimproc#plineopen3(self.proc.statements[0].statement) | |
let self.proc.current_proc = proc | |
let self.pid = proc.pid | |
let self.pid_list = proc.pid_list | |
let self.proc.condition = self.proc.statements[0].condition | |
let self.proc.statements = self.proc.statements[1:] | |
let self.proc.stdin = s:fdopen_pgroup(self.proc, proc.stdin, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let self.proc.stdout = s:fdopen_pgroup(self.proc, proc.stdout, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let self.proc.stderr = s:fdopen_pgroup(self.proc, proc.stderr, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
endif | |
endif | |
if self.proc.current_proc.stdout.eof | |
let self.proc.stdout.eof = 1 | |
let self.proc.stdout.__eof = 1 | |
endif | |
if self.proc.current_proc.stderr.eof | |
let self.proc.stderr.eof = 1 | |
let self.proc.stderr.__eof = 1 | |
endif | |
return output | |
endfunction"}}} | |
1 0.000003 function! s:write_pgroup(str, ...) dict "{{{ | |
let timeout = get(a:000, 0, s:write_timeout) | |
let nleft = 0 | |
if !self.fd.eof | |
" Write data. | |
let nleft = self.fd.write(a:str, timeout) | |
endif | |
return nleft | |
endfunction"}}} | |
1 0.000003 function! s:vp_pty_open(npipe, width, height, hstdin, hstdout, hstderr, argv) | |
let [pid; fdlist] = s:libcall('vp_pty_open', | |
\ [a:npipe, a:width, a:height, | |
\ a:hstdin, a:hstdout, a:hstderr, len(a:argv)] + a:argv) | |
return [pid] + fdlist | |
endfunction | |
1 0.000002 function! s:vp_pty_close() dict | |
call s:libcall('vp_pty_close', [self.fd]) | |
endfunction | |
1 0.000002 function! s:vp_pty_read(number, timeout) dict | |
let [hd, eof] = s:libcall('vp_pty_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
endfunction | |
1 0.000005 function! s:vp_pty_write(hd, timeout) dict | |
let [nleft] = s:libcall('vp_pty_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
endfunction | |
1 0.000002 function! s:vp_get_winsize() dict | |
if self.is_pty && vimproc#util#is_windows() | |
return [winwidth(0)-5, winheight(0)] | |
endif | |
for pid in self.pid_list | |
let [width, height] = s:libcall('vp_pty_get_winsize', [pid]) | |
endfor | |
return [width, height] | |
endfunction | |
1 0.000002 function! s:vp_set_winsize(width, height) dict | |
if vimproc#util#is_windows() || !self.is_valid | |
" Not implemented. | |
return | |
endif | |
if self.is_pty | |
if self.stdin.eof == 0 && self.stdin.fd[-1].is_pty | |
call s:libcall('vp_pty_set_winsize', | |
\ [self.stdin.fd[-1].fd, a:width-5, a:height]) | |
endif | |
if self.stdout.eof == 0 && self.stdout.fd[0].is_pty | |
call s:libcall('vp_pty_set_winsize', | |
\ [self.stdout.fd[0].fd, a:width-5, a:height]) | |
endif | |
if self.stderr.eof == 0 && self.stderr.fd[0].is_pty | |
call s:libcall('vp_pty_set_winsize', | |
\ [self.stderr.fd[0].fd, a:width-5, a:height]) | |
endif | |
endif | |
" Send SIGWINCH = 28 signal. | |
for pid in self.pid_list | |
call vimproc#kill(pid, 28) | |
endfor | |
endfunction | |
1 0.000003 function! s:vp_kill(sig) dict | |
if a:sig != 0 | |
call s:close_all(self) | |
let self.is_valid = 0 | |
endif | |
let ret = 0 | |
for pid in get(self, 'pid_list', [self.pid]) | |
let ret = vimproc#kill(pid, a:sig) | |
endfor | |
return ret | |
endfunction | |
1 0.000002 function! s:vp_pgroup_kill(sig) dict | |
if a:sig != 0 | |
call s:close_all(self) | |
let self.is_valid = 0 | |
endif | |
if self.pid == 0 | |
" Ignore. | |
return | |
endif | |
return self.current_proc.kill(a:sig) | |
endfunction | |
1 0.000005 function! s:waitpid(pid) | |
try | |
let [cond, status] = s:libcall('vp_waitpid', [a:pid]) | |
" echomsg string([cond, status]) | |
if cond ==# 'run' | |
" Add process list. | |
let s:bg_processes[a:pid] = a:pid | |
let [cond, status] = ['exit', '0'] | |
elseif vimproc#util#is_windows() | |
call s:libcall('vp_close_handle', [a:pid]) | |
endif | |
let s:last_status = status | |
catch | |
let [cond, status] = ['error', '0'] | |
endtry | |
return [cond, str2nr(status)] | |
endfunction | |
1 0.000002 function! s:vp_checkpid() dict | |
try | |
let [cond, status] = s:libcall('vp_waitpid', [self.pid]) | |
if cond !=# 'run' | |
let [self.cond, self.status] = [cond, status] | |
endif | |
catch /waitpid() error:\|vp_waitpid:/ | |
let [cond, status] = ['error', '0'] | |
endtry | |
return [cond, str2nr(status)] | |
endfunction | |
1 0.000003 function! s:vp_waitpid() dict | |
call s:close_all(self) | |
let self.is_valid = 0 | |
if has_key(self, 'cond') && has_key(self, 'status') | |
" Use cache. | |
let [cond, status] = [self.cond, self.status] | |
else | |
let [cond, status] = s:waitpid(self.pid) | |
endif | |
if cond ==# 'exit' | |
let self.pid = 0 | |
endif | |
if has_key(self, 'pid_list') | |
for pid in self.pid_list[: -2] | |
call s:waitpid(pid) | |
endfor | |
endif | |
return [cond, str2nr(status)] | |
endfunction | |
1 0.000005 function! s:vp_pgroup_waitpid() dict | |
call s:close_all(self) | |
let self.is_valid = 0 | |
if !has_key(self, 'cond') || | |
\ !has_key(self, 'status') | |
return s:waitpid(self.pid) | |
endif | |
return [self.cond, self.status] | |
endfunction | |
1 0.000003 function! s:vp_socket_open(host, port) | |
let [socket] = s:libcall('vp_socket_open', [a:host, a:port]) | |
return socket | |
endfunction | |
1 0.000002 function! s:vp_socket_close() dict | |
call s:libcall('vp_socket_close', [self.fd]) | |
let self.is_valid = 0 | |
endfunction | |
1 0.000004 function! s:vp_socket_read(number, timeout) dict | |
let [hd, eof] = s:libcall('vp_socket_read', | |
\ [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
endfunction | |
1 0.000002 function! s:vp_socket_write(hd, timeout) dict | |
let [nleft] = s:libcall('vp_socket_write', | |
\ [self.fd, a:hd, a:timeout]) | |
return nleft | |
endfunction | |
1 0.000002 function! s:vp_host_exists(host) | |
let [rval] = s:libcall('vp_host_exists', [a:host]) | |
return rval | |
endfunction | |
" Initialize. | |
1 0.000004 if !exists('s:dll_handle') | |
1 0.000492 0.000006 let s:dll_handle = s:vp_dlopen(g:vimproc#dll_path) | |
1 0.000003 let s:last_status = 0 | |
1 0.000002 let s:last_errmsg = '' | |
1 0.000001 endif | |
" vimproc dll version check. "{{{ | |
1 0.000001 try | |
1 0.000120 0.000006 let dll_version = vimproc#dll_version() | |
1 0.000011 0.000005 if dll_version < vimproc#version() | |
call s:print_error(printf('Your vimproc binary version is "%d",'. | |
\ ' but vimproc version is "%d".', | |
\ dll_version, vimproc#version())) | |
endif | |
1 0.000006 catch | |
call s:print_error(v:throwpoint) | |
call s:print_error(v:exception) | |
call s:print_error('Your vimproc binary is too old!') | |
call s:print_error('Please re-compile it.') | |
endtry | |
1 0.000002 unlet dll_version | |
"}}} | |
" Restore 'cpoptions' {{{ | |
1 0.000007 let &cpo = s:save_cpo | |
1 0.000002 unlet s:save_cpo | |
" }}} | |
" __END__ | |
" vim:foldmethod=marker:fen:sw=2:sts=2 | |
SCRIPT /Users/Experiment/.dotfiles/vim/bundle/vimproc.vim/autoload/vimproc/parser.vim | |
Sourced 1 time | |
Total time: 0.001216 | |
Self time: 0.001216 | |
count total (s) self (s) | |
"============================================================================= | |
" FILE: parser.vim | |
" AUTHOR: Shougo Matsushita <[email protected]> | |
" Last Modified: 23 Mar 2013. | |
" License: MIT license {{{ | |
" Permission is hereby granted, free of charge, to any person obtaining | |
" a copy of this software and associated documentation files (the | |
" "Software"), to deal in the Software without restriction, including | |
" without limitation the rights to use, copy, modify, merge, publish, | |
" distribute, sublicense, and/or sell copies of the Software, and to | |
" permit persons to whom the Software is furnished to do so, subject to | |
" the following conditions: | |
" | |
" The above copyright notice and this permission notice shall be included | |
" in all copies or substantial portions of the Software. | |
" | |
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
" }}} | |
"============================================================================= | |
" Saving 'cpoptions' {{{ | |
1 0.000007 let s:save_cpo = &cpo | |
1 0.000006 set cpo&vim | |
" }}} | |
" For vimshell parser. | |
1 0.000004 function! vimproc#parser#parse_pipe(statement) "{{{ | |
let commands = [] | |
for cmdline in vimproc#parser#split_pipe(a:statement) | |
" Split args. | |
let cmdline = s:parse_cmdline(cmdline) | |
" Parse redirection. | |
if cmdline =~ '[<>]' | |
let [fd, cmdline] = s:parse_redirection(cmdline) | |
else | |
let fd = { 'stdin' : '', 'stdout' : '', 'stderr' : '' } | |
endif | |
for key in ['stdout', 'stderr'] | |
if fd[key] == '' || fd[key] =~ '^>' | |
continue | |
endif | |
if fd[key] ==# '/dev/clip' | |
" Clear. | |
let @+ = '' | |
elseif fd[key] ==# '/dev/quickfix' | |
" Clear quickfix. | |
call setqflist([]) | |
endif | |
endfor | |
call add(commands, { | |
\ 'args' : vimproc#parser#split_args(cmdline), | |
\ 'fd' : fd | |
\}) | |
endfor | |
return commands | |
endfunction"}}} | |
1 0.000004 function! s:parse_cmdline(cmdline) "{{{ | |
let cmdline = a:cmdline | |
" Expand block. | |
if cmdline =~ '{' | |
let cmdline = s:parse_block(cmdline) | |
endif | |
" Expand tilde. | |
if cmdline =~ '\~' | |
let cmdline = s:parse_tilde(cmdline) | |
endif | |
" Expand filename. | |
if cmdline =~ ' =' | |
let cmdline = s:parse_equal(cmdline) | |
endif | |
" Expand variables. | |
if cmdline =~ '\$' | |
let cmdline = s:parse_variables(cmdline) | |
endif | |
" Expand wildcard. | |
if cmdline =~ '[[*?]\|\\[()|]' | |
let cmdline = s:parse_wildcard(cmdline) | |
endif | |
return s:parse_tilde(cmdline) | |
endfunction"}}} | |
1 0.000004 function! vimproc#parser#parse_statements(script) "{{{ | |
if type(a:script) == type('') && a:script =~ '^\s*:' | |
return [ { 'statement' : a:script, 'condition' : 'always' } ] | |
endif | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
let statements = [] | |
let statement = '' | |
let i = 0 | |
while i < max | |
if script[i] == ';' | |
if statement != '' | |
call add(statements, | |
\ { 'statement' : statement, | |
\ 'condition' : 'always', | |
\}) | |
endif | |
let statement = '' | |
let i += 1 | |
elseif script[i] == '&' | |
if i+1 < max && script[i+1] == '&' | |
if statement != '' | |
call add(statements, | |
\ { 'statement' : statement, | |
\ 'condition' : 'true', | |
\}) | |
endif | |
let statement = '' | |
let i += 2 | |
else | |
let statement .= script[i] | |
let i += 1 | |
endif | |
elseif script[i] == '|' | |
if i+1 < max && script[i+1] == '|' | |
if statement != '' | |
call add(statements, | |
\ { 'statement' : statement, | |
\ 'condition' : 'false', | |
\}) | |
endif | |
let statement = '' | |
let i += 2 | |
else | |
let statement .= script[i] | |
let i += 1 | |
endif | |
elseif script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let statement .= string | |
elseif script[i] == '"' | |
" Double quote. | |
let [string, i] = s:skip_double_quote(script, i) | |
let statement .= string | |
elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let statement .= string | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let statement .= '\' . script[i] | |
let i += 1 | |
elseif script[i] == '#' | |
" Comment. | |
break | |
else | |
let statement .= script[i] | |
let i += 1 | |
endif | |
endwhile | |
if statement !~ '^\s*$' | |
call add(statements, | |
\ { 'statement' : statement, | |
\ 'condition' : 'always', | |
\}) | |
endif | |
return statements | |
endfunction"}}} | |
1 0.000003 function! vimproc#parser#split_statements(script) "{{{ | |
return map(vimproc#parser#parse_statements(a:script), | |
\ 'v:val.statement') | |
endfunction"}}} | |
1 0.000003 function! vimproc#parser#split_args(script) "{{{ | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
let args = [] | |
let arg = '' | |
let i = 0 | |
while i < max | |
if script[i] == "'" | |
" Single quote. | |
let [arg_quote, i] = s:parse_single_quote(script, i) | |
let arg .= arg_quote | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '"' | |
" Double quote. | |
let [arg_quote, i] = s:parse_double_quote(script, i) | |
let arg .= arg_quote | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '`' | |
" Back quote. | |
let head = i > 0 ? script[: i-1] : [] | |
let [arg_quote, i] = s:parse_back_quote(script, i) | |
" Re-parse script. | |
return vimproc#parser#split_args( | |
\ head + split(arg_quote, '\zs') + script[i :]) | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= script[i] | |
let i += 1 | |
elseif script[i] == '#' | |
" Comment. | |
break | |
elseif script[i] != ' ' | |
let arg .= script[i] | |
let i += 1 | |
else | |
" Space. | |
if arg != '' | |
call add(args, arg) | |
endif | |
let arg = '' | |
let i += 1 | |
endif | |
endwhile | |
if arg != '' | |
call add(args, arg) | |
endif | |
return args | |
endfunction"}}} | |
1 0.000004 function! vimproc#parser#split_args_through(script) "{{{ | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
let args = [] | |
let arg = '' | |
let i = 0 | |
while i < max | |
if script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '"' | |
" Double quote. | |
let [string, i] = s:skip_double_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= '\'.script[i] | |
let i += 1 | |
elseif script[i] != ' ' | |
let arg .= script[i] | |
let i += 1 | |
else | |
" Space. | |
if arg != '' | |
call add(args, arg) | |
endif | |
let arg = '' | |
let i += 1 | |
endif | |
endwhile | |
if arg != '' | |
call add(args, arg) | |
endif | |
return args | |
endfunction"}}} | |
1 0.000004 function! vimproc#parser#split_pipe(script) "{{{ | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
let command = '' | |
let i = 0 | |
let commands = [] | |
while i < max | |
if script[i] == '|' | |
" Pipe. | |
call add(commands, command) | |
" Search next command. | |
let command = '' | |
let i += 1 | |
elseif script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let command .= string | |
elseif script[i] == '"' | |
" Double quote. | |
let [string, i] = s:skip_double_quote(script, i) | |
let command .= string | |
elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let command .= string | |
elseif script[i] == '\' && i + 1 < max | |
" Escape. | |
let command .= '\' . script[i+1] | |
let i += 2 | |
else | |
let command .= script[i] | |
let i += 1 | |
endif | |
endwhile | |
call add(commands, command) | |
return commands | |
endfunction"}}} | |
1 0.000004 function! vimproc#parser#split_commands(script) "{{{ | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
let commands = [] | |
let command = '' | |
let i = 0 | |
while i < max | |
if script[i] == '\' | |
" Escape. | |
let command .= script[i] | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let command .= script[i] | |
let i += 1 | |
elseif script[i] == '|' | |
if command != '' | |
call add(commands, command) | |
endif | |
let command = '' | |
let i += 1 | |
else | |
let command .= script[i] | |
let i += 1 | |
endif | |
endwhile | |
if command != '' | |
call add(commands, command) | |
endif | |
return commands | |
endfunction"}}} | |
1 0.000004 function! vimproc#parser#expand_wildcard(wildcard) "{{{ | |
" Check wildcard. | |
let i = 0 | |
let max = len(a:wildcard) | |
let script = '' | |
let found = 0 | |
while i < max | |
if a:wildcard[i] == '*' || a:wildcard[i] == '?' || a:wildcard[i] == '[' | |
let found = 1 | |
break | |
else | |
let [script, i] = s:skip_else(script, a:wildcard, i) | |
endif | |
endwhile | |
if !found | |
return [ a:wildcard ] | |
endif | |
let wildcard = a:wildcard | |
" Exclude wildcard. | |
let exclude = matchstr(wildcard, '\\\@<!\~\zs.\+$') | |
let exclude_wilde = [] | |
if exclude != '' | |
" Truncate wildcard. | |
let wildcard = wildcard[: len(wildcard)-len(exclude)-2] | |
let exclude_wilde = vimproc#parser#expand_wildcard(exclude) | |
endif | |
" Modifier. | |
let modifier = matchstr(wildcard, '\\\@<!(\zs.\+\ze)$') | |
if modifier != '' | |
" Truncate wildcard. | |
let wildcard = wildcard[: len(wildcard)-len(modifier)-3] | |
endif | |
" Expand wildcard. | |
let expanded = split(escape(substitute( | |
\ glob(wildcard, 1), '\\', '/', 'g'), ' '), '\n') | |
if empty(expanded) | |
" Use original string. | |
return [ a:wildcard ] | |
else | |
" Check exclude wildcard. | |
let candidates = expanded | |
let expanded = [] | |
for candidate in candidates | |
let found = 0 | |
for ex in exclude_wilde | |
if candidate ==# ex | |
let found = 1 | |
break | |
endif | |
endfor | |
if !found | |
call add(expanded, candidate) | |
endif | |
endfor | |
endif | |
if modifier != '' | |
" Check file modifier. | |
let i = 0 | |
let max = len(modifier) | |
while i < max | |
if modifier[i] ==# '/' | |
" Directory. | |
let expr = 'getftype(v:val) ==# "dir"' | |
elseif modifier[i] ==# '.' | |
" Normal. | |
let expr = 'getftype(v:val) ==# "file"' | |
elseif modifier[i] ==# '@' | |
" Link. | |
let expr = 'getftype(v:val) ==# "link"' | |
elseif modifier[i] ==# '=' | |
" Socket. | |
let expr = 'getftype(v:val) ==# "socket"' | |
elseif modifier[i] ==# 'p' | |
" FIFO Pipe. | |
let expr = 'getftype(v:val) ==# "pipe"' | |
elseif modifier[i] ==# '*' | |
" Executable. | |
let expr = 'getftype(v:val) ==# "pipe"' | |
elseif modifier[i] ==# '%' | |
" Device. | |
if modifier[i :] =~# '^%[bc]' | |
if modifier[i] ==# 'b' | |
" Block device. | |
let expr = 'getftype(v:val) ==# "bdev"' | |
else | |
" Character device. | |
let expr = 'getftype(v:val) ==# "cdev"' | |
endif | |
let i += 1 | |
else | |
let expr = 'getftype(v:val) ==# "bdev" || getftype(v:val) ==# "cdev"' | |
endif | |
else | |
" Unknown. | |
return [] | |
endif | |
call filter(expanded, expr) | |
let i += 1 | |
endwhile | |
endif | |
return filter(expanded, 'v:val != "." && v:val != ".."') | |
endfunction"}}} | |
" Parse helper. | |
1 0.000003 function! s:parse_block(script) "{{{ | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == '{' | |
" Block. | |
let head = matchstr(a:script[: i-1], '[^[:blank:]]*$') | |
" Truncate script. | |
let script = script[: -len(head)-1] | |
let block = matchstr(a:script, '{\zs.*[^\\]\ze}', i) | |
let foot = join(vimproc#parser#split_args(s:parse_cmdline( | |
\ a:script[matchend(a:script, '{.*[^\\]}', i) :]))) | |
if block == '' | |
throw 'Exception: Block is not found.' | |
elseif block =~ '^\d\+\.\.\d\+$' | |
" Range block. | |
let start = matchstr(block, '^\d\+') | |
let end = matchstr(block, '\d\+$') | |
let zero = len(matchstr(block, '^0\+'))+1 | |
let pattern = '%0' . zero . 'd' | |
for b in range(start, end) | |
" Concat. | |
let script .= head . printf(pattern, b) . foot . ' ' | |
endfor | |
else | |
" Normal block. | |
for b in split(block, ',', 1) | |
" Concat. | |
let script .= head . escape(b, ' ') . foot . ' ' | |
endfor | |
endif | |
return script | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return script | |
endfunction"}}} | |
1 0.000003 function! s:parse_tilde(script) "{{{ | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == ' ' && a:script[i+1] == '~' | |
" Tilde. | |
" Expand home directory. | |
let script .= ' ' . escape(substitute($HOME, '\\', '/', 'g'), '\ ') | |
let i += 2 | |
elseif i == 0 && a:script[i] == '~' | |
" Tilde. | |
" Expand home directory. | |
let script .= escape(substitute($HOME, '\\', '/', 'g'), '\ ') | |
let i += 1 | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return script | |
endfunction"}}} | |
1 0.000002 function! s:parse_equal(script) "{{{ | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
while i < max - 1 | |
if a:script[i] == ' ' && a:script[i+1] == '=' | |
" Expand filename. | |
let prog = matchstr(a:script, '^=\zs[^[:blank:]]*', i+1) | |
if prog == '' | |
let [script, i] = s:skip_else(script, a:script, i) | |
else | |
let filename = vimproc#get_command_path(prog) | |
if filename == '' | |
throw printf('Error: File "%s" is not found.', prog) | |
else | |
let script .= filename | |
endif | |
let i += matchend(a:script, '^=[^[:blank:]]*', i+1) | |
endif | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return script | |
endfunction"}}} | |
1 0.000003 function! s:parse_variables(script) "{{{ | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
try | |
while i < max | |
if a:script[i] == '$' && a:script[i :] =~ '^$$\?\h' | |
" Eval variables. | |
let variable_name = matchstr(a:script, '^$$\?\zs\h\w*', i) | |
if exists('b:vimshell') | |
" For vimshell. | |
let script_head = a:script[i :] | |
if script_head =~ '^$\l' && | |
\ has_key(b:vimshell.variables, variable_name) | |
let script .= b:vimshell.variables[variable_name] | |
elseif script_head =~ '^\$\$' && | |
\ has_key(b:vimshell.system_variables, variable_name) | |
let script .= b:vimshell.system_variables[variable_name] | |
elseif script_head =~ '^$\h' | |
let script .= vimproc#util#substitute_path_separator( | |
\ eval(variable_name)) | |
endif | |
else | |
let script .= vimproc#util#substitute_path_separator( | |
\ eval(matchstr(a:script, '^$\h\w*', i))) | |
endif | |
let i = matchend(a:script, '^$$\?\h\w*', i) | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
catch /^Vim\%((\a\+)\)\=:E15/ | |
" Parse error. | |
return a:script | |
endtry | |
return script | |
endfunction"}}} | |
1 0.000003 function! s:parse_wildcard(script) "{{{ | |
let script = '' | |
for arg in vimproc#parser#split_args_through(a:script) | |
let script .= join(vimproc#parser#expand_wildcard(arg)) . ' ' | |
endfor | |
return script | |
endfunction"}}} | |
1 0.000003 function! s:parse_redirection(script) "{{{ | |
let script = '' | |
let fd = { 'stdin' : '', 'stdout' : '', 'stderr' : '' } | |
let i = 0 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == '<' | |
" Input redirection. | |
let fd.stdin = matchstr(a:script, '<\s*\zs\f*', i) | |
let i = matchend(a:script, '<\s*\zs\f*', i) | |
elseif a:script[i] =~ '^[12]' && a:script[i :] =~ '^[12]>' | |
" Output redirection. | |
let i += 2 | |
if a:script[i-2] == 1 | |
let fd.stdout = matchstr(a:script, '^\s*\zs\f*', i) | |
else | |
let fd.stderr = matchstr(a:script, '^\s*\zs\(\f\+\|&\d\+\)', i) | |
if fd.stderr ==# '&1' | |
" Redirection to stdout. | |
let fd.stderr = '/dev/stdout' | |
endif | |
endif | |
let i = matchend(a:script, '^\s*\zs\(\f\+\|&\d\+\)', i) | |
elseif a:script[i] == '>' | |
" Output redirection. | |
if a:script[i :] =~ '^>&' | |
" Output stderr. | |
let i += 2 | |
let fd.stderr = matchstr(a:script, '^\s*\zs\f*', i) | |
elseif a:script[i :] =~ '^>>' | |
" Append stdout. | |
let i += 2 | |
let fd.stdout = '>' . matchstr(a:script, '^\s*\zs\f*', i) | |
else | |
" Output stdout. | |
let i += 1 | |
let fd.stdout = matchstr(a:script, '^\s*\zs\f*', i) | |
endif | |
let i = matchend(a:script, '^\s*\zs\f*', i) | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return [fd, script] | |
endfunction"}}} | |
1 0.000003 function! s:parse_single_quote(script, i) "{{{ | |
if a:script[a:i] != "'" | |
return ['', a:i] | |
endif | |
let arg = '' | |
let i = a:i + 1 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == "'" | |
if i+1 < max && a:script[i+1] == "'" | |
" Escape quote. | |
let arg .= "'" | |
let i += 2 | |
else | |
" Quote end. | |
return [arg, i+1] | |
endif | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
throw 'Exception: Quote ('') is not found.' | |
endfunction"}}} | |
1 0.000003 function! s:parse_double_quote(script, i) "{{{ | |
if a:script[a:i] != '"' | |
return ['', a:i] | |
endif | |
let escape_sequences = { | |
\ 'a' : "\<C-g>", 'b' : "\<BS>", | |
\ 't' : "\<Tab>", 'r' : "\<CR>", | |
\ 'n' : "\<LF>", 'e' : "\<Esc>", | |
\ '\' : '\', '?' : '?', | |
\ '"' : '"', "'" : "'", | |
\ '`' : '`', | |
\} | |
let arg = '' | |
let i = a:i + 1 | |
let script = type(a:script) == type([]) ? | |
\ a:script : split(a:script, '\zs') | |
let max = len(script) | |
while i < max | |
if script[i] == '"' | |
" Quote end. | |
return [arg, i+1] | |
elseif script[i] == '$' | |
" Eval variables. | |
let var = matchstr(join(script[i :], ''), '^$\h\w*') | |
if var != '' | |
let arg .= s:parse_variables(var) | |
let i += len(var) | |
else | |
let arg .= '$' | |
let i += 1 | |
endif | |
elseif script[i] == '`' | |
" Backquote. | |
let [arg_quote, i] = s:parse_back_quote(script, i) | |
let arg .= arg_quote | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
if script[i] == 'x' | |
let num = matchstr(join(script[i+1 :], ''), '^\x\+') | |
let arg .= nr2char(str2nr(num, 16)) | |
let i += len(num) | |
elseif has_key(escape_sequences, script[i]) | |
let arg .= escape_sequences[script[i]] | |
else | |
let arg .= '\' . script[i] | |
endif | |
let i += 1 | |
else | |
let arg .= script[i] | |
let i += 1 | |
endif | |
endwhile | |
throw 'Exception: Quote (") is not found.' | |
endfunction"}}} | |
1 0.000003 function! s:parse_back_quote(script, i) "{{{ | |
if a:script[a:i] != '`' | |
return ['', a:i] | |
endif | |
let arg = '' | |
let max = len(a:script) | |
if a:i + 1 < max && a:script[a:i + 1] == '=' | |
" Vim eval quote. | |
let i = a:i + 2 | |
while i < max | |
if a:script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= '\' . a:script[i] | |
let i += 1 | |
elseif a:script[i] == '`' | |
" Quote end. | |
return [eval(arg), i+1] | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
else | |
" Eval quote. | |
let i = a:i + 1 | |
while i < max | |
if a:script[i] == '`' | |
" Quote end. | |
return [substitute(vimproc#system(arg), '\n$', '', ''), i+1] | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
endif | |
throw 'Exception: Quote (`) is not found.' | |
endfunction"}}} | |
" Skip helper. | |
1 0.000003 function! s:skip_single_quote(script, i) "{{{ | |
let max = len(a:script) | |
let string = '' | |
let i = a:i | |
" a:script[i] is always "'" when this function is called | |
if i >= max || a:script[i] != '''' | |
throw 'Exception: Quote ('') is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
while i < max | |
if a:script[i] == '''' | |
if i+1 < max && a:script[i+1] == '''' | |
" Escape quote. | |
let string .= a:script[i] | |
let i += 1 | |
else | |
break | |
endif | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endwhile | |
if i < max | |
" must end with "'" | |
if a:script[i] != '''' | |
throw 'Exception: Quote ('') is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endif | |
return [string, i] | |
endfunction"}}} | |
1 0.000003 function! s:skip_double_quote(script, i) "{{{ | |
let max = len(a:script) | |
let string = '' | |
let i = a:i | |
" a:script[i] is always '"' when this function is called | |
if i >= max || a:script[i] != '"' | |
throw 'Exception: Quote (") is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
while i < max | |
if a:script[i] == '\' | |
\ && i+1 < max && a:script[i+1] == '"' | |
" Escape quote. | |
let string .= a:script[i] | |
let i += 1 | |
elseif a:script[i] == '"' | |
break | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endwhile | |
if i < max | |
" must end with '"' | |
if a:script[i] != '"' | |
throw 'Exception: Quote (") is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endif | |
return [string, i] | |
endfunction"}}} | |
1 0.000003 function! s:skip_back_quote(script, i) "{{{ | |
let max = len(a:script) | |
let string = '' | |
let i = a:i | |
" a:script[i] is always '`' when this function is called | |
if a:script[i] != '`' | |
throw 'Exception: Quote (`) is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
while i < max && a:script[i] != '`' | |
let string .= a:script[i] | |
let i += 1 | |
endwhile | |
if i < max | |
" must end with "`" | |
if a:script[i] != '`' | |
throw 'Exception: Quote (`) is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endif | |
return [string, i] | |
endfunction"}}} | |
1 0.000004 function! s:skip_else(args, script, i) "{{{ | |
if a:script[a:i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(a:script, a:i) | |
let script = a:args . string | |
elseif a:script[a:i] == '"' | |
" Double quote. | |
let [string, i] = s:skip_double_quote(a:script, a:i) | |
let script = a:args . string | |
elseif a:script[a:i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(a:script, a:i) | |
let script = a:args . string | |
elseif a:script[a:i] == '\' | |
" Escape. | |
let script = a:args . '\' . a:script[a:i+1] | |
let i = a:i + 2 | |
else | |
let script = a:args . a:script[a:i] | |
let i = a:i + 1 | |
endif | |
return [script, i] | |
endfunction"}}} | |
" Restore 'cpoptions' {{{ | |
1 0.000008 let &cpo = s:save_cpo | |
" }}} | |
" vim:foldmethod=marker:fen:sw=2:sts=2 | |
FUNCTION <SNR>138_close() | |
Called 13000 times | |
Total time: 1.217022 | |
Self time: 0.086447 | |
count total (s) self (s) | |
13000 0.016405 if self.is_valid | |
9000 0.443483 0.055578 call self.f_close() | |
9000 0.005669 endif | |
13000 0.019017 let self.is_valid = 0 | |
13000 0.015397 let self.eof = 1 | |
13000 0.014781 let self.__eof = 1 | |
FUNCTION <SNR>138_system() | |
Called 1000 times | |
Total time: 8.351791 | |
Self time: 0.477644 | |
count total (s) self (s) | |
1000 0.002249 if empty(a:cmdline) | |
let s:last_status = 0 | |
let s:last_errmsg = '' | |
return '' | |
endif | |
" Open pipe. | |
1000 4.158457 0.015158 let subproc = (type(a:cmdline[0]) == type('')) ? vimproc#popen3(a:cmdline) : a:is_pty ? vimproc#ptyopen(a:cmdline): vimproc#pgroup_open(a:cmdline) | |
1000 0.002711 if a:input != '' | |
" Write input. | |
1000 0.548755 0.025533 call subproc.stdin.write(a:input) | |
1000 0.000742 endif | |
1000 0.002648 if a:timeout > 0 && has('reltime') && v:version >= 702 | |
let start = reltime() | |
let timeout = a:timeout | |
else | |
1000 0.001535 let timeout = 0 | |
1000 0.000617 endif | |
1000 0.001320 if !a:is_passwd | |
1000 0.207430 0.004641 call subproc.stdin.close() | |
1000 0.000663 endif | |
1000 0.001466 let output = '' | |
1000 0.001899 let s:last_errmsg = '' | |
5035 0.012008 while !subproc.stdout.eof || !subproc.stderr.eof | |
4035 0.005882 if timeout > 0 "{{{ | |
" Check timeout. | |
let end = split(reltimestr(reltime(start)))[0] * 1000 | |
if end > timeout && !subproc.stdout.eof | |
" Kill process. | |
" 15 == SIGTERM | |
try | |
call subproc.kill(15) | |
call subproc.waitpid() | |
catch | |
" Ignore error. | |
endtry | |
throw 'vimproc: vimproc#system(): Timeout.' | |
endif | |
endif"}}} | |
4035 0.005631 if !subproc.stdout.eof "{{{ | |
4035 1.361904 0.028763 let out = subproc.stdout.read(1000, 0) | |
4035 0.010202 if a:is_passwd && out =~# g:vimproc_password_pattern | |
redraw | |
echo out | |
" Password input. | |
set imsearch=0 | |
let in = vimproc#util#iconv(inputsecret('Input Secret : ')."\<NL>", &encoding, vimproc#util#termencoding()) | |
call subproc.stdin.write(in) | |
else | |
4035 0.010300 let output .= out | |
4035 0.003099 endif | |
4035 0.002890 endif"}}} | |
4035 0.006094 if !subproc.stderr.eof "{{{ | |
3729 1.608745 0.025857 let out = subproc.stderr.read(1000, 0) | |
3729 0.009233 if a:is_passwd && out =~# g:vimproc_password_pattern | |
redraw | |
echo out | |
" Password input. | |
set imsearch=0 | |
let in = vimproc#util#iconv(inputsecret('Input Secret : ') . "\<NL>", &encoding, vimproc#util#termencoding()) | |
call subproc.stdin.write(in) | |
else | |
3729 0.011830 let s:last_errmsg .= out | |
3729 0.008289 let output .= out | |
3729 0.004728 endif | |
3729 0.002686 endif"}}} | |
4035 0.004012 endwhile | |
1000 0.092429 0.005570 let [cond, status] = subproc.waitpid() | |
" Newline convert. | |
1000 0.005587 0.003638 if vimproc#util#is_mac() | |
1000 0.010945 let output = substitute(output, '\r\n\@!', '\n', 'g') | |
1000 0.002232 elseif has('win32') || has('win64') | |
let output = substitute(output, '\r\n', '\n', 'g') | |
endif | |
1000 0.004249 return output | |
FUNCTION <SNR>138_convert_args() | |
Called 1000 times | |
Total time: 1.381888 | |
Self time: 0.039578 | |
count total (s) self (s) | |
1000 0.002022 if empty(a:args) | |
return [] | |
endif | |
1000 0.005839 0.004125 if vimproc#util#is_windows() && !executable(a:args[0]) | |
" Search from internal commands. | |
let internal_commands = [ 'copy', 'dir', 'echo', 'erase', 'ftype', 'md', 'mkdir', 'move', 'path', 'rd', 'ren', 'rename', 'rmdir', 'start', 'time', 'type', 'ver', 'vol'] | |
let index = index(internal_commands, a:args[0]) | |
if index >= 0 | |
" Use cmd.exe | |
return ['cmd', '/c', internal_commands[index]] + a:args[1:] | |
endif | |
endif | |
1000 1.155631 0.009925 let command_name = vimproc#get_command_name(a:args[0]) | |
1000 0.204451 0.009561 return vimproc#analyze_shebang(command_name) + a:args[1:] | |
FUNCTION <SNR>138_closed_fdopen() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return { 'fd' : -1, 'eof' : 1, '__eof' : 1, 'is_valid' : 0, 'buffer' : '', 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'),} | |
FUNCTION <SNR>140_skip_back_quote() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let max = len(a:script) | |
let string = '' | |
let i = a:i | |
" a:script[i] is always '`' when this function is called | |
if a:script[i] != '`' | |
throw 'Exception: Quote (`) is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
while i < max && a:script[i] != '`' | |
let string .= a:script[i] | |
let i += 1 | |
endwhile | |
if i < max | |
" must end with "`" | |
if a:script[i] != '`' | |
throw 'Exception: Quote (`) is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endif | |
return [string, i] | |
FUNCTION vimproc#system_bg() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
" Open pipe. | |
let subproc = vimproc#popen3(a:cmdline) | |
if empty(subproc) | |
" Not supported path error. | |
return '' | |
endif | |
" Close handles. | |
call s:close_all(subproc) | |
let s:bg_processes[subproc.pid] = subproc.pid | |
return '' | |
FUNCTION <SNR>138_vp_dlclose() | |
Called 1 time | |
Total time: 0.000202 | |
Self time: 0.000008 | |
count total (s) self (s) | |
1 0.000202 0.000008 call s:libcall('vp_dlclose', [a:handle]) | |
FUNCTION <SNR>140_parse_wildcard() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = '' | |
for arg in vimproc#parser#split_args_through(a:script) | |
let script .= join(vimproc#parser#expand_wildcard(arg)) . ' ' | |
endfor | |
return script | |
FUNCTION vimproc#system() | |
Called 1000 times | |
Total time: 13.699283 | |
Self time: 0.070427 | |
count total (s) self (s) | |
1000 0.003407 if type(a:cmdline) == type('') | |
1000 0.004648 if a:cmdline =~ '&\s*$' | |
let cmdline = substitute(a:cmdline, '&\s*$', '', '') | |
return vimproc#system_bg(cmdline) | |
endif | |
1000 1.627601 0.014261 let args = vimproc#parser#parse_statements(a:cmdline) | |
2000 0.002925 for arg in args | |
1000 3.670519 0.006794 let arg.statement = vimproc#parser#parse_pipe(arg.statement) | |
1000 0.000950 endfor | |
1000 0.000550 else | |
let args = [{'statement' : [{ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, 'args' : a:cmdline }], 'condition' : 'always' }] | |
endif | |
1000 0.002880 let timeout = get(a:000, 1, 0) | |
1000 0.002656 let input = get(a:000, 0, '') | |
1000 8.365492 0.013701 return s:system(args, 0, input, timeout, 0) | |
FUNCTION vimproc#plineopen3() | |
Called 1000 times | |
Total time: 3.615096 | |
Self time: 0.028658 | |
count total (s) self (s) | |
1000 0.004652 let commands = type(a:commands) == type('') ? vimproc#parser#parse_pipe(a:commands) : a:commands | |
1000 0.002428 let is_pty = get(a:000, 0, 0) | |
1000 3.606681 0.020243 return s:plineopen(3, commands, is_pty) | |
FUNCTION vimproc#popen2() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let args = type(a:args) == type('') ? vimproc#parser#split_args(a:args) : a:args | |
return s:plineopen(2, [{ 'args' : args, 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, }], 0) | |
FUNCTION vimproc#popen3() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let args = type(a:args) == type('') ? vimproc#parser#split_args(a:args) : a:args | |
return s:plineopen(3, [{ 'args' : args, 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, }], 0) | |
FUNCTION vimproc#kill() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:sig == 0 && vimproc#util#is_windows() | |
" Use waitpid(). | |
let [cond, status] = s:waitpid(a:pid) | |
return cond ==# 'run' | |
endif | |
try | |
let [ret] = s:libcall('vp_kill', [a:pid, a:sig]) | |
catch /kill() error:/ | |
let s:last_errmsg = v:exception | |
return 1 | |
endtry | |
return ret | |
FUNCTION <SNR>140_parse_cmdline() | |
Called 1000 times | |
Total time: 1.316947 | |
Self time: 0.058359 | |
count total (s) self (s) | |
1000 0.004458 let cmdline = a:cmdline | |
" Expand block. | |
1000 0.004302 if cmdline =~ '{' | |
let cmdline = s:parse_block(cmdline) | |
endif | |
" Expand tilde. | |
1000 0.002552 if cmdline =~ '\~' | |
let cmdline = s:parse_tilde(cmdline) | |
endif | |
" Expand filename. | |
1000 0.003089 if cmdline =~ ' =' | |
let cmdline = s:parse_equal(cmdline) | |
endif | |
" Expand variables. | |
1000 0.002423 if cmdline =~ '\$' | |
let cmdline = s:parse_variables(cmdline) | |
endif | |
" Expand wildcard. | |
1000 0.012641 if cmdline =~ '[[*?]\|\\[()|]' | |
let cmdline = s:parse_wildcard(cmdline) | |
endif | |
1000 1.265245 0.006657 return s:parse_tilde(cmdline) | |
FUNCTION vimproc#parser#split_commands() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
let max = len(script) | |
let commands = [] | |
let command = '' | |
let i = 0 | |
while i < max | |
if script[i] == '\' | |
" Escape. | |
let command .= script[i] | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let command .= script[i] | |
let i += 1 | |
elseif script[i] == '|' | |
if command != '' | |
call add(commands, command) | |
endif | |
let command = '' | |
let i += 1 | |
else | |
let command .= script[i] | |
let i += 1 | |
endif | |
endwhile | |
if command != '' | |
call add(commands, command) | |
endif | |
return commands | |
FUNCTION <SNR>138_waitpid() | |
Called 1000 times | |
Total time: 0.154450 | |
Self time: 0.038506 | |
count total (s) self (s) | |
1000 0.001431 try | |
1000 0.121839 0.008238 let [cond, status] = s:libcall('vp_waitpid', [a:pid]) | |
" echomsg string([cond, status]) | |
1000 0.001828 if cond ==# 'run' | |
" Add process list. | |
let s:bg_processes[a:pid] = a:pid | |
let [cond, status] = ['exit', '0'] | |
elseif vimproc#util#is_windows() | |
call s:libcall('vp_close_handle', [a:pid]) | |
endif | |
1000 0.005671 let s:last_status = status | |
1000 0.001104 catch | |
let [cond, status] = ['error', '0'] | |
endtry | |
1000 0.003402 return [cond, str2nr(status)] | |
FUNCTION <SNR>138_plineopen() | |
Called 1000 times | |
Total time: 3.586438 | |
Self time: 0.499361 | |
count total (s) self (s) | |
1000 0.001678 let pid_list = [] | |
1000 0.001435 let stdin_list = [] | |
1000 0.001349 let stdout_list = [] | |
1000 0.001212 let stderr_list = [] | |
1000 0.001401 let npipe = a:npipe | |
" Open input. | |
1000 0.006208 let hstdin = (empty(a:commands) || a:commands[0].fd.stdin == '')? 0 : vimproc#fopen(a:commands[0].fd.stdin, 'O_RDONLY').fd | |
1000 0.006771 0.004748 let is_pty = !vimproc#util#is_windows() && a:is_pty | |
1000 0.001371 let cnt = 0 | |
2000 0.006380 for command in a:commands | |
1000 0.002821 if is_pty && command.fd.stdout == '' && cnt == 0 && len(a:commands) != 1 | |
" pty_open() use pipe. | |
let hstdout = 1 | |
else | |
1000 0.001863 let mode = 'O_WRONLY | O_CREAT' | |
1000 0.004528 if command.fd.stdout =~ '^>' | |
let mode .= ' | O_APPEND' | |
let command.fd.stdout = command.fd.stdout[1:] | |
else | |
1000 0.003430 let mode .= ' | O_TRUNC' | |
1000 0.000743 endif | |
1000 0.019109 0.007047 let hstdout = s:is_pseudo_device(command.fd.stdout) ? 0 : vimproc#fopen(command.fd.stdout, mode).fd | |
1000 0.000767 endif | |
1000 0.002345 if is_pty && command.fd.stderr == '' && cnt == 0 && len(a:commands) != 1 | |
" pty_open() use pipe. | |
let hstderr = 1 | |
else | |
1000 0.002323 let mode = 'O_WRONLY | O_CREAT' | |
1000 0.003457 if command.fd.stderr =~ '^>' | |
let mode .= ' | O_APPEND' | |
let command.fd.stderr = command.fd.stderr[1:] | |
else | |
1000 0.002069 let mode .= ' | O_TRUNC' | |
1000 0.000634 endif | |
1000 0.017466 0.006259 let hstderr = s:is_pseudo_device(command.fd.stderr) ? 0 : vimproc#fopen(command.fd.stderr, mode).fd | |
1000 0.000737 endif | |
1000 0.002524 if command.fd.stderr ==# '/dev/stdout' | |
let npipe = 2 | |
endif | |
1000 1.387238 0.005350 let args = s:convert_args(command.args) | |
1000 0.005320 let command_name = fnamemodify(args[0], ':t:r') | |
1000 0.007976 let pty_npipe = cnt == 0 && hstdin == 0 && hstdout == 0 && hstderr == 0 && exists('g:vimproc_popen2_commands') && get(g:vimproc_popen2_commands, command_name, 0) != 0 ? 2 : npipe | |
1000 0.002527 if is_pty && (cnt == 0 || cnt == len(a:commands)-1) | |
" Use pty_open(). | |
let pipe = s:vp_pty_open(pty_npipe, winwidth(0)-5, winheight(0), hstdin, hstdout, hstderr, args) | |
else | |
1000 0.800576 0.026799 let pipe = s:vp_pipe_open(pty_npipe, hstdin, hstdout, hstderr, args) | |
1000 0.001529 endif | |
1000 0.002717 if len(pipe) == 4 | |
1000 0.004251 let [pid, fd_stdin, fd_stdout, fd_stderr] = pipe | |
1000 0.262469 0.028996 let stderr = s:fdopen(fd_stderr, 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
1000 0.001077 else | |
let [pid, fd_stdin, fd_stdout] = pipe | |
let stderr = s:closed_fdopen( 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
endif | |
1000 0.016472 call add(pid_list, pid) | |
1000 0.147210 0.007210 let stdin = s:fdopen(fd_stdin, 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
1000 0.004558 let stdin.is_pty = is_pty && (cnt == 0 || cnt == len(a:commands)-1) && hstdin == 0 | |
1000 0.008658 call add(stdin_list, stdin) | |
1000 0.144067 0.006469 let stdout = s:fdopen(fd_stdout, 'vp_pipe_close', 'vp_pipe_read', 'vp_pipe_write') | |
1000 0.003951 let stdout.is_pty = is_pty && (cnt == 0 || cnt == len(a:commands)-1) && hstdout == 0 | |
1000 0.005708 call add(stdout_list, stdout) | |
1000 0.054742 let stderr.is_pty = is_pty && (cnt == 0 || cnt == len(a:commands)-1) && hstderr == 0 | |
1000 0.005136 call add(stderr_list, stderr) | |
1000 0.006547 let hstdin = stdout_list[-1].fd | |
1000 0.003560 let cnt += 1 | |
1000 0.001274 endfor | |
1000 0.002198 let proc = {} | |
1000 0.002199 let proc.pid_list = pid_list | |
1000 0.003004 let proc.pid = pid_list[-1] | |
1000 0.111981 0.006706 let proc.stdin = s:fdopen_pipes(stdin_list, 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
1000 0.113163 0.006578 let proc.stdout = s:fdopen_pipes(stdout_list, 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
1000 0.121309 0.006762 let proc.stderr = s:fdopen_pipes(stderr_list, 'vp_pipes_close', 'read_pipes', 'write_pipes') | |
1000 0.020387 0.005591 let proc.get_winsize = s:funcref('vp_get_winsize') | |
1000 0.019168 0.005254 let proc.set_winsize = s:funcref('vp_set_winsize') | |
1000 0.018625 0.004939 let proc.kill = s:funcref('vp_kill') | |
1000 0.017780 0.004740 let proc.waitpid = s:funcref('vp_waitpid') | |
1000 0.018019 0.004813 let proc.checkpid = s:funcref('vp_checkpid') | |
1000 0.002089 let proc.is_valid = 1 | |
1000 0.001937 let proc.is_pty = is_pty | |
1000 0.001288 if a:is_pty | |
let proc.ttyname = '' | |
let proc.get_winsize = s:funcref('vp_get_winsize') | |
let proc.set_winsize = s:funcref('vp_set_winsize') | |
endif | |
1000 0.006802 return proc | |
FUNCTION vimproc#decode_signal() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:signal == 2 | |
return 'SIGINT' | |
elseif a:signal == 3 | |
return 'SIGQUIT' | |
elseif a:signal == 4 | |
return 'SIGILL' | |
elseif a:signal == 6 | |
return 'SIGABRT' | |
elseif a:signal == 8 | |
return 'SIGFPE' | |
elseif a:signal == 9 | |
return 'SIGKILL' | |
elseif a:signal == 11 | |
return 'SIGSEGV' | |
elseif a:signal == 13 | |
return 'SIGPIPE' | |
elseif a:signal == 14 | |
return 'SIGALRM' | |
elseif a:signal == 15 | |
return 'SIGTERM' | |
elseif a:signal == 10 | |
return 'SIGUSR1' | |
elseif a:signal == 12 | |
return 'SIGUSR2' | |
elseif a:signal == 17 | |
return 'SIGCHLD' | |
elseif a:signal == 18 | |
return 'SIGCONT' | |
elseif a:signal == 19 | |
return 'SIGSTOP' | |
elseif a:signal == 20 | |
return 'SIGTSTP' | |
elseif a:signal == 21 | |
return 'SIGTTIN' | |
elseif a:signal == 22 | |
return 'SIGTTOU' | |
else | |
return 'UNKNOWN' | |
endif | |
FUNCTION <SNR>140_skip_single_quote() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let max = len(a:script) | |
let string = '' | |
let i = a:i | |
" a:script[i] is always "'" when this function is called | |
if i >= max || a:script[i] != '''' | |
throw 'Exception: Quote ('') is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
while i < max | |
if a:script[i] == '''' | |
if i+1 < max && a:script[i+1] == '''' | |
" Escape quote. | |
let string .= a:script[i] | |
let i += 1 | |
else | |
break | |
endif | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endwhile | |
if i < max | |
" must end with "'" | |
if a:script[i] != '''' | |
throw 'Exception: Quote ('') is not found.' | |
endif | |
let string .= a:script[i] | |
let i += 1 | |
endif | |
return [string, i] | |
FUNCTION <SNR>138_read() | |
Called 7764 times | |
Total time: 1.556420 | |
Self time: 0.230253 | |
count total (s) self (s) | |
7764 0.013660 if self.__eof | |
let self.eof = 1 | |
return '' | |
endif | |
7764 0.020460 let number = get(a:000, 0, -1) | |
7764 0.022879 let timeout = get(a:000, 1, s:read_timeout) | |
7764 1.281076 0.055391 let [hd, eof] = self.f_read(number, timeout) | |
7764 0.018255 let self.eof = eof | |
7764 0.014042 let self.__eof = eof | |
7764 0.013195 if hd == '' | |
6764 0.007423 return '' | |
endif | |
" Note: if output string is too long, if_lua is too slow. | |
1000 0.119432 0.018950 return (vimproc#util#has_lua() && len(hd) < 1024) ? s:hd2str_lua([hd]) : s:hd2str([hd]) | |
" return s:hd2str([hd]) | |
FUNCTION vimproc#parser#parse_statements() | |
Called 1000 times | |
Total time: 1.611962 | |
Self time: 1.503834 | |
count total (s) self (s) | |
1000 0.008529 if type(a:script) == type('') && a:script =~ '^\s*:' | |
return [ { 'statement' : a:script, 'condition' : 'always' } ] | |
endif | |
1000 0.032403 let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
1000 0.002698 let max = len(script) | |
1000 0.001689 let statements = [] | |
1000 0.001532 let statement = '' | |
1000 0.001245 let i = 0 | |
23000 0.021302 while i < max | |
22000 0.042988 if script[i] == ';' | |
if statement != '' | |
call add(statements, { 'statement' : statement, 'condition' : 'always',}) | |
endif | |
let statement = '' | |
let i += 1 | |
elseif script[i] == '&' | |
if i+1 < max && script[i+1] == '&' | |
if statement != '' | |
call add(statements, { 'statement' : statement, 'condition' : 'true',}) | |
endif | |
let statement = '' | |
let i += 2 | |
else | |
let statement .= script[i] | |
let i += 1 | |
endif | |
elseif script[i] == '|' | |
if i+1 < max && script[i+1] == '|' | |
if statement != '' | |
call add(statements, { 'statement' : statement, 'condition' : 'false',}) | |
endif | |
let statement = '' | |
let i += 2 | |
else | |
let statement .= script[i] | |
let i += 1 | |
endif | |
elseif script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let statement .= string | |
elseif script[i] == '"' | |
" Double quote. | |
1000 0.119871 0.011743 let [string, i] = s:skip_double_quote(script, i) | |
1000 0.002484 let statement .= string | |
1000 0.001165 elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let statement .= string | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let statement .= '\' . script[i] | |
let i += 1 | |
elseif script[i] == '#' | |
" Comment. | |
break | |
else | |
21000 0.054313 let statement .= script[i] | |
21000 0.026732 let i += 1 | |
21000 0.012572 endif | |
22000 0.015132 endwhile | |
1000 0.008630 if statement !~ '^\s*$' | |
1000 0.006420 call add(statements, { 'statement' : statement, 'condition' : 'always',}) | |
1000 0.000780 endif | |
1000 0.001238 return statements | |
FUNCTION <SNR>138_list2str() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return s:hd2str(s:list2hd([a:lis])) | |
FUNCTION <SNR>138_vp_get_winsize() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if self.is_pty && vimproc#util#is_windows() | |
return [winwidth(0)-5, winheight(0)] | |
endif | |
for pid in self.pid_list | |
let [width, height] = s:libcall('vp_pty_get_winsize', [pid]) | |
endfor | |
return [width, height] | |
FUNCTION <SNR>138_pgroup_open() | |
Called 1000 times | |
Total time: 4.113566 | |
Self time: 0.125704 | |
count total (s) self (s) | |
1000 0.001696 let proc = {} | |
1000 3.631350 0.016254 let proc.current_proc = vimproc#plineopen{a:npipe}(a:statements[0].statement, a:is_pty) | |
1000 0.003404 let proc.pid = proc.current_proc.pid | |
1000 0.003197 let proc.pid_list = proc.current_proc.pid_list | |
1000 0.042276 let proc.condition = a:statements[0].condition | |
1000 0.004156 let proc.statements = a:statements[1:] | |
1000 0.127410 0.010735 let proc.stdin = s:fdopen_pgroup(proc, proc.current_proc.stdin, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
1000 0.120766 0.007537 let proc.stdout = s:fdopen_pgroup(proc, proc.current_proc.stdout, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
1000 0.120857 0.007557 let proc.stderr = s:fdopen_pgroup(proc, proc.current_proc.stderr, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
1000 0.020040 0.005267 let proc.kill = s:funcref('vp_pgroup_kill') | |
1000 0.020020 0.005231 let proc.waitpid = s:funcref('vp_pgroup_waitpid') | |
1000 0.002149 let proc.is_valid = 1 | |
1000 0.001825 let proc.is_pty = 0 | |
" echomsg expand('<sfile>') | |
" echomsg 'open:' string(map(copy(proc.current_proc.stdin.fd), 'v:val.fd')) | |
" echomsg 'open:' string(map(copy(proc.current_proc.stdout.fd), 'v:val.fd')) | |
" echomsg 'open:' string(map(copy(proc.current_proc.stderr.fd), 'v:val.fd')) | |
1000 0.004205 return proc | |
FUNCTION <SNR>138_write_pipes() | |
Called 1000 times | |
Total time: 0.500360 | |
Self time: 0.025581 | |
count total (s) self (s) | |
1000 0.003608 let timeout = get(a:000, 0, s:write_timeout) | |
1000 0.002278 if self.fd[0].eof | |
return 0 | |
endif | |
" Write data. | |
1000 0.484499 0.009720 let nleft = self.fd[0].write(a:str, timeout) | |
1000 0.003511 let self.eof = self.fd[0].eof | |
1000 0.001324 return nleft | |
FUNCTION <SNR>138_vp_pgroup_kill() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:sig != 0 | |
call s:close_all(self) | |
let self.is_valid = 0 | |
endif | |
if self.pid == 0 | |
" Ignore. | |
return | |
endif | |
return self.current_proc.kill(a:sig) | |
FUNCTION <SNR>140_parse_single_quote() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:script[a:i] != "'" | |
return ['', a:i] | |
endif | |
let arg = '' | |
let i = a:i + 1 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == "'" | |
if i+1 < max && a:script[i+1] == "'" | |
" Escape quote. | |
let arg .= "'" | |
let i += 2 | |
else | |
" Quote end. | |
return [arg, i+1] | |
endif | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
throw 'Exception: Quote ('') is not found.' | |
FUNCTION <SNR>138_str2list() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return map(range(len(a:str)), 'char2nr(a:str[v:val])') | |
FUNCTION <SNR>138_list2hd() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return join(map(a:lis, 'printf("%02X", v:val)'), '') | |
FUNCTION <SNR>138_finalize() | |
Called 1 time | |
Total time: 0.000252 | |
Self time: 0.000016 | |
count total (s) self (s) | |
1 0.000039 0.000005 call s:garbage_collect(1) | |
1 0.000004 if exists('s:dll_handle') | |
1 0.000207 0.000005 call s:vp_dlclose(s:dll_handle) | |
1 0.000001 endif | |
FUNCTION <SNR>140_parse_variables() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
try | |
while i < max | |
if a:script[i] == '$' && a:script[i :] =~ '^$$\?\h' | |
" Eval variables. | |
let variable_name = matchstr(a:script, '^$$\?\zs\h\w*', i) | |
if exists('b:vimshell') | |
" For vimshell. | |
let script_head = a:script[i :] | |
if script_head =~ '^$\l' && has_key(b:vimshell.variables, variable_name) | |
let script .= b:vimshell.variables[variable_name] | |
elseif script_head =~ '^\$\$' && has_key(b:vimshell.system_variables, variable_name) | |
let script .= b:vimshell.system_variables[variable_name] | |
elseif script_head =~ '^$\h' | |
let script .= vimproc#util#substitute_path_separator( eval(variable_name)) | |
endif | |
else | |
let script .= vimproc#util#substitute_path_separator( eval(matchstr(a:script, '^$\h\w*', i))) | |
endif | |
let i = matchend(a:script, '^$$\?\h\w*', i) | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
catch /^Vim\%((\a\+)\)\=:E15/ | |
" Parse error. | |
return a:script | |
endtry | |
return script | |
FUNCTION <SNR>140_parse_redirection() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = '' | |
let fd = { 'stdin' : '', 'stdout' : '', 'stderr' : '' } | |
let i = 0 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == '<' | |
" Input redirection. | |
let fd.stdin = matchstr(a:script, '<\s*\zs\f*', i) | |
let i = matchend(a:script, '<\s*\zs\f*', i) | |
elseif a:script[i] =~ '^[12]' && a:script[i :] =~ '^[12]>' | |
" Output redirection. | |
let i += 2 | |
if a:script[i-2] == 1 | |
let fd.stdout = matchstr(a:script, '^\s*\zs\f*', i) | |
else | |
let fd.stderr = matchstr(a:script, '^\s*\zs\(\f\+\|&\d\+\)', i) | |
if fd.stderr ==# '&1' | |
" Redirection to stdout. | |
let fd.stderr = '/dev/stdout' | |
endif | |
endif | |
let i = matchend(a:script, '^\s*\zs\(\f\+\|&\d\+\)', i) | |
elseif a:script[i] == '>' | |
" Output redirection. | |
if a:script[i :] =~ '^>&' | |
" Output stderr. | |
let i += 2 | |
let fd.stderr = matchstr(a:script, '^\s*\zs\f*', i) | |
elseif a:script[i :] =~ '^>>' | |
" Append stdout. | |
let i += 2 | |
let fd.stdout = '>' . matchstr(a:script, '^\s*\zs\f*', i) | |
else | |
" Output stdout. | |
let i += 1 | |
let fd.stdout = matchstr(a:script, '^\s*\zs\f*', i) | |
endif | |
let i = matchend(a:script, '^\s*\zs\f*', i) | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return [fd, script] | |
FUNCTION <SNR>138_vp_checkpid() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
try | |
let [cond, status] = s:libcall('vp_waitpid', [self.pid]) | |
if cond !=# 'run' | |
let [self.cond, self.status] = [cond, status] | |
endif | |
catch /waitpid() error:\|vp_waitpid:/ | |
let [cond, status] = ['error', '0'] | |
endtry | |
return [cond, str2nr(status)] | |
FUNCTION <SNR>138_str2hd() | |
Called 1000 times | |
Total time: 0.189896 | |
Self time: 0.189896 | |
count total (s) self (s) | |
1000 0.189188 return join(map(range(len(a:str)), 'printf("%02X", char2nr(a:str[v:val]))'), '') | |
FUNCTION vimproc#delete_trash() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if !vimproc#util#is_windows() | |
call s:print_error('Not implemented in this platform.') | |
return | |
endif | |
let filename = a:filename | |
if !filewritable(filename) && !isdirectory(filename) | |
return 1 | |
endif | |
" Substitute path separator to "/". | |
let filename = substitute( fnamemodify(filename, ':p'), '/', '\\', 'g') | |
" Delete last /. | |
if filename =~ '[^:][/\\]$' | |
" Delete last /. | |
let filename = filename[: -2] | |
endif | |
" Encoding conversion. | |
let filename = vimproc#util#iconv(filename, &encoding, vimproc#util#termencoding()) | |
let [ret] = s:libcall('vp_delete_trash', [filename]) | |
return str2nr(ret) | |
FUNCTION <SNR>140_parse_tilde() | |
Called 1000 times | |
Total time: 1.258588 | |
Self time: 0.465511 | |
count total (s) self (s) | |
1000 0.003636 let script = '' | |
1000 0.001693 let i = 0 | |
1000 0.002594 let max = len(a:script) | |
23000 0.021754 while i < max | |
22000 0.060717 if a:script[i] == ' ' && a:script[i+1] == '~' | |
" Tilde. | |
" Expand home directory. | |
let script .= ' ' . escape(substitute($HOME, '\\', '/', 'g'), '\ ') | |
let i += 2 | |
elseif i == 0 && a:script[i] == '~' | |
" Tilde. | |
" Expand home directory. | |
let script .= escape(substitute($HOME, '\\', '/', 'g'), '\ ') | |
let i += 1 | |
else | |
22000 0.913555 0.120478 let [script, i] = s:skip_else(script, a:script, i) | |
22000 0.015069 endif | |
22000 0.012837 endwhile | |
1000 0.001069 return script | |
FUNCTION vimproc#get_last_errmsg() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return substitute(vimproc#util#iconv(s:last_errmsg, vimproc#util#stderrencoding(), &encoding), '\n$', '', '') | |
FUNCTION <SNR>138_write_pgroup() | |
Called 1000 times | |
Total time: 0.523222 | |
Self time: 0.022862 | |
count total (s) self (s) | |
1000 0.005434 let timeout = get(a:000, 0, s:write_timeout) | |
1000 0.001649 let nleft = 0 | |
1000 0.001675 if !self.fd.eof | |
" Write data. | |
1000 0.507837 0.007477 let nleft = self.fd.write(a:str, timeout) | |
1000 0.000858 endif | |
1000 0.001093 return nleft | |
FUNCTION <SNR>138_fdopen() | |
Called 3000 times | |
Total time: 0.511071 | |
Self time: 0.125570 | |
count total (s) self (s) | |
3000 0.496416 0.110915 return { 'fd' : a:fd, 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'),} | |
FUNCTION vimproc#system2() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if empty(a:000) | |
return '' | |
endif | |
if len(a:0) > 1 | |
let args = deepcopy(a:000) | |
let args[1] = vimproc#util#iconv( args[1], &encoding, vimproc#util#stdinencoding()) | |
else | |
let args = a:000 | |
endif | |
let output = call('vimproc#system', args) | |
" This function converts application encoding to &encoding. | |
let output = vimproc#util#iconv( output, vimproc#util#stdoutencoding(), &encoding) | |
let s:last_errmsg = vimproc#util#iconv( s:last_errmsg, vimproc#util#stderrencoding(), &encoding) | |
return output | |
FUNCTION vimproc#write() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:string == '' | |
return | |
endif | |
let mode = get(a:000, 0, a:filename =~ '^>' ? 'a' : 'w') | |
let filename = a:filename =~ '^>' ? a:filename[1:] : a:filename | |
if filename ==# '/dev/null' | |
" Nothing. | |
elseif filename ==# '/dev/clip' | |
" Write to clipboard. | |
if mode =~ 'a' | |
let @+ .= a:string | |
else | |
let @+ = a:string | |
endif | |
elseif filename ==# '/dev/quickfix' | |
" Write to quickfix. | |
let qflist = getqflist() | |
for str in split(a:string, '\n\|\r\n') | |
if str =~ '^.\+:.\+:.\+$' | |
let line = split(str[2:], ':') | |
let filename = str[:1] . line[0] | |
if len(line) >= 3 && line[1] =~ '^\d\+$' | |
call add(qflist, { 'filename' : filename, 'lnum' : line[1], 'text' : join(line[2:], ':'), }) | |
else | |
call add(qflist, { 'text' : str, }) | |
endif | |
endif | |
endfor | |
call setqflist(qflist) | |
else | |
" Write file. | |
let mode = 'O_WRONLY | O_CREAT' | |
if mode =~ 'a' | |
" Append mode. | |
let mode .= '| O_APPEND' | |
endif | |
let hfile = vimproc#fopen(filename, mode) | |
call hfile.write(a:string) | |
call hfile.close() | |
endif | |
FUNCTION vimproc#readdir() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let dirname = substitute(substitute( vimproc#util#expand(a:dirname), '\\', '/', 'g'), '/$', '', '') | |
if dirname == '' | |
let dirname = getcwd() | |
endif | |
if !isdirectory(dirname) | |
return [] | |
endif | |
let dirname = vimproc#util#iconv(dirname, &encoding, vimproc#util#termencoding()) | |
try | |
let files = s:libcall('vp_readdir', [dirname]) | |
catch /vp_readdir/ | |
return [] | |
endtry | |
call map(files, 'vimproc#util#iconv( v:val, vimproc#util#termencoding(), &encoding)') | |
if vimproc#util#is_windows() | |
call map(files, 'vimproc#util#substitute_path_separator(v:val)') | |
endif | |
return files | |
FUNCTION <SNR>138_garbage_collect() | |
Called 1 time | |
Total time: 0.000034 | |
Self time: 0.000034 | |
count total (s) self (s) | |
1 0.000005 for pid in values(s:bg_processes) | |
" Check processes. | |
try | |
let [cond, status] = s:libcall('vp_waitpid', [pid]) | |
" echomsg string([pid, cond, status]) | |
if cond !=# 'run' || a:is_force | |
if cond !=# 'exit' | |
" Kill process. | |
" 15 == SIGTERM | |
call vimproc#kill(pid, 15) | |
endif | |
if vimproc#util#is_windows() | |
call s:libcall('vp_close_handle', [pid]) | |
endif | |
call remove(s:bg_processes, pid) | |
endif | |
catch | |
" Ignore error. | |
endtry | |
endfor | |
FUNCTION <SNR>138_read_pipes() | |
Called 7764 times | |
Total time: 1.778845 | |
Self time: 0.222425 | |
count total (s) self (s) | |
7764 0.035331 if type(self.fd[-1]) != type({}) | |
let self.eof = 1 | |
return '' | |
endif | |
7764 0.021043 let number = get(a:000, 0, -1) | |
7764 0.023275 let timeout = get(a:000, 1, s:read_timeout) | |
7764 1.613859 0.057439 let output = self.fd[-1].read(number, timeout) | |
7764 0.027131 let self.eof = self.fd[-1].eof | |
7764 0.011455 return output | |
FUNCTION <SNR>138_split() | |
Called 13767 times | |
Total time: 0.697695 | |
Self time: 0.697695 | |
count total (s) self (s) | |
13767 0.031818 let result = [] | |
13767 0.013884 lua << EOF | |
do | |
local result = vim.eval('result') | |
local str = vim.eval('a:str') | |
local sep = vim.eval('a:sep') | |
local last | |
if string.find(str, sep, 1, true) == nil then | |
result:add(str) | |
else | |
for part, pos in string.gmatch(str, | |
'(.-)' .. sep .. '()') do | |
result:add(part) | |
last = pos | |
end | |
result:add(string.sub(str, last)) | |
end | |
end | |
EOF | |
13767 0.025868 return result | |
FUNCTION <SNR>138_vp_file_open() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [fd] = s:libcall('vp_file_open', [a:path, a:flags, a:mode]) | |
return fd | |
FUNCTION <SNR>140_parse_equal() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
while i < max - 1 | |
if a:script[i] == ' ' && a:script[i+1] == '=' | |
" Expand filename. | |
let prog = matchstr(a:script, '^=\zs[^[:blank:]]*', i+1) | |
if prog == '' | |
let [script, i] = s:skip_else(script, a:script, i) | |
else | |
let filename = vimproc#get_command_path(prog) | |
if filename == '' | |
throw printf('Error: File "%s" is not found.', prog) | |
else | |
let script .= filename | |
endif | |
let i += matchend(a:script, '^=[^[:blank:]]*', i+1) | |
endif | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return script | |
FUNCTION <SNR>138_is_pseudo_device() | |
Called 2000 times | |
Total time: 0.023269 | |
Self time: 0.019781 | |
count total (s) self (s) | |
2000 0.012728 0.009240 if vimproc#util#is_windows() && ( a:filename ==# '/dev/stdin' || a:filename ==# '/dev/stdout' || a:filename ==# '/dev/stderr') | |
return 1 | |
endif | |
2000 0.005021 return a:filename == '' || a:filename ==# '/dev/null' || a:filename ==# '/dev/clip' || a:filename ==# '/dev/quickfix' | |
FUNCTION vimproc#shellescape() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return string(a:string) | |
FUNCTION vimproc#version() | |
Called 2 times | |
Total time: 0.000012 | |
Self time: 0.000012 | |
count total (s) self (s) | |
2 0.000011 return str2nr(printf('%2d%02d', 7, 1)) | |
FUNCTION <SNR>138_vp_pgroup_waitpid() | |
Called 1000 times | |
Total time: 0.086859 | |
Self time: 0.016724 | |
count total (s) self (s) | |
1000 0.074581 0.004446 call s:close_all(self) | |
1000 0.001325 let self.is_valid = 0 | |
1000 0.003369 if !has_key(self, 'cond') || !has_key(self, 'status') | |
return s:waitpid(self.pid) | |
endif | |
1000 0.002167 return [self.cond, self.status] | |
FUNCTION <SNR>140_parse_back_quote() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:script[a:i] != '`' | |
return ['', a:i] | |
endif | |
let arg = '' | |
let max = len(a:script) | |
if a:i + 1 < max && a:script[a:i + 1] == '=' | |
" Vim eval quote. | |
let i = a:i + 2 | |
while i < max | |
if a:script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= '\' . a:script[i] | |
let i += 1 | |
elseif a:script[i] == '`' | |
" Quote end. | |
return [eval(arg), i+1] | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
else | |
" Eval quote. | |
let i = a:i + 1 | |
while i < max | |
if a:script[i] == '`' | |
" Quote end. | |
return [substitute(vimproc#system(arg), '\n$', '', ''), i+1] | |
else | |
let arg .= a:script[i] | |
let i += 1 | |
endif | |
endwhile | |
endif | |
throw 'Exception: Quote (`) is not found.' | |
FUNCTION <SNR>138_vp_file_write() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [nleft] = s:libcall('vp_file_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
FUNCTION <SNR>138_read_pgroup() | |
Called 7764 times | |
Total time: 2.916029 | |
Self time: 0.569625 | |
count total (s) self (s) | |
7764 0.027215 let number = get(a:000, 0, -1) | |
7764 0.025254 let timeout = get(a:000, 1, s:read_timeout) | |
7764 0.012087 let output = '' | |
7764 0.012287 if !self.fd.eof | |
7764 1.829422 0.050577 let output = self.fd.read(number, timeout) | |
7764 0.007034 endif | |
7764 0.021693 if self.proc.current_proc.stdout.eof && self.proc.current_proc.stderr.eof | |
" Get status. | |
1000 0.577950 0.010391 let [cond, status] = self.proc.current_proc.waitpid() | |
1000 0.004115 if empty(self.proc.statements) || (self.proc.condition ==# 'true' && status) || (self.proc.condition ==# 'false' && !status) | |
1000 0.002120 let self.proc.statements = [] | |
" Caching status. | |
1000 0.002287 let self.proc.cond = cond | |
1000 0.002016 let self.proc.status = status | |
1000 0.000695 else | |
" Initialize next statement. | |
let proc = vimproc#plineopen3(self.proc.statements[0].statement) | |
let self.proc.current_proc = proc | |
let self.pid = proc.pid | |
let self.pid_list = proc.pid_list | |
let self.proc.condition = self.proc.statements[0].condition | |
let self.proc.statements = self.proc.statements[1:] | |
let self.proc.stdin = s:fdopen_pgroup(self.proc, proc.stdin, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let self.proc.stdout = s:fdopen_pgroup(self.proc, proc.stdout, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
let self.proc.stderr = s:fdopen_pgroup(self.proc, proc.stderr, 'vp_pgroup_close', 'read_pgroup', 'write_pgroup') | |
endif | |
1000 0.000522 endif | |
7764 0.012439 if self.proc.current_proc.stdout.eof | |
1694 0.003032 let self.proc.stdout.eof = 1 | |
1694 0.002663 let self.proc.stdout.__eof = 1 | |
1694 0.001060 endif | |
7764 0.010672 if self.proc.current_proc.stderr.eof | |
1306 0.002061 let self.proc.stderr.eof = 1 | |
1306 0.001884 let self.proc.stderr.__eof = 1 | |
1306 0.000752 endif | |
7764 0.009122 return output | |
FUNCTION <SNR>138_hd2list() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return map(split(a:hd, '..\zs'), 'str2nr(v:val, 16)') | |
FUNCTION vimproc#open() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let filename = vimproc#util#iconv(fnamemodify(a:filename, ':p'), &encoding, vimproc#util#termencoding()) | |
if filename =~ '^\%(https\?\|ftp\)://' && !vimproc#host_exists(filename) | |
" URI is invalid. | |
call s:print_error('vimproc#open: URI "' . filename . '" is invalid.') | |
return | |
endif | |
" Detect desktop environment. | |
if vimproc#util#is_windows() | |
" For URI only. | |
"execute '!start rundll32 url.dll,FileProtocolHandler' filename | |
call s:libcall('vp_open', [filename]) | |
elseif has('win32unix') | |
" Cygwin. | |
call vimproc#system(['cygstart', filename]) | |
elseif executable('xdg-open') | |
" Linux. | |
call vimproc#system_bg(['xdg-open', filename]) | |
elseif exists('$KDE_FULL_SESSION') && $KDE_FULL_SESSION ==# 'true' | |
" KDE. | |
call vimproc#system_bg(['kioclient', 'exec', filename]) | |
elseif exists('$GNOME_DESKTOP_SESSION_ID') | |
" GNOME. | |
call vimproc#system_bg(['gnome-open', filename]) | |
elseif executable('exo-open') | |
" Xfce. | |
call vimproc#system_bg(['exo-open', filename]) | |
elseif vimproc#util#is_mac() && executable('open') | |
" Mac OS. | |
call vimproc#system_bg(['open', filename]) | |
else | |
" Give up. | |
call s:print_error('vimproc#open: Not supported.') | |
endif | |
FUNCTION <SNR>138_vp_set_winsize() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if vimproc#util#is_windows() || !self.is_valid | |
" Not implemented. | |
return | |
endif | |
if self.is_pty | |
if self.stdin.eof == 0 && self.stdin.fd[-1].is_pty | |
call s:libcall('vp_pty_set_winsize', [self.stdin.fd[-1].fd, a:width-5, a:height]) | |
endif | |
if self.stdout.eof == 0 && self.stdout.fd[0].is_pty | |
call s:libcall('vp_pty_set_winsize', [self.stdout.fd[0].fd, a:width-5, a:height]) | |
endif | |
if self.stderr.eof == 0 && self.stderr.fd[0].is_pty | |
call s:libcall('vp_pty_set_winsize', [self.stderr.fd[0].fd, a:width-5, a:height]) | |
endif | |
endif | |
" Send SIGWINCH = 28 signal. | |
for pid in self.pid_list | |
call vimproc#kill(pid, 28) | |
endfor | |
FUNCTION <SNR>138_vp_socket_write() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [nleft] = s:libcall('vp_socket_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
FUNCTION vimproc#plineopen2() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let commands = type(a:commands) == type('') ? vimproc#parser#parse_pipe(a:commands) : a:commands | |
let is_pty = get(a:000, 0, 0) | |
return s:plineopen(2, commands, is_pty) | |
FUNCTION vimproc#pgroup_open() | |
Called 1000 times | |
Total time: 4.143299 | |
Self time: 0.029733 | |
count total (s) self (s) | |
1000 0.002730 if type(a:statements) == type('') | |
let statements = vimproc#parser#parse_statements(a:statements) | |
for statement in statements | |
let statement.statement = vimproc#parser#parse_pipe(statement.statement) | |
endfor | |
else | |
1000 0.001970 let statements = a:statements | |
1000 0.000579 endif | |
1000 0.002392 let is_pty = get(a:000, 0, 0) | |
1000 0.002214 let npipe = get(a:000, 1, 3) | |
1000 4.123172 0.009606 return s:pgroup_open(statements, is_pty && !vimproc#util#is_windows(), npipe) | |
FUNCTION vimproc#fopen() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let mode = get(a:000, 0, 0644) | |
let fd = s:vp_file_open(a:path, a:flags, mode) | |
let proc = s:fdopen(fd, 'vp_file_close', 'vp_file_read', 'vp_file_write') | |
return proc | |
FUNCTION vimproc#get_last_status() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return s:last_status | |
FUNCTION vimproc#parser#split_pipe() | |
Called 1000 times | |
Total time: 0.874019 | |
Self time: 0.773370 | |
count total (s) self (s) | |
1000 0.033543 let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
1000 0.003172 let max = len(script) | |
1000 0.001518 let command = '' | |
1000 0.001260 let i = 0 | |
1000 0.001406 let commands = [] | |
23000 0.019729 while i < max | |
22000 0.039835 if script[i] == '|' | |
" Pipe. | |
call add(commands, command) | |
" Search next command. | |
let command = '' | |
let i += 1 | |
elseif script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let command .= string | |
elseif script[i] == '"' | |
" Double quote. | |
1000 0.107129 0.006480 let [string, i] = s:skip_double_quote(script, i) | |
1000 0.002296 let command .= string | |
1000 0.001140 elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let command .= string | |
elseif script[i] == '\' && i + 1 < max | |
" Escape. | |
let command .= '\' . script[i+1] | |
let i += 2 | |
else | |
21000 0.050796 let command .= script[i] | |
21000 0.023734 let i += 1 | |
21000 0.012099 endif | |
22000 0.012881 endwhile | |
1000 0.003758 call add(commands, command) | |
1000 0.001211 return commands | |
FUNCTION <SNR>138_funcref() | |
Called 67000 times | |
Total time: 0.991150 | |
Self time: 0.448052 | |
count total (s) self (s) | |
67000 0.961953 0.418855 return function(s:SID_PREFIX().a:funcname) | |
FUNCTION <SNR>138_vp_pipe_open() | |
Called 1000 times | |
Total time: 0.773777 | |
Self time: 0.073011 | |
count total (s) self (s) | |
1000 0.005446 0.003628 if vimproc#util#is_windows() | |
let cmdline = s:quote_arg(substitute(a:argv[0], '/', '\', 'g')) | |
for arg in a:argv[1:] | |
let cmdline .= ' ' . s:quote_arg(arg) | |
endfor | |
let [pid; fdlist] = s:libcall('vp_pipe_open', [a:npipe, a:hstdin, a:hstdout, a:hstderr, cmdline]) | |
else | |
1000 0.729541 0.030593 let [pid; fdlist] = s:libcall('vp_pipe_open', [a:npipe, a:hstdin, a:hstdout, a:hstderr, len(a:argv)] + a:argv) | |
1000 0.001414 endif | |
1000 0.002991 if a:npipe != len(fdlist) | |
call s:print_error(printf('a:npipe = %d, a:argv = %s', a:npipe, string(a:argv))) | |
call s:print_error(printf('fdlist = %s', string(fdlist))) | |
echoerr 'Bug behavior is detected!: ' . pid | |
endif | |
1000 0.007420 return [pid] + fdlist | |
FUNCTION vimproc#analyze_shebang() | |
Called 1000 times | |
Total time: 0.194890 | |
Self time: 0.191017 | |
count total (s) self (s) | |
1000 0.092181 0.088308 if !filereadable(a:filename) || getfsize(a:filename) > 100000 || (vimproc#util#is_windows() && '.'.fnamemodify(a:filename, ':e') !~? '^'.substitute($PATHEXT, ';', '$\\|^', 'g').'$') | |
" Maybe a binary file. | |
return [a:filename] | |
endif | |
1000 0.075427 let lines = readfile(a:filename, '', 1) | |
1000 0.019261 if empty(lines) || lines[0] !~ '^#!.\+' | |
" Shebang not found. | |
1000 0.002261 return [a:filename] | |
endif | |
" Get shebang line. | |
let shebang = split(matchstr(lines[0], '^#!\zs.\+')) | |
" Convert command name. | |
if vimproc#util#is_windows() && shebang[0] =~ '^/' | |
let shebang[0] = vimproc#get_command_name( fnamemodify(shebang[0], ':t')) | |
endif | |
return shebang + [a:filename] | |
FUNCTION vimproc#ptyopen() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let commands = type(a:commands) == type('') ? vimproc#parser#parse_pipe(a:commands) : a:commands | |
let npipe = get(a:000, 0, 3) | |
return s:plineopen(npipe, commands, !vimproc#util#is_windows()) | |
FUNCTION <SNR>138_vp_dlopen() | |
Called 1 time | |
Total time: 0.000485 | |
Self time: 0.000010 | |
count total (s) self (s) | |
1 0.000483 0.000008 let [handle] = s:libcall('vp_dlopen', [a:path]) | |
1 0.000001 return handle | |
FUNCTION vimproc#parser#split_statements() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return map(vimproc#parser#parse_statements(a:script), 'v:val.statement') | |
FUNCTION vimproc#system_passwd() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if type(a:cmdline) == type('') | |
let args = vimproc#parser#parse_pipe(a:cmdline) | |
else | |
let args = [{ 'fd' : { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, 'args' : a:cmdline }] | |
endif | |
let timeout = a:0 >= 2 ? a:2 : 0 | |
let input = a:0 >= 1 ? a:1 : '' | |
let lang_save = $LANG | |
try | |
let $LANG = 'C' | |
return s:system(args, 1, input, timeout, 1) | |
finally | |
let $LANG = lang_save | |
endtry | |
FUNCTION <SNR>140_skip_else() | |
Called 22000 times | |
Total time: 0.793077 | |
Self time: 0.689958 | |
count total (s) self (s) | |
22000 0.053894 if a:script[a:i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(a:script, a:i) | |
let script = a:args . string | |
elseif a:script[a:i] == '"' | |
" Double quote. | |
1000 0.109034 0.005915 let [string, i] = s:skip_double_quote(a:script, a:i) | |
1000 0.002395 let script = a:args . string | |
1000 0.001262 elseif a:script[a:i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(a:script, a:i) | |
let script = a:args . string | |
elseif a:script[a:i] == '\' | |
" Escape. | |
let script = a:args . '\' . a:script[a:i+1] | |
let i = a:i + 2 | |
else | |
21000 0.059685 let script = a:args . a:script[a:i] | |
21000 0.037731 let i = a:i + 1 | |
21000 0.013404 endif | |
22000 0.034685 return [script, i] | |
FUNCTION <SNR>138_hd2str() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
" a:hd is a list because to avoid copying the value. | |
return get(s:libcall('vp_decode', [a:hd[0]]), 0, '') | |
FUNCTION vimproc#dll_version() | |
Called 1 time | |
Total time: 0.000114 | |
Self time: 0.000010 | |
count total (s) self (s) | |
1 0.000111 0.000007 let [dll_version] = s:libcall('vp_dlversion', []) | |
1 0.000003 return str2nr(dll_version) | |
FUNCTION <SNR>138_vp_pipe_close() | |
Called 3000 times | |
Total time: 0.387905 | |
Self time: 0.039629 | |
count total (s) self (s) | |
" echomsg 'close:'.self.fd | |
3000 0.005110 if self.fd != 0 | |
3000 0.369880 0.021604 call s:libcall('vp_pipe_close', [self.fd]) | |
3000 0.006168 let self.fd = 0 | |
3000 0.002101 endif | |
FUNCTION vimproc#test_readdir() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let start = reltime() | |
call split(glob(a:dirname.'/*'), '\n') | |
echomsg reltimestr(reltime(start)) | |
let start = reltime() | |
call vimproc#readdir(a:dirname) | |
echomsg reltimestr(reltime(start)) | |
FUNCTION <SNR>138_vp_pty_open() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [pid; fdlist] = s:libcall('vp_pty_open', [a:npipe, a:width, a:height, a:hstdin, a:hstdout, a:hstderr, len(a:argv)] + a:argv) | |
return [pid] + fdlist | |
FUNCTION <SNR>138_vp_waitpid() | |
Called 1000 times | |
Total time: 0.567559 | |
Self time: 0.049716 | |
count total (s) self (s) | |
1000 0.372416 0.009023 call s:close_all(self) | |
1000 0.002064 let self.is_valid = 0 | |
1000 0.003219 if has_key(self, 'cond') && has_key(self, 'status') | |
" Use cache. | |
let [cond, status] = [self.cond, self.status] | |
else | |
1000 0.164071 0.009621 let [cond, status] = s:waitpid(self.pid) | |
1000 0.000812 endif | |
1000 0.001524 if cond ==# 'exit' | |
1000 0.001551 let self.pid = 0 | |
1000 0.000586 endif | |
1000 0.002195 if has_key(self, 'pid_list') | |
1000 0.003425 for pid in self.pid_list[: -2] | |
call s:waitpid(pid) | |
endfor | |
1000 0.000522 endif | |
1000 0.002841 return [cond, str2nr(status)] | |
FUNCTION <SNR>138_vp_pty_close() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
call s:libcall('vp_pty_close', [self.fd]) | |
FUNCTION <SNR>138_vp_pipe_write() | |
Called 1000 times | |
Total time: 0.263796 | |
Self time: 0.017821 | |
count total (s) self (s) | |
1000 0.002721 if self.fd == 0 | |
return 0 | |
endif | |
1000 0.256016 0.010041 let [nleft] = s:libcall('vp_pipe_write', [self.fd, a:hd, a:timeout]) | |
1000 0.001630 return nleft | |
FUNCTION <SNR>138_quote_arg() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return a:arg =~ '[ "]' ? '"' . substitute(a:arg, '"', '\\"', 'g') . '"' : a:arg | |
FUNCTION vimproc#parser#split_args() | |
Called 1000 times | |
Total time: 1.364627 | |
Self time: 1.137431 | |
count total (s) self (s) | |
1000 0.035525 let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
1000 0.002789 let max = len(script) | |
1000 0.001415 let args = [] | |
1000 0.001279 let arg = '' | |
1000 0.001140 let i = 0 | |
23000 0.019814 while i < max | |
22000 0.042736 if script[i] == "'" | |
" Single quote. | |
let [arg_quote, i] = s:parse_single_quote(script, i) | |
let arg .= arg_quote | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '"' | |
" Double quote. | |
1000 0.237130 0.009934 let [arg_quote, i] = s:parse_double_quote(script, i) | |
1000 0.002336 let arg .= arg_quote | |
1000 0.001346 if arg == '' | |
call add(args, '') | |
endif | |
1000 0.001017 elseif script[i] == '`' | |
" Back quote. | |
let head = i > 0 ? script[: i-1] : [] | |
let [arg_quote, i] = s:parse_back_quote(script, i) | |
" Re-parse script. | |
return vimproc#parser#split_args( head + split(arg_quote, '\zs') + script[i :]) | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= script[i] | |
let i += 1 | |
elseif script[i] == '#' | |
" Comment. | |
break | |
elseif script[i] != ' ' | |
18000 0.043506 let arg .= script[i] | |
18000 0.020709 let i += 1 | |
18000 0.011116 else | |
" Space. | |
3000 0.003529 if arg != '' | |
3000 0.009091 call add(args, arg) | |
3000 0.001961 endif | |
3000 0.003694 let arg = '' | |
3000 0.003348 let i += 1 | |
3000 0.001794 endif | |
22000 0.013106 endwhile | |
1000 0.001337 if arg != '' | |
1000 0.003288 call add(args, arg) | |
1000 0.000668 endif | |
1000 0.001013 return args | |
FUNCTION <SNR>138_vp_pipe_read() | |
Called 7764 times | |
Total time: 1.225685 | |
Self time: 0.140384 | |
count total (s) self (s) | |
7764 0.014786 if self.fd == 0 | |
return ['', 1] | |
endif | |
7764 1.165047 0.079746 let [hd, eof] = s:libcall('vp_pipe_read', [self.fd, a:number, a:timeout]) | |
7764 0.019053 return [hd, eof] | |
FUNCTION <SNR>138_hd2str_lua() | |
Called 1000 times | |
Total time: 0.087670 | |
Self time: 0.087670 | |
count total (s) self (s) | |
1000 0.004652 let ret = [] | |
1000 0.001331 lua << EOF | |
do | |
local ret = vim.eval('ret') | |
local hd = vim.eval('a:hd') | |
if hd[0] == nil then | |
hd[0] = '' | |
end | |
local len = string.len(hd[0]) | |
local s = '' | |
for i = 1, len, 2 do | |
s = s .. string.char(tonumber(string.sub(hd[0], i, i+1), 16)) | |
end | |
ret:add(s) | |
end | |
EOF | |
1000 0.004314 return ret[0] | |
FUNCTION vimproc#socket_open() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let fd = s:vp_socket_open(a:host, a:port) | |
return s:fdopen(fd, 'vp_socket_close', 'vp_socket_read', 'vp_socket_write') | |
FUNCTION <SNR>138_vp_pty_write() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [nleft] = s:libcall('vp_pty_write', [self.fd, a:hd, a:timeout]) | |
return nleft | |
FUNCTION <SNR>138_vp_pgroup_close() | |
Called 3000 times | |
Total time: 0.213754 | |
Self time: 0.010575 | |
count total (s) self (s) | |
3000 0.212514 0.009335 call self.fd.close() | |
FUNCTION <SNR>138_fdopen_pty() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
return { 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', 'fd_stdin' : a:fd_stdin, 'fd_stdout' : a:fd_stdout, 'f_close' : s:funcref(a:f_close), 'f_read' : s:funcref(a:f_read), 'f_write' : s:funcref(a:f_write), 'close' : s:funcref('close'), 'read' : s:funcref('read'), 'write' : s:funcref('write'), 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'),} | |
FUNCTION <SNR>138_vp_file_close() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if self.fd != 0 | |
call s:libcall('vp_file_close', [self.fd]) | |
let self.fd = 0 | |
endif | |
FUNCTION <SNR>138_vp_pty_read() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [hd, eof] = s:libcall('vp_pty_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
FUNCTION <SNR>140_parse_block() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = '' | |
let i = 0 | |
let max = len(a:script) | |
while i < max | |
if a:script[i] == '{' | |
" Block. | |
let head = matchstr(a:script[: i-1], '[^[:blank:]]*$') | |
" Truncate script. | |
let script = script[: -len(head)-1] | |
let block = matchstr(a:script, '{\zs.*[^\\]\ze}', i) | |
let foot = join(vimproc#parser#split_args(s:parse_cmdline( a:script[matchend(a:script, '{.*[^\\]}', i) :]))) | |
if block == '' | |
throw 'Exception: Block is not found.' | |
elseif block =~ '^\d\+\.\.\d\+$' | |
" Range block. | |
let start = matchstr(block, '^\d\+') | |
let end = matchstr(block, '\d\+$') | |
let zero = len(matchstr(block, '^0\+'))+1 | |
let pattern = '%0' . zero . 'd' | |
for b in range(start, end) | |
" Concat. | |
let script .= head . printf(pattern, b) . foot . ' ' | |
endfor | |
else | |
" Normal block. | |
for b in split(block, ',', 1) | |
" Concat. | |
let script .= head . escape(b, ' ') . foot . ' ' | |
endfor | |
endif | |
return script | |
else | |
let [script, i] = s:skip_else(script, a:script, i) | |
endif | |
endwhile | |
return script | |
FUNCTION <SNR>138_fdopen_pgroup() | |
Called 3000 times | |
Total time: 0.343204 | |
Self time: 0.084341 | |
count total (s) self (s) | |
3000 0.341292 0.082429 return { 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', 'proc' : a:proc, 'fd' : a:fd, 'f_close' : s:funcref(a:f_close), 'close' : s:funcref('close'), 'read' : s:funcref(a:f_read), 'write' : s:funcref(a:f_write), 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'),} | |
FUNCTION <SNR>138_vp_pipes_close() | |
Called 3000 times | |
Total time: 0.483824 | |
Self time: 0.062150 | |
count total (s) self (s) | |
6000 0.010513 for fd in self.fd | |
3000 0.003170 try | |
3000 0.432312 0.010638 call fd.close() | |
3000 0.008351 catch /vimproc: vp_pipe_close: / | |
" Ignore error. | |
endtry | |
3000 0.002841 endfor | |
FUNCTION <SNR>138_write() | |
Called 1000 times | |
Total time: 0.474779 | |
Self time: 0.021087 | |
count total (s) self (s) | |
1000 0.004083 let timeout = get(a:000, 0, s:write_timeout) | |
1000 0.195829 0.005933 let hd = s:str2hd(a:str) | |
1000 0.273871 0.010075 return self.f_write(hd, timeout) | |
FUNCTION <SNR>140_skip_double_quote() | |
Called 3000 times | |
Total time: 0.311896 | |
Self time: 0.311896 | |
count total (s) self (s) | |
3000 0.010343 let max = len(a:script) | |
3000 0.004889 let string = '' | |
3000 0.004219 let i = a:i | |
" a:script[i] is always '"' when this function is called | |
3000 0.008900 if i >= max || a:script[i] != '"' | |
throw 'Exception: Quote (") is not found.' | |
endif | |
3000 0.008318 let string .= a:script[i] | |
3000 0.004051 let i += 1 | |
15000 0.014117 while i < max | |
15000 0.040231 if a:script[i] == '\' && i+1 < max && a:script[i+1] == '"' | |
" Escape quote. | |
let string .= a:script[i] | |
let i += 1 | |
elseif a:script[i] == '"' | |
3000 0.002358 break | |
endif | |
12000 0.033863 let string .= a:script[i] | |
12000 0.015194 let i += 1 | |
12000 0.008353 endwhile | |
3000 0.002851 if i < max | |
" must end with '"' | |
3000 0.006122 if a:script[i] != '"' | |
throw 'Exception: Quote (") is not found.' | |
endif | |
3000 0.007812 let string .= a:script[i] | |
3000 0.003883 let i += 1 | |
3000 0.001581 endif | |
3000 0.005038 return [string, i] | |
FUNCTION <SNR>138_vp_socket_close() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
call s:libcall('vp_socket_close', [self.fd]) | |
let self.is_valid = 0 | |
FUNCTION vimproc#host_exists() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let rval = s:vp_host_exists( substitute(substitute(a:host, '^\a\+://', '', ''), '/.*$', '', '')) | |
return 0 + rval | |
FUNCTION vimproc#system_gui() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if vimproc#util#is_windows() | |
silent execute ':!start ' . join(map(vimproc#parser#split_args(a:cmdline), '"\"".v:val."\""')) | |
return '' | |
else | |
return vimproc#system_bg(a:cmdline) | |
endif | |
FUNCTION <SNR>138_vp_socket_open() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [socket] = s:libcall('vp_socket_open', [a:host, a:port]) | |
return socket | |
FUNCTION <SNR>138_vp_kill() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
if a:sig != 0 | |
call s:close_all(self) | |
let self.is_valid = 0 | |
endif | |
let ret = 0 | |
for pid in get(self, 'pid_list', [self.pid]) | |
let ret = vimproc#kill(pid, a:sig) | |
endfor | |
return ret | |
FUNCTION <SNR>138_vp_file_read() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [hd, eof] = s:libcall('vp_file_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
FUNCTION <SNR>140_parse_double_quote() | |
Called 1000 times | |
Total time: 0.227196 | |
Self time: 0.227196 | |
count total (s) self (s) | |
1000 0.002491 if a:script[a:i] != '"' | |
return ['', a:i] | |
endif | |
1000 0.010087 let escape_sequences = { 'a' : "\<C-g>", 'b' : "\<BS>", 't' : "\<Tab>", 'r' : "\<CR>", 'n' : "\<LF>", 'e' : "\<Esc>", '\' : '\', '?' : '?', '"' : '"', "'" : "'", '`' : '`',} | |
1000 0.001403 let arg = '' | |
1000 0.002346 let i = a:i + 1 | |
1000 0.004616 let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
1000 0.002204 let max = len(script) | |
5000 0.005080 while i < max | |
5000 0.009778 if script[i] == '"' | |
" Quote end. | |
1000 0.002155 return [arg, i+1] | |
elseif script[i] == '$' | |
" Eval variables. | |
let var = matchstr(join(script[i :], ''), '^$\h\w*') | |
if var != '' | |
let arg .= s:parse_variables(var) | |
let i += len(var) | |
else | |
let arg .= '$' | |
let i += 1 | |
endif | |
elseif script[i] == '`' | |
" Backquote. | |
let [arg_quote, i] = s:parse_back_quote(script, i) | |
let arg .= arg_quote | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
if script[i] == 'x' | |
let num = matchstr(join(script[i+1 :], ''), '^\x\+') | |
let arg .= nr2char(str2nr(num, 16)) | |
let i += len(num) | |
elseif has_key(escape_sequences, script[i]) | |
let arg .= escape_sequences[script[i]] | |
else | |
let arg .= '\' . script[i] | |
endif | |
let i += 1 | |
else | |
4000 0.010115 let arg .= script[i] | |
4000 0.004771 let i += 1 | |
4000 0.002450 endif | |
4000 0.003791 endwhile | |
throw 'Exception: Quote (") is not found.' | |
FUNCTION <SNR>138_fdopen_pipes() | |
Called 3000 times | |
Total time: 0.326407 | |
Self time: 0.077825 | |
count total (s) self (s) | |
3000 0.324848 0.076266 return { 'eof' : 0, '__eof' : 0, 'is_valid' : 1, 'buffer' : '', 'fd' : a:fd, 'f_close' : s:funcref(a:f_close), 'close' : s:funcref('close'), 'read' : s:funcref(a:f_read), 'write' : s:funcref(a:f_write), 'read_line' : s:funcref('read_line'), 'read_lines' : s:funcref('read_lines'),} | |
FUNCTION vimproc#parser#expand_wildcard() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
" Check wildcard. | |
let i = 0 | |
let max = len(a:wildcard) | |
let script = '' | |
let found = 0 | |
while i < max | |
if a:wildcard[i] == '*' || a:wildcard[i] == '?' || a:wildcard[i] == '[' | |
let found = 1 | |
break | |
else | |
let [script, i] = s:skip_else(script, a:wildcard, i) | |
endif | |
endwhile | |
if !found | |
return [ a:wildcard ] | |
endif | |
let wildcard = a:wildcard | |
" Exclude wildcard. | |
let exclude = matchstr(wildcard, '\\\@<!\~\zs.\+$') | |
let exclude_wilde = [] | |
if exclude != '' | |
" Truncate wildcard. | |
let wildcard = wildcard[: len(wildcard)-len(exclude)-2] | |
let exclude_wilde = vimproc#parser#expand_wildcard(exclude) | |
endif | |
" Modifier. | |
let modifier = matchstr(wildcard, '\\\@<!(\zs.\+\ze)$') | |
if modifier != '' | |
" Truncate wildcard. | |
let wildcard = wildcard[: len(wildcard)-len(modifier)-3] | |
endif | |
" Expand wildcard. | |
let expanded = split(escape(substitute( glob(wildcard, 1), '\\', '/', 'g'), ' '), '\n') | |
if empty(expanded) | |
" Use original string. | |
return [ a:wildcard ] | |
else | |
" Check exclude wildcard. | |
let candidates = expanded | |
let expanded = [] | |
for candidate in candidates | |
let found = 0 | |
for ex in exclude_wilde | |
if candidate ==# ex | |
let found = 1 | |
break | |
endif | |
endfor | |
if !found | |
call add(expanded, candidate) | |
endif | |
endfor | |
endif | |
if modifier != '' | |
" Check file modifier. | |
let i = 0 | |
let max = len(modifier) | |
while i < max | |
if modifier[i] ==# '/' | |
" Directory. | |
let expr = 'getftype(v:val) ==# "dir"' | |
elseif modifier[i] ==# '.' | |
" Normal. | |
let expr = 'getftype(v:val) ==# "file"' | |
elseif modifier[i] ==# '@' | |
" Link. | |
let expr = 'getftype(v:val) ==# "link"' | |
elseif modifier[i] ==# '=' | |
" Socket. | |
let expr = 'getftype(v:val) ==# "socket"' | |
elseif modifier[i] ==# 'p' | |
" FIFO Pipe. | |
let expr = 'getftype(v:val) ==# "pipe"' | |
elseif modifier[i] ==# '*' | |
" Executable. | |
let expr = 'getftype(v:val) ==# "pipe"' | |
elseif modifier[i] ==# '%' | |
" Device. | |
if modifier[i :] =~# '^%[bc]' | |
if modifier[i] ==# 'b' | |
" Block device. | |
let expr = 'getftype(v:val) ==# "bdev"' | |
else | |
" Character device. | |
let expr = 'getftype(v:val) ==# "cdev"' | |
endif | |
let i += 1 | |
else | |
let expr = 'getftype(v:val) ==# "bdev" || getftype(v:val) ==# "cdev"' | |
endif | |
else | |
" Unknown. | |
return [] | |
endif | |
call filter(expanded, expr) | |
let i += 1 | |
endwhile | |
endif | |
return filter(expanded, 'v:val != "." && v:val != ".."') | |
FUNCTION vimproc#parser#split_args_through() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let script = type(a:script) == type([]) ? a:script : split(a:script, '\zs') | |
let max = len(script) | |
let args = [] | |
let arg = '' | |
let i = 0 | |
while i < max | |
if script[i] == "'" | |
" Single quote. | |
let [string, i] = s:skip_single_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '"' | |
" Double quote. | |
let [string, i] = s:skip_double_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '`' | |
" Back quote. | |
let [string, i] = s:skip_back_quote(script, i) | |
let arg .= string | |
if arg == '' | |
call add(args, '') | |
endif | |
elseif script[i] == '\' | |
" Escape. | |
let i += 1 | |
if i >= max | |
throw 'Exception: Join to next line (\).' | |
endif | |
let arg .= '\'.script[i] | |
let i += 1 | |
elseif script[i] != ' ' | |
let arg .= script[i] | |
let i += 1 | |
else | |
" Space. | |
if arg != '' | |
call add(args, arg) | |
endif | |
let arg = '' | |
let i += 1 | |
endif | |
endwhile | |
if arg != '' | |
call add(args, arg) | |
endif | |
return args | |
FUNCTION vimproc#get_command_name() | |
Called 1000 times | |
Total time: 1.145706 | |
Self time: 0.043466 | |
count total (s) self (s) | |
1000 0.004749 let path = get(a:000, 0, $PATH) | |
1000 0.002282 let cnt = a:0 < 2 ? 1 : a:2 | |
1000 1.122269 0.020029 let files = split(substitute(vimproc#util#substitute_path_separator( vimproc#filepath#which(a:command, path)), '//', '/', 'g'), '\n') | |
1000 0.001536 if cnt < 0 | |
return files | |
endif | |
1000 0.003047 let file = get(files, 0, '') | |
1000 0.001451 if file == '' | |
throw printf( 'vimproc#get_command_name: File "%s" is not found.', a:command) | |
endif | |
1000 0.000986 return file | |
FUNCTION <SNR>138_read_line() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let lines = call(self.read_lines, a:000, self) | |
let self.buffer = join(lines[1:], "\n") . self.buffer | |
let self.eof = (self.buffer != '') ? 0 : self.__eof | |
return get(lines, 0, '') | |
FUNCTION <SNR>138_print_error() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
echohl Error | echomsg a:string | echohl None | |
FUNCTION <SNR>138_read_lines() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let res = self.buffer | |
while !self.eof && stridx(res, "\n") < 0 | |
let out = call(self.read, a:000, self) | |
if out == '' | |
break | |
endif | |
let res .= out | |
endwhile | |
let lines = split(res, '\r\?\n', 1) | |
if self.eof | |
let self.buffer = '' | |
return lines | |
else | |
let self.buffer = empty(lines)? '' : lines[-1] | |
let lines = lines[ : -2] | |
endif | |
let self.eof = (self.buffer != '') ? 0 : self.__eof | |
return lines | |
FUNCTION <SNR>138_vp_host_exists() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [rval] = s:libcall('vp_host_exists', [a:host]) | |
return rval | |
FUNCTION <SNR>138_SID_PREFIX() | |
Called 67000 times | |
Total time: 0.543098 | |
Self time: 0.543098 | |
count total (s) self (s) | |
67000 0.203296 if !exists('s:sid_prefix') | |
1 0.000202 let s:sid_prefix = matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSID_PREFIX$') | |
1 0.000002 endif | |
67000 0.082370 return s:sid_prefix | |
FUNCTION <SNR>138_vp_socket_read() | |
Called 0 times | |
Total time: 0.000000 | |
Self time: 0.000000 | |
count total (s) self (s) | |
let [hd, eof] = s:libcall('vp_socket_read', [self.fd, a:number, a:timeout]) | |
return [hd, eof] | |
FUNCTION vimproc#parser#parse_pipe() | |
Called 1000 times | |
Total time: 3.663725 | |
Self time: 0.108132 | |
count total (s) self (s) | |
1000 0.003698 let commands = [] | |
2000 0.888594 0.014575 for cmdline in vimproc#parser#split_pipe(a:statement) | |
" Split args. | |
1000 1.322285 0.005338 let cmdline = s:parse_cmdline(cmdline) | |
" Parse redirection. | |
1000 0.007300 if cmdline =~ '[<>]' | |
let [fd, cmdline] = s:parse_redirection(cmdline) | |
else | |
1000 0.003535 let fd = { 'stdin' : '', 'stdout' : '', 'stderr' : '' } | |
1000 0.000644 endif | |
3000 0.004608 for key in ['stdout', 'stderr'] | |
2000 0.004780 if fd[key] == '' || fd[key] =~ '^>' | |
2000 0.002317 continue | |
endif | |
if fd[key] ==# '/dev/clip' | |
" Clear. | |
let @+ = '' | |
elseif fd[key] ==# '/dev/quickfix' | |
" Clear quickfix. | |
call setqflist([]) | |
endif | |
endfor | |
1000 1.378488 0.013861 call add(commands, { 'args' : vimproc#parser#split_args(cmdline), 'fd' : fd}) | |
1000 0.001048 endfor | |
1000 0.001154 return commands | |
FUNCTION <SNR>138_libcall() | |
Called 13767 times | |
Total time: 2.492874 | |
Self time: 1.795179 | |
count total (s) self (s) | |
" End Of Value | |
13767 0.029448 let EOV = "\xFF" | |
13767 0.169795 let args = empty(a:args) ? '' : (join(reverse(copy(a:args)), EOV) . EOV) | |
13767 1.104868 let stack_buf = libcall(g:vimproc#dll_path, a:func, args) | |
13767 0.850072 0.152377 let result = s:split(stack_buf, EOV) | |
13767 0.068147 if !empty(result) && result[-1] != '' | |
if stack_buf[len(stack_buf) - 1] ==# EOV | |
" Note: If &encoding equals "cp932" and output ends multibyte first byte, | |
" will fail split. | |
return result | |
endif | |
let s:lasterr = result | |
let msg = vimproc#util#iconv(string(result), vimproc#util#termencoding(), &encoding) | |
throw printf('vimproc: %s: %s', a:func, msg) | |
endif | |
13767 0.039023 return result[:-2] | |
FUNCTION <SNR>138_close_all() | |
Called 2000 times | |
Total time: 0.433528 | |
Self time: 0.044148 | |
count total (s) self (s) | |
2000 0.006008 if has_key(a:self, 'stdin') | |
2000 0.026287 0.008211 call a:self.stdin.close() | |
2000 0.001262 endif | |
2000 0.004297 if has_key(a:self, 'stdout') | |
2000 0.200085 0.006794 call a:self.stdout.close() | |
2000 0.001266 endif | |
2000 0.004271 if has_key(a:self, 'stderr') | |
2000 0.185312 0.007299 call a:self.stderr.close() | |
2000 0.001228 endif | |
FUNCTIONS SORTED ON TOTAL TIME | |
count total (s) self (s) function | |
1000 13.699283 0.070427 vimproc#system() | |
1000 8.351791 0.477644 <SNR>138_system() | |
1000 4.143299 0.029733 vimproc#pgroup_open() | |
1000 4.113566 0.125704 <SNR>138_pgroup_open() | |
1000 3.663725 0.108132 vimproc#parser#parse_pipe() | |
1000 3.615096 0.028658 vimproc#plineopen3() | |
1000 3.586438 0.499361 <SNR>138_plineopen() | |
7764 2.916029 0.569625 <SNR>138_read_pgroup() | |
13767 2.492874 1.795179 <SNR>138_libcall() | |
7764 1.778845 0.222425 <SNR>138_read_pipes() | |
1000 1.611962 1.503834 vimproc#parser#parse_statements() | |
7764 1.556420 0.230253 <SNR>138_read() | |
1000 1.381888 0.039578 <SNR>138_convert_args() | |
1000 1.364627 1.137431 vimproc#parser#split_args() | |
1000 1.316947 0.058359 <SNR>140_parse_cmdline() | |
1000 1.258588 0.465511 <SNR>140_parse_tilde() | |
7764 1.225685 0.140384 <SNR>138_vp_pipe_read() | |
13000 1.217022 0.086447 <SNR>138_close() | |
1000 1.145706 0.043466 vimproc#get_command_name() | |
67000 0.991150 0.448052 <SNR>138_funcref() | |
FUNCTIONS SORTED ON SELF TIME | |
count total (s) self (s) function | |
13767 2.492874 1.795179 <SNR>138_libcall() | |
1000 1.611962 1.503834 vimproc#parser#parse_statements() | |
1000 1.364627 1.137431 vimproc#parser#split_args() | |
1000 0.874019 0.773370 vimproc#parser#split_pipe() | |
13767 0.697695 <SNR>138_split() | |
22000 0.793077 0.689958 <SNR>140_skip_else() | |
7764 2.916029 0.569625 <SNR>138_read_pgroup() | |
67000 0.543098 <SNR>138_SID_PREFIX() | |
1000 3.586438 0.499361 <SNR>138_plineopen() | |
1000 8.351791 0.477644 <SNR>138_system() | |
1000 1.258588 0.465511 <SNR>140_parse_tilde() | |
67000 0.991150 0.448052 <SNR>138_funcref() | |
3000 0.311896 <SNR>140_skip_double_quote() | |
7764 1.556420 0.230253 <SNR>138_read() | |
1000 0.227196 <SNR>140_parse_double_quote() | |
7764 1.778845 0.222425 <SNR>138_read_pipes() | |
1000 0.194890 0.191017 vimproc#analyze_shebang() | |
1000 0.189896 <SNR>138_str2hd() | |
7764 1.225685 0.140384 <SNR>138_vp_pipe_read() | |
1000 4.113566 0.125704 <SNR>138_pgroup_open() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment