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(''))
|
|
|
|
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
|
|
|
|
|
2019-11-16 15:28:42 +00:00
|
|
|
|
2019-08-22 15:36:17 +00:00
|
|
|
function! gitgutter#highlight#linenr_disable() abort
|
|
|
|
let g:gitgutter_highlight_linenrs = 0
|
|
|
|
call s:define_sign_linenr_highlights()
|
|
|
|
|
|
|
|
if !g:gitgutter_signs
|
|
|
|
call gitgutter#sign#clear_signs(bufnr(''))
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#linenr_enable() abort
|
2019-11-16 15:28:42 +00:00
|
|
|
let old_highlight_linenrs = g:gitgutter_highlight_linenrs
|
2019-08-22 15:36:17 +00:00
|
|
|
|
|
|
|
let g:gitgutter_highlight_linenrs = 1
|
|
|
|
call s:define_sign_linenr_highlights()
|
|
|
|
|
2019-11-16 15:28:42 +00:00
|
|
|
if !old_highlight_linenrs && !g:gitgutter_signs
|
2019-08-22 15:36:17 +00:00
|
|
|
call gitgutter#all(1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! gitgutter#highlight#linenr_toggle() abort
|
|
|
|
if g:gitgutter_highlight_linenrs
|
|
|
|
call gitgutter#highlight#linenr_disable()
|
|
|
|
else
|
|
|
|
call gitgutter#highlight#linenr_enable()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
|
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.
|
|
|
|
|
2019-03-08 11:04:56 +00:00
|
|
|
" When they are invisible.
|
2016-11-22 08:36:31 +00:00
|
|
|
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
|
|
|
|
2019-03-08 11:04:56 +00:00
|
|
|
" When they are visible.
|
2020-04-26 01:56:16 +00:00
|
|
|
|
|
|
|
" If GitGutter* highlights are already defined, either by the user or the colourscheme,
|
|
|
|
" set their backgrounds to the sign column's.
|
|
|
|
for type in ["Add", "Change", "Delete"]
|
|
|
|
if hlexists("GitGutter".type)
|
|
|
|
" Were the highlight self-contained we could just declare the
|
|
|
|
" background attributes and they would be merged. But it might be a
|
|
|
|
" link, in which case it would be overwritten. So re-declare it in its
|
|
|
|
" entirety.
|
|
|
|
let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type)
|
|
|
|
execute "highlight GitGutter".type." guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2019-03-08 11:04:56 +00:00
|
|
|
" By default use Diff* foreground colors with SignColumn's background.
|
|
|
|
for type in ['Add', 'Change', 'Delete']
|
|
|
|
let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type)
|
|
|
|
execute "highlight GitGutter".type."Default guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
|
|
|
|
execute "highlight default link GitGutter".type." GitGutter".type."Default"
|
|
|
|
endfor
|
|
|
|
highlight default link GitGutterChangeDelete GitGutterChange
|
2016-11-22 08:36:31 +00:00
|
|
|
|
|
|
|
" 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
|
2019-08-22 15:36:17 +00:00
|
|
|
|
|
|
|
highlight default link GitGutterAddLineNr CursorLineNr
|
|
|
|
highlight default link GitGutterChangeLineNr CursorLineNr
|
|
|
|
highlight default link GitGutterDeleteLineNr CursorLineNr
|
|
|
|
highlight default link GitGutterChangeDeleteLineNr CursorLineNr
|
2019-11-16 15:28:42 +00:00
|
|
|
|
|
|
|
" Highlights used intra line.
|
|
|
|
highlight GitGutterAddIntraLine gui=reverse cterm=reverse
|
|
|
|
highlight GitGutterDeleteIntraLine gui=reverse cterm=reverse
|
2020-04-26 01:56:16 +00:00
|
|
|
" Set diff syntax colours (used in the preview window) - diffAdded,diffChanged,diffRemoved -
|
|
|
|
" to match the signs, if not set aleady.
|
|
|
|
for [dtype,type] in [['Added','Add'], ['Changed','Change'], ['Removed','Delete']]
|
|
|
|
if !hlexists('diff'.dtype)
|
|
|
|
let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type)
|
|
|
|
execute "highlight diff".dtype." guifg=".guifg." ctermfg=".ctermfg." guibg=NONE ctermbg=NONE"
|
|
|
|
endif
|
|
|
|
endfor
|
2016-11-22 08:36:31 +00:00
|
|
|
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
|
|
|
|
|
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()
|
2019-08-22 15:36:17 +00:00
|
|
|
call s:define_sign_linenr_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
|
|
|
|
|
2019-08-22 15:36:17 +00:00
|
|
|
function! s:define_sign_linenr_highlights() abort
|
|
|
|
if has('nvim-0.3.2')
|
|
|
|
try
|
|
|
|
if g:gitgutter_highlight_linenrs
|
2019-11-16 15:28:42 +00:00
|
|
|
sign define GitGutterLineAdded numhl=GitGutterAddLineNr
|
|
|
|
sign define GitGutterLineModified numhl=GitGutterChangeLineNr
|
|
|
|
sign define GitGutterLineRemoved numhl=GitGutterDeleteLineNr
|
|
|
|
sign define GitGutterLineRemovedFirstLine numhl=GitGutterDeleteLineNr
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow numhl=GitGutterDeleteLineNr
|
|
|
|
sign define GitGutterLineModifiedRemoved numhl=GitGutterChangeDeleteLineNr
|
2019-08-22 15:36:17 +00:00
|
|
|
else
|
|
|
|
sign define GitGutterLineAdded numhl=
|
|
|
|
sign define GitGutterLineModified numhl=
|
|
|
|
sign define GitGutterLineRemoved numhl=
|
|
|
|
sign define GitGutterLineRemovedFirstLine numhl=
|
|
|
|
sign define GitGutterLineRemovedAboveAndBelow numhl=
|
|
|
|
sign define GitGutterLineModifiedRemoved numhl=
|
|
|
|
endif
|
|
|
|
catch /E475/
|
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
endfunction
|
2019-03-08 11:04:56 +00:00
|
|
|
|
2019-08-22 15:36:17 +00:00
|
|
|
function! s:get_hl(group, what, mode) abort
|
|
|
|
let r = synIDattr(synIDtrans(hlID(a:group)), a:what, a:mode)
|
|
|
|
if empty(r) || r == -1
|
|
|
|
return 'NONE'
|
2019-03-08 11:04:56 +00:00
|
|
|
endif
|
2019-08-22 15:36:17 +00:00
|
|
|
return r
|
|
|
|
endfunction
|
2019-03-08 11:04:56 +00:00
|
|
|
|
2019-08-22 15:36:17 +00:00
|
|
|
function! s:get_foreground_colors(group) abort
|
|
|
|
let ctermfg = s:get_hl(a:group, 'fg', 'cterm')
|
|
|
|
let guifg = s:get_hl(a:group, 'fg', 'gui')
|
2019-03-08 11:04:56 +00:00
|
|
|
return [guifg, ctermfg]
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 14:56:26 +00:00
|
|
|
function! s:get_background_colors(group) abort
|
2019-08-22 15:36:17 +00:00
|
|
|
let ctermbg = s:get_hl(a:group, 'bg', 'cterm')
|
|
|
|
let guibg = s:get_hl(a:group, 'bg', 'gui')
|
2016-11-22 08:36:31 +00:00
|
|
|
return [guibg, ctermbg]
|
|
|
|
endfunction
|