Leverage 'suffixesadd'

This commit is contained in:
Tim Pope 2014-01-15 18:14:32 -05:00
parent 76a99139d1
commit 15f98b06f7

View File

@ -420,15 +420,20 @@ function! fireplace#findresource(resource, ...) abort
if a:resource ==# '' if a:resource ==# ''
return '' return ''
endif endif
let path = a:0 ? a:1 : fireplace#path() let resource = a:resource
let file = findfile(a:resource, escape(join(path, ','), ' ')) if a:0 > 2 && type(a:3) == type([])
if !empty(file) let suffixes = a:3
return file else
let suffixes = [''] + split(get(a:000, 2, ''), ',')
endif endif
for jar in path for dir in a:0 ? a:1 : fireplace#path()
if fnamemodify(jar, ':e') ==# 'jar' && index(fireplace#jar_contents(jar), a:resource) >= 0 for suffix in suffixes
return 'zipfile:' . jar . '::' . a:resource if fnamemodify(dir, ':e') ==# 'jar' && index(fireplace#jar_contents(dir), resource . suffix) >= 0
endif return 'zipfile:' . dir . '::' . resource . suffix
elseif filereadable(dir . '/' . resource . suffix)
return dir . (exists('+shellslash') && !&shellslash ? '\' : '/') . resource . suffix
endif
endfor
endfor endfor
return '' return ''
endfunction endfunction
@ -937,15 +942,17 @@ function! fireplace#source(symbol) abort
\ ' (:line (meta v))]))' \ ' (:line (meta v))]))'
let result = fireplace#evalparse(cmd) let result = fireplace#evalparse(cmd)
if type(result) == type([]) if type(result) == type([])
return '+' . result[1] . ' ' . fireplace#findresource(result[0]) let file = fireplace#findresource(result[0])
else if !empty(file)
return '' return '+' . result[1] . ' ' . fnameescape(file)
endif
endif endif
return ''
endfunction endfunction
function! s:Edit(cmd, keyword) abort function! s:Edit(cmd, keyword) abort
try try
if a:keyword =~# '^\k\+/$' if a:keyword =~# '^\k\+[/.]$'
let location = fireplace#findfile(a:keyword[0: -2]) let location = fireplace#findfile(a:keyword[0: -2])
elseif a:keyword =~# '^\k\+\.[^/.]\+$' elseif a:keyword =~# '^\k\+\.[^/.]\+$'
let location = fireplace#findfile(a:keyword) let location = fireplace#findfile(a:keyword)
@ -956,7 +963,7 @@ function! s:Edit(cmd, keyword) abort
return '' return ''
endtry endtry
if location !=# '' if location !=# ''
if matchstr(location, '^+\d\+ \zs.*') ==# expand('%:p') && a:cmd ==# 'edit' if matchstr(location, '^+\d\+ \zs.*') ==# fnameescape(expand('%:p')) && a:cmd ==# 'edit'
return matchstr(location, '\d\+') return matchstr(location, '\d\+')
else else
return a:cmd.' '.location.'|let &l:path = '.string(&l:path) return a:cmd.' '.location.'|let &l:path = '.string(&l:path)
@ -973,7 +980,12 @@ nnoremap <silent> <Plug>FireplaceDtabjump :<C-U>exe <SID>Edit('tabedit', expand(
augroup fireplace_source augroup fireplace_source
autocmd! autocmd!
autocmd FileType clojure setlocal includeexpr=tr(v:fname,'.-','/_') autocmd FileType clojure setlocal includeexpr=tr(v:fname,'.-','/_')
autocmd FileType clojure setlocal suffixesadd=.clj,.java autocmd FileType clojure
\ if expand('%:e') ==# 'cljs' |
\ setlocal suffixesadd=.cljs,.cljx,.clj,.java |
\ else |
\ setlocal suffixesadd=.clj,.cljx,.cljs,.java |
\ endif
autocmd FileType clojure setlocal define=^\\s*(def\\w* autocmd FileType clojure setlocal define=^\\s*(def\\w*
autocmd FileType clojure command! -bar -buffer -nargs=1 -complete=customlist,fireplace#eval_complete Djump :exe s:Edit('edit', <q-args>) autocmd FileType clojure command! -bar -buffer -nargs=1 -complete=customlist,fireplace#eval_complete Djump :exe s:Edit('edit', <q-args>)
autocmd FileType clojure command! -bar -buffer -nargs=1 -complete=customlist,fireplace#eval_complete Dsplit :exe s:Edit('split', <q-args>) autocmd FileType clojure command! -bar -buffer -nargs=1 -complete=customlist,fireplace#eval_complete Dsplit :exe s:Edit('split', <q-args>)
@ -989,29 +1001,35 @@ augroup END
function! fireplace#findfile(path) abort function! fireplace#findfile(path) abort
let path = a:path let path = a:path
if path !~# '[/.]' && path =~# '^\k\+$' if a:path !~# '/'
let path = fireplace#evalparse('((ns-aliases *ns*) '.s:qsym(path).' '.s:qsym(path).')') let path = tr(a:path, '.-', '/_')
else
let path = substitute(a:path, '^/', '')
endif endif
if path !~# '/' let resource = fireplace#findresource(path, fireplace#path(), 0, &suffixesadd)
let path = tr(path, '.-', '/_') if !empty(resource)
return resource
elseif fnamemodify(a:path, ':p') ==# a:path && filereadable(a:path)
return path
elseif a:path[0] !=# '/' && filereadable(expand('%:h') . '/' . path)
return expand('%:h') . '/' . path
endif endif
if path !~# '\.\w\+$' return ''
let path .= '.clj'
endif
return fireplace#findresource(path)
endfunction endfunction
function! s:GF(cmd, file) abort function! s:GF(cmd, file) abort
if a:file =~# '^[^/]*/[^/.]*$' && a:file =~# '^\k\+$' if a:file =~# '^[^/]*/[^/.]*$' && a:file =~# '^\k\+$'
let [file, jump] = split(a:file, "/") let [file, jump] = split(a:file, "/")
if file !~# '\.'
try
let file = fireplace#evalparse('((ns-aliases *ns*) '.s:qsym(file).' '.s:qsym(file).')')
catch /^Clojure:/
endtry
endif
else else
let file = a:file let file = a:file
endif endif
try let file = fireplace#findfile(file)
let file = fireplace#findfile(file)
catch /^Clojure:/
return ''
endtry
if file ==# '' if file ==# ''
let v:errmsg = "Couldn't find file for ".a:file let v:errmsg = "Couldn't find file for ".a:file
return 'echoerr v:errmsg' return 'echoerr v:errmsg'