Refactoring Find motion!
This commit is contained in:
parent
6cb60225bf
commit
fe8d8448cf
@ -14,29 +14,15 @@ function! EasyMotion#reset()
|
|||||||
return ""
|
return ""
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
" Motion functions {{{
|
" Motion functions {{{
|
||||||
|
" == Find Motion =========================
|
||||||
function! EasyMotion#F(visualmode, direction) " {{{
|
function! EasyMotion#F(visualmode, direction) " {{{
|
||||||
let char = s:GetSearchChar(a:visualmode)
|
let char = s:GetSearchChar(a:visualmode)
|
||||||
|
|
||||||
let re = escape(char, '.$^~')
|
|
||||||
|
|
||||||
if g:EasyMotion_use_migemo
|
|
||||||
if ! has_key(s:migemo_dicts, &l:encoding)
|
|
||||||
let s:migemo_dicts[&l:encoding] = s:load_migemo_dict()
|
|
||||||
endif
|
|
||||||
if re =~# '^\a$'
|
|
||||||
let re = s:migemo_dicts[&l:encoding][re]
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if empty(char)
|
if empty(char)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if g:EasyMotion_smartcase && char =~# '\v\U'
|
let re = s:findMotion(char)
|
||||||
let re = '\c' . re
|
|
||||||
else
|
|
||||||
let re = '\C' . re
|
|
||||||
endif
|
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@ -47,22 +33,7 @@ endfunction "}}}
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let re = escape(char, '.$^~')
|
let re = s:findMotion(char)
|
||||||
|
|
||||||
if g:EasyMotion_use_migemo
|
|
||||||
if ! has_key(s:migemo_dicts, &l:encoding)
|
|
||||||
let s:migemo_dicts[&l:encoding] = s:load_migemo_dict()
|
|
||||||
endif
|
|
||||||
if re =~# '^\a$'
|
|
||||||
let re = s:migemo_dicts[&l:encoding][re]
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if g:EasyMotion_smartcase && char =~# '\v\U'
|
|
||||||
let re = '\c' . re
|
|
||||||
else
|
|
||||||
let re = '\C' . re
|
|
||||||
endif
|
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@ -73,16 +44,7 @@ endfunction "}}}
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let re = escape(char, '.$^~')
|
let re = s:findMotion(char)
|
||||||
|
|
||||||
if g:EasyMotion_use_migemo
|
|
||||||
if ! has_key(s:migemo_dicts, &l:encoding)
|
|
||||||
let s:migemo_dicts[&l:encoding] = s:load_migemo_dict()
|
|
||||||
endif
|
|
||||||
if re =~# '^\a$'
|
|
||||||
let re = s:migemo_dicts[&l:encoding][re]
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if a:direction == 1
|
if a:direction == 1
|
||||||
" backward
|
" backward
|
||||||
@ -92,16 +54,9 @@ endfunction "}}}
|
|||||||
let re = '.\ze' . re
|
let re = '.\ze' . re
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if g:EasyMotion_smartcase && char =~# '\v\U'
|
|
||||||
let re = '\c' . re
|
|
||||||
else
|
|
||||||
let re = '\C' . re
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
" == Word Motion =========================
|
||||||
function! EasyMotion#WB(visualmode, direction) " {{{
|
function! EasyMotion#WB(visualmode, direction) " {{{
|
||||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@ -114,7 +69,7 @@ endfunction "}}}
|
|||||||
function! EasyMotion#EW(visualmode, direction) " {{{
|
function! EasyMotion#EW(visualmode, direction) " {{{
|
||||||
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
" == JK Motion ===========================
|
||||||
function! EasyMotion#JK(visualmode, direction) " {{{
|
function! EasyMotion#JK(visualmode, direction) " {{{
|
||||||
if g:EasyMotion_startofline
|
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() : '', '')
|
||||||
@ -123,10 +78,11 @@ endfunction "}}}
|
|||||||
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||||
endif
|
endif
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
" == Search Motion =======================
|
||||||
function! EasyMotion#Search(visualmode, direction) " {{{
|
function! EasyMotion#Search(visualmode, direction) " {{{
|
||||||
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '')
|
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '')
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
" == JumpToAnywhere Motion ===============
|
||||||
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
|
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
|
||||||
let re = '\v' .
|
let re = '\v' .
|
||||||
\ '(<.|^$)' . '|' .
|
\ '(<.|^$)' . '|' .
|
||||||
@ -256,17 +212,17 @@ endfunction "}}}
|
|||||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
" == User Motion =========================
|
||||||
function! EasyMotion#User(pattern, visualmode, direction) " {{{
|
function! EasyMotion#User(pattern, visualmode, direction) " {{{
|
||||||
let re = escape(a:pattern, '|')
|
let re = escape(a:pattern, '|')
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! EasyMotion#UserMapping(re, mapping, direction) " {{{
|
function! EasyMotion#UserMapping(re, mapping, direction) " {{{
|
||||||
silent exec "nnoremap ".a:mapping." :call EasyMotion#User('".a:re."', 0, ".a:direction.")<CR>"
|
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 "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>"
|
silent exec "vnoremap ".a:mapping." :<C-u>call EasyMotion#User('".a:re."', 0,".a:direction.")<CR>"
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Helper functions {{{
|
" Helper functions {{{
|
||||||
function! s:Message(message) " {{{
|
function! s:Message(message) " {{{
|
||||||
@ -377,6 +333,40 @@ function! s:load_migemo_dict() "{{{
|
|||||||
throw "Error: ".enc." is not supported. Migemo is made disabled."
|
throw "Error: ".enc." is not supported. Migemo is made disabled."
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:findMotion(char) "{{{
|
||||||
|
" Find Motion: S,F,T
|
||||||
|
let re = escape(a:char, '.$^~')
|
||||||
|
|
||||||
|
if g:EasyMotion_use_migemo
|
||||||
|
let re = s:convertMigemo(re)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if g:EasyMotion_smartcase
|
||||||
|
let re = s:convertSmartcase(re, a:char)
|
||||||
|
endif
|
||||||
|
|
||||||
|
return re
|
||||||
|
endfunction "}}}
|
||||||
|
function! s:convertMigemo(re) "{{{
|
||||||
|
let re = a:re
|
||||||
|
if ! has_key(s:migemo_dicts, &l:encoding)
|
||||||
|
let s:migemo_dicts[&l:encoding] = s:load_migemo_dict()
|
||||||
|
endif
|
||||||
|
if re =~# '^\a$'
|
||||||
|
let re = s:migemo_dicts[&l:encoding][re]
|
||||||
|
endif
|
||||||
|
return re
|
||||||
|
endfunction "}}}
|
||||||
|
function! s:convertSmartcase(re, char) "{{{
|
||||||
|
if a:char =~# '\v\U'
|
||||||
|
let re = '\c' . a:re
|
||||||
|
else
|
||||||
|
let re = '\C' . a:re
|
||||||
|
endif
|
||||||
|
return re
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Grouping algorithms {{{
|
" Grouping algorithms {{{
|
||||||
let s:grouping_algorithms = {
|
let s:grouping_algorithms = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user