Skip to content

s:projectionist_detect: only handle .vim files #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions autoload/scriptease.vim
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,22 @@ function! s:lencompare(a, b) abort
return len(a:a) - len(a:b)
endfunction

function! scriptease#locate(path) abort
let path = fnamemodify(a:path, ':p')
let candidates = []
for glob in split(&runtimepath, ',')
let candidates += filter(split(glob(glob), "\n"), 'path[0 : len(v:val)-1] ==# v:val && path[len(v:val)] =~# "[\\/]"')
endfor
if empty(candidates)
return ['', '']
" a:path should be absolute and resolved for symlinks.
" a:1 can be a list of candidates, which must not be empty.
function! scriptease#locate(path, ...) abort
if a:0
let candidates = a:1
else
let candidates = []
for glob in split(&runtimepath, ',')
let candidates += filter(split(glob(resolve(glob)), "\n"), 'a:path[0 : len(v:val)-1] ==# v:val && a:path[len(v:val)] =~# "[\\/]"')
endfor
if empty(candidates)
return ['', '']
endif
endif
let preferred = sort(candidates, s:function('s:lencompare'))[-1]
return [preferred, path[strlen(preferred)+1 : -1]]
return [preferred, a:path[strlen(preferred)+1 : -1]]
endfunction

function! scriptease#runtime_command(bang, ...) abort
Expand All @@ -419,7 +424,7 @@ function! scriptease#runtime_command(bang, ...) abort
if a:0
let files = a:000
elseif &filetype ==# 'vim' || expand('%:e') ==# 'vim'
let files = [scriptease#locate(expand('%:p'))[1]]
let files = [scriptease#locate(resolve(expand('%:p')))[1]]
if empty(files[0])
let files = ['%']
endif
Expand Down
15 changes: 13 additions & 2 deletions plugin/scriptease.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,19 @@ augroup END
" Section: Projectionist

function! s:projectionist_detect() abort
let file = get(g:, 'projectionist_file', '')
let path = substitute(scriptease#locate(file)[0], '[\/]after$', '', '')
let file = resolve(get(g:, 'projectionist_file', ''))

" Build a list of candidates here to skip unnecessary autoloading of
" scriptease#locate.
let candidates = []
for glob in split(&runtimepath, ',')
let candidates += filter(split(glob(resolve(glob)), "\n"), 'file[0 : len(v:val)-1] ==# v:val && file[len(v:val)] =~# "[\\/]"')
endfor
if empty(candidates)
return
endif

let path = substitute(scriptease#locate(file, candidates)[0], '[\/]after$', '', '')
if !empty(path)
let reload = ":Runtime ./{open}autoload,plugin{close}/**/*.vim"
call projectionist#append(path, {
Expand Down