This repository was archived by the owner on Nov 19, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -89,18 +89,39 @@ function! s:ConvertDoEndToBrackets()
8989 endif
9090endfunction
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 )
105126endfunction
106127
You can’t perform that action at this time.
0 commit comments