Skip to content

Commit 41558c3

Browse files
author
Benjamin Miller
committed
Add run spec block
1 parent 4f6d165 commit 41558c3

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ or the "run spec" mapping:
102102
will toggle the spec between "it" and "iit." This works especially well if
103103
you have a karma watch going, as shown in the [screencast][screencast].
104104

105+
You are able to do the same with a describe block using the block command:
106+
107+
:AngularRunSpecBlock
108+
109+
or the coresponding mapping:
110+
111+
<leader>rb
112+
105113
### Syntastic syntax checker ignores
106114

107115
You know how you use syntastic to check your syntax as you edit, because

doc/angular.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ have a karma watch going. Wut, you don't use karma watch? Dude!
5555
files and running your tests automatically when you
5656
save files.
5757

58+
:AngularRunSpecBlock Prefore the same acation as :AngularRunSpec using the
59+
describe block the cursor is currenlty in.
60+
5861
ABOUT *angular-about*
5962

6063
Grab the latest version or report a bug on GitHub:

plugin/angular.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,38 @@ function! s:SearchUpForPattern(pattern) abort
174174
endfunction
175175

176176

177+
function! s:AngularRunSpecBlock() abort
178+
" save cursor position so we can go back
179+
let b:angular_pos = getpos('.')
180+
181+
cal s:SearchUpForPattern('describe(')
182+
183+
let l:wordundercursor = expand('<cword>')
184+
185+
if l:wordundercursor == "describe"
186+
" if there was a spec (anywhere in the file) highlighted with "ddescribe" before, revert it to "describe"
187+
let l:positionofspectorun = getpos('.')
188+
189+
" this can move the cursor, hence setting the cursor back
190+
%s/ddescribe/describe/ge
191+
%s/iit/it/ge
192+
193+
" move cursor back to the spec we want to run
194+
call setpos('.', l:positionofspectorun)
195+
196+
" change the current spec to "ddescribe"
197+
execute 'silent normal! cwddescribe'
198+
elseif l:wordundercursor == "ddescribe"
199+
" delete the second d in "ddescribe"
200+
execute 'silent normal! x'
201+
endif
202+
203+
update " write the file if modified
204+
205+
" Reset cursor to previous position.
206+
call setpos('.', b:angular_pos)
207+
endfunction
208+
177209
function! s:AngularRunSpec() abort
178210
" save cursor position so we can go back
179211
let b:angular_pos = getpos('.')
@@ -230,5 +262,7 @@ augroup END
230262
augroup angular_run_spec
231263
autocmd!
232264
autocmd FileType javascript command! -buffer AngularRunSpec :call s:AngularRunSpec()
265+
autocmd FileType javascript command! -buffer AngularRunSpecBlock :call s:AngularRunSpecBlock()
233266
autocmd FileType javascript nnoremap <silent><buffer> <Leader>rs :AngularRunSpec<CR>
267+
autocmd FileType javascript nnoremap <silent><buffer> <Leader>rb :AngularRunSpecBlock<CR>
234268
augroup END

0 commit comments

Comments
 (0)