22" FILE: vimproc.vim
33" AUTHOR: Shougo Matsushita <[email protected] > (Modified)44" Yukihiro Nakadaira <yukihiro.nakadaira at gmail.com> (Original)
5- " Last Modified: 15 Jun 2013.
5+ " Last Modified: 25 Jun 2013.
66" License: MIT license {{{
77" Permission is hereby granted, free of charge, to any person obtaining
88" a copy of this software and associated documentation files (the
@@ -662,14 +662,20 @@ function! vimproc#host_exists(host) "{{{
662662endfunction " }}}
663663
664664function ! vimproc#kill (pid, sig ) " {{{
665+ if a: sig == 0 && vimproc#util#is_windows ()
666+ " Use waitpid().
667+ let [cond, status] = s: waitpid (a: pid )
668+ return cond == # ' run'
669+ endif
670+
665671 try
666- call s: libcall (' vp_kill' , [a: pid , a: sig ])
672+ let [ ret ] = s: libcall (' vp_kill' , [a: pid , a: sig ])
667673 catch /kill() error:/
668674 let s: last_errmsg = v: exception
669675 return 1
670676 endtry
671677
672- return 0
678+ return ret
673679endfunction " }}}
674680
675681function ! vimproc#decode_signal (signal) " {{{
@@ -812,12 +818,6 @@ function! vimproc#delete_trash(filename) "{{{
812818
813819 let filename = a: filename
814820
815- " Delete last /.
816- if filename = ~ ' [^:]/$'
817- " Delete last /.
818- let filename = filename[: -2 ]
819- endif
820-
821821 if ! filewritable (filename) && ! isdirectory (filename)
822822 return 1
823823 endif
@@ -826,6 +826,12 @@ function! vimproc#delete_trash(filename) "{{{
826826 let filename = substitute (
827827 \ fnamemodify (filename, ' :p' ), ' /' , ' \\' , ' g' )
828828
829+ " Delete last /.
830+ if filename = ~ ' [^:][/\\]$'
831+ " Delete last /.
832+ let filename = filename[: -2 ]
833+ endif
834+
829835 " Encoding conversion.
830836 let filename = vimproc#util#iconv (filename,
831837 \ &encoding , vimproc#util#termencoding ())
@@ -1126,12 +1132,36 @@ function! s:split(str, sep)
11261132 return result
11271133endfunction
11281134
1135+ function ! s: split_lua (str, sep)
1136+ let result = []
1137+ lua << EOF
1138+ do
1139+ local pos = 1
1140+ local result = vim .eval (' result' )
1141+ local str = vim .eval (' a:str' )
1142+ local sep = vim .eval (' a:sep' )
1143+ local tmp = string .find (str, sep, pos, true)
1144+
1145+ while tmp ~= nil do
1146+ result: add (string .sub (str, pos, tmp- 1 ))
1147+ pos = tmp + 1
1148+ tmp = string .find (str, sep, pos, true)
1149+ end
1150+
1151+ result: add (string .sub (str, pos))
1152+ end
1153+ EOF
1154+
1155+ return result
1156+ endfunction
1157+
11291158function ! s: libcall (func , args ) " {{{
11301159 " End Of Value
11311160 let EOV = " \xFF "
11321161 let args = empty (a: args ) ? ' ' : (join (reverse (copy (a: args )), EOV) . EOV)
11331162 let stack_buf = libcall (g: vimproc #dll_path, a: func , args )
1134- let result = s: split (stack_buf, EOV)
1163+ let result = vimproc#util#has_lua () ?
1164+ \ s: split_lua (stack_buf, EOV) : s: split (stack_buf, EOV)
11351165 if ! empty (result) && result[-1 ] != ' '
11361166 if stack_buf[len (stack_buf) - 1 ] == # EOV
11371167 " Note: If &encoding equals "cp932" and output ends multibyte first byte,
@@ -1418,29 +1448,31 @@ function! s:vp_set_winsize(width, height) dict
14181448endfunction
14191449
14201450function ! s: vp_kill (sig ) dict
1421- call s: close_all (self )
1451+ if a: sig != 0
1452+ call s: close_all (self )
1453+ let self .is_valid = 0
1454+ endif
14221455
1423- let self .is_valid = 0
1456+ let ret = 0
1457+ for pid in get (self , ' pid_list' , [self .pid])
1458+ let ret = vimproc#kill (pid, a: sig )
1459+ endfor
14241460
1425- if has_key (self , ' pid_list' )
1426- for pid in self .pid_list
1427- call vimproc#kill (pid, a: sig )
1428- endfor
1429- else
1430- call vimproc#kill (self .pid, a: sig )
1431- endif
1461+ return ret
14321462endfunction
14331463
14341464function ! s: vp_pgroup_kill (sig ) dict
1435- call s: close_all (self )
1436- let self .is_valid = 0
1465+ if a: sig != 0
1466+ call s: close_all (self )
1467+ let self .is_valid = 0
1468+ endif
14371469
14381470 if self .pid == 0
14391471 " Ignore.
14401472 return
14411473 endif
14421474
1443- call self .current_proc.kill (a: sig )
1475+ return self .current_proc.kill (a: sig )
14441476endfunction
14451477
14461478function ! s: waitpid (pid)
0 commit comments