@@ -398,17 +398,22 @@ function! s:lencompare(a, b) abort
398
398
return len (a: a ) - len (a: b )
399
399
endfunction
400
400
401
- function ! scriptease#locate (path ) abort
402
- let path = fnamemodify (a: path , ' :p' )
403
- let candidates = []
404
- for glob in split (&runtimepath , ' ,' )
405
- let candidates += filter (split (glob (glob ), " \n " ), ' path[0 : len(v:val)-1] ==# v:val && path[len(v:val)] =~# "[\\/]"' )
406
- endfor
407
- if empty (candidates)
408
- return [' ' , ' ' ]
401
+ " a:path should be absolute and resolved for symlinks.
402
+ " a:1 can be a list of candidates, which must not be empty.
403
+ function ! scriptease#locate (path , ... ) abort
404
+ if a: 0
405
+ let candidates = a: 1
406
+ else
407
+ let candidates = []
408
+ for glob in split (&runtimepath , ' ,' )
409
+ let candidates += filter (split (glob (resolve (glob )), " \n " ), ' a:path[0 : len(v:val)-1] ==# v:val && a:path[len(v:val)] =~# "[\\/]"' )
410
+ endfor
411
+ if empty (candidates)
412
+ return [' ' , ' ' ]
413
+ endif
409
414
endif
410
415
let preferred = sort (candidates, s: function (' s:lencompare' ))[-1 ]
411
- return [preferred, path [strlen (preferred)+ 1 : -1 ]]
416
+ return [preferred, a: path [strlen (preferred)+ 1 : -1 ]]
412
417
endfunction
413
418
414
419
function ! scriptease#runtime_command (bang , ... ) abort
@@ -419,7 +424,7 @@ function! scriptease#runtime_command(bang, ...) abort
419
424
if a: 0
420
425
let files = a: 000
421
426
elseif &filetype == # ' vim' || expand (' %:e' ) == # ' vim'
422
- let files = [scriptease#locate (expand (' %:p' ))[1 ]]
427
+ let files = [scriptease#locate (resolve ( expand (' %:p' ) ))[1 ]]
423
428
if empty (files [0 ])
424
429
let files = [' %' ]
425
430
endif
0 commit comments