diff --git a/autoload/highlight.vim b/autoload/highlight.vim index 3e61c1d..7bbdd7e 100644 --- a/autoload/highlight.vim +++ b/autoload/highlight.vim @@ -30,6 +30,44 @@ let s:active_register = "\"" let s:registry = {} +" FUNCTION: ExpandRegister(reg) {{{1 +" ============================================================================== +" Convenience method to determine which register is being currently used. +" The unnamed register defaults to the last used register to avoid having to +" constantly prefix registration. This can be changed by setting the value of +" g:persist_unnamed_register to 1. + +function! highlight#expand_register(reg) + if !g:persist_unnamed_register && a:reg ==# '"' + return s:active_register + endif + return a:reg +endfunction + + +" FUNCTION: ExpandFlag(flag) {{{1 +" ============================================================================== +" Convenience method used to make the mappings in plugin/highlight.vim a bit +" easier to read through. The passed flag can be: +" +" c: Indicates the current word, with word boundary. +" g: Indicates the current word, without word boundary. +" v: Indicates the current visual selection. +" +" Throws an error otherwise. + +function! highlight#expand_flag(flag) abort + if a:flag ==# 'c' + return '\<' . expand('') . '\>' + elseif a:flag ==# 'g' + return expand('') + elseif a:flag ==# 'v' + return highlight#get_visual_selection() + endif + throw 'Could not expand passed flag: ' . a:flag +endfunction + + " FUNCTION: CountPattern(pattern) {{{1 " ============================================================================== " Convenience method used to display the number of times the passed pattern has diff --git a/plugin/hightlight.vim b/plugin/hightlight.vim index 28f84d1..a1b04c7 100644 --- a/plugin/hightlight.vim +++ b/plugin/hightlight.vim @@ -55,72 +55,34 @@ if !exists('g:persist_unnamed_register') endif -" FUNCTION: ExpandRegister(reg) {{{1 -" ============================================================================== -" Convenience method to determine which register is being currently used. -" The unnamed register defaults to the last used register to avoid having to -" constantly prefix registration. This can be changed by setting the value of -" g:persist_unnamed_register to 1. - -function! s:ExpandRegister(reg) - if !g:persist_unnamed_register && a:reg ==# '"' - return s:active_register - endif - return a:reg -endfunction - - -" FUNCTION: ExpandFlag(flag) {{{1 -" ============================================================================== -" Convenience method used to make the mappings in plugin/highlight.vim a bit -" easier to read through. The passed flag can be: -" -" c: Indicates the current word, with word boundary. -" g: Indicates the current word, without word boundary. -" v: Indicates the current visual selection. -" -" Throws an error otherwise. - -function! s:ExpandFlag(flag) abort - if a:flag ==# 'c' - return '\<' . expand('') . '\>' - elseif a:flag ==# 'g' - return expand('') - elseif a:flag ==# 'v' - return highlight#get_visual_selection() - endif - throw 'Could not expand passed flag: ' . a:flag -endfunction - - " MAPPINGS: {{{1 " ============================================================================== " Append Searches noremap HRegistry_AppendToSearch - \ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('c')) - \ call highlight#count_pattern(s:ExpandFlag('c')) + \ :call highlight#append_to_search(highlight#expand_register(v:register), highlight#expand_flag('c')) + \ call highlight#count_pattern(highlight#expand_flag('c')) noremap HRegistry_GAppendToSearch - \ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('g')) - \ call highlight#count_pattern(s:ExpandFlag('g')) + \ :call highlight#append_to_search(highlight#expand_register(v:register), highlight#expand_flag('g')) + \ call highlight#count_pattern(highlight#expand_flag('g')) noremap HRegistry_VisualAppendToSearch - \ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('v')) - \ call highlight#count_pattern(s:ExpandFlag('v')) + \ :call highlight#append_to_search(highlight#expand_register(v:register), highlight#expand_flag('v')) + \ call highlight#count_pattern(highlight#expand_flag('v')) " Remove Searches noremap HRegistry_RemoveFromSearch - \ :call highlight#remove_from_search(s:ExpandRegister(v:register), s:ExpandFlag('c')) + \ :call highlight#remove_from_search(highlight#expand_register(v:register), highlight#expand_flag('c')) noremap HRegistry_VisualRemoveFromSearch - \ :call highlight#remove_from_search(s:ExpandRegister(v:register), s:ExpandFlag('v')) + \ :call highlight#remove_from_search(highlight#expand_register(v:register), highlight#expand_flag('v')) " Other Modifications noremap HRegistry_ClearRegister - \ :call highlight#clear_register(s:ExpandRegister(v:register)) - \ call highlight#activate_register(s:ExpandRegister(v:register)) + \ :call highlight#clear_register(highlight#expand_register(v:register)) + \ call highlight#activate_register(highlight#expand_register(v:register)) noremap HRegistry_ActivateRegister - \ :call highlight#activate_register(s:ExpandRegister(v:register)) + \ :call highlight#activate_register(highlight#expand_register(v:register)) noremap HRegistry_CountLastSeen - \ :call highlight#count_pattern(s:ExpandFlag('c')) + \ :call highlight#count_pattern(highlight#expand_flag('c')) " Normal Mappings nmap & HRegistry_AppendToSearch