Skip to content

Commit 9743118

Browse files
committed
s:projectionist_detect: skip autoloading without candidates
This avoids sourcing the autoload file for `scriptease#locate` when not editing relevant files.
1 parent 9dc2518 commit 9743118

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

autoload/scriptease.vim

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,22 @@ function! s:lencompare(a, b) abort
398398
return len(a:a) - len(a:b)
399399
endfunction
400400

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
409414
endif
410415
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]]
412417
endfunction
413418

414419
function! scriptease#runtime_command(bang, ...) abort
@@ -419,7 +424,7 @@ function! scriptease#runtime_command(bang, ...) abort
419424
if a:0
420425
let files = a:000
421426
elseif &filetype ==# 'vim' || expand('%:e') ==# 'vim'
422-
let files = [scriptease#locate(expand('%:p'))[1]]
427+
let files = [scriptease#locate(resolve(expand('%:p')))[1]]
423428
if empty(files[0])
424429
let files = ['%']
425430
endif

plugin/scriptease.vim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,19 @@ augroup END
113113
" Section: Projectionist
114114

115115
function! s:projectionist_detect() abort
116-
let file = get(g:, 'projectionist_file', '')
117-
let path = substitute(scriptease#locate(file)[0], '[\/]after$', '', '')
116+
let file = resolve(get(g:, 'projectionist_file', ''))
117+
118+
" Build a list of candidates here to skip unnecessary autoloading of
119+
" scriptease#locate.
120+
let candidates = []
121+
for glob in split(&runtimepath, ',')
122+
let candidates += filter(split(glob(resolve(glob)), "\n"), 'file[0 : len(v:val)-1] ==# v:val && file[len(v:val)] =~# "[\\/]"')
123+
endfor
124+
if empty(candidates)
125+
return
126+
endif
127+
128+
let path = substitute(scriptease#locate(file, candidates)[0], '[\/]after$', '', '')
118129
if !empty(path)
119130
let reload = ":Runtime ./{open}autoload,plugin{close}/**/*.vim"
120131
call projectionist#append(path, {

0 commit comments

Comments
 (0)