Last active
April 5, 2017 20:04
-
-
Save tpope/c4b49b5719b17a4f79bb95520c264869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if !exists('s:path') | |
if type(get(g:, 'lua_path')) == type([]) | |
let s:path = g:lua_path | |
else | |
let s:path = split(system('lua -e "print(package.path)"')[0:-2], ';') | |
if v:shell_error | |
let path = [] | |
endif | |
endif | |
endif | |
let &l:sua = join(uniq(map(copy(s:path), 'matchstr(v:val, "[^?]*$")')), ',') | |
if empty(&l:sua) | |
let &l:sua = '/init.lua,.lua' | |
endif | |
if !empty(s:path) | |
let &l:path = join(uniq(map(copy(s:path), 'matchstr(v:val, "[^?]*")')), ',') | |
endif | |
setlocal include=^\\%(\\s*\\%(local\\s\\+\\w\\+\\\|[[:alnum:]_.]\\+\\)\\s*=\\)\\=\\s*require\\s*(\\s*[\"'] | |
setlocal includeexpr=LuauIncludeExpr(v:fname) | |
if exists('b:undo_ftplugin') | |
let b:undo_ftplugin .= '|setlocal path< suffixesadd< include< includeexpr<' | |
endif | |
function! LuauIncludeExpr(fname) abort | |
if a:fname =~# '/' || a:fname =~# '\.lua$' | |
return a:fname | |
endif | |
let fname = tr(a:fname, '.', '/') | |
let file = fname | |
while file !=# '.' | |
for suffix in split(&l:suffixesadd, ',') | |
let path = findfile(file . suffix) | |
if !empty(path) | |
return file . suffix | |
endif | |
endfor | |
let file = fnamemodify(file, ':h') | |
endwhile | |
return fname | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment