Alternate between test and implementation

Closes #33.
This commit is contained in:
Tim Pope 2013-01-25 12:26:53 -05:00
parent f653f18e64
commit d2bc102487
2 changed files with 49 additions and 0 deletions

View File

@ -91,6 +91,21 @@ gf Go to the file for the namespace under the cursor.
:Dsplit {symbol} Jump to the definition for the given symbol in a
split.
*foreplay-:A*
:A In a test file, edit the implementation, and vice
versa. Basically adds or removes -test from the end
of the current namespace and searches for it in the
class path.
*foreplay-:AS*
:AS Like :A, but in a split.
*foreplay-:AV*
:AV Like :A, but in a vertical split.
*foreplay-:AT*
:AT Like :A, but in a tab.
EVALUATING CODE *foreplay-eval*
All code is evaluated in the namespace of the current file, requiring it if

View File

@ -966,6 +966,40 @@ augroup foreplay_doc
autocmd FileType clojure command! -buffer -bar -nargs=1 -complete=customlist,foreplay#eval_complete Source :exe s:Lookup('clojure.repl', 'source', <q-args>)
augroup END
" }}}1
" Alternate {{{1
augroup foreplay_alternate
autocmd!
autocmd FileType clojure command! -buffer -bar -bang A :exe s:Alternate('edit<bang>')
autocmd FileType clojure command! -buffer -bar AS :exe s:Alternate('split')
autocmd FileType clojure command! -buffer -bar AV :exe s:Alternate('vsplit')
autocmd FileType clojure command! -buffer -bar AT :exe s:Alternate('tabedit')
augroup END
function! s:alternates() abort
let ns = foreplay#ns()
if ns =~# '-test$'
let alt = [ns[0:-6]]
elseif ns =~# '\.test\.'
let alt = [substitute(ns, '\.test\.', '.', '')]
else
let alt = [ns . '-test', substitute(ns, '\.', '.test.', '')]
endif
return map(alt, 'tr(v:val, ".-", "/_") . ".clj"')
endfunction
function! s:Alternate(cmd) abort
let alternates = s:alternates()
for file in alternates
let path = foreplay#findresource(file)
if !empty(path)
return a:cmd . ' ' . fnameescape(path)
endif
endfor
return 'echoerr '.string("Couldn't find " . alternates[0] . "in class path")
endfunction
" }}}1
" Leiningen {{{1