diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index fa10e57..92520c6 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -3,7 +3,7 @@ " Author: Kim Silkebækken " haya14busa " Source: https://github.com/Lokaltog/vim-easymotion -" Last Change: 13 Feb 2014. +" Last Change: 15 Feb 2014. "============================================================================= " Saving 'cpoptions' {{{ scriptencoding utf-8 @@ -364,34 +364,21 @@ function! s:RestoreValue() "{{{ call s:VarReset('&virtualedit') call s:VarReset('&foldmethod') endfunction "}}} -function! s:turn_on_hl_error() "{{{ - if exists("s:old_hl_error") - execute "highlight Error " . s:old_hl_error - unlet s:old_hl_error - endif -endfunction "}}} function! s:turn_off_hl_error() "{{{ - if exists("s:old_hl_error") - return s:old_hl_error + let s:error_hl = EasyMotion#highlight#capture('Error') + call EasyMotion#highlight#turn_off(s:error_hl) + let s:matchparen_hl = EasyMotion#highlight#capture('MatchParen') + call EasyMotion#highlight#turn_off(s:matchparen_hl) +endfunction "}}} +function! s:turn_on_hl_error() "{{{ + if exists('s:error_hl') + call EasyMotion#highlight#turn_on(s:error_hl) + unlet s:error_hl endif - if hlexists("Error") - let save_verbose = &verbose - let &verbose = 0 - try - redir => error - silent highlight Error - redir END - finally - let &verbose = save_verbose - endtry - " NOTE: do not match across newlines, to remove 'links to Foo' - " (https://github.com/Lokaltog/vim-easymotion/issues/95) - let hl = substitute(matchstr(error, 'xxx \zs[^\n]*'), '[ \t\n]\+\|cleared', ' ', 'g') - if !empty(substitute(hl, '\s', '', 'g')) - let s:old_hl_error = hl - endif - highlight Error NONE - return s:old_hl_error + + if exists('s:matchparen_hl') + call EasyMotion#highlight#turn_on(s:matchparen_hl) + unlet s:matchparen_hl endif endfunction "}}} " -- Draw -------------------------------- diff --git a/autoload/EasyMotion/highlight.vim b/autoload/EasyMotion/highlight.vim index d1c774d..f6327f1 100644 --- a/autoload/EasyMotion/highlight.vim +++ b/autoload/EasyMotion/highlight.vim @@ -193,7 +193,50 @@ function! EasyMotion#highlight#add_color_group(new_groups) "{{{ endfor endfunction "}}} - +function! EasyMotion#highlight#capture(hlname) "{{{ + " Based On: https://github.com/t9md/vim-ezbar + " https://github.com/osyo-manga/vital-over + let hlname = a:hlname + if !hlexists(hlname) + return + endif + while 1 + let save_verbose = &verbose + let &verbose = 0 + try + redir => HL_SAVE + execute 'silent! highlight ' . hlname + redir END + finally + let &verbose = save_verbose + endtry + if !empty(matchstr(HL_SAVE, 'xxx cleared$')) + return '' + endif + " follow highlight link + let ml = matchlist(HL_SAVE, 'links to \zs.*') + if !empty(ml) + let hlname = ml[0] + continue + endif + break + endwhile + let HL_SAVE = substitute(matchstr(HL_SAVE, 'xxx \zs.*'), + \ '[ \t\n]\+', ' ', 'g') + return [hlname, HL_SAVE] +endfunction "}}} +function! EasyMotion#highlight#turn_off(hl) "{{{ + if type(a:hl) != type([]) + return + endif + execute 'highlight ' . a:hl[0] . ' NONE' +endfunction "}}} +function! EasyMotion#highlight#turn_on(hl) "{{{ + if type(a:hl) != type([]) + return + endif + execute 'highlight ' . a:hl[0] . ' ' . a:hl[1] +endfunction "}}} " Restore 'cpoptions' {{{ let &cpo = s:save_cpo