Remove s:color_registry and default colors. Add statusline
parent
4ad297598e
commit
b6e562e89d
|
@ -7,19 +7,18 @@
|
||||||
" SCRIPT VARIABLES:
|
" SCRIPT VARIABLES:
|
||||||
" ======================================================================
|
" ======================================================================
|
||||||
|
|
||||||
" s:last_seen :: String {{{2
|
" s:last_pattern_seen :: String {{{2
|
||||||
" ----------------------------------------------------------------------
|
" ----------------------------------------------------------------------
|
||||||
" The pattern last appended to a registry list.
|
" The pattern last appended to a registry list.
|
||||||
|
|
||||||
let s:last_seen = @/
|
let s:last_pattern_seen = @/
|
||||||
|
|
||||||
|
|
||||||
" s:registry_colors :: { String : String } {{{2
|
" s:active_register :: String {{{2
|
||||||
" ----------------------------------------------------------------------
|
" ----------------------------------------------------------------------
|
||||||
" Mapping between registry name and color that should be used for
|
" The register currently active. This defaults to the unnamed register.
|
||||||
" highlighting.
|
|
||||||
|
|
||||||
let s:registry_colors = {}
|
let s:active_register = "\""
|
||||||
|
|
||||||
|
|
||||||
" s:registry :: { String : { String : Match } } {{{2
|
" s:registry :: { String : { String : Match } } {{{2
|
||||||
|
@ -30,6 +29,31 @@ let s:registry_colors = {}
|
||||||
let s:registry = {}
|
let s:registry = {}
|
||||||
|
|
||||||
|
|
||||||
|
" FUNCTION: Statusline() {{{1
|
||||||
|
" ======================================================================
|
||||||
|
" Allow for integrating the currently highlighted section into the statusline.
|
||||||
|
" If airline is found, synchronize the accent with the highlighting.
|
||||||
|
" Can use as follows:
|
||||||
|
" call airline#parts#define_function('foo', 'highlight#airline_status')
|
||||||
|
" call airline#parts#define_minwidth('foo', 50)
|
||||||
|
" call airline#parts#define_condition('foo', 'getcwd() =~ "work_dir"')
|
||||||
|
" let g:airline_section_y = airline#section#create_right(['ffenc', 'foo'])
|
||||||
|
|
||||||
|
function! highlight#statusline(...)
|
||||||
|
let l:group_name = highlight#get_group_name(s:active_register)
|
||||||
|
" If airline is defined, this function should be called in the context of
|
||||||
|
" airline#parts#define_function('foo', 'highlight#airline_status'). Thus it
|
||||||
|
" should be sufficient to check that airline#parts#define_accent exists to
|
||||||
|
" ensure airline is defined.
|
||||||
|
if a:0 > 0 && exists('*airline#parts#define_accent')
|
||||||
|
call airline#parts#define_accent(a:1, l:group_name)
|
||||||
|
return airline#section#create_right([a:1])
|
||||||
|
else
|
||||||
|
return '%#' . l:group_name . '#xxx (" . s:active_register . ")%*'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" FUNCTION: GetGroupName(reg) {{{1
|
" FUNCTION: GetGroupName(reg) {{{1
|
||||||
" ======================================================================
|
" ======================================================================
|
||||||
" Note group names are not allowed to have special characters; they
|
" Note group names are not allowed to have special characters; they
|
||||||
|
@ -46,7 +70,6 @@ endfunction
|
||||||
|
|
||||||
function! highlight#init_register(reg, color)
|
function! highlight#init_register(reg, color)
|
||||||
call highlight#clear_register(a:reg)
|
call highlight#clear_register(a:reg)
|
||||||
let s:registry_colors[a:reg] = a:color
|
|
||||||
exe 'hi ' . highlight#get_group_name(a:reg) .
|
exe 'hi ' . highlight#get_group_name(a:reg) .
|
||||||
\ ' cterm=bold,underline ctermfg=' . a:color
|
\ ' cterm=bold,underline ctermfg=' . a:color
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -59,12 +82,9 @@ endfunction
|
||||||
|
|
||||||
function! highlight#clear_register(reg)
|
function! highlight#clear_register(reg)
|
||||||
exe 'hi clear ' . highlight#get_group_name(a:reg)
|
exe 'hi clear ' . highlight#get_group_name(a:reg)
|
||||||
if has_key(s:registry_colors, a:reg)
|
|
||||||
unlet s:registry_colors[a:reg]
|
|
||||||
endif
|
|
||||||
if has_key(s:registry, a:reg)
|
if has_key(s:registry, a:reg)
|
||||||
for key in keys(s:registry[a:reg])
|
for key in keys(s:registry[a:reg])
|
||||||
call matchdelete(s:registry[a:reg][key])
|
silent! call matchdelete(s:registry[a:reg][key])
|
||||||
unlet s:registry[a:reg][key]
|
unlet s:registry[a:reg][key]
|
||||||
endfor
|
endfor
|
||||||
unlet s:registry[a:reg]
|
unlet s:registry[a:reg]
|
||||||
|
@ -91,10 +111,10 @@ endfunction
|
||||||
" FUNCTION: CountLastSeen() {{{1
|
" FUNCTION: CountLastSeen() {{{1
|
||||||
" ======================================================================
|
" ======================================================================
|
||||||
|
|
||||||
function! highlight#count_last_seen()
|
function! highlight#count_last_pattern_seen()
|
||||||
if len(@/) > 0
|
if len(@/) > 0
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
exe ' %s/' . s:last_seen . '//gne'
|
exe ' %s/' . s:last_pattern_seen . '//gne'
|
||||||
call setpos('.', pos)
|
call setpos('.', pos)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -105,14 +125,14 @@ endfunction
|
||||||
" We must actively set the search register to perform searches as expected.
|
" We must actively set the search register to perform searches as expected.
|
||||||
|
|
||||||
function! highlight#activate_register(reg)
|
function! highlight#activate_register(reg)
|
||||||
if has_key(s:registry, a:reg) && has_key(s:registry_colors, a:reg)
|
let s:active_register = a:reg
|
||||||
|
if has_key(s:registry, a:reg)
|
||||||
let search = ''
|
let search = ''
|
||||||
for key in keys(s:registry[a:reg])
|
for key in keys(s:registry[a:reg])
|
||||||
let search = search . key . '\|'
|
let search = search . key . '\|'
|
||||||
endfor
|
endfor
|
||||||
let @/ = search[:-3]
|
let @/ = search[:-3]
|
||||||
exe 'hi Search cterm=bold,underline ctermbg=none ctermfg=' .
|
exe 'hi! link Search ' . highlight#get_group_name(a:reg)
|
||||||
\ s:registry_colors[a:reg]
|
|
||||||
set hlsearch
|
set hlsearch
|
||||||
else
|
else
|
||||||
let @/ = ''
|
let @/ = ''
|
||||||
|
@ -124,14 +144,13 @@ endfunction
|
||||||
" ======================================================================
|
" ======================================================================
|
||||||
|
|
||||||
function! highlight#append_to_search(reg, pattern)
|
function! highlight#append_to_search(reg, pattern)
|
||||||
let s:last_seen = a:pattern
|
let s:last_pattern_seen = a:pattern
|
||||||
if len(a:pattern) == 0
|
if len(a:pattern) == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
if !has_key(s:registry_colors, a:reg)
|
|
||||||
call highlight#init_register(a:reg, g:highlight_register_default_color)
|
|
||||||
endif
|
|
||||||
if !has_key(s:registry, a:reg)
|
if !has_key(s:registry, a:reg)
|
||||||
|
" TODO(jrpotter): Change to one of least used color.
|
||||||
|
call highlight#init_register(a:reg, 'Yellow')
|
||||||
let s:registry[a:reg] = {}
|
let s:registry[a:reg] = {}
|
||||||
endif
|
endif
|
||||||
" Don't want to add multiple match objects into registry
|
" Don't want to add multiple match objects into registry
|
||||||
|
|
|
@ -13,14 +13,6 @@ let g:loaded_highlight_registry = 1
|
||||||
" GLOBAL VARIABLES:
|
" GLOBAL VARIABLES:
|
||||||
" ======================================================================
|
" ======================================================================
|
||||||
|
|
||||||
" g:highlight_register_default_color :: String {{{2
|
|
||||||
" ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
if !exists('g:highlight_register_default_color')
|
|
||||||
let g:highlight_register_default_color = 'Yellow'
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
" g:highlight_registry :: { String : String } {{{2
|
" g:highlight_registry :: { String : String } {{{2
|
||||||
" ----------------------------------------------------------------------
|
" ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -45,13 +37,13 @@ endif
|
||||||
" Append Searches
|
" Append Searches
|
||||||
noremap <Plug>HRegistry_AppendToSearch
|
noremap <Plug>HRegistry_AppendToSearch
|
||||||
\ :call highlight#append_to_search(v:register, '\<'.expand('<cword>').'\>')<Bar>
|
\ :call highlight#append_to_search(v:register, '\<'.expand('<cword>').'\>')<Bar>
|
||||||
\ call highlight#count_last_seen()<CR>
|
\ call highlight#count_last_pattern_seen()<CR>
|
||||||
noremap <Plug>HRegistry_GlobalAppendToSearch
|
noremap <Plug>HRegistry_GlobalAppendToSearch
|
||||||
\ :call highlight#append_to_search(v:register, expand('<cword>'))<Bar>
|
\ :call highlight#append_to_search(v:register, expand('<cword>'))<Bar>
|
||||||
\ call highlight#count_last_seen()<CR>
|
\ call highlight#count_last_pattern_seen()<CR>
|
||||||
noremap <Plug>HRegistry_VisualAppendToSearch
|
noremap <Plug>HRegistry_VisualAppendToSearch
|
||||||
\ :call highlight#append_to_search(v:register, highlight#get_visual_selection())<Bar>
|
\ :call highlight#append_to_search(v:register, highlight#get_visual_selection())<Bar>
|
||||||
\ call highlight#count_last_seen()<CR>
|
\ call highlight#count_last_pattern_seen()<CR>
|
||||||
|
|
||||||
" Remove Searches
|
" Remove Searches
|
||||||
noremap <Plug>HRegistry_RemoveFromSearch
|
noremap <Plug>HRegistry_RemoveFromSearch
|
||||||
|
@ -65,7 +57,7 @@ noremap <Plug>HRegistry_ClearRegister
|
||||||
noremap <Plug>HRegistry_ActivateRegister
|
noremap <Plug>HRegistry_ActivateRegister
|
||||||
\ :call highlight#activate_register(v:register)<CR>
|
\ :call highlight#activate_register(v:register)<CR>
|
||||||
noremap <Plug>HRegistry_CountLastSeen
|
noremap <Plug>HRegistry_CountLastSeen
|
||||||
\ :call highlight#count_last_seen()<CR>
|
\ :call highlight#count_last_pattern_seen()<CR>
|
||||||
|
|
||||||
" Normal Mappings
|
" Normal Mappings
|
||||||
nmap <silent> & <Plug>HRegistry_AppendToSearch
|
nmap <silent> & <Plug>HRegistry_AppendToSearch
|
||||||
|
|
Loading…
Reference in New Issue