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

Commit f39304b

Browse files
committed
Refactor: remove duplication
1 parent 809295b commit f39304b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

plugin/blockle.vim

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ let s:cpo_save = &cpo
1717
set cpo&vim
1818

1919
function! 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
7670
endfunction
7771

7872
function! 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
10795
endfunction
10896

10997
function! s:goToNearestBlockBounds()
@@ -125,8 +113,13 @@ function! s:goToNearestBlockBounds()
125113
endfunction
126114

127115
function! 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)
139136
endfunction
140137

0 commit comments

Comments
 (0)