Improve exception handling

This commit is contained in:
Kim Silkebækken 2011-03-29 17:04:19 +02:00
parent fea0d68d5a
commit 1864b1d3fd

View File

@ -223,6 +223,7 @@
" Highlight source
let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1)
try
" Set lines with markers
call s:SetLines(lines_items, 'marker')
@ -235,10 +236,8 @@
call s:Prompt('Group character')
endif
let input_char = s:GetChar()
redraw
let char = s:GetChar()
finally
" Restore original lines
call s:SetLines(lines_items, 'orig')
@ -246,23 +245,24 @@
call matchdelete(target_hl_id)
redraw
endtry
" Check that we have an input char
if empty(input_char)
if empty(char)
throw 'Cancelled'
endif
" Check if the input char is valid
if ! has_key(s:key_to_index, input_char) || s:key_to_index[input_char] >= targets_len
if ! has_key(s:key_to_index, char) || s:key_to_index[char] >= targets_len
throw 'Invalid target'
endif
if single_group
" Return target coordinates
return a:groups[0][s:key_to_index[input_char]]
return a:groups[0][s:key_to_index[char]]
else
" Prompt for target character
return s:PromptUser([a:groups[s:key_to_index[input_char]]])
return s:PromptUser([a:groups[s:key_to_index[char]]])
endif
endfunction "}}}
function! s:EasyMotion(regexp, direction, visualmode) " {{{
@ -353,7 +353,7 @@
call setpos('.', [0, coords[0], coords[1]])
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
catch /.*/
catch
redraw
" Show exception message
@ -366,18 +366,16 @@
call setpos('.', [0, orig_pos[0], orig_pos[1]])
endif
finally
redraw
" Remove shading
if g:EasyMotion_do_shade && exists('shade_hl_id')
call matchdelete(shade_hl_id)
endif
" Restore properties
call s:VarReset('&scrolloff')
call s:VarReset('&modified')
call s:VarReset('&modifiable')
call s:VarReset('&readonly')
" Remove shading
if g:EasyMotion_do_shade && exists('shade_hl_id')
call matchdelete(shade_hl_id)
endif
endtry
endfunction " }}}
" }}}