Skip to content

Commit e447c29

Browse files
authored
Merge pull request #168 from lambdalisue/feat/highlight-inheritance-util
feat: add highlight inheritance utility and improve blame divider styling
2 parents c165cfb + 118fef5 commit e447c29

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

autoload/gin/internal/util.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ function! gin#internal#util#debounce(expr, delay) abort
66
let s:debounce_timers[a:expr] = timer_start(a:delay, { -> execute(a:expr) })
77
endfunction
88

9+
" Inherit highlight attributes from a source group and apply additional attributes
10+
" @param target_group The name of the target highlight group
11+
" @param source_group The name of the source highlight group to inherit from
12+
" @param extra_attrs Dictionary with additional attributes (e.g., {'gui': 'strikethrough', 'cterm': 'strikethrough'})
13+
function! gin#internal#util#highlight_inherit(target_group, source_group, extra_attrs) abort
14+
let source_hl = execute('highlight ' . a:source_group)
15+
let guifg = matchstr(source_hl, 'guifg=\zs\S\+')
16+
let guibg = matchstr(source_hl, 'guibg=\zs\S\+')
17+
let ctermfg = matchstr(source_hl, 'ctermfg=\zs\S\+')
18+
let ctermbg = matchstr(source_hl, 'ctermbg=\zs\S\+')
19+
20+
let hl_cmd = 'highlight ' . a:target_group
21+
if has_key(a:extra_attrs, 'gui') | let hl_cmd .= ' gui=' . a:extra_attrs.gui | endif
22+
if has_key(a:extra_attrs, 'cterm') | let hl_cmd .= ' cterm=' . a:extra_attrs.cterm | endif
23+
if !empty(guifg) | let hl_cmd .= ' guifg=' . guifg | endif
24+
if !empty(guibg) | let hl_cmd .= ' guibg=' . guibg | endif
25+
if !empty(ctermfg) | let hl_cmd .= ' ctermfg=' . ctermfg | endif
26+
if !empty(ctermbg) | let hl_cmd .= ' ctermbg=' . ctermbg | endif
27+
28+
execute hl_cmd
29+
endfunction
30+
931
function gin#internal#util#input(opts) abort
1032
return s:input(a:opts)
1133
endfunction

plugin/gin-blame.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@ if exists('g:loaded_gin_blame')
33
endif
44
let g:loaded_gin_blame = 1
55

6+
function! s:init_highlights() abort
7+
call gin#internal#util#highlight_inherit(
8+
\ 'GinBlameDivider',
9+
\ 'Comment',
10+
\ {'gui': 'strikethrough', 'cterm': 'strikethrough'}
11+
\ )
12+
sign define GinBlameDividerSign linehl=GinBlameDivider
13+
endfunction
14+
615
augroup gin_plugin_blame_internal
716
autocmd!
817
autocmd BufReadCmd ginblame://*
918
\ call denops#request('gin', 'blame:edit', [bufnr(), expand('<amatch>')])
1019
autocmd BufReadCmd ginblamenav://*
1120
\ call denops#request('gin', 'blame:edit:nav', [bufnr(), expand('<amatch>')])
21+
autocmd ColorScheme * call s:init_highlights()
1222
augroup END
1323

1424
function! s:command(bang, mods, args) abort
@@ -20,5 +30,4 @@ endfunction
2030

2131
command! -bang -bar -nargs=* GinBlame call s:command(<q-bang>, <q-mods>, [<f-args>])
2232

23-
highlight GinBlameDivider gui=strikethrough cterm=strikethrough guifg=#505050 ctermfg=black
24-
sign define GinBlameDividerSign linehl=GinBlameDivider
33+
call s:init_highlights()

0 commit comments

Comments
 (0)