auto commit

This commit is contained in:
Supasorn Suwajanakorn 2013-05-15 19:32:47 -07:00
parent 008e81e523
commit bbd92e49c8
2 changed files with 48 additions and 11 deletions

View File

@ -59,6 +59,26 @@
endfunction "}}}
" }}}
" Motion functions {{{
function! EasyMotion#LineYank()
let orig_pos = [line('.'), col('.')]
call EasyMotion#JK(0, 2)
if g:EasyMotion_cancelled
return ''
else
let pos1 = [line('.'), col('.')]
keepjumps call cursor(orig_pos[0], orig_pos[1])
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', '', pos1[0])
if g:EasyMotion_cancelled
return ''
else
normal! V
keepjumps call cursor(pos1[0], pos1[1])
normal! y
keepjumps call cursor(orig_pos[0], orig_pos[1])
normal! p
endif
endif
endfunction
function! EasyMotion#F(visualmode, direction) " {{{
let char = s:GetSearchChar(a:visualmode)
@ -68,7 +88,7 @@
let re = '\C' . escape(char, '.$^~')
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1), 0)
endfunction " }}}
function! EasyMotion#S(visualmode, direction) " {{{
@ -80,7 +100,7 @@
let re = '\C' . escape(char, '.$^~')
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1), 0)
endfunction " }}}
function! EasyMotion#T(visualmode, direction) " {{{
@ -96,25 +116,25 @@
let re = '\C.' . escape(char, '.$^~')
endif
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1), 0)
endfunction " }}}
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))
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1), 0)
endfunction " }}}
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), 0)
endfunction " }}}
function! EasyMotion#JK(visualmode, direction) " {{{
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '', 0)
endfunction " }}}
function! EasyMotion#Search(visualmode, direction) " {{{
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '')
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '', 0)
endfunction " }}}
" }}}
" Helper functions {{{
@ -506,7 +526,7 @@
return s:PromptUser(target)
endif
endfunction "}}}
function! s:EasyMotion(regexp, direction, visualmode, mode) " {{{
function! s:EasyMotion(regexp, direction, visualmode, mode, hlcurrent) " {{{
let orig_pos = [line('.'), col('.')]
let targets = []
@ -597,6 +617,9 @@
let shade_hl_id = matchadd(g:EasyMotion_hl_group_shade, shade_hl_re, 0)
endif
if a:hlcurrent != 0
let shade_hl_line_id = matchadd(g:EasyMotion_hl_line_group_shade, '\%'. a:hlcurrent .'l.*', 1)
endif
" }}}
" Prompt user for target group/character
@ -626,6 +649,7 @@
call cursor(coords[0], coords[1])
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
let g:EasyMotion_cancelled = 0
catch
redraw
@ -639,6 +663,7 @@
keepjumps call cursor(orig_pos[0], orig_pos[1])
endif
" }}}
let g:EasyMotion_cancelled = 1
finally
" Restore properties {{{
call s:VarReset('&scrolloff')
@ -652,6 +677,9 @@
if g:EasyMotion_do_shade && exists('shade_hl_id')
call matchdelete(shade_hl_id)
endif
if a:hlcurrent && exists('shade_hl_line_id')
call matchdelete(shade_hl_line_id)
endif
" }}}
endtry
endfunction " }}}

View File

@ -23,6 +23,7 @@
\ , 'hl2_first_group_target' : 'EasyMotionTarget2First'
\ , 'hl2_second_group_target' : 'EasyMotionTarget2Second'
\ , 'hl_group_shade' : 'EasyMotionShade'
\ , 'hl_line_group_shade' : 'EasyMotionShadeLine'
\ })
" }}}
" Default highlighting {{{
@ -44,17 +45,23 @@
\ , 'cterm' : ['NONE', 'red' , 'bold']
\ }
let s:shade_hl_defaults = {
\ 'gui' : ['NONE', '#777777' , 'NONE']
\ , 'cterm256': ['NONE', '242' , 'NONE']
\ , 'cterm' : ['NONE', 'grey' , 'NONE']
\ }
let s:shade_hl_line_defaults = {
\ 'gui' : ['NONE', '#FFFFFF' , 'NONE']
\ , 'cterm256': ['NONE', '242' , 'NONE']
\ , 'cterm' : ['NONE', 'grey' , 'NONE']
\ }
call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults)
call EasyMotion#InitHL(g:EasyMotion_hl2_first_group_target, s:target_hl2_first_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_line_group_shade, s:shade_hl_line_defaults)
" Reset highlighting after loading a new color scheme {{{
augroup EasyMotionInitHL
@ -64,6 +71,7 @@
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl2_first_group_target, s:target_hl2_first_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_line_group_shade, s:shade_hl_line_defaults)
augroup end
" }}}
" }}}
@ -84,6 +92,7 @@
\ , 'gE': { 'name': 'EW' , 'dir': 1 }
\ , 'j' : { 'name': 'JK' , 'dir': 0 }
\ , 'k' : { 'name': 'JK' , 'dir': 1 }
\ , 'l' : { 'name': 'JK' , 'dir': 2 }
\ , 'n' : { 'name': 'Search' , 'dir': 0 }
\ , 'N' : { 'name': 'Search' , 'dir': 1 }
\ })