Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Alternate between test and implementation

Closes #33.
  • Loading branch information...
commit d2bc1024872618b6da41e336e0a187606e3ed058 1 parent f653f18
@tpope authored
Showing with 49 additions and 0 deletions.
  1. +15 −0 doc/foreplay.txt
  2. +34 −0 plugin/foreplay.vim
View
15 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
View
34 plugin/foreplay.vim
@@ -967,6 +967,40 @@ augroup foreplay_doc
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
function! s:hunt(start, anchor) abort
Please sign in to comment.
Something went wrong with that request. Please try again.