motiejus/dotfiles

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.jakstys.lt/motiejus/dotfiles.git
Log | Tree | Refs | README | LICENSE

commit fb5661211dc632b03a49a19bdbdc2cbf6d691f56 (tree)
parent 276f89837f6cea617b04f757e6242323068cfaa5
Author: Tim Pope <code@tpope.net>
Date:   Sat,  7 Jul 2012 17:30:08 -0400

Colorize hashes in blame

References #369.

Diffstat:
Mplugin/fugitive.vim | 36+++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim @@ -1670,6 +1670,7 @@ augroup fugitive_blame autocmd FileType fugitiveblame setlocal nomodeline | if exists('b:git_dir') | let &l:keywordprg = s:repo().keywordprg() | endif autocmd Syntax fugitiveblame call s:BlameSyntax() autocmd User Fugitive if s:buffer().type('file', 'blob') | exe "command! -buffer -bar -bang -range=0 -nargs=* Gblame :execute s:Blame(<bang>0,<line1>,<line2>,<count>,[<f-args>])" | endif + autocmd ColorScheme,GUIEnter * call s:RehighlightBlame() augroup END function! s:linechars(pattern) abort @@ -1858,6 +1859,8 @@ function! s:BlameJump(suffix) abort return '' endfunction +let s:hash_colors = {} + function! s:BlameSyntax() abort let b:current_syntax = 'fugitiveblame' let conceal = has('conceal') ? ' conceal' : '' @@ -1876,7 +1879,7 @@ function! s:BlameSyntax() abort syn match FugitiveblameNotCommittedYet "(\@<=Not Committed Yet\>" contained containedin=FugitiveblameAnnotation hi def link FugitiveblameBoundary Keyword hi def link FugitiveblameHash Identifier - hi def link FugitiveblameUncommitted Function + hi def link FugitiveblameUncommitted Ignore hi def link FugitiveblameTime PreProc hi def link FugitiveblameLineNumber Number hi def link FugitiveblameOriginalFile String @@ -1884,6 +1887,37 @@ function! s:BlameSyntax() abort hi def link FugitiveblameShort FugitiveblameDelimiter hi def link FugitiveblameDelimiter Delimiter hi def link FugitiveblameNotCommittedYet Comment + let seen = {} + for lnum in range(1, line('$')) + let hash = matchstr(getline(lnum), '^\^\=\zs\x\{6\}') + if hash ==# '' || hash ==# '000000' || has_key(seen, hash) + continue + endif + let seen[hash] = 1 + if &t_Co > 16 && exists('g:CSApprox_loaded') + \ && empty(get(s:hash_colors, hash)) + let [s, r, g, b; __] = map(matchlist(hash, '\(\x\x\)\(\x\x\)\(\x\x\)'), 'str2nr(v:val,16)') + let color = csapprox#per_component#Approximate(r, g, b) + if color == 16 && &background ==# 'dark' + let color = 8 + endif + let s:hash_colors[hash] = ' ctermfg='.color + else + let s:hash_colors[hash] = '' + endif + exe 'syn match FugitiveblameHash'.hash.' "\%(^\^\=\)\@<='.hash.'\x\{1,34\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite' + endfor + call s:RehighlightBlame() +endfunction + +function! s:RehighlightBlame() abort + for [hash, cterm] in items(s:hash_colors) + if !empty(cterm) || has('gui_running') + exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.get(s:hash_colors, hash, '') + else + exe 'hi link FugitiveblameHash'.hash.' Identifier' + endif + endfor endfunction " Section: Gbrowse