@@ -10,6 +10,14 @@ if !exists('g:git_bin')
10
10
let g: git_bin = ' git'
11
11
endif
12
12
13
+ if ! exists (' g:git_author_highlight' )
14
+ let g: git_author_highlight = { }
15
+ endif
16
+
17
+ if ! exists (' g:git_highlight_blame' )
18
+ let g: git_highlight_blame = 0
19
+ endif
20
+
13
21
nnoremap <Leader> gd :GitDiff<Enter>
14
22
nnoremap <Leader> gD :GitDiff --cached<Enter>
15
23
nnoremap <Leader> gs :GitStatus<Enter>
@@ -195,12 +203,47 @@ function! GitBlame()
195
203
setlocal nomodifiable
196
204
setlocal nowrap scrollbind
197
205
206
+ if g: git_highlight_blame
207
+ call s: DoHighlightGitBlame ()
208
+ endif
209
+
198
210
wincmd p
199
211
setlocal nowrap scrollbind
200
212
201
213
syncbind
202
214
endfunction
203
215
216
+ " Experimental
217
+ function ! s: DoHighlightGitBlame ()
218
+ for l in range (1 , line (' $' ))
219
+ let line = getline (l )
220
+ let [commit, author] = matchlist (line , ' \(\x\+\) (\(.\{-}\)\s* \d\d\d\d-\d\d-\d\d' )[1 :2 ]
221
+ let syntax_name = s: LoadSyntaxRuleFor ({ ' author' : author })
222
+ execute ' syntax match' syntax_name ' +\%' . l . ' l.*+'
223
+ endfor
224
+ endfunction
225
+
226
+ function ! s: LoadSyntaxRuleFor (params)
227
+ let author = a: params .author
228
+ let name = ' gitBlameAuthor_' . substitute (author, ' \s' , ' _' , ' g' )
229
+ if (! hlID (name))
230
+ if has_key (g: git_author_highlight , author)
231
+ execute ' highlight' name g: git_author_highlight [author]
232
+ else
233
+ let [n1, n2] = [0 , 1 ]
234
+ for c in split (author, ' \zs' )
235
+ let n1 = (n1 + char2nr (c )) % 8
236
+ let n2 = (n2 + char2nr (c ) * 3 ) % 8
237
+ endfor
238
+ if n1 == n2
239
+ let n1 = (n2 + 1 ) % 8
240
+ endif
241
+ execute ' highlight' name printf (' ctermfg=%d ctermbg=%d' , n1, n2)
242
+ endif
243
+ endif
244
+ return name
245
+ endfunction
246
+
204
247
function ! GitDoCommand (args )
205
248
let git_output = s: SystemGit (a: args )
206
249
let git_output = substitute (git_output, ' \n*$' , ' ' , ' ' )
0 commit comments