Skip to content

Commit

Permalink
syntax/magit.vim: rework syntax file
Browse files Browse the repository at this point in the history
simplify some rules, prefer match VS region when possible
(region where misused, as match is enough)
  • Loading branch information
jreybert committed Feb 22, 2017
1 parent e4c4c18 commit 910c21b
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions syntax/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ syn include @diff syntax/diff.vim
execute 'syn match titleEntry "' . g:magit_section_re . '\n=\+"'
hi def link titleEntry Comment

execute 'syn match commitMsgExceed "\(=\+\n.\{' . g:magit_commit_title_limit . '}\)\@<=.*$"'
execute 'syn region commitMsg start=/' . g:magit_sections.commit . '/ end=/\%(' . g:magit_section_re . '\)\@=/ contains=titleEntry'
execute 'syn match commitMsgExceed "\%(=\+\n\+\_^.\{' . g:magit_commit_title_limit . '}\)\@<=.*$" contained containedin=commitMsg'
hi def link commitMsgExceed Comment

execute 'syn match stashEntry "' . g:magit_stash_re . '"'
Expand All @@ -22,8 +23,6 @@ hi def link stashEntry String
execute 'syn match fileEntry "' . g:magit_file_re . '"'
hi def link fileEntry String

execute 'syn region gitTitle start=/^$\n' . g:magit_section_re . '/ end=/^$/ contains=titleEntry,commitMsgExceed'

execute 'syn region gitStash start=/' . g:magit_stash_re . '/ end=/\%(' .
\ g:magit_stash_re . '\)\@=/ contains=stashEntry fold'

Expand All @@ -34,23 +33,15 @@ execute 'syn region gitHunk start=/' .
\ g:magit_hunk_re . '/ end=/\%(' . g:magit_end_diff_re . '\|' . g:magit_hunk_re
\ '\)\@=/ contains=@diff fold'

execute 'syn region gitInfo start=/^' . g:magit_sections.info . '$/ end=/' .
\ g:magit_section_re . '/'
execute 'syn match gitInfoRepo "\%(' . g:magit_section_info.cur_repo . ':\)\@<=.*$" oneline'
execute 'syn match gitInfoBranch "\%(' . g:magit_section_info.cur_branch . ':\)\@<=.*$" oneline'
execute 'syn match gitCommitMode "\%(' . g:magit_section_info.commit_mode . ':\)\@<=.*$" oneline'
execute 'syn match gitInfoCommit "\%(' . g:magit_section_info.cur_commit . ':\)\@<=.*$" contains=infoSha1 oneline'
syntax match infoSha1 containedin=gitInfoCommit "\x\{7}"

execute 'syn region gitInfoRepo start=/^' . g:magit_section_info.cur_repo .
\ ':\s*.*/hs=s+20 end=/$/ oneline'
highlight default link gitInfoRepo Directory
execute 'syn region gitInfoBranch start=/^' . g:magit_section_info.cur_branch .
\ ':\s*.*/hs=s+20 end=/$/ oneline'
highlight default link gitInfoBranch Identifier
execute 'syn region gitCommitMode start=/^' . g:magit_section_info.commit_mode .
\ ':\s*.*/hs=s+20 end=/$/ oneline'
highlight default link gitCommitMode Special

execute 'syn region gitInfoCommit start=/^' . g:magit_section_info.cur_commit .
\ ':\s*\(.*\)/ end=/$/ contains=infoSha1 oneline'
syntax match infoSha1 containedin=gitInfoCommit "\x\{7}"
highlight default link infoSha1 Identifier


let b:current_syntax = "magit"

0 comments on commit 910c21b

Please sign in to comment.