Skip to content
This repository was archived by the owner on Nov 19, 2017. It is now read-only.

Commit ba95be2

Browse files
committed
Add ability to call from within a block
1 parent 9e3fca9 commit ba95be2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

plugin/blockle.vim

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,39 @@ function! s:ConvertDoEndToBrackets()
8989
endif
9090
endfunction
9191

92-
function! s:ToggleDoEndOrBrackets()
93-
if &ft!='ruby' | return | endif
92+
function! s:goToNearestBlockBounds()
9493
let char = getline('.')[col('.')-1]
9594
if char =~ '[{}]'
95+
return char
96+
endif
97+
98+
let word = expand('<cword>')
99+
if word =~ '\vdo|end'
100+
return word
101+
endif
102+
103+
let endline = line('.')+5
104+
echo endline
105+
if search('\vend|}', 'cs', endline)
106+
return expand('<cword>')
107+
endif
108+
109+
return ''
110+
endfunction
111+
112+
function! s:ToggleDoEndOrBrackets()
113+
if &ft!='ruby' | return | endif
114+
115+
let block_bound = s:goToNearestBlockBounds()
116+
117+
if block_bound =~ '[{}]'
96118
call <SID>ConvertBracketsToDoEnd()
119+
elseif block_bound =~ '\vdo|end'
120+
call <SID>ConvertDoEndToBrackets()
97121
else
98-
if expand('<cword>') =~ '\vdo|end'
99-
call <SID>ConvertDoEndToBrackets()
100-
else
101-
throw 'Cannot toggle block: cursor is not on {, }, do or end'
102-
endif
122+
throw 'Cannot toggle block: cursor is not on {, }, do or end'
103123
endif
124+
104125
silent! call repeat#set("\<Plug>BlockToggle", -1)
105126
endfunction
106127

0 commit comments

Comments
 (0)