2 Commits

Author SHA1 Message Date
Tim Pope
70eba584a8 Timestamp WIP 2012-10-09 18:37:03 -04:00
Tim Pope
c80dba42df Colorize hashes in blame 2012-10-09 18:37:03 -04:00

View File

@@ -1551,6 +1551,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 * call s:RehighlightBlame()
augroup END
function! s:linechars(pattern)
@@ -1736,6 +1737,9 @@ function! s:BlameJump(suffix) abort
return ''
endfunction
let s:load_time = localtime()
let s:hash_colors = {}
function! s:BlameSyntax() abort
let b:current_syntax = 'fugitiveblame'
let conceal = has('conceal') ? ' conceal' : ''
@@ -1754,7 +1758,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
@@ -1762,6 +1766,70 @@ function! s:BlameSyntax() abort
hi def link FugitiveblameShort FugitiveblameDelimiter
hi def link FugitiveblameDelimiter Delimiter
hi def link FugitiveblameNotCommittedYet Comment
call s:HighlightBlameDates()
for lnum in range(1, line('$'))
let match = matchlist(getline(lnum), '\<\(\d\d\d\d\)-\(\d\d\)-\(\d\d\).\(\d\d\):\(\d\d\):\(\d\d\) \([+-]\d\d\d\d\)\>')[0:7]
if !empty(match)
let age = s:load_time - call(s:function('s:unixtime'), match[1:7])
else
let match = matchlist(getline(lnum), '\<\(\d\+\) \([+-]\d\d\d\d\)\>')[0:2]
if !empty(match)
let age = s:load_time - match[1]
endif
endif
if exists('age') && exists('*log')
let staleness = age < 0 ? 0 : float2nr(ceil(log(1+age/86400)))
if staleness > 15 | let staleness = 15 | endif
exe 'syn match FugitiveblameTime'.staleness.' "\<'.match[0].'\>" contained containedin=FugitiveblameAnnotation'
endif
let hash = matchstr(getline(lnum), '^\^\=\zs\x\{6\}')
if hash ==# '' || hash ==# '000000'
continue
endif
if &t_Co > 16 && exists('*csapprox#per_component#Approximate') && !has_key(s:hash_colors, hash)
let [a, 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
endif
exe 'syn match FugitiveblameHash'.hash.' "\%(^\^\=\)\@<='.hash.'\x\{1,34\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite'
exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.get(s:hash_colors, hash, '')
endfor
endfunction
function! s:HighlightBlameDates() abort
for i in range(0, 15)
let shade = 0x11 * (&background == 'dark' ? 0xf - i : i)
if &t_Co > 16 && exists('*csapprox#per_component#Approximate')
let cterm = ' ctermfg='.csapprox#per_component#Approximate(shade, shade, shade)
else
let cterm = ''
endif
execute 'hi FugitiveblameTime'.i.' guifg=#'.repeat(printf('%02x', shade),3).cterm
endfor
endfunction
function! s:RehighlightBlame() abort
call s:HighlightBlameDates()
for [hash, cterm] in items(s:hash_colors)
exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.cterm
endfor
endfunction
function! s:unixtime(year,mon,day,hour,min,sec, ...) abort
let y = a:year + 4800 - (a:mon <= 2)
let m = a:mon + (a:mon <= 2 ? 9 : -3)
let jul = a:day + (153*m+2)/5 + 1461*y/4 - 32083
let days = jul - y/100 + y/400 + 38 - 2440588
let offset = a:0 ? a:1 : '0000'
let seconds = days * 86400 + a:hour * 3600 + a:min * 60 + a:sec
let seconds -= 3600 * matchstr(offset, '[+-]\=\d\d') - 60 * matchstr(offset, '\d\d$')
return seconds
endfunction
" }}}1