Skip to content

Commit

Permalink
Replace bindings with something useful ruby ones
Browse files Browse the repository at this point in the history
When used with rails.vim, allow sending alternate files

Within a ruby file, use the <leader>t mapping to run the corresponding
spec. Within a cucumber feature file, the same mapping will run just
that scenario.
  • Loading branch information
jgdavey committed Oct 23, 2011
1 parent ac3ae9e commit 668bbf6
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions plugin/tslime.vim
Expand Up @@ -63,9 +63,36 @@ function! s:Tmux_Vars()
end
endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:first_readable_file(files) abort
let files = type(a:files) == type([]) ? copy(a:files) : split(a:files,"\n")
for file in files
if filereadable(rails#app().path(file))
return file
endif
endfor
return files[0]
endfunction

function! s:SendAlternateToTmux() abort
let current_file = expand("%")
if current_file =~# '_spec.rb$'
let command = "rspec ".current_file."\n"
elseif exists('g:autoloaded_rails')
let related_file = s:first_readable_file(rails#buffer().related())
let command = "rspec ".related_file."\n"
else
let command = "!!\n"
endif
return Send_to_Tmux(command)
endfunction

augroup tmux
autocmd!

autocmd FileType ruby map <buffer> <leader>t :w \| :call <SID>SendAlternateToTmux()<CR>
autocmd FileType cucumber map <buffer> <leader>t
\ :w \| :call Send_to_Tmux('cucumber '.expand("%").":".line('.')."\n")<CR>
vmap <C-c><C-c> "ry :call Send_to_Tmux(@r)<CR>
nmap <C-c><C-c> vip<C-c><C-c>
augroup END

nmap <C-c>v :call <SID>Tmux_Vars()<CR>

0 comments on commit 668bbf6

Please sign in to comment.