auto commit

This commit is contained in:
Supasorn Suwajanakorn 2013-05-15 14:05:02 -07:00
parent 27a8f3ddb4
commit 008e81e523
2 changed files with 87 additions and 46 deletions

View File

@ -70,6 +70,19 @@
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#S(visualmode, direction) " {{{
let char = s:GetSearchChar(a:visualmode)
if empty(char)
return
endif
let re = '\C' . escape(char, '.$^~')
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
endfunction " }}}
function! EasyMotion#T(visualmode, direction) " {{{ function! EasyMotion#T(visualmode, direction) " {{{
let char = s:GetSearchChar(a:visualmode) let char = s:GetSearchChar(a:visualmode)
@ -360,8 +373,8 @@
let lines = {} let lines = {}
let lines_marks = {} let lines_marks = {}
let hl_coords = [] let hl_coords = []
let hl_coords2 = [] " Highlight for two characters let hl2_first_coords = [] " Highlight for two characters
let overlap_coords = [] " Highlight for two characters let hl2_second_coords = [] " Highlight for two characters
let coord_key_dict = s:CreateCoordKeyDict(a:groups) let coord_key_dict = s:CreateCoordKeyDict(a:groups)
@ -398,8 +411,12 @@
" Substitute marker character if line length > 0 " Substitute marker character if line length > 0
let c = 0 let c = 0
while c < target_key_len while c < target_key_len && c < 2
let lines[line_num]['marker'] = substitute(lines[line_num]['marker'], '\%' . (col_num + c) . 'c.', strpart(target_key, c, 1), '') if strlen(lines[line_num]['marker']) >= col_num + c
let lines[line_num]['marker'] = substitute(lines[line_num]['marker'], '\%' . (col_num + c) . 'c.', strpart(target_key, c, 1), '')
else
let lines[line_num]['marker'] = lines[line_num]['marker'] . strpart(target_key, c, 1)
endif
let c += 1 let c += 1
endwhile endwhile
else else
@ -409,26 +426,13 @@
" Add highlighting coordinates " Add highlighting coordinates
if target_key_len == 1 if target_key_len == 1
if has_key(lines_marks[line_num], col_num) call add(hl_coords, '\%' . line_num . 'l\%' . col_num . 'c')
call add(overlap_coords, '\%' . line_num . 'l\%' . col_num . 'c')
else
call add(hl_coords, '\%' . line_num . 'l\%' . col_num . 'c')
endif
let lines_marks[line_num][col_num] = 1 let lines_marks[line_num][col_num] = 1
else else
let c = 0 call add(hl2_first_coords, '\%' . line_num . 'l\%' . (col_num) . 'c')
call add(hl2_second_coords, '\%' . line_num . 'l\%' . (col_num + 1) . 'c')
while c < target_key_len let lines_marks[line_num][col_num] = 1
if has_key(lines_marks[line_num], col_num + c) let lines_marks[line_num][col_num + 1] = 1
call add(overlap_coords, '\%' . line_num . 'l\%' . (col_num + c) . 'c')
else
call add(hl_coords2, '\%' . line_num . 'l\%' . (col_num + c) . 'c')
endif
let lines_marks[line_num][col_num + c] = 1
let c += 1
endwhile
endif endif
" Add marker/target lenght difference for multibyte " Add marker/target lenght difference for multibyte
@ -440,16 +444,17 @@
let lines_items = items(lines) let lines_items = items(lines)
" }}} " }}}
" Highlight targets {{{ " Highlight targets {{{
let target_hl_id = matchadd(g:EasyMotion_hl_group_target, join(hl_coords, '\|'), 1) if len(hl_coords) > 0
if len(hl_coords2) > 0 let target_hl_id = matchadd(g:EasyMotion_hl_group_target, join(hl_coords, '\|'), 1)
let target_hl2_id = matchadd(g:EasyMotion_hl2_group_target, join(hl_coords2, '\|'), 1)
endif endif
if len(overlap_coords) > 0 if len(hl2_second_coords) > 0
let target_overlap_id = matchadd(g:EasyMotion_hl_group_overlap, join(overlap_coords, '\|'), 1) let target_hl2_second_id = matchadd(g:EasyMotion_hl2_second_group_target, join(hl2_second_coords, '\|'), 1)
endif
if len(hl2_first_coords) > 0
let target_hl2_first_id = matchadd(g:EasyMotion_hl2_first_group_target, join(hl2_first_coords, '\|'), 1)
endif endif
" }}} " }}}
try try
" Set lines with markers " Set lines with markers
call s:SetLines(lines_items, 'marker') call s:SetLines(lines_items, 'marker')
@ -469,11 +474,11 @@
if exists('target_hl_id') if exists('target_hl_id')
call matchdelete(target_hl_id) call matchdelete(target_hl_id)
endif endif
if exists('target_hl2_id') if exists('target_hl2_first_id')
call matchdelete(target_hl2_id) call matchdelete(target_hl2_first_id)
endif endif
if exists('target_overlap_id') if exists('target_hl2_second_id')
call matchdelete(target_overlap_id) call matchdelete(target_hl2_second_id)
endif endif
" }}} " }}}
@ -515,8 +520,8 @@
call s:VarReset('&virtualedit', '') call s:VarReset('&virtualedit', '')
" }}} " }}}
" Find motion targets {{{ " Find motion targets {{{
let search_direction = (a:direction == 1 ? 'b' : '') let search_direction = (a:direction >= 1 ? 'b' : '')
let search_stopline = line(a:direction == 1 ? 'w0' : 'w$') let search_stopline = line(a:direction >= 1 ? 'w0' : 'w$')
while 1 while 1
let pos = searchpos(a:regexp, search_direction, search_stopline) let pos = searchpos(a:regexp, search_direction, search_stopline)
@ -534,6 +539,38 @@
call add(targets, pos) call add(targets, pos)
endwhile endwhile
if a:direction == 2
keepjumps call cursor(orig_pos[0], orig_pos[1])
let targets2 = []
while 1
let pos = searchpos(a:regexp, '', line('w$'))
if pos == [0, 0]
break
endif
if foldclosed(pos[0]) != -1
continue
endif
call add(targets2, pos)
endwhile
let t1 = 0
let t2 = 0
let targets3 = []
while t1 < len(targets) || t2 < len(targets2)
if t1 < len(targets)
call add(targets3, targets[t1])
let t1 += 1
endif
if t2 < len(targets2)
call add(targets3, targets2[t2])
let t2 += 1
endif
endwhile
let targets = targets3
endif
let targets_len = len(targets) let targets_len = len(targets)
if targets_len == 0 if targets_len == 0
throw 'No matches' throw 'No matches'
@ -550,9 +587,12 @@
if a:direction == 1 if a:direction == 1
" Backward " Backward
let shade_hl_re = '\%'. line('w0') .'l\_.*' . shade_hl_pos let shade_hl_re = '\%'. line('w0') .'l\_.*' . shade_hl_pos
else elseif a:direction == 0
" Forward " Forward
let shade_hl_re = shade_hl_pos . '\_.*\%'. line('w$') .'l' let shade_hl_re = shade_hl_pos . '\_.*\%'. line('w$') .'l'
elseif a:direction == 2
" Both directions"
let shade_hl_re = '\%'. line('w0') .'l\_.*\%'. line('w$') .'l'
endif endif
let shade_hl_id = matchadd(g:EasyMotion_hl_group_shade, shade_hl_re, 0) let shade_hl_id = matchadd(g:EasyMotion_hl_group_shade, shade_hl_re, 0)

View File

@ -19,10 +19,10 @@
\ , 'do_mapping' : 1 \ , 'do_mapping' : 1
\ , 'grouping' : 1 \ , 'grouping' : 1
\ \
\ , 'hl_group_target' : 'EasyMotionTarget' \ , 'hl_group_target' : 'EasyMotionTarget'
\ , 'hl2_group_target' : 'EasyMotionTarget2' \ , 'hl2_first_group_target' : 'EasyMotionTarget2First'
\ , 'hl_group_overlap' : 'EasyMotionOverlap' \ , 'hl2_second_group_target' : 'EasyMotionTarget2Second'
\ , 'hl_group_shade' : 'EasyMotionShade' \ , 'hl_group_shade' : 'EasyMotionShade'
\ }) \ })
" }}} " }}}
" Default highlighting {{{ " Default highlighting {{{
@ -32,14 +32,14 @@
\ , 'cterm' : ['NONE', 'red' , 'bold'] \ , 'cterm' : ['NONE', 'red' , 'bold']
\ } \ }
let s:target_hl2_defaults = { let s:target_hl2_first_defaults = {
\ 'gui' : ['NONE', '#ffb400' , 'bold'] \ 'gui' : ['NONE', '#ffb400' , 'bold']
\ , 'cterm256': ['NONE', '196' , 'bold'] \ , 'cterm256': ['NONE', '196' , 'bold']
\ , 'cterm' : ['NONE', 'red' , 'bold'] \ , 'cterm' : ['NONE', 'red' , 'bold']
\ } \ }
let s:target_hl_overlap_defaults = { let s:target_hl2_second_defaults = {
\ 'gui' : ['NONE', '#ff0000' , 'bold'] \ 'gui' : ['NONE', '#b98300' , 'bold']
\ , 'cterm256': ['NONE', '196' , 'bold'] \ , 'cterm256': ['NONE', '196' , 'bold']
\ , 'cterm' : ['NONE', 'red' , 'bold'] \ , 'cterm' : ['NONE', 'red' , 'bold']
\ } \ }
@ -52,8 +52,8 @@
\ } \ }
call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults) call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults)
call EasyMotion#InitHL(g:EasyMotion_hl2_group_target, s:target_hl2_defaults) call EasyMotion#InitHL(g:EasyMotion_hl2_first_group_target, s:target_hl2_first_defaults)
call EasyMotion#InitHL(g:EasyMotion_hl_group_overlap, s:target_hl_overlap_defaults) call EasyMotion#InitHL(g:EasyMotion_hl2_second_group_target, s:target_hl2_second_defaults)
call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults) call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults)
" Reset highlighting after loading a new color scheme {{{ " Reset highlighting after loading a new color scheme {{{
@ -61,8 +61,8 @@
autocmd! autocmd!
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults) autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults)
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl2_group_target, s:target_hl2_defaults) autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl2_first_group_target, s:target_hl2_first_defaults)
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_overlap, s:target_hl_overlap_defaults) autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl2_second_group_target, s:target_hl2_second_defaults)
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults) autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults)
augroup end augroup end
" }}} " }}}
@ -71,6 +71,7 @@
call EasyMotion#InitMappings({ call EasyMotion#InitMappings({
\ 'f' : { 'name': 'F' , 'dir': 0 } \ 'f' : { 'name': 'F' , 'dir': 0 }
\ , 'F' : { 'name': 'F' , 'dir': 1 } \ , 'F' : { 'name': 'F' , 'dir': 1 }
\ , 's' : { 'name': 'S' , 'dir': 2 }
\ , 't' : { 'name': 'T' , 'dir': 0 } \ , 't' : { 'name': 'T' , 'dir': 0 }
\ , 'T' : { 'name': 'T' , 'dir': 1 } \ , 'T' : { 'name': 'T' , 'dir': 1 }
\ , 'w' : { 'name': 'WB' , 'dir': 0 } \ , 'w' : { 'name': 'WB' , 'dir': 0 }