2018-03-31 14:56:26 +00:00
|
|
|
function! gitgutter#highlight#line_disable() abort
|
|
|
|
let g:gitgutter_highlight_lines = 0
|
|
|
|
call s:define_sign_line_highlights()
|
|
|
|
|
|
|
|
if !g:gitgutter_signs
|
|
|
|
call gitgutter#sign#clear_signs(bufnr(''))
|
|
|
|
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#line_enable() abort
|
|
|
|
let old_highlight_lines = g:gitgutter_highlight_lines
|
|
|
|
|
|
|
|
let g:gitgutter_highlight_lines = 1
|
|
|
|
call s:define_sign_line_highlights()
|
|
|
|
|
|
|
|
if !old_highlight_lines && !g:gitgutter_signs
|
|
|
|
call gitgutter#all(1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#line_toggle() abort
|
|
|
|
if g:gitgutter_highlight_lines
|
|
|
|
call gitgutter#highlight#line_disable()
|
|
|
|
else
|
|
|
|
call gitgutter#highlight#line_enable()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-11-22 08:36:31 +00:00
|
|
|
function! gitgutter#highlight#define_sign_column_highlight() abort
|
|
|
|
if g:gitgutter_override_sign_column_highlight
|
|
|
|
highlight! link SignColumn LineNr
|
|
|
|
else
|
|
|
|
highlight default link SignColumn LineNr
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#define_highlights() abort
|
2018-03-31 14:56:26 +00:00
|
|
|
let [guibg, ctermbg] = s:get_background_colors('SignColumn')
|
2016-11-22 08:36:31 +00:00
|
|
|
|
|
|
|
" Highlights used by the signs.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
execute "highlight GitGutterAddInvisible guifg=bg guibg=" . guibg . " ctermfg=" . ctermbg . " ctermbg=" . ctermbg
|
|
|
|
execute "highlight GitGutterChangeInvisible guifg=bg guibg=" . guibg . " ctermfg=" . ctermbg . " ctermbg=" . ctermbg
|
|
|
|
execute "highlight GitGutterDeleteInvisible guifg=bg guibg=" . guibg . " ctermfg=" . ctermbg . " ctermbg=" . ctermbg
|
2017-11-24 13:54:40 +00:00
|
|
|
highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible
|
2016-11-22 08:36:31 +00:00
|
|
|
|
|
|
|
highlight default link GitGutterAdd GitGutterAddDefault
|
|
|
|
highlight default link GitGutterChange GitGutterChangeDefault
|
|
|
|
highlight default link GitGutterDelete GitGutterDeleteDefault
|
|
|
|
highlight default link GitGutterChangeDelete GitGutterChangeDeleteDefault
|
|
|
|
|
|
|
|
" Highlights used for the whole line.
|
|
|
|
|
|
|
|
highlight default link GitGutterAddLine DiffAdd
|
|
|
|
highlight default link GitGutterChangeLine DiffChange
|
|
|
|
highlight default link GitGutterDeleteLine DiffDelete
|
|
|
|
highlight default link GitGutterChangeDeleteLine GitGutterChangeLine
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#define_signs() abort
|
|
|
|
sign define GitGutterLineAdded
|
|
|
|
sign define GitGutterLineModified
|
|
|
|
sign define GitGutterLineRemoved
|
|
|
|
sign define GitGutterLineRemovedFirstLine
|
2018-11-01 10:03:42 +00:00
|
|
|
sign define GitGutterLineRemovedAboveAndBelow
|
2016-11-22 08:36:31 +00:00
|
|
|
sign define GitGutterLineModifiedRemoved
|
|
|
|
sign define GitGutterDummy
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
call s:define_sign_text()
|
2016-11-22 08:36:31 +00:00
|
|
|
call gitgutter#highlight#define_sign_text_highlights()
|
2018-03-31 14:56:26 +00:00
|
|
|
call s:define_sign_line_highlights()
|
2016-11-22 08:36:31 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
function! s:define_sign_text() abort
|
2018-11-01 10:03:42 +00:00
|
|
|
execute "sign define GitGutterLineAdded text=" . g:gitgutter_sign_added
|
|
|
|
execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified
|
|
|
|
execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed
|
|
|
|
execute "sign define GitGutterLineRemovedFirstLine text=" . g:gitgutter_sign_removed_first_line
|
|
|
|
execute "sign define GitGutterLineRemovedAboveAndBelow text=" . g:gitgutter_sign_removed_above_and_below
|
|
|
|
execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed
|
2016-11-22 08:36:31 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#define_sign_text_highlights() abort
|
|
|
|
" Once a sign's text attribute has been defined, it cannot be undefined or
|
|
|
|
" set to an empty value. So to make signs' text disappear (when toggling
|
|
|
|
" off or disabling) we make them invisible by setting their foreground colours
|
|
|
|
" to the background's.
|
|
|
|
if g:gitgutter_signs
|
2018-11-01 10:03:42 +00:00
|
|
|
sign define GitGutterLineAdded texthl=GitGutterAdd
|
|
|
|
sign define GitGutterLineModified texthl=GitGutterChange
|
|
|
|
sign define GitGutterLineRemoved texthl=GitGutterDelete
|
|
|
|
sign define GitGutterLineRemovedFirstLine texthl=GitGutterDelete
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow texthl=GitGutterDelete
|
|
|
|
sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDelete
|
2016-11-22 08:36:31 +00:00
|
|
|
else
|
2018-11-01 10:03:42 +00:00
|
|
|
sign define GitGutterLineAdded texthl=GitGutterAddInvisible
|
|
|
|
sign define GitGutterLineModified texthl=GitGutterChangeInvisible
|
|
|
|
sign define GitGutterLineRemoved texthl=GitGutterDeleteInvisible
|
|
|
|
sign define GitGutterLineRemovedFirstLine texthl=GitGutterDeleteInvisible
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow texthl=GitGutterDeleteInvisible
|
|
|
|
sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDeleteInvisible
|
2016-11-22 08:36:31 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
function! s:define_sign_line_highlights() abort
|
2016-11-22 08:36:31 +00:00
|
|
|
if g:gitgutter_highlight_lines
|
2018-11-01 10:03:42 +00:00
|
|
|
sign define GitGutterLineAdded linehl=GitGutterAddLine
|
|
|
|
sign define GitGutterLineModified linehl=GitGutterChangeLine
|
|
|
|
sign define GitGutterLineRemoved linehl=GitGutterDeleteLine
|
|
|
|
sign define GitGutterLineRemovedFirstLine linehl=GitGutterDeleteLine
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow linehl=GitGutterDeleteLine
|
|
|
|
sign define GitGutterLineModifiedRemoved linehl=GitGutterChangeDeleteLine
|
2016-11-22 08:36:31 +00:00
|
|
|
else
|
2018-11-01 10:03:42 +00:00
|
|
|
sign define GitGutterLineAdded linehl=
|
|
|
|
sign define GitGutterLineModified linehl=
|
|
|
|
sign define GitGutterLineRemoved linehl=
|
|
|
|
sign define GitGutterLineRemovedFirstLine linehl=
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow linehl=
|
|
|
|
sign define GitGutterLineModifiedRemoved linehl=
|
2016-11-22 08:36:31 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
function! s:get_background_colors(group) abort
|
2016-11-22 08:36:31 +00:00
|
|
|
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
|
2018-03-31 14:56:26 +00:00
|
|
|
return s:get_background_colors(link_matches[1])
|
2016-11-22 08:36:31 +00:00
|
|
|
endif
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
let ctermbg = s:match_highlight(highlight, 'ctermbg=\([0-9A-Za-z]\+\)')
|
|
|
|
let guibg = s:match_highlight(highlight, 'guibg=\([#0-9A-Za-z]\+\)')
|
2016-11-22 08:36:31 +00:00
|
|
|
return [guibg, ctermbg]
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
function! s:match_highlight(highlight, pattern) abort
|
2016-11-22 08:36:31 +00:00
|
|
|
let matches = matchlist(a:highlight, a:pattern)
|
|
|
|
if len(matches) == 0
|
|
|
|
return 'NONE'
|
|
|
|
endif
|
|
|
|
return matches[1]
|
|
|
|
endfunction
|