Merge branch 'feature/easymotion-user' into master

This commit is contained in:
haya14busa 2014-01-22 16:28:29 +09:00
commit 83ebeb2050
2 changed files with 55 additions and 19 deletions

View File

@ -43,6 +43,11 @@ function! EasyMotion#init()
\ '(#\zs.)' \ '(#\zs.)'
let g:EasyMotion_re_line_anywhere = get(g:, 'EasyMotion_re_line_anywhere', re) let g:EasyMotion_re_line_anywhere = get(g:, 'EasyMotion_re_line_anywhere', re)
"}}} "}}}
" For other plugin
let s:EasyMotion_is_cancelled = 0
" 0 -> Success
" 1 -> Cancel
let g:EasyMotion_ignore_exception = 0
return "" return ""
endfunction "}}} endfunction "}}}
" Reset: {{{ " Reset: {{{
@ -110,6 +115,7 @@ function! EasyMotion#S(num_strokes, visualmode, direction) " {{{
let re = s:findMotion(a:num_strokes) let re = s:findMotion(a:num_strokes)
if s:handleEmpty(re, a:visualmode) | return | endif if s:handleEmpty(re, a:visualmode) | return | endif
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#T(num_strokes, visualmode, direction) " {{{ function! EasyMotion#T(num_strokes, visualmode, direction) " {{{
if a:direction == 1 if a:direction == 1
@ -130,26 +136,31 @@ function! EasyMotion#T(num_strokes, visualmode, direction) " {{{
let re = '.\ze\('.re.'\)' let re = '.\ze\('.re.'\)'
endif endif
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- Word Motion ------------------------- " -- Word Motion -------------------------
function! EasyMotion#WB(visualmode, direction) " {{{ function! EasyMotion#WB(visualmode, direction) " {{{
"FIXME: inconsistent with default vim motion "FIXME: inconsistent with default vim motion
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#WBW(visualmode, direction) " {{{ function! EasyMotion#WBW(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#E(visualmode, direction) " {{{ function! EasyMotion#E(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let is_inclusive = mode(1) ==# 'no' ? 1 : 0 let is_inclusive = mode(1) ==# 'no' ? 1 : 0
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#EW(visualmode, direction) " {{{ function! EasyMotion#EW(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let is_inclusive = mode(1) ==# 'no' ? 1 : 0 let is_inclusive = mode(1) ==# 'no' ? 1 : 0
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- JK Motion --------------------------- " -- JK Motion ---------------------------
function! EasyMotion#JK(visualmode, direction) " {{{ function! EasyMotion#JK(visualmode, direction) " {{{
@ -161,24 +172,29 @@ function! EasyMotion#JK(visualmode, direction) " {{{
let prev_column = getpos('.')[2] - 1 let prev_column = getpos('.')[2] - 1
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', 0)
endif endif
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#Sol(visualmode, direction) " {{{ function! EasyMotion#Sol(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '') call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#Eol(visualmode, direction) " {{{ function! EasyMotion#Eol(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion('\(\w\|\s*\zs\|.\|^\)$', a:direction, a:visualmode ? visualmode() : '', '') call s:EasyMotion('\(\w\|\s*\zs\|.\|^\)$', a:direction, a:visualmode ? visualmode() : '', '')
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- Search Motion ----------------------- " -- Search Motion -----------------------
function! EasyMotion#Search(visualmode, direction) " {{{ function! EasyMotion#Search(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- JumpToAnywhere Motion --------------- " -- JumpToAnywhere Motion ---------------
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{ function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- Line Motion ------------------------- " -- Line Motion -------------------------
function! EasyMotion#SL(num_strokes, visualmode, direction) " {{{ function! EasyMotion#SL(num_strokes, visualmode, direction) " {{{
@ -193,6 +209,7 @@ function! EasyMotion#SL(num_strokes, visualmode, direction) " {{{
let re = s:findMotion(a:num_strokes) let re = s:findMotion(a:num_strokes)
if s:handleEmpty(re, a:visualmode) | return | endif if s:handleEmpty(re, a:visualmode) | return | endif
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{ function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{
if a:direction == 1 if a:direction == 1
@ -207,38 +224,42 @@ function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{
if s:handleEmpty(re, a:visualmode) | return | endif if s:handleEmpty(re, a:visualmode) | return | endif
let re = a:direction == 1 ? '\('.re.'\)\zs.' : '.\ze\('.re.'\)' let re = a:direction == 1 ? '\('.re.'\)\zs.' : '.\ze\('.re.'\)'
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#WBL(visualmode, direction) " {{{ function! EasyMotion#WBL(visualmode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let is_inclusive = mode(1) ==# 'no' ? 1 : 0 let is_inclusive = mode(1) ==# 'no' ? 1 : 0
let s:flag.within_line = 1 let s:flag.within_line = 1
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#EL(visualmode, direction) " {{{ function! EasyMotion#EL(visualmode, direction) " {{{
let s:flag.within_line = 1 let s:flag.within_line = 1
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let is_inclusive = mode(1) ==# 'no' ? 1 : 0 let is_inclusive = mode(1) ==# 'no' ? 1 : 0
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#LineAnywhere(visualmode, direction) " {{{ function! EasyMotion#LineAnywhere(visualmode, direction) " {{{
let s:flag.within_line = 1 let s:flag.within_line = 1
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let re = g:EasyMotion_re_line_anywhere let re = g:EasyMotion_re_line_anywhere
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', 0) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', 0)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- Special Motion ---------------------- " -- Special Motion ----------------------
function! EasyMotion#SelectLines() "{{{ function! EasyMotion#SelectLines() "{{{
let orig_pos = [line('.'), col('.')] let orig_pos = [line('.'), col('.')]
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, 0, 0, 1) call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, 0, 0, 1)
if s:EasyMotion_cancelled if s:EasyMotion_is_cancelled
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
return '' return ''
else else
let pos1 = [line('.'), col('.')] let pos1 = [line('.'), col('.')]
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, pos1[0], 1, 1) call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, pos1[0], 1, 1)
if s:EasyMotion_cancelled if s:EasyMotion_is_cancelled
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
return '' return ''
else else
@ -313,7 +334,7 @@ function! EasyMotion#SelectPhrase() "{{{
" First " First
call s:EasyMotion(re, 2, '', 0, 0, 0, 0, 0) call s:EasyMotion(re, 2, '', 0, 0, 0, 0, 0)
if s:EasyMotion_cancelled if s:EasyMotion_is_cancelled
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
return '' return ''
endif endif
@ -324,7 +345,7 @@ function! EasyMotion#SelectPhrase() "{{{
" Second " Second
call s:EasyMotion(re, 2, '', 0, 0, 0, 0, pos1) call s:EasyMotion(re, 2, '', 0, 0, 0, 0, pos1)
if s:EasyMotion_cancelled if s:EasyMotion_is_cancelled
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
return '' return ''
endif endif
@ -364,19 +385,20 @@ function! EasyMotion#SelectPhraseDelete() "{{{
endif endif
endfunction "}}} endfunction "}}}
" -- User Motion ------------------------- " -- User Motion -------------------------
" TODO: more improvement function! EasyMotion#User(pattern, visualmode, direction, inclusive) " {{{
function! EasyMotion#User(pattern, mode, direction) " {{{
let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 let s:current.is_operator = mode(1) ==# 'no' ? 1: 0
let visualmode = match('\v([Vv])|(C-v)', a:mode) > 0 ? visualmode() : '' let is_inclusive = mode(1) ==# 'no' ? a:inclusive : 0
let re = escape(a:pattern, '|') let re = a:pattern
call s:EasyMotion(re, a:direction, visualmode, 0) call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" -- Repeat Motion ----------------------- " -- Repeat Motion -----------------------
function! EasyMotion#Repeat(visualmode) " {{{ function! EasyMotion#Repeat(visualmode) " {{{
" Repeat previous motion with previous targets " Repeat previous motion with previous targets
if s:previous ==# {} if s:previous ==# {}
call s:Message("Previous targets doesn't exist") call s:Message("Previous targets doesn't exist")
return let s:EasyMotion_is_cancelled = 1
return s:EasyMotion_is_cancelled
endif endif
let re = s:previous.regexp let re = s:previous.regexp
let direction = s:previous.direction let direction = s:previous.direction
@ -389,12 +411,14 @@ function! EasyMotion#Repeat(visualmode) " {{{
let is_inclusive = mode(1) ==# 'no' ? 1 : 0 let is_inclusive = mode(1) ==# 'no' ? 1 : 0
call s:EasyMotion(re, direction, a:visualmode ? visualmode() : '', is_inclusive) call s:EasyMotion(re, direction, a:visualmode ? visualmode() : '', is_inclusive)
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#DotRepeat(visualmode) " {{{ function! EasyMotion#DotRepeat(visualmode) " {{{
" Repeat previous '.' motion with previous targets and operator " Repeat previous '.' motion with previous targets and operator
if s:dot_repeat ==# {} if s:dot_repeat ==# {}
call s:Message("Previous motion doesn't exist") call s:Message("Previous motion doesn't exist")
return let s:EasyMotion_is_cancelled = 1
return s:EasyMotion_is_cancelled
endif endif
let re = s:dot_repeat.regexp let re = s:dot_repeat.regexp
@ -408,12 +432,14 @@ function! EasyMotion#DotRepeat(visualmode) " {{{
let s:flag.dot_repeat = 1 " s:EasyMotion() always call reset let s:flag.dot_repeat = 1 " s:EasyMotion() always call reset
silent call s:EasyMotion(re, direction, 0, is_inclusive) silent call s:EasyMotion(re, direction, 0, is_inclusive)
endfor endfor
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
function! EasyMotion#NextPrevious(visualmode, direction) " {{{ function! EasyMotion#NextPrevious(visualmode, direction) " {{{
" Move next/previous destination using previous motion regexp " Move next/previous destination using previous motion regexp
if s:previous ==# {} if s:previous ==# {}
call s:Message("Previous targets doesn't exist") call s:Message("Previous targets doesn't exist")
return let s:EasyMotion_is_cancelled = 1
return s:EasyMotion_is_cancelled
endif endif
let re = s:previous.regexp let re = s:previous.regexp
let search_direction = (a:direction >= 1 ? 'b' : '') let search_direction = (a:direction >= 1 ? 'b' : '')
@ -435,6 +461,7 @@ function! EasyMotion#NextPrevious(visualmode, direction) " {{{
" -- Activate EasyMotion ----------------- {{{ " -- Activate EasyMotion ----------------- {{{
let s:EasyMotion_is_active = 1 let s:EasyMotion_is_active = 1
call EasyMotion#attach_active_autocmd() "}}} call EasyMotion#attach_active_autocmd() "}}}
return s:EasyMotion_is_cancelled
endfunction " }}} endfunction " }}}
" }}} " }}}
" Helper Functions: {{{ " Helper Functions: {{{
@ -658,7 +685,7 @@ function! s:should_use_smartcase(input) "{{{
if g:EasyMotion_smartcase == 0 if g:EasyMotion_smartcase == 0
return 0 return 0
endif endif
" return 1 if input didn't match upporcase letter " return 1 if input didn't match uppercase letter
return match(a:input, '\u') == -1 return match(a:input, '\u') == -1
endfunction "}}} endfunction "}}}
function! s:handleEmpty(input, visualmode) "{{{ function! s:handleEmpty(input, visualmode) "{{{
@ -667,6 +694,7 @@ function! s:handleEmpty(input, visualmode) "{{{
if ! empty(a:visualmode) if ! empty(a:visualmode)
silent exec 'normal! gv' silent exec 'normal! gv'
endif endif
let s:EasyMotion_is_cancelled = 1 " Cancel
return 1 return 1
endif endif
return 0 return 0
@ -1545,15 +1573,16 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive, ...) " {{{
endif "}}} endif "}}}
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
let s:EasyMotion_cancelled = 0 " Success let s:EasyMotion_is_cancelled = 0 " Success
"}}} "}}}
catch catch
redraw redraw
" Show exception message " Show exception message
if g:EasyMotion_ignore_exception != 1
call s:Message(v:exception) call s:Message(v:exception)
call s:Message(v:throwpoint) endif
" -- Restore original cursor position/selection {{{ " -- Restore original cursor position/selection {{{
if ! empty(a:visualmode) if ! empty(a:visualmode)
@ -1563,7 +1592,7 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive, ...) " {{{
keepjumps call cursor(orig_pos[0], orig_pos[1]) keepjumps call cursor(orig_pos[0], orig_pos[1])
endif endif
" }}} " }}}
let s:EasyMotion_cancelled = 1 " Cancel let s:EasyMotion_is_cancelled = 1 " Cancel
finally finally
" -- Restore properties ------------------ {{{ " -- Restore properties ------------------ {{{
call s:RestoreValue() call s:RestoreValue()
@ -1573,7 +1602,7 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive, ...) " {{{
call EasyMotion#highlight#delete_highlight() call EasyMotion#highlight#delete_highlight()
" }}} " }}}
if s:EasyMotion_cancelled == 0 " Success if s:EasyMotion_is_cancelled == 0 " Success
" -- Landing Highlight ------------------- {{{ " -- Landing Highlight ------------------- {{{
if g:EasyMotion_landing_highlight if g:EasyMotion_landing_highlight
call EasyMotion#highlight#add_highlight(a:regexp, 'EasyMotionMoveHL') call EasyMotion#highlight#add_highlight(a:regexp, 'EasyMotionMoveHL')

View File

@ -2,7 +2,7 @@
" FILE: highlight.vim " FILE: highlight.vim
" AUTHOR: haya14busa " AUTHOR: haya14busa
" Reference: https://github.com/t9md/vim-smalls " Reference: https://github.com/t9md/vim-smalls
" Last Change: 21 Jan 2014. " Last Change: 22 Jan 2014.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -73,6 +73,13 @@ function! EasyMotion#highlight#attach_autocmd() "{{{
\ | autocmd! plugin-easymotion * <buffer> \ | autocmd! plugin-easymotion * <buffer>
augroup END augroup END
endfunction "}}} endfunction "}}}
function! EasyMotion#highlight#add_color_group(new_groups) "{{{
let s:priorities = extend(deepcopy(s:priorities), a:new_groups)
for group in keys(a:new_groups)
let s:h.ids[group] = []
endfor
endfunction "}}}
" Restore 'cpoptions' {{{ " Restore 'cpoptions' {{{
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo