Merge branch 'refactoring' into master
This commit is contained in:
commit
762ad9cc17
@ -12,9 +12,9 @@ set cpo&vim
|
||||
" == Init {{{
|
||||
function! EasyMotion#init()
|
||||
" Init Migemo Dictionary
|
||||
let s:old = {}
|
||||
let s:previous = {}
|
||||
call EasyMotion#reset()
|
||||
let s:migemo_dicts = {}
|
||||
let s:line_flag = 0
|
||||
" Anywhere regular expression: {{{
|
||||
let re = '\v' .
|
||||
\ '(<.|^$)' . '|' .
|
||||
@ -44,15 +44,21 @@ function! EasyMotion#init()
|
||||
endfunction "}}}
|
||||
" == Reset {{{
|
||||
function! EasyMotion#reset()
|
||||
let s:line_flag = 0
|
||||
let s:flag = {
|
||||
\ 'within_line' : 0,
|
||||
\ 'dot_repeat' : 0,
|
||||
\ }
|
||||
return ""
|
||||
endfunction "}}}
|
||||
" == Motion functions {{{
|
||||
" -- Find Motion -------------------------
|
||||
function! EasyMotion#S(num_strokes, visualmode, direction) " {{{
|
||||
let s:old['input'] = get(s:old, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:old.input)
|
||||
let s:old['input'] = input
|
||||
let s:previous['input'] = get(s:previous, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:previous.input)
|
||||
let s:previous['input'] = input
|
||||
|
||||
let mode = mode(1)
|
||||
let is_exclusive = mode ==# 'no' ? 1 : 0
|
||||
|
||||
" Check that we have an input char
|
||||
if empty(input)
|
||||
@ -67,12 +73,15 @@ function! EasyMotion#S(num_strokes, visualmode, direction) " {{{
|
||||
|
||||
let re = s:findMotion(input)
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#T(num_strokes, visualmode, direction) " {{{
|
||||
let s:old['input'] = get(s:old, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:old.input)
|
||||
let s:old['input'] = input
|
||||
let s:previous['input'] = get(s:previous, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:previous.input)
|
||||
let s:previous['input'] = input
|
||||
|
||||
let mode = mode(1)
|
||||
let is_exclusive = mode ==# 'no' ? 1 : 0
|
||||
|
||||
" Check that we have an input char
|
||||
if empty(input)
|
||||
@ -95,28 +104,31 @@ function! EasyMotion#T(num_strokes, visualmode, direction) " {{{
|
||||
let re = '.\ze' . re
|
||||
endif
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
" -- Word Motion -------------------------
|
||||
function! EasyMotion#WB(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBW(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#E(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EW(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
" -- JK Motion ---------------------------
|
||||
function! EasyMotion#JK(visualmode, direction) " {{{
|
||||
"FIXME: support exclusive
|
||||
if g:EasyMotion_startofline
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
else
|
||||
let prev_column = getpos('.')[2] - 1
|
||||
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endif
|
||||
endfunction " }}}
|
||||
function! EasyMotion#Sol(visualmode, direction) " {{{
|
||||
@ -127,17 +139,20 @@ function! EasyMotion#Eol(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- Search Motion -----------------------
|
||||
function! EasyMotion#Search(visualmode, direction) " {{{
|
||||
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
" -- JumpToAnywhere Motion ---------------
|
||||
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
|
||||
call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
" -- Line Motion -------------------------
|
||||
function! EasyMotion#SL(num_strokes, visualmode, direction) " {{{
|
||||
let s:old['input'] = get(s:old, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:old.input)
|
||||
let s:old['input'] = input
|
||||
let s:previous['input'] = get(s:previous, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:previous.input)
|
||||
let s:previous['input'] = input
|
||||
|
||||
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
|
||||
" Check that we have an input char
|
||||
if empty(input)
|
||||
@ -150,16 +165,18 @@ function! EasyMotion#SL(num_strokes, visualmode, direction) " {{{
|
||||
return
|
||||
endif
|
||||
|
||||
let s:line_flag = 1
|
||||
let s:flag.within_line = 1
|
||||
|
||||
let re = s:findMotion(input)
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{
|
||||
let s:old['input'] = get(s:old, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:old.input)
|
||||
let s:old['input'] = input
|
||||
let s:previous['input'] = get(s:previous, 'input', '')
|
||||
let input = EasyMotion#command_line#GetInput(a:num_strokes, s:previous.input)
|
||||
let s:previous['input'] = input
|
||||
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
|
||||
" Check that we have an input char
|
||||
if empty(input)
|
||||
@ -172,7 +189,7 @@ function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{
|
||||
return
|
||||
endif
|
||||
|
||||
let s:line_flag = 1
|
||||
let s:flag.within_line = 1
|
||||
|
||||
let re = s:findMotion(input)
|
||||
|
||||
@ -184,33 +201,34 @@ function! EasyMotion#TL(num_strokes, visualmode, direction) " {{{
|
||||
let re = '.\ze' . re
|
||||
endif
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBL(visualmode, direction) " {{{
|
||||
let s:line_flag = 1
|
||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
let s:flag.within_line = 1
|
||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EL(visualmode, direction) " {{{
|
||||
let s:line_flag = 1
|
||||
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
let s:flag.within_line = 1
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#LineAnywhere(visualmode, direction) " {{{
|
||||
let s:line_flag = 1
|
||||
let s:flag.within_line = 1
|
||||
let re = g:EasyMotion_re_line_anywhere
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', 0)
|
||||
endfunction " }}}
|
||||
" -- Special Motion ----------------------
|
||||
function! EasyMotion#SelectLines() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', '', 0, 0, 1)
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, 0, 0, 1)
|
||||
if s:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
else
|
||||
let pos1 = [line('.'), col('.')]
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', '', pos1[0], 1, 1)
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', 0, pos1[0], 1, 1)
|
||||
if s:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
@ -285,7 +303,7 @@ function! EasyMotion#SelectPhrase() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
" First
|
||||
call s:EasyMotion(re, 2, '', '', 0, 0, 0, 0)
|
||||
call s:EasyMotion(re, 2, '', 0, 0, 0, 0, 0)
|
||||
if s:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
@ -296,7 +314,7 @@ function! EasyMotion#SelectPhrase() "{{{
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
|
||||
" Second
|
||||
call s:EasyMotion(re, 2, '', '', 0, 0, 0, pos1)
|
||||
call s:EasyMotion(re, 2, '', 0, 0, 0, 0, pos1)
|
||||
if s:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
@ -340,25 +358,21 @@ endfunction "}}}
|
||||
function! EasyMotion#User(pattern, mode, direction) " {{{
|
||||
let visualmode = match('\v([Vv])|(C-v)', a:mode) > 0 ? visualmode() : ''
|
||||
let re = escape(a:pattern, '|')
|
||||
call s:EasyMotion(re, a:direction, visualmode, a:mode)
|
||||
endfunction " }}}
|
||||
function! EasyMotion#UserMapping(re, mapping, direction) " {{{
|
||||
silent exec "nnoremap ".a:mapping." :call EasyMotion#User('".a:re."', 0, ".a:direction.")<CR>"
|
||||
silent exec "onoremap ".a:mapping." :call EasyMotion#User('".a:re."', 0, ".a:direction.")<CR>"
|
||||
silent exec "vnoremap ".a:mapping." :<C-u>call EasyMotion#User('".a:re."', 0,".a:direction.")<CR>"
|
||||
call s:EasyMotion(re, a:direction, visualmode, 0)
|
||||
endfunction " }}}
|
||||
" -- Repeat Motion -----------------------
|
||||
function! EasyMotion#Repeat(visualmode) " {{{
|
||||
" Repeat previous motion with previous targets
|
||||
if s:old ==# {}
|
||||
if s:previous ==# {}
|
||||
call s:Message("Previous targets doesn't exist")
|
||||
return
|
||||
endif
|
||||
let re = s:old.regexp
|
||||
let direction = s:old.direction
|
||||
let s:line_flag = s:old.line_flag
|
||||
let re = s:previous.regexp
|
||||
let direction = s:previous.direction
|
||||
let s:flag.within_line = s:previous.line_flag
|
||||
let is_exclusive = mode(1) ==# 'no' ? 1 : 0
|
||||
|
||||
call s:EasyMotion(re, direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
call s:EasyMotion(re, direction, a:visualmode ? visualmode() : '', is_exclusive)
|
||||
endfunction " }}}
|
||||
|
||||
" }}}
|
||||
@ -599,7 +613,7 @@ function! s:should_use_migemo(char) "{{{
|
||||
endif
|
||||
|
||||
" TODO: use direction
|
||||
if s:line_flag == 1
|
||||
if s:flag.within_line == 1
|
||||
let first_line = line('.')
|
||||
let end_line = line('.')
|
||||
else
|
||||
@ -1008,9 +1022,9 @@ function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
|
||||
" -- Repeat EasyMotion ------------------- {{{
|
||||
if a:allows_repeat &&
|
||||
\ char == '.' &&
|
||||
\ exists('s:old_target_coord')
|
||||
\ exists('s:previous_target_coord')
|
||||
" For SelectLines
|
||||
return s:old_target_coord
|
||||
return s:previous_target_coord
|
||||
endif "}}}
|
||||
" -- Check if the input char is valid ---- {{{
|
||||
if ! has_key(a:groups, char)
|
||||
@ -1028,7 +1042,7 @@ function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
|
||||
return s:PromptUser(target, a:allows_repeat, a:fixed_column)
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
function! s:EasyMotion(regexp, direction, visualmode, is_exclusive, ...) " {{{
|
||||
" For Special Function {{{
|
||||
" For SelectLines(), to highlight previous selected line
|
||||
let hlcurrent = a:0 >= 1 ? a:1 : 0
|
||||
@ -1050,9 +1064,9 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
let targets = []
|
||||
|
||||
" Store Regular Expression
|
||||
let s:old['regexp'] = a:regexp
|
||||
let s:old['direction'] = a:direction
|
||||
let s:old['line_flag'] = s:line_flag == 1 ? 1 : 0
|
||||
let s:previous['regexp'] = a:regexp
|
||||
let s:previous['direction'] = a:direction
|
||||
let s:previous['line_flag'] = s:flag.within_line == 1 ? 1 : 0
|
||||
|
||||
try
|
||||
" -- Reset properties -------------------- {{{
|
||||
@ -1065,7 +1079,7 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
let search_stopline = a:direction >= 1 ? win_first_line : win_last_line
|
||||
let search_at_cursor = fixed_column ? 'c' : ''
|
||||
|
||||
if s:line_flag == 1
|
||||
if s:flag.within_line == 1
|
||||
let search_stopline = orig_pos[0]
|
||||
endif
|
||||
"}}}
|
||||
@ -1130,7 +1144,7 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
endif
|
||||
|
||||
let targets2 = []
|
||||
if s:line_flag == 0
|
||||
if s:flag.within_line == 0
|
||||
let search_stopline = win_last_line
|
||||
else
|
||||
let search_stopline = !empty(a:visualmode) ? c_pos[0] : orig_pos[0]
|
||||
@ -1211,17 +1225,19 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Jump back before prompt{{{
|
||||
" -- Jump back before prompt for visual scroll {{{
|
||||
" Because searchpos() change current cursor position and
|
||||
" if you just use cursor([orig_num, orig_pos]) to jump back,
|
||||
" current line will bebecome center of window
|
||||
keepjumps call cursor(win_first_line,0)
|
||||
normal! zt
|
||||
if ! empty(a:visualmode)
|
||||
keepjumps call cursor(win_first_line,0)
|
||||
normal! zt
|
||||
endif
|
||||
"}}}
|
||||
|
||||
" -- Prompt user for target group/character {{{
|
||||
let coords = s:PromptUser(groups, allows_repeat, fixed_column)
|
||||
let s:old_target_coord = coords
|
||||
let s:previous_target_coord = coords
|
||||
"}}}
|
||||
|
||||
" -- Update selection -------------------- {{{
|
||||
@ -1234,15 +1250,18 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
" -- Update cursor position -------------- {{{
|
||||
call cursor(orig_pos[0], orig_pos[1])
|
||||
" Handle operator-pending mode {{{
|
||||
if a:mode == 'no'
|
||||
if a:is_exclusive == 1
|
||||
" This mode requires that we eat one more
|
||||
" character to the right if we're using
|
||||
" a forward motion
|
||||
normal! v
|
||||
endif
|
||||
" }}}
|
||||
call cursor(win_first_line, 0)
|
||||
normal! zt
|
||||
" Adjuast screen for visual scroll {{{
|
||||
if ! empty(a:visualmode)
|
||||
keepjumps call cursor(win_first_line, 0)
|
||||
normal! zt
|
||||
endif "}}}
|
||||
keepjumps call cursor(coords[0], coords[1])
|
||||
|
||||
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
|
||||
|
Loading…
x
Reference in New Issue
Block a user