Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Git Log (and Log Graph) Branch Name Highlighting #78

Closed
KSR-Yasuda opened this issue Sep 13, 2021 · 2 comments
Closed

Comments

@KSR-Yasuda
Copy link

KSR-Yasuda commented Sep 13, 2021

Couldn't you highlight branch name in git log --decorate and git log --decorate --graph?

In --all mode, highlighting would be strongly expected to find branches easily.

LogGraph_BranchRefName_Highlight


I started the first step with the diff below,
however, by my poor vim-syntax knowledge,
I couldn't avoid the false positive that contains () in commit message...

--- a/syntax/git.vim
+++ b/syntax/git.vim
@@ -18,8 +18,10 @@ syn region gitHead start=/\%(^commit\%( \x\{4,\}\)\{1,\}\%(\s*(.*)\)\=$\)\@=/ en
 " minimize false positives by verifying contents of buffer
 if getline(1) =~# '^\x\{7,\} ' && getline('$') =~# '^\x\{7,\} '
   syn match gitHashAbbrev /^\x\{7,\} \@=/ contains=@NoSpell
+  syn match gitHashRef    /(.\{-})/ contains=@NoSpell
 elseif getline(1) =~#     '^[|\/\\_ ]\{-\}\*[|\/\\_ ]\{-\} \x\{7,\} '
   syn match gitHashAbbrev /^[|\/\\_ ]\{-\}\*[|\/\\_ ]\{-\} \zs\x\{7,\} \@=/ contains=@NoSpell
+  syn match gitHashRef    /(.\{-})/ contains=@NoSpell
 endif
 " git log --graph
 syn region gitGraph start=/\%(^[|\/\\_ ]*\*[|\/\\_ ]\{-\} commit\%( \x\{4,\}\)\{1,\}\%(\s*(.*)\)\=$\)\@=/ end=/^\%([|\/\\_ ]*$\)\@=/ contains=@NoSpell
@@ -74,12 +76,13 @@ syn match  gitDate      /-\=\d\+ [+-]\d\d\d\d\>/               contained
 syn match  gitDate      /\<\d\+ \l\+ ago\>/                    contained
 syn match  gitType      /\<\%(tag\|commit\|tree\|blob\)\>/     contained nextgroup=gitHashAbbrev skipwhite
 syn match  gitReference /\S\+\S\@!/                            contained
-syn match  gitHash      /\<\x\{40,\}\>/             contained nextgroup=gitIdentity,gitHash skipwhite contains=@NoSpell
+syn match  gitHash      /\<\x\{40,\}\>/             contained nextgroup=gitIdentity,gitHash,gitHashRef skipwhite contains=@NoSpell
 syn match  gitReflogOld /^\x\{40,\} \@=/            contained nextgroup=gitReflogNew skipwhite contains=@NoSpell
 syn match  gitReflogNew /\<\x\{40,\} \@=/           contained nextgroup=gitIdentity skipwhite contains=@NoSpell
-syn match  gitHashAbbrev /\<\x\{4,\}\>/             contained nextgroup=gitHashAbbrev skipwhite contains=@NoSpell
-syn match  gitHashAbbrev /\<\x\{4,39\}\.\.\./he=e-3 contained nextgroup=gitHashAbbrev skipwhite contains=@NoSpell
+syn match  gitHashAbbrev /\<\x\{4,\}\>/             contained nextgroup=gitHashAbbrev,gitHashRef skipwhite contains=@NoSpell
+syn match  gitHashAbbrev /\<\x\{4,39\}\.\.\./he=e-3 contained nextgroup=gitHashAbbrev,gitHashRef skipwhite contains=@NoSpell
 syn match  gitHashStage /\<\x\{4,\}\>/              contained nextgroup=gitStage skipwhite contains=@NoSpell
+syn match  gitHashRef /(.\{-})/                     contained skipwhite contains=@NoSpell
 syn match  gitStage     /\<\d\t\@=/                 contained
 
 
@@ -98,6 +101,7 @@ hi def link gitDate              Number
 hi def link gitMode              Number
 hi def link gitHashStage         gitHash
 hi def link gitHashAbbrev        gitHash
+hi def link gitHashRef           gitIdentityKeyword
 hi def link gitReflogOld         gitHash
 hi def link gitReflogNew         gitHash
 hi def link gitHash              Identifier
@tpope
Copy link
Owner

tpope commented Sep 13, 2021

The solution to your false positive is nextgroup. But I'm worried about other false positives, commit messages like (Hopefully) fix bug. Since --decorate is not the default, most people will only ever see false positives. That's why I decided it not to bother with this at all. Not saying I will never budge on this, but it's going to be an uphill battle. You might want to start with the more modest goal of fixing the --decorate --pretty=medium case.

See also the loosely related tpope/vim-fugitive#1713 (comment).

@tpope tpope closed this as completed Sep 13, 2021
@KSR-Yasuda
Copy link
Author

Okay, I got it's not quite easy. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants