Skip to content

Commit

Permalink
Follow linked highlight groups to find background colors
Browse files Browse the repository at this point in the history
  • Loading branch information
wellle committed Apr 7, 2014
1 parent 7e7ccea commit 47ffb2e
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions autoload/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ function! highlight#define_sign_column_highlight()
endfunction

function! highlight#define_highlights()
redir => sign_highlight
silent highlight SignColumn
redir END
let sign_ctermbg = matchlist(sign_highlight, 'ctermbg=\(\S\+\)')[1]
let sign_guibg = matchlist(sign_highlight, 'guibg=\(\S\+\)')[1]
let [guibg, ctermbg] = highlight#get_background_colors('SignColumn')

" Highlights used by the signs.
execute "highlight GitGutterAddDefault guifg=#009900 guibg=".sign_guibg." ctermfg=2 ctermbg=".sign_ctermbg
execute "highlight GitGutterChangeDefault guifg=#bbbb00 guibg=".sign_guibg." ctermfg=3 ctermbg=".sign_ctermbg
execute "highlight GitGutterDeleteDefault guifg=#ff2222 guibg=".sign_guibg." ctermfg=1 ctermbg=".sign_ctermbg
execute "highlight GitGutterAddDefault guifg=#009900 guibg=" . guibg . " ctermfg=2 ctermbg=" . ctermbg
execute "highlight GitGutterChangeDefault guifg=#bbbb00 guibg=" . guibg . " ctermfg=3 ctermbg=" . ctermbg
execute "highlight GitGutterDeleteDefault guifg=#ff2222 guibg=" . guibg . " ctermfg=1 ctermbg=" . ctermbg
highlight default link GitGutterChangeDeleteDefault GitGutterChangeDefault

highlight default link GitGutterAdd GitGutterAddDefault
Expand Down Expand Up @@ -66,3 +62,26 @@ function! highlight#define_sign_line_highlights()
sign define GitGutterLineModifiedRemoved linehl=
endif
endfunction

function! highlight#get_background_colors(group)
redir => highlight
silent execute 'silent highlight ' . a:group
redir END

let link_matches = matchlist(highlight, 'links to \(\S\+\)')
if len(link_matches) > 0 " follow the link
return highlight#get_background_colors(link_matches[1])
endif

let ctermbg = highlight#match_highlight(highlight, 'ctermbg=\(\S\+\)')
let guibg = highlight#match_highlight(highlight, 'guibg=\(\S\+\)')
return [guibg, ctermbg]
endfunction

function! highlight#match_highlight(highlight, pattern)
let matches = matchlist(a:highlight, a:pattern)
if len(matches) == 0
return 'NONE'
endif
return matches[1]
endfunction

0 comments on commit 47ffb2e

Please sign in to comment.