Handle EasyMotion exception separating from unexpected one

Conflicts:
	autoload/EasyMotion.vim
This commit is contained in:
haya14busa 2014-06-12 15:29:46 +09:00
parent cd63e50838
commit f524597ce1

View File

@ -358,6 +358,9 @@ function! s:Prompt(message) " {{{
echo a:message . ': ' echo a:message . ': '
echohl None echohl None
endfunction " }}} endfunction " }}}
function! s:Throw(message)
throw 'EasyMotion: ' . a:message
endfunction
" -- Save & Restore values --------------- " -- Save & Restore values ---------------
function! s:SaveValue() "{{{ function! s:SaveValue() "{{{
if ! s:current.is_search if ! s:current.is_search
@ -417,6 +420,7 @@ function! s:GetChar() " {{{
endif endif
return nr2char(char) return nr2char(char)
endfunction " }}} endfunction " }}}
" -- Find Motion Helper ------------------ " -- Find Motion Helper ------------------
function! s:findMotion(num_strokes, direction) "{{{ function! s:findMotion(num_strokes, direction) "{{{
" Find Motion: S,F,T " Find Motion: S,F,T
@ -606,7 +610,7 @@ endfunction "}}}
function! s:GetVisualStartPosition(c_pos, v_start, v_end, search_direction) "{{{ function! s:GetVisualStartPosition(c_pos, v_start, v_end, search_direction) "{{{
let vmode = mode(1) let vmode = mode(1)
if vmode !~# "^[Vv\<C-v>]" if vmode !~# "^[Vv\<C-v>]"
throw 'Unkown visual mode:'.vmode call s:Throw('Unkown visual mode:'.vmode)
endif endif
if vmode ==# 'V' "line-wise Visual if vmode ==# 'V' "line-wise Visual
@ -617,7 +621,7 @@ function! s:GetVisualStartPosition(c_pos, v_start, v_end, search_direction) "{{{
elseif a:search_direction == 'b' elseif a:search_direction == 'b'
return a:v_end return a:v_end
else else
throw 'Unkown search_direction' call s:throw('Unkown search_direction')
endif endif
else else
if a:c_pos[0] == a:v_start[0] if a:c_pos[0] == a:v_start[0]
@ -684,6 +688,15 @@ function! EasyMotion#activate(is_visual) "{{{
endif endif
endfunction "}}} endfunction "}}}
"}}} "}}}
function! s:restore_cursor_state(visualmode) "{{{
" -- Restore original cursor position/selection
if ! empty(a:visualmode)
silent exec 'normal! gv'
keepjumps call cursor(s:current.cursor_position)
else
keepjumps call cursor(s:current.original_position)
endif
endfunction " }}}
" Grouping Algorithms: {{{ " Grouping Algorithms: {{{
let s:grouping_algorithms = { let s:grouping_algorithms = {
\ 1: 'SCTree' \ 1: 'SCTree'
@ -1055,12 +1068,12 @@ function! s:PromptUser(groups) "{{{
" -- Check if we have an input char ------ {{{ " -- Check if we have an input char ------ {{{
if empty(char) if empty(char)
throw 'Cancelled' call s:Throw('Cancelled')
endif endif
" }}} " }}}
" -- Check if the input char is valid ---- {{{ " -- Check if the input char is valid ---- {{{
if ! has_key(a:groups, char) if ! has_key(a:groups, char)
throw 'Invalid target' call s:Throw('Invalid target')
endif endif
" }}} " }}}
@ -1259,7 +1272,7 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive) " {{{
" Handle no match"{{{ " Handle no match"{{{
let targets_len = len(targets) let targets_len = len(targets)
if targets_len == 0 if targets_len == 0
throw 'No matches' call s:Throw('No matches')
endif endif
"}}} "}}}
@ -1444,23 +1457,24 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive) " {{{
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
let s:EasyMotion_is_cancelled = 0 " Success let s:EasyMotion_is_cancelled = 0 " Success
"}}} "}}}
catch /^EasyMotion:.*/
catch
redraw redraw
" Show exception message " Show exception message
if g:EasyMotion_ignore_exception != 1 if g:EasyMotion_ignore_exception != 1
call s:Message(v:exception) echo v:exception
endif endif
" -- Restore original cursor position/selection {{{ let s:previous['regexp'] = a:regexp
if ! empty(a:visualmode) " -- Activate EasyMotion ----------------- {{{
silent exec 'normal! gv' let s:EasyMotion_is_active = 1
keepjumps call cursor(s:current.cursor_position) call EasyMotion#attach_active_autocmd() "}}}
else
keepjumps call cursor(s:current.original_position) call s:restore_cursor_state(a:visualmode)
endif let s:EasyMotion_is_cancelled = 1 " Cancel
" }}} catch
call s:Message(v:exception . ' : ' . v:throwpoint)
call s:restore_cursor_state(a:visualmode)
let s:EasyMotion_is_cancelled = 1 " Cancel let s:EasyMotion_is_cancelled = 1 " Cancel
finally finally
" -- Restore properties ------------------ {{{ " -- Restore properties ------------------ {{{