Skip to content

Commit 368ea85

Browse files
committed
Prevent false-positive ref syntax highlighting in Gstatus
Subject lines that begin with an open parenthesis and have no other refs attached have their first parenthesised text syntax highlighted. Use concealed artificial parentheses in such cases.
1 parent d566080 commit 368ea85

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

autoload/fugitive.vim

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,33 +1705,49 @@ function! s:IgnoreRefs(refs, refsToIgnore) abort
17051705
return index(a:refsToIgnore, a:ref) == -1
17061706
endfunction
17071707

1708+
" Strip the outer parentheses
17081709
let refs = split(a:refs[1:-2], ", ")
17091710
let refs = filter(refs, function('ShouldPreserveRef', [a:refsToIgnore]))
17101711

17111712
if len(a:refs) == 0
17121713
return ''
17131714
endif
17141715

1715-
return '(' . join(refs, ", ") . ')'
1716+
return '(' . join(refs, ", ") . ') '
17161717
endfunction
17171718

17181719
function! s:QueryLog(refspec, refToIgnore) abort
17191720
let lines = s:LinesError(['log', '-n', '256', '--pretty=format:%h%x09%d%x09%s', a:refspec, '--'])[0]
17201721
call map(lines, 'split(v:val, "\t", 1)')
17211722
let refsToIgnore = [a:refToIgnore, 'HEAD']
17221723

1723-
function! HandleRefs(refsToIgnore, refs) abort
1724-
return s:IgnoreRefs(trim(a:refs), a:refsToIgnore)
1724+
function! HandleRefs(refsToIgnore, subject, refs) abort
1725+
let refs = trim(a:refs)
1726+
let refs = s:IgnoreRefs(refs, a:refsToIgnore)
1727+
1728+
if len(refs) == 0 && a:subject[0] == '('
1729+
" Add artificial (concealed) empty parentheses for refs. Helps avoid
1730+
" syntax highlighting false-positives (subject lines beginning with an
1731+
" open parenthesis).
1732+
return '()'
1733+
endif
1734+
1735+
return refs
1736+
endfunction
1737+
1738+
function! CreateLineDict(refsToIgnore, index, parts) abort
1739+
let subject = join(a:parts[2 : -1], "\t")
1740+
return {"type": "Log", "commit": a:parts[0], "refs": HandleRefs(a:refsToIgnore, subject, a:parts[1]), "subject": subject}
17251741
endfunction
17261742

1727-
call map(lines, '{"type": "Log", "commit": v:val[0], "refs": ' . string(function('HandleRefs', [refsToIgnore])) . '(v:val[1]), "subject": join(v:val[2 : -1], "\t")}')
1743+
call map(lines, function('CreateLineDict', [refsToIgnore]))
17281744
return lines
17291745
endfunction
17301746

17311747
function! s:FormatLog(dict) abort
17321748
setlocal conceallevel=3
17331749
setlocal concealcursor=nc
1734-
return a:dict.commit . ' ' . ((len(a:dict.refs) > 0) ? ("\x1f" . a:dict.refs . ' ') : '') . a:dict.subject
1750+
return a:dict.commit . ' ' . ((len(a:dict.refs) > 0) ? a:dict.refs : '') . a:dict.subject
17351751
endfunction
17361752

17371753
function! s:FormatRebase(dict) abort

syntax/fugitive.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ syn match fugitiveDone /^done\>/ contained containedin=@fugitiveSection nextgrou
2323
syn match fugitiveStop /^stop\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite
2424
syn match fugitiveModifier /^[MADRCU?]\{1,2} / contained containedin=@fugitiveSection
2525
syn match fugitiveSymbolicRef /\.\@!\%(\.\.\@!\|[^[:space:][:cntrl:]\:.]\)\+\.\@<!/ contained
26-
syn match fugitiveHash /^\x\{4,\}\S\@!/ contained containedin=@fugitiveSection nextgroup=fugitiveRefsConcealedMarker skipwhite
26+
syn match fugitiveHash /^\x\{4,\}\S\@!/ contained containedin=@fugitiveSection nextgroup=fugitiveRefs skipwhite
2727
syn match fugitiveHash /\S\@<!\x\{4,\}\S\@!/ contained
28-
syn match fugitiveRefsConcealedMarker "\%x1f" contained nextgroup=fugitiveRefs conceal
28+
syn match fugitiveRefs '()' contained conceal
2929
syn match fugitiveRefs /([^)]\+)/hs=s+1,he=e-1 contained
3030

3131
syn region fugitiveHunk start=/^\%(@@\+ -\)\@=/ end=/^\%([A-Za-z?@]\|$\)\@=/ contains=@fugitiveDiff containedin=@fugitiveSection fold

0 commit comments

Comments
 (0)