Skip to content

Commit d52b554

Browse files
committed
fix: syntax mismatch in git diff
1 parent edc603d commit d52b554

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

syntax/gitmessengerpopup.vim

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ if exists('b:current_syntax')
22
finish
33
endif
44

5-
syn match gitmessengerHeader '^ \=\%(History\|Commit\|\%(Author \|Committer \)\=Date\|Author\|Committer\):' display
6-
syn match gitmessengerHash '\%(^ \=Commit: \+\)\@<=[[:xdigit:]]\+' display
7-
syn match gitmessengerHistory '\%(^ \=History: \+\)\@<=#\d\+' display
8-
syn match gitmessengerEmail '\%(^ \=\%(Author\|Committer\): \+.*\)\@<=<.\+>' display
5+
if get(g:, 'git_messenger_popup_content_margins', v:true)
6+
let margin_pat = '^ '
7+
else
8+
let margin_pat = '^'
9+
endif
10+
11+
syn sync fromstart
12+
13+
exe 'syn match gitmessengerHeader "' . margin_pat . '\%(History\|Commit\|\%(Author \|Committer \)\=Date\|Author\|Committer\):" display'
14+
exe 'syn match gitmessengerHash "\%(' . margin_pat . 'Commit: \+\)\@<=[[:xdigit:]]\+" display'
15+
exe 'syn match gitmessengerHistory "\%(' . margin_pat . 'History: \+\)\@<=#\d\+" display'
16+
exe 'syn match gitmessengerEmail "\%(' . margin_pat . '\%(Author\|Committer\): \+.*\)\@<=<.\+>" display'
917

1018
" Diff included in popup
1119
" There are two types of diff format; 'none' 'current', 'all', 'current.word', 'all.word'.
@@ -14,22 +22,24 @@ syn match gitmessengerEmail '\%(^ \=\%(Author\|Committer\): \+.*\)\@<=<.\+>' dis
1422
" b:__gitmessenger_diff is set by Blame.render() in blame.vim.
1523
if get(b:, '__gitmessenger_diff', '') =~# '\.word$'
1624
if has('conceal') && get(g:, 'git_messenger_conceal_word_diff_marker', v:true)
17-
syn region diffWordsRemoved matchgroup=Conceal start=/\[-/ end=/-]/ concealends oneline
18-
syn region diffWordsAdded matchgroup=Conceal start=/{+/ end=/+}/ concealends oneline
25+
syn region diffWordsRemoved matchgroup=Conceal start=/\[-/ end=/-]/ concealends oneline contained containedin=gitDiff
26+
syn region diffWordsAdded matchgroup=Conceal start=/{+/ end=/+}/ concealends oneline contained containedin=gitDiff
1927
else
20-
syn region diffWordsRemoved start=/\[-/ end=/-]/ oneline
21-
syn region diffWordsAdded start=/{+/ end=/+}/ oneline
28+
syn region diffWordsRemoved start=/\[-/ end=/-]/ oneline contained containedin=gitDiff
29+
syn region diffWordsAdded start=/{+/ end=/+}/ oneline contained containedin=gitDiff
2230
endif
2331
else
24-
syn match diffRemoved "^ \=-.*" display
25-
syn match diffAdded "^ \=+.*" display
32+
exe 'syn match diffRemoved "' . margin_pat . '-.*" contained containedin=gitDiff display'
33+
exe 'syn match diffAdded "' . margin_pat . '+.*" contained containedin=gitDiff display'
2634
endif
2735

28-
syn match diffFile "^ \=diff --git .*" display
29-
syn match diffOldFile "^ \=--- a\>.*" display
30-
syn match diffNewFile "^ \=+++ b\>.*" display
31-
syn match diffIndexLine "^ \=index \x\{7,}\.\.\x\{7,}.*" display
32-
syn match diffLine "^ \=@@ .*" display
36+
exe 'syn match diffFile "' . margin_pat . 'diff --git .*" display'
37+
exe 'syn match diffOldFile "' . margin_pat . '--- \(a\>.*\|/dev/null\)" display'
38+
exe 'syn match diffNewFile "' . margin_pat . '+++ \(b\>.*\|/dev/null\)" display'
39+
exe 'syn match diffIndexLine "' . margin_pat . 'index \x\{7,}\.\.\x\{7,}.*" display'
40+
exe 'syn match diffLine "' . margin_pat . '@@ .*" contained containedin=gitDiff display'
41+
42+
exec 'syn region gitDiff start=/' . margin_pat . '\%(@@ -\)\@=/ end=/' . margin_pat . '\%(diff --git\)\@=/ contains=diffRemoved,diffAdded,diffLine,diffWordsRemoved,diffWordsAdded'
3343

3444
hi def link gitmessengerHeader Identifier
3545
hi def link gitmessengerHash Comment

0 commit comments

Comments
 (0)