From e759a854866d0cc2d2995e4b4f1a2dae4568a1e0 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 19 Aug 2019 08:04:35 -0400 Subject: [PATCH] Provide separate highlight groups for file sections References https://github.com/tpope/vim-fugitive/issues/1159 --- syntax/fugitive.vim | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/syntax/fugitive.vim b/syntax/fugitive.vim index f3c497b..afc0c0b 100644 --- a/syntax/fugitive.vim +++ b/syntax/fugitive.vim @@ -9,24 +9,39 @@ syn include @fugitiveDiff syntax/diff.vim syn match fugitiveHeader /^[A-Z][a-z][^:]*:/ nextgroup=fugitiveHash,fugitiveSymbolicRef skipwhite -syn region fugitiveSection start=/^\%(.*(\d\+)$\)\@=/ contains=fugitiveHeading end=/^$\@=/ +syn region fugitiveSection start=/^\%(.*(\d\+)$\)\@=/ contains=fugitiveHeading end=/^$/ +syn cluster fugitiveSection contains=fugitiveSection syn match fugitiveHeading /^[A-Z][a-z][^:]*\ze (\d\+)$/ contains=fugitivePreposition contained nextgroup=fugitiveCount skipwhite syn match fugitiveCount /(\d\+)/hs=s+1,he=e-1 contained syn match fugitivePreposition /\<\%([io]nto\|from\|to\|Rebasing\%( detached\)\=\)\>/ transparent contained nextgroup=fugitiveHash,fugitiveSymbolicRef skipwhite -syn match fugitiveInstruction /^\l\l\+\>/ contained containedin=fugitiveSection nextgroup=fugitiveHash skipwhite -syn match fugitiveDone /^done\>/ contained containedin=fugitiveSection nextgroup=fugitiveHash skipwhite -syn match fugitiveStop /^stop\>/ contained containedin=fugitiveSection nextgroup=fugitiveHash skipwhite -syn match fugitiveModifier /^[MADRCU?]\{1,2} / contained containedin=fugitiveSection -syn match FugitiveSymbolicRef /\.\@!\%(\.\.\@!\|[^[:space:][:cntrl:]\:.]\)\+\.\@/ contained containedin=fugitiveSection +syn match fugitiveInstruction /^\l\l\+\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite +syn match fugitiveDone /^done\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite +syn match fugitiveStop /^stop\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite +syn match fugitiveModifier /^[MADRCU?]\{1,2} / contained containedin=@fugitiveSection +syn match fugitiveSymbolicRef /\.\@!\%(\.\.\@!\|[^[:space:][:cntrl:]\:.]\)\+\.\@/ contained containedin=@fugitiveSection syn match fugitiveHash /\<\x\{4,\}\>/ contained -syn region fugitiveHunk start=/^\%(@@\+ -\)\@=/ end=/^\%([A-Za-z?@]\|$\)\@=/ contains=@fugitiveDiff containedin=fugitiveSection fold +syn region fugitiveHunk start=/^\%(@@\+ -\)\@=/ end=/^\%([A-Za-z?@]\|$\)\@=/ contains=@fugitiveDiff containedin=@fugitiveSection fold + +for s:section in ['Untracked', 'Unstaged', 'Staged'] + exe 'syn region fugitive' . s:section . 'Section start=/^\%(' . s:section . ' .*(\d\+)$\)\@=/ contains=fugitive' . s:section . 'Heading end=/^$/' + exe 'syn match fugitive' . s:section . 'Modifier /^[MADRCU?] / contained containedin=fugitive' . s:section . 'Section' + exe 'syn cluster fugitiveSection add=fugitive' . s:section . 'Section' + exe 'syn match fugitive' . s:section . 'Heading /^[A-Z][a-z][^:]*\ze (\d\+)$/ contains=fugitivePreposition contained nextgroup=fugitiveCount skipwhite' +endfor +unlet s:section hi def link fugitiveHeader Label hi def link fugitiveHeading PreProc +hi def link fugitiveUntrackedHeading PreCondit +hi def link fugitiveUnstagedHeading Macro +hi def link fugitiveStagedHeading Include hi def link fugitiveModifier Type +hi def link fugitiveUntrackedModifier StorageClass +hi def link fugitiveUnstagedModifier Structure +hi def link fugitiveStagedModifier Typedef hi def link fugitiveInstruction Type hi def link fugitiveStop Function hi def link fugitiveHash Identifier