@@ -335,7 +335,16 @@ function! dispatch#compiler_options(compiler) abort
335335endfunction
336336
337337function ! s: completion_filter (results, query) abort
338- return filter (a: results , ' strpart(v:val, 0, len(a:query)) ==# a:query' )
338+ if type (get (g: , ' completion_filter' )) == type ({})
339+ return g: completion_filter .Apply (a: results , a: query )
340+ else
341+ return filter (a: results , ' strpart(v:val, 0, len(a:query)) ==# a:query' )
342+ endif
343+ endfunction
344+
345+ function ! s: file_complete (A) abort
346+ return map (split (glob (substitute (a: A , ' \(.\@<=[\\/]\|$\)' , ' *\1' , ' g' )), " \n " ),
347+ \ ' isdirectory(v:val) ? v:val . dispatch#slash() : v:val' )
339348endfunction
340349
341350function ! s: compiler_complete (compiler , A, L, P ) abort
@@ -363,8 +372,7 @@ function! s:compiler_complete(compiler, A, L, P) abort
363372 return results
364373 elseif type (results) != type (' ' )
365374 unlet ! results
366- let results = join (map (split (glob (a: A .' *' ), " \n " ),
367- \ ' isdirectory(v:val) ? v:val . dispatch#slash() : v:val' ), " \n " )
375+ let results = join (s: file_complete (a: A ), " \n " )
368376 endif
369377
370378 return s: completion_filter (split (results, " \n " ), a: A )
@@ -375,13 +383,15 @@ function! dispatch#command_complete(A, L, P) abort
375383 if len >= 0 && len <= a: P
376384 let compiler = dispatch#compiler_for_program (matchstr (a: L , ' \s\zs.*' ))
377385 return s: compiler_complete (compiler , a: A , ' Make ' .strpart (a: L , len ), a: P- len + 5 )
386+ elseif a: A = ~# ' ^\%(\w:\|\.\)\=[\/]'
387+ let executables = s: file_complete (a: A )
378388 else
379389 let executables = []
380390 for dir in split ($PATH , has (' win32' ) ? ' ;' : ' :' )
381- let executables += map (split (glob (dir .' /' .a: A .' *' ), " \n " ), ' v:val[strlen(dir)+1 : -1]' )
391+ let executables += map (split (glob (dir .' /' .substitute ( a: A, ' . ' , ' *& ' , ' g ' ) .' *' ), " \n " ), ' v:val[strlen(dir)+1 : -1]' )
382392 endfor
383- return s: completion_filter (sort (dispatch#uniq (executables)), a: A )
384393 endif
394+ return s: completion_filter (sort (dispatch#uniq (executables)), a: A )
385395endfunction
386396
387397function ! dispatch#make_complete (A, L, P ) abort
0 commit comments