Merge branch 'feature/repeat_and_enter' into master

This commit is contained in:
haya14busa 2014-01-10 17:16:45 +09:00
commit d3bbdd90cc
3 changed files with 189 additions and 78 deletions

View File

@ -7,13 +7,43 @@
let s:save_cpo = &cpo
set cpo&vim
" }}}
" == Reset {{{
function! EasyMotion#reset()
" Reset Migemo Dictionary
" == Init {{{
function! EasyMotion#init()
" Init Migemo Dictionary
let s:migemo_dicts = {}
let s:line_flag = 0
" Anywhere regular expression: {{{
let re = '\v' .
\ '(<.|^$)' . '|' .
\ '(.>|^$)' . '|' .
\ '(\l)\zs(\u)' . '|' .
\ '(_\zs.)' . '|' .
\ '(#\zs.)'
" 1. word
" 2. end of word
" 3. CamelCase
" 4. after '_' hoge_foo
" 5. after '#' hoge#foo
let g:EasyMotion_re_anywhere = get(g:, 'EasyMotion_re_anywhere', re)
" Anywhere regular expression within line:
let re = '\v' .
\ '(<.|^$)' . '|' .
\ '(.>|^$)' . '|' .
\ '(\l)\zs(\u)' . '|' .
\ '(_\zs.)' . '|' .
\ '(#\zs.)'
let g:EasyMotion_re_line_anywhere = get(g:, 'EasyMotion_re_line_anywhere', re)
"}}}
return ""
endfunction "}}}
" == Reset {{{
function! EasyMotion#reset()
let s:line_flag = 0
return ""
endfunction "}}}
" == Motion functions {{{
" -- Find Motion -------------------------
function! EasyMotion#F(visualmode, direction) " {{{
@ -88,23 +118,6 @@ function! EasyMotion#Search(visualmode, direction) " {{{
endfunction " }}}
" -- JumpToAnywhere Motion ---------------
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
if !exists('g:EasyMotion_re_anywhere')
" Anywhere regular expression: {{{
let re = '\v' .
\ '(<.|^$)' . '|' .
\ '(.>|^$)' . '|' .
\ '(\l)\zs(\u)' . '|' .
\ '(_\zs.)' . '|' .
\ '(#\zs.)'
" 1. word
" 2. end of word
" 3. CamelCase
" 4. after '_' hoge_foo
" 5. after '#' hoge#foo
"}}}
let g:EasyMotion_re_anywhere = get(g:, 'EasyMotion_re_anywhere', re)
endif
"
call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', '')
endfunction " }}}
" -- Line Motion -------------------------
@ -119,53 +132,52 @@ function! EasyMotion#SL(visualmode, direction) " {{{
if a:visualmode
call s:before_visual()
endif
let re = '\%' . line('.') . 'l' . re
let s:line_flag = 1
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
endfunction " }}}
function! EasyMotion#TL(visualmode, direction) " {{{
let char = s:GetSearchChar(a:visualmode)
if empty(char)
return
endif
let re = s:findMotion(char)
if a:direction == 1
" backward
let re = re . '\zs.'
else
" forward
let re = '.\ze' . re
endif
if a:visualmode
call s:before_visual()
endif
let s:line_flag = 1
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
endfunction " }}}
function! EasyMotion#WBL(visualmode, direction) " {{{
if a:visualmode
call s:before_visual()
endif
call s:EasyMotion('\%'.line('.').'l'.'\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
let s:line_flag = 1
" call s:EasyMotion('\%'.line('.').'l'.'\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
endfunction " }}}
function! EasyMotion#EL(visualmode, direction) " {{{
if a:visualmode
call s:before_visual()
endif
call s:EasyMotion('\%'.line('.').'l'.'\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
let s:line_flag = 1
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
endfunction " }}}
function! EasyMotion#LineAnywhere(visualmode, direction) " {{{
if ! exists('s:re_line_flag') "{{{
" Load once!
" Anywhere regular expression:
let re = '\v' .
\ '(<.|^$)' . '|' .
\ '(.>|^$)' . '|' .
\ '(\l)\zs(\u)' . '|' .
\ '(_\zs.)' . '|' .
\ '(#\zs.)'
let re_lineanywhere = get(g:, 'EasyMotion_re_line_anywhere', re)
if match(re_lineanywhere, '\\v') < 0
let s:re_line_flag = '\%'
let bracket_before = '\('
let bracket_after = '\)'
else
let re_lineanywhere = substitute(re_lineanywhere,'\\v','','')
let s:re_line_flag = '\v%'
let bracket_before = '('
let bracket_after = ')'
endif
let s:re_line_after = 'l' . bracket_before . re_lineanywhere . bracket_after
endif "}}}
if a:visualmode
call s:before_visual()
endif
let re = s:re_line_flag . line('.') . s:re_line_after
let s:line_flag = 1
let re = g:EasyMotion_re_line_anywhere
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', '')
endfunction " }}}
" -- Special Motion ----------------------
@ -290,6 +302,19 @@ function! EasyMotion#UserMapping(re, mapping, direction) " {{{
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>"
endfunction " }}}
" -- Repeat Motion -----------------------
function! EasyMotion#Repeat(visualmode, direction) " {{{
" Repeat previous motion with previous targets
if ! exists('s:old')
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
call s:EasyMotion(re, direction, a:visualmode ? visualmode() : '', mode(1))
endfunction " }}}
" }}}
" == Helper functions {{{
@ -865,6 +890,9 @@ function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
if g:EasyMotion_use_upper == 1 && match(g:EasyMotion_keys, '\l') == -1
let char = toupper(char)
endif
if char ==# ' ' && g:EasyMotion_enter_jump_first == 1
let char = g:EasyMotion_keys[0]
endif
" }}}
finally
" Restore original lines
@ -906,8 +934,11 @@ function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
endif
" }}}
" -- Repeat EasyMotion ------------------- {{{
if a:allows_repeat && char == '.'
return g:EasyMotion_old_target
if a:allows_repeat &&
\ char == '.' &&
\ exists('s:old_target_coord')
" For SelectLines
return s:old_target_coord
endif "}}}
" -- Check if the input char is valid ---- {{{
if ! has_key(a:groups, char)
@ -940,6 +971,18 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
let orig_pos = [line('.'), col('.')]
let targets = []
" Store Regular Expression
let s:old = {
\ 'regexp': a:regexp,
\ 'direction': a:direction,
\ }
if s:line_flag == 1
let s:old['line_flag'] = 1
else
let s:old['line_flag'] = 0
endif
try
" -- Reset properties -------------------- {{{
" Save original value and set new value
@ -950,6 +993,10 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
let search_direction = (a:direction >= 1 ? 'b' : '')
let search_stopline = line(a:direction >= 1 ? 'w0' : 'w$')
let search_at_cursor = fixed_column ? 'c' : ''
if s:line_flag == 1
let search_stopline = line('.')
endif
"}}}
" Handle visual mode {{{
@ -1005,8 +1052,13 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
keepjumps call cursor(orig_pos[0], orig_pos[1])
endif
let targets2 = []
if s:line_flag == 0
let search_stopline = line('w$')
else
let search_stopline = line('.')
endif
while 1
let pos = searchpos(a:regexp, '', line('w$'))
let pos = searchpos(a:regexp, '', search_stopline)
" Reached end of search range
if pos == [0, 0]
break
@ -1021,31 +1073,30 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
call add(targets2, pos)
endwhile
" Merge match target dict"{{{
let t1 = 0
let t2 = 0
let t1 = 0 " backward
let t2 = 0 " forward
let targets3 = []
while t1 < len(targets) || t2 < len(targets2)
if t1 < len(targets)
call add(targets3, targets[t1])
let t1 += 1
endif
" Forward -> Backward -> F -> B -> ...
if t2 < len(targets2)
call add(targets3, targets2[t2])
let t2 += 1
endif
if t1 < len(targets)
call add(targets3, targets[t1])
let t1 += 1
endif
endwhile
let targets = targets3
"}}}
endif
"}}}
" Handle no match"{{{
let targets_len = len(targets)
if targets_len == 0
throw 'No matches'
endif
"}}}
" }}}
let GroupingFn = function('s:GroupingAlgorithm' . s:grouping_algorithms[g:EasyMotion_grouping])
let groups = GroupingFn(targets, split(g:EasyMotion_keys, '\zs'))
@ -1078,7 +1129,7 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
" -- Prompt user for target group/character {{{
let coords = s:PromptUser(groups, allows_repeat, fixed_column)
let g:EasyMotion_old_target = coords
let s:old_target_coord = coords
"}}}
" -- Update selection -------------------- {{{
@ -1127,7 +1178,8 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
let s:EasyMotion_cancelled = 1
finally
" -- Restore properties ------------------ {{{
call s:RestoreValue()
call s:RestoreValue()
call EasyMotion#reset()
" }}}
" -- Remove shading ---------------------- {{{
if g:EasyMotion_do_shade && exists('shade_hl_id') && (!fixed_column)
@ -1140,9 +1192,9 @@ function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
endtry
endfunction " }}}
"}}}
" == Call Reset {{{
call EasyMotion#reset()
"}}}
" == Call init {{{
call EasyMotion#init()
"}}}
" == Restore 'cpoptions' {{{
let &cpo = s:save_cpo

View File

@ -1,4 +1,4 @@
*easymotion.txt* Version 2.0 Last change:23 Dec 2013.
*easymotion.txt* Version 2.0 Last change:10 Jan 2014.
______ __ ___ __ _
@ -29,13 +29,14 @@ CONTENTS *easymotion-contents*
4.7 EasyMotion_smartsign ........... |EasyMotion_smartsign|
4.8 EasyMotion_use_migemo .......... |EasyMotion_use_migemo|
4.9 EasyMotion_use_upper .......... |EasyMotion_use_upper|
4.10 Custom highlighting ............ |easymotion-custom-hl|
4.11 Custom mappings ................ |easymotion-custom-mappings|
4.11.1 Leader key ............... |easymotion-leader-key|
4.11.2 Custom keys .............. |easymotion-custom-keys|
4.12 Easymotion special functions ... |easymotion-special-mappings|
4.12.1 Select Line .............. |easymotion-select-line|
4.12.2 Select Phrase ............ |easymotion-select-phrase|
4.10 Custom highlighting ........... |easymotion-custom-hl|
4.11 Custom mappings ............... |easymotion-custom-mappings|
4.11.1 Leader key .............. |easymotion-leader-key|
4.11.2 Custom keys ............. |easymotion-custom-keys|
4.12 Easymotion special functions .. |easymotion-special-mappings|
4.12.1 Select Line ............. |easymotion-select-line|
4.12.2 Select Phrase ........... |easymotion-select-phrase|
4.13 EasyMotion_enter_jump_first ... |EasyMotion_enter_jump_first|
5. License ............................ |easymotion-license|
6. Known bugs ......................... |easymotion-known-bugs|
7. Contributing ....................... |easymotion-contributing|
@ -150,9 +151,15 @@ EasyMotion <Plug> table *easymotion-plug-table*
<Plug>(easymotion-bd-jk) | See |<Plug>(easymotion-bd-jk)|
<Plug>(easymotion-bd-n) | See |<Plug>(easymotion-bd-n)|
<Plug>(easymotion-jumptoanywhere) | See |<Plug>(easymotion-jumptoanywhere)|
<Plug>(easymotion-repeat) | See |<Plug>(easymotion-repeat)|
|
Within Line Motion |
----------------------------------|---------------------------------
<Plug>(easymotion-sl) | See |<Plug>(easymotion-sl)|
<Plug>(easymotion-fl) | See |<Plug>(easymotion-fl)|
<Plug>(easymotion-Fl) | See |<Plug>(easymotion-Fl)|
<Plug>(easymotion-tl) | See |<Plug>(easymotion-tl)|
<Plug>(easymotion-Tl) | See |<Plug>(easymotion-Tl)|
<Plug>(easymotion-wl) | See |<Plug>(easymotion-wl)|
<Plug>(easymotion-bl) | See |<Plug>(easymotion-bl)|
<Plug>(easymotion-bd-wl) | See |<Plug>(easymotion-bd-wl)|
@ -174,6 +181,8 @@ EasyMotion <Plug> table *easymotion-plug-table*
These mappings are not mapped by Default.
Bidirection ~
<Plug>(easymotion-bd-w) *<Plug>(easymotion-bd-w)*
Beginning of word forward and backward. See |w| & |b|.
Note: bd is short for bidirectional
@ -193,6 +202,8 @@ These mappings are not mapped by Default.
<Plug>(easymotion-bd-n) *<Plug>(easymotion-bd-n)*
Jump to latest "/" or "?" forward. See |n| & |N|.
Jump To Anywhere ~
<Plug>(easymotion-jumptoanywhere) *<Plug>(easymotion-jumptoanywhere)*
JumpToAnywhere motion!
Default: Beginning and End of word, Camelcase, after '_',
@ -215,12 +226,38 @@ These mappings are not mapped by Default.
\ '(<.|.$)' . '|' .
\ '(\l)\zs(\u)' . '|' .
<
Within line motion *easymotion-within-line*
Repeat ~
<Plug>(easymotion-repeat) *<Plug>(easymotion-repeat)*
Repeat last motion!
Repeat last motion type including input target character.
Nothing will happen when previous motion doesn't exist.
Within line motion ~
*easymotion-within-line*
<Plug>(easymotion-sl) *<Plug>(easymotion-sl)*
This function is same as |<Plug>(easymoion-s)|, except range
is within current cursor line.
<Plug>(easymotion-fl) *<Plug>(easymotion-fl)*
This function is same as |<Plug>(easymoion-f)|, except range
is within current cursor line.
<Plug>(easymotion-Fl) *<Plug>(easymotion-Fl)*
This function is same as |<Plug>(easymoion-F)|, except range
is within current cursor line.
<Plug>(easymotion-tl) *<Plug>(easymotion-tl)*
This function is same as |<Plug>(easymoion-t)|, except range
is within current cursor line.
<Plug>(easymotion-Tl) *<Plug>(easymotion-Tl)*
This function is same as |<Plug>(easymoion-T)|, except range
is within current cursor line.
<Plug>(easymotion-wl) *<Plug>(easymotion-wl)*
This function is same as |<Plug>(easymoion-w)|, except range
is within current cursor line.
@ -677,6 +714,21 @@ or map it by yourself(Recommend)
Note: special phrase function when d & y is a little bit different. So you
should map them individually, don't define omap only.
------------------------------------------------------------------------------
4.13 Jump to first match by Enter *EasyMotion_enter_jump_first*
*g:EasyMotion_enter_jump_first*
Type Enter key and jump to first match (first letter of |g:EasyMotion_keys| ).
Set this option to 1 if you want to enable this feature.
Example:
>
let g:EasyMotion_enter_jump_first = 1
<
Default: 0
==============================================================================
5. License *easymotion-license*

View File

@ -28,6 +28,7 @@ set cpo&vim
\ , 'skipfoldedline' : 1
\ , 'use_migemo' : 0
\ , 'use_upper' : 0
\ , 'enter_jump_first' : 0
\
\ , 'hl_group_target' : 'EasyMotionTarget'
\ , 'hl2_first_group_target' : 'EasyMotionTarget2First'
@ -130,12 +131,18 @@ set cpo&vim
\ , 'lineanywhere' : { 'name': 'LineAnywhere' , 'dir': 2 }
\
\ , 'sl' : { 'name': 'SL' , 'dir': 2 }
\ , 'fl' : { 'name': 'SL' , 'dir': 0 }
\ , 'Fl' : { 'name': 'SL' , 'dir': 1 }
\ , 'tl' : { 'name': 'TL' , 'dir': 0 }
\ , 'Tl' : { 'name': 'TL' , 'dir': 1 }
\ , 'wl' : { 'name': 'WBL' , 'dir': 0 }
\ , 'bl' : { 'name': 'WBL' , 'dir': 1 }
\ , 'bd-wl' : { 'name': 'WBL' , 'dir': 2 }
\ , 'el' : { 'name': 'EL' , 'dir': 0 }
\ , 'gel' : { 'name': 'EL' , 'dir': 1 }
\ , 'bd-el' : { 'name': 'EL' , 'dir': 2 }
\
\ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 }
\ }, 0) " Prepare <Plug> but don't map by default.
" }}}
" }}}