From 6efa5c1e9d9a23c17d8ce0e78764aced19826d86 Mon Sep 17 00:00:00 2001 From: Rocky Zhang Date: Fri, 16 May 2025 00:24:53 -0700 Subject: [PATCH] fix: syntax mismatch in git diff --- syntax/gitmessengerpopup.vim | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/syntax/gitmessengerpopup.vim b/syntax/gitmessengerpopup.vim index 10f8c0f..2afd393 100644 --- a/syntax/gitmessengerpopup.vim +++ b/syntax/gitmessengerpopup.vim @@ -2,10 +2,18 @@ if exists('b:current_syntax') finish endif -syn match gitmessengerHeader '^ \=\%(History\|Commit\|\%(Author \|Committer \)\=Date\|Author\|Committer\):' display -syn match gitmessengerHash '\%(^ \=Commit: \+\)\@<=[[:xdigit:]]\+' display -syn match gitmessengerHistory '\%(^ \=History: \+\)\@<=#\d\+' display -syn match gitmessengerEmail '\%(^ \=\%(Author\|Committer\): \+.*\)\@<=<.\+>' display +if get(g:, 'git_messenger_popup_content_margins', v:true) + let s:margin_pat = '^ ' +else + let s:margin_pat = '^' +endif + +exe 'syn sync minlines=' . &lines + +exe 'syn match gitmessengerHeader "' . s:margin_pat . '\%(History\|Commit\|\%(Author \|Committer \)\=Date\|Author\|Committer\):" display' +exe 'syn match gitmessengerHash "\%(' . s:margin_pat . 'Commit: \+\)\@<=[[:xdigit:]]\+" display' +exe 'syn match gitmessengerHistory "\%(' . s:margin_pat . 'History: \+\)\@<=#\d\+" display' +exe 'syn match gitmessengerEmail "\%(' . s:margin_pat . '\%(Author\|Committer\): \+.*\)\@<=<.\+>" display' " Diff included in popup " There are two types of diff format; 'none' 'current', 'all', 'current.word', 'all.word'. @@ -14,22 +22,24 @@ syn match gitmessengerEmail '\%(^ \=\%(Author\|Committer\): \+.*\)\@<=<.\+>' dis " b:__gitmessenger_diff is set by Blame.render() in blame.vim. if get(b:, '__gitmessenger_diff', '') =~# '\.word$' if has('conceal') && get(g:, 'git_messenger_conceal_word_diff_marker', v:true) - syn region diffWordsRemoved matchgroup=Conceal start=/\[-/ end=/-]/ concealends oneline - syn region diffWordsAdded matchgroup=Conceal start=/{+/ end=/+}/ concealends oneline + syn region diffWordsRemoved matchgroup=Conceal start=/\[-/ end=/-]/ concealends oneline contained containedin=gitDiff + syn region diffWordsAdded matchgroup=Conceal start=/{+/ end=/+}/ concealends oneline contained containedin=gitDiff else - syn region diffWordsRemoved start=/\[-/ end=/-]/ oneline - syn region diffWordsAdded start=/{+/ end=/+}/ oneline + syn region diffWordsRemoved start=/\[-/ end=/-]/ oneline contained containedin=gitDiff + syn region diffWordsAdded start=/{+/ end=/+}/ oneline contained containedin=gitDiff endif else - syn match diffRemoved "^ \=-.*" display - syn match diffAdded "^ \=+.*" display + exe 'syn match diffRemoved "' . s:margin_pat . '-.*" contained containedin=gitDiff display' + exe 'syn match diffAdded "' . s:margin_pat . '+.*" contained containedin=gitDiff display' endif -syn match diffFile "^ \=diff --git .*" display -syn match diffOldFile "^ \=--- a\>.*" display -syn match diffNewFile "^ \=+++ b\>.*" display -syn match diffIndexLine "^ \=index \x\{7,}\.\.\x\{7,}.*" display -syn match diffLine "^ \=@@ .*" display +exe 'syn match diffFile "' . s:margin_pat . 'diff --git .*" display' +exe 'syn match diffOldFile "' . s:margin_pat . '--- \(a\>.*\|/dev/null\)" display' +exe 'syn match diffNewFile "' . s:margin_pat . '+++ \(b\>.*\|/dev/null\)" display' +exe 'syn match diffIndexLine "' . s:margin_pat . 'index \x\{7,}\.\.\x\{7,}.*" display' +exe 'syn match diffLine "' . s:margin_pat . '@@ .*" contained containedin=gitDiff display' + +exec 'syn region gitDiff start=/' . s:margin_pat . '\%(@@ -\)\@=/ end=/' . s:margin_pat . '\%(diff --git\)\@=/ contains=diffRemoved,diffAdded,diffLine,diffWordsRemoved,diffWordsAdded' hi def link gitmessengerHeader Identifier hi def link gitmessengerHash Comment