@@ -17,10 +17,6 @@ let s:cpo_save = &cpo
1717set cpo &vim
1818
1919function ! s: ConvertBracketsToDoEnd ()
20- let reg = getreg (' "' , 1 )
21- let regtype = getregtype (' "' )
22- let cb_save = &clipboard
23- set clipboard -= unnamed
2420 let char = getline (' .' )[col (' .' )-1 ]
2521 if char== ' }'
2622 norm %
@@ -71,15 +67,9 @@ function! s:ConvertBracketsToDoEnd()
7167 norm! send
7268 call setpos (' .' , begin_pos)
7369 endif
74- call setreg (' "' , reg , regtype)
75- let &clipboard = cb_save
7670endfunction
7771
7872function ! s: ConvertDoEndToBrackets ()
79- let reg = getreg (' "' , 1 )
80- let regtype = getregtype (' "' )
81- let cb_save = &clipboard
82- set clipboard -= unnamed
8373 let char = getline (' .' )[col (' .' )-1 ]
8474 let w = expand (' <cword>' )
8575 if w == ' end'
@@ -102,8 +92,6 @@ function! s:ConvertDoEndToBrackets()
10292 " if search(' \+', 'c', begin_num) | :.s/\([^ ]\) \+/\1 /g | endif
10393 call setpos (' .' , do_pos)
10494 endif
105- call setreg (' "' , reg , regtype)
106- let &clipboard = cb_save
10795endfunction
10896
10997function ! s: goToNearestBlockBounds ()
@@ -125,8 +113,13 @@ function! s:goToNearestBlockBounds()
125113endfunction
126114
127115function ! s: ToggleDoEndOrBrackets ()
128- let block_bound = s: goToNearestBlockBounds ()
116+ " Save anonymous register and clipboard settings
117+ let reg = getreg (' "' , 1 )
118+ let regtype = getregtype (' "' )
119+ let cb_save = &clipboard
120+ set clipboard -= unnamed
129121
122+ let block_bound = s: goToNearestBlockBounds ()
130123 if block_bound == ' {' || block_bound == ' }'
131124 call s: ConvertBracketsToDoEnd ()
132125 elseif block_bound == # ' do' || block_bound == # ' end'
@@ -135,6 +128,10 @@ function! s:ToggleDoEndOrBrackets()
135128 echo ' Cannot toggle block: cursor is not on {, }, do or end'
136129 endif
137130
131+ " Restore anonymous register and clipboard settings
132+ call setreg (' "' , reg , regtype)
133+ let &clipboard = cb_save
134+
138135 silent ! call repeat#set (" \<Plug> BlockToggle" , -1 )
139136endfunction
140137
0 commit comments