diff --git a/doc/foreplay.txt b/doc/foreplay.txt index 69836cd..43ccfa7 100644 --- a/doc/foreplay.txt +++ b/doc/foreplay.txt @@ -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 diff --git a/plugin/foreplay.vim b/plugin/foreplay.vim index be993e6..cf947b1 100644 --- a/plugin/foreplay.vim +++ b/plugin/foreplay.vim @@ -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', ) augroup END +" }}}1 +" Alternate {{{1 + +augroup foreplay_alternate + autocmd! + autocmd FileType clojure command! -buffer -bar -bang A :exe s:Alternate('edit') + 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