22" FILE: vimproc.vim
33" AUTHOR: Shougo Matsushita <[email protected] > (Modified)44" Yukihiro Nakadaira <yukihiro.nakadaira at gmail.com> (Original)
5- " Last Modified: 25 Jun 2013.
5+ " Last Modified: 02 Aug 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
@@ -205,7 +205,7 @@ function! vimproc#get_command_name(command, ...) "{{{
205205 return files
206206 endif
207207
208- let file = get (files , 0 , ' ' )
208+ let file = get (files , cnt - 1 , ' ' )
209209
210210 if file == ' '
211211 throw printf (
@@ -781,12 +781,12 @@ function! vimproc#write(filename, string, ...) "{{{
781781endfunction " }}}
782782
783783function ! vimproc#readdir (dirname) " {{{
784- let dirname = substitute (substitute (
785- \ vimproc#util#expand (a: dirname ),
786- \ ' \\' , ' /' , ' g' ), ' /$' , ' ' , ' ' )
784+ let dirname = vimproc#util#expand (a: dirname )
787785 if dirname == ' '
788786 let dirname = getcwd ()
789787 endif
788+ let dirname = substitute (dirname, ' .\zs/$' , ' ' , ' ' )
789+ let dirname = substitute (dirname, ' //' , ' /' , ' g' )
790790
791791 if ! isdirectory (dirname)
792792 return []
@@ -801,11 +801,12 @@ function! vimproc#readdir(dirname) "{{{
801801 return []
802802 endtry
803803
804- call map (files , 'vimproc#util#iconv (
804+ call map (filter ( files , ' v:val !~ "/\\.\\.\\?$" ' ) , 'vimproc#util#iconv (
805805 \ v: val , vimproc#util#termencoding (), &encoding )')
806806 if vimproc#util#is_windows ()
807807 call map (files , ' vimproc#util#substitute_path_separator(v:val)' )
808808 endif
809+ call map (files , " substitute(v:val, '/\\ ./', '/', 'g')" )
809810
810811 return files
811812endfunction " }}}
@@ -906,22 +907,13 @@ function! s:read_lines(...) dict "{{{
906907
907908 let lines = split (res , ' \r\?\n' , 1 )
908909
909- if self .eof
910- let self .buffer = ' '
911- return lines
912- else
913- let self .buffer = empty (lines )? ' ' : lines [-1 ]
914- let lines = lines [ : -2 ]
915- endif
916-
917- let self .eof = (self .buffer != ' ' ) ? 0 : self .__eof
918- return lines
910+ let self .buffer = get (lines , -1 , 0 )
911+ return lines [ : -2 ]
919912endfunction " }}}
920913function ! s: read_line (... ) dict " {{{
921914 let lines = call (self .read_lines, a: 000 , self )
922915 let self .buffer = join (lines [1 :], " \n " ) . self .buffer
923- let self .eof = (self .buffer != ' ' ) ? 0 : self .__eof
924-
916+ let self .eof = (self .buffer != ' ' ) ? (self .__eof && self .buffer == ' ' ) : self .__eof
925917 return get (lines , 0 , ' ' )
926918endfunction " }}}
927919
@@ -1117,51 +1109,55 @@ let s:read_timeout = 100
11171109let s: write_timeout = 100
11181110let s: bg_processes = {}
11191111
1120- function ! s: split (str, sep)
1121- let [result, pos] = [[], 0 ]
1122- while 1
1123- let tmp = stridx (a: str , a: sep , pos)
1124- if tmp == -1
1125- call add (result, strpart (a: str , pos))
1126- break
1127- endif
1128- call add (result, strpart (a: str , pos, tmp - pos))
1129- let pos = tmp + 1
1130- endwhile
1131-
1132- return result
1133- endfunction
1134-
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)
1112+ if vimproc#util#has_lua ()
1113+ function ! s: split (str, sep)
1114+ let result = []
1115+ lua << EOF
1116+ do
1117+ local result = vim .eval (' result' )
1118+ local str = vim .eval (' a:str' )
1119+ local sep = vim .eval (' a:sep' )
1120+ local last
1121+
1122+ if string .find (str, sep, 1 , true) == nil then
1123+ result: add (str)
1124+ else
1125+ for part, pos in string .gmatch (str,
1126+ ' (.-)' .. sep .. ' ()' ) do
1127+ result: add (part)
1128+ last = pos
1129+ end
1130+
1131+ result: add (string .sub (str, last ))
1132+ end
11491133 end
1150-
1151- result: add (string .sub (str, pos))
1152- end
11531134EOF
11541135
1155- return result
1156- endfunction
1136+ return result
1137+ endfunction
1138+ else
1139+ function ! s: split (str, sep)
1140+ let [result, pos] = [[], 0 ]
1141+ while 1
1142+ let tmp = stridx (a: str , a: sep , pos)
1143+ if tmp == -1
1144+ call add (result, strpart (a: str , pos))
1145+ break
1146+ endif
1147+ call add (result, strpart (a: str , pos, tmp - pos))
1148+ let pos = tmp + 1
1149+ endwhile
1150+
1151+ return result
1152+ endfunction
1153+ endif
11571154
11581155function ! s: libcall (func , args ) " {{{
11591156 " End Of Value
11601157 let EOV = " \xFF "
11611158 let args = empty (a: args ) ? ' ' : (join (reverse (copy (a: args )), EOV) . EOV)
11621159 let stack_buf = libcall (g: vimproc #dll_path, a: func , args )
1163- let result = vimproc#util#has_lua () ?
1164- \ s: split_lua (stack_buf, EOV) : s: split (stack_buf, EOV)
1160+ let result = s: split (stack_buf, EOV)
11651161 if ! empty (result) && result[-1 ] != ' '
11661162 if stack_buf[len (stack_buf) - 1 ] == # EOV
11671163 " Note: If &encoding equals "cp932" and output ends multibyte first byte,
@@ -1230,7 +1226,8 @@ function! s:vp_file_write(hd, timeout) dict
12301226endfunction
12311227
12321228function ! s: quote_arg (arg)
1233- return a: arg = ~ ' [ "]' ? ' "' . substitute (a: arg , ' "' , ' \\"' , ' g' ) . ' "' : a: arg
1229+ return (a: arg == ' ' || a: arg = ~ ' [ "]' ) ?
1230+ \ ' "' . substitute (a: arg , ' "' , ' \\"' , ' g' ) . ' "' : a: arg
12341231endfunction
12351232
12361233function ! s: vp_pipe_open (npipe, hstdin, hstdout, hstderr, argv ) " {{{
0 commit comments