Refactor try/catch blocks

This commit is contained in:
Kim Silkebækken 2011-03-28 22:36:39 +02:00
parent ebb93269cf
commit 49a4795a86

View File

@ -215,9 +215,6 @@
let lines_items = items(lines)
" }}}
let input_char = ''
try
" Highlight source
let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1)
@ -236,19 +233,20 @@
let input_char = nr2char(getchar())
redraw
finally
" Restore original lines
call <SID>SetLines(lines_items, 'orig')
" Un-highlight code
call matchdelete(target_hl_id)
redraw
" Check if the input char is valid
if ! has_key(s:key_to_index, input_char) || s:key_to_index[input_char] >= targets_len
" Invalid input char
return []
else
throw 'Cancelled'
endif
if single_group
" Return target coordinates
return a:groups[0][s:key_to_index[input_char]]
@ -256,8 +254,6 @@
" Prompt for target character
return s:PromptUser([a:groups[s:key_to_index[input_char]]])
endif
endif
endtry
endfunction "}}}
function! s:EasyMotion(regexp, direction, visualmode) " {{{
let orig_pos = [line('.'), col('.')]
@ -336,14 +332,6 @@
" Prompt user for target group/character
let coords = <SID>PromptUser(groups)
" Remove shading
if g:EasyMotion_shade
call matchdelete(shade_hl_id)
endif
if len(coords) != 2
throw 'Cancelled'
else
if ! empty(a:visualmode)
" Store original marks
let m_a = getpos("'a")
@ -365,7 +353,6 @@
endif
call <SID>Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
endif
catch /.*/
redraw
@ -381,6 +368,11 @@
finally
redraw
" Remove shading
if g:EasyMotion_shade
call matchdelete(shade_hl_id)
endif
" Restore properties
call <SID>VarReset('&scrolloff')
call <SID>VarReset('&modified')