-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvim-ruby-conque.vim
More file actions
142 lines (123 loc) · 4.73 KB
/
vim-ruby-conque.vim
File metadata and controls
142 lines (123 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
" ============================================================================
" File: vim-ruby-conque.vim
" Description: Run ruby, rspec, rake in ConqueTerm using colorized output
" Maintainer: Yan Pritzker <yan@pritzker.ws>
" Last Change: December 8, 2011
" Version: 0.0.1
" License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" ============================================================================
" Automatically uses 'rspec' if you have rspec2
" installed, or 'spec' for rspec1. You can override
" This by setting up your vimrc like this:
"
" let g:ruby_conque_rspec_runner='spec'
"
function! GetRubyConqueRspecCommand()
if exists('g:ruby_conque_rspec_runner')
return g:ruby_conque_rspec_runner
else
if executable('rspec')
return 'rspec'
elseif executable('bundle exec rspec')
return 'bundle exec rspec'
elseif executable('spec')
return 'spec'
elseif executable('bundle exec spec')
return 'bundle exec spec'
endif
endif
endfunction
" Lets you choose the ruby interpreter
"
" let g:ruby_conque_ruby='rvm-auto-ruby'
"
function! GetRubyConqueRubyCommand()
if exists('g:ruby_conque_ruby')
return g:ruby_conque_ruby
else
return 'ruby'
endif
endfunction
" Always deletes any existing instance prior to runing the next one
function! RunSingleConque(command)
" Close quickfix and location windows that are in the way
:cclose
:lclose
call CloseSingleConque()
" Keep track of the last command issued.
let g:last_conque_command = a:command
let g:single_conque = conque_term#open(a:command, ['botright split', 'res 10'])
endfunction
function! CloseSingleConque()
try
if(exists("g:single_conque"))
exec "bdelete " . g:single_conque.buffer_name
endif
catch
endtry
endfunction
function! RunRubyCurrentFileConque()
call RunSingleConque(GetRubyConqueRubyCommand() . " " . bufname('%'))
endfunction
function! RunRspecCurrentLineConque()
call RunSingleConque(GetRubyConqueRspecCommand() . " " . bufname('%') . " -l " . line('.') . " --color")
endfunction
function! RunRspecCurrentFileConque()
call RunSingleConque(GetRubyConqueRspecCommand() . " " . bufname('%') . " --color")
endfunction
function! RunCucumberCurrentLineConque()
call RunSingleConque("cucumber" . " " . bufname('%') . ":" . line('.'))
endfunction
function! RunCucumberCurrentFileConque()
call RunSingleConque("cucumber" . " " . bufname('%'))
endfunction
function! RunRakeConque()
call RunSingleConque("rake")
endfunction
function! RunLastConqueCommand()
if exists("g:last_conque_command")
call RunSingleConque(g:last_conque_command)
else
echo "You haven't run a Vim-Ruby-Conque command to repeat."
endif
endfunction
" Requires https://github.com/skwp/vim-spec-finder
function! RunRspecRelated()
call RunSingleConque(GetRubyConqueRspecCommand() . " " . RelatedSpec() . " --color")
endfunction
" Get around Conques annoying trapping of input in some kind of strange
" inputless input mode. Also added q to close the buffer. n and p jump between
" errors in the output buffer.
function! RubyConqueControls(single_conque)
:setlocal nolist
:map <buffer> j j
:map <buffer> k k
:map <buffer> q <C-w>c
:map <silent><buffer> n /^\s\+\d\+)<CR>:noh<CR>zt
:map <silent><buffer> p ?^\s\+\d\+)<CR>:noh<CR>zt
:map <silent><buffer> f /Finished in<CR>:noh<CR>zt
endfunction
call conque_term#register_function('after_startup', 'RubyConqueControls')
command! RunRubyCurrentFileConque call RunRubyCurrentFileConque()
command! RunRspecCurrentFileConque call RunRspecCurrentFileConque()
command! RunRspecCurrentLineConque call RunRspecCurrentLineConque()
command! RunCucumberCurrentLineConque call RunCucumberCurrentLineConque()
command! RunCucumberCurrentFileConque call RunCucumberCurrentFileConque()
command! RunRakeConque call RunRakeConque()
command! RunLastConqueCommand call RunLastConqueCommand()
command! RunRspecRelated call RunRspecRelated()
command! CloseSingleConque call CloseSingleConque()
nmap <silent> <Leader>rcrr :RunRubyCurrentFileConque<CR>
nmap <silent> <Leader>rcss :RunRspecCurrentFileConque<CR>
nmap <silent> <Leader>rcll :RunRspecCurrentLineConque<CR>
nmap <silent> <Leader>rccl :RunCucumberCurrentLineConque<CR>
nmap <silent> <Leader>rccc :RunCucumberCurrentFileConque<CR>
nmap <silent> <Leader>rcRR :RunRakeConque<CR>
nmap <silent> <Leader>rcrl :RunLastConqueCommand<CR>
nmap <silent> <Leader>rcrel :RunRspecRelated<CR>
nmap <silent> <Leader>rccc :CloseSingleConque<CR>