codekingpro/portable-devtools
114k
1" Vim syntax file2" Language: Mail file3" Previous Maintainer: Felix von Leitner <leitner@math.fu-berlin.de>4" Maintainer: GI <a@b.c>, where a='gi1242+vim', b='gmail', c='com'5" Last Change: Thu 25 Jan 2024 10:34:02 AM EST6 7" Quit when a syntax file was already loaded8if exists("b:current_syntax")9 finish10endif11 12let s:cpo_save = &cpo13set cpo&vim14 15syn spell toplevel16 17" The mail header is recognized starting with a "keyword:" line and ending18" with an empty line or other line that can't be in the header. All lines of19" the header are highlighted. Headers of quoted messages (quoted with >) are20" also highlighted.21 22" Syntax clusters23syn cluster mailHeaderFields contains=mailHeaderKey,mailSubject,mailHeaderEmail,@mailLinks24syn cluster mailLinks contains=mailURL,mailEmail25syn cluster mailQuoteExps contains=mailQuoteExp1,mailQuoteExp2,mailQuoteExp3,mailQuoteExp4,mailQuoteExp5,mailQuoteExp626 27syn case match28" For "From " matching case is required. The "From " is not matched in quoted29" emails30" According to RFC 2822 any printable ASCII character can appear in a field31" name, except ':'.32syn region mailHeader contains=@mailHeaderFields,@NoSpell start="^From .*\d\d\d\d$" skip="^\s" end="\v^[!-9;-~]*([^!-~]|$)"me=s-1 fold33syn match mailHeaderKey contained contains=mailEmail,@NoSpell "^From\s.*\d\d\d\d$"34 35" Nothing else depends on case. 36syn case ignore37 38" Headers in properly quoted (with "> " or ">") emails are matched39syn region mailHeader keepend contains=@mailHeaderFields,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)*\)\v(newsgroups|x-([a-z\-])*|path|xref|message-id|from|((in-)?reply-)?to|b?cc|subject|return-path|received|date|replied):" skip="^\z1\s" end="\v^\z1[!-9;-~]*([^!-~]|$)"me=s-1 end="\v^\z1@!"me=s-1 end="\v^\z1(\> ?)+"me=s-1 fold40 41" Usenet headers42syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(Newsgroups|Followup-To|Message-ID|Supersedes|Control):.*$"43 44 45syn region mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@mailQuoteExps,@NoSpell start="\v(^(\> ?)*)@<=(to|b?cc):" skip=",$" end="$"46syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(from|reply-to):.*$" fold47syn match mailHeaderKey contained contains=@NoSpell "\v(^(\> ?)*)@<=date:"48syn match mailSubject contained "\v^subject:.*$" fold49syn match mailSubject contained contains=@NoSpell "\v(^(\> ?)+)@<=subject:.*$"50 51" Anything in the header between < and > is an email address52syn match mailHeaderEmail contained contains=@NoSpell "<.\{-}>"53 54" Mail Signatures. (Begin with "-- ", end with change in quote level)55syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps start="^--\s$" end="^$" end="^\(> \?\)\+"me=s-1 fold56syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)\+\)--\s$" end="^\z1$" end="^\z1\@!"me=s-1 end="^\z1\(> \?\)\+"me=s-1 fold57 58" Treat verbatim Text special.59syn region mailVerbatim contains=@NoSpell keepend start="^#v+$" end="^#v-$" fold 60syn region mailVerbatim contains=@mailQuoteExps,@NoSpell keepend start="^\z(\(> \?\)\+\)#v+$" end="\z1#v-$" fold 61 62" URLs start with a known protocol or www,web,w3.63syn match mailURL contains=@NoSpell `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-z0-9/]`64syn match mailEmail contains=@NoSpell "\v[_=a-z\./+0-9-]+\@[a-z0-9._-]+\a{2}"65 66" Don't spell emojis67syn match mailEmoji contains=@NoSpell "\%#=2\v[\U1f300-\U1f64f\U1f900-\U1f9ff]"68 69" Make sure quote markers in regions (header / signature) have correct color70syn match mailQuoteExp1 contained "\v^(\> ?)"71syn match mailQuoteExp2 contained "\v^(\> ?){2}"72syn match mailQuoteExp3 contained "\v^(\> ?){3}"73syn match mailQuoteExp4 contained "\v^(\> ?){4}"74syn match mailQuoteExp5 contained "\v^(\> ?){5}"75syn match mailQuoteExp6 contained "\v^(\> ?){6}"76 77" Even and odd quoted lines. Order is important here!78syn region mailQuoted6 keepend contains=mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{5}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold79syn region mailQuoted5 keepend contains=mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{4}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold80syn region mailQuoted4 keepend contains=mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{3}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold81syn region mailQuoted3 keepend contains=mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{2}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold82syn region mailQuoted2 keepend contains=mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{1}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold83syn region mailQuoted1 keepend contains=mailQuoted2,mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z([a-z]\+>\|[]|}>]\)" end="^\z1\@!" fold84 85" Need to sync on the header. Assume we can do that within 100 lines86if exists("mail_minlines")87 exec "syn sync minlines=" . mail_minlines88else89 syn sync minlines=10090endif91 92" Define the default highlighting.93hi def link mailVerbatim Special94hi def link mailHeader PreProc95hi def link mailHeaderKey Type96hi def link mailSignature Comment97hi def link mailHeaderEmail mailEmail98hi def link mailEmail String99hi def link mailURL Constant100hi def link mailSubject Statement101hi def link mailQuoted1 Function102hi def link mailQuoted3 mailQuoted1103hi def link mailQuoted5 mailQuoted1104hi def link mailQuoted2 Identifier105hi def link mailQuoted4 mailQuoted2106hi def link mailQuoted6 mailQuoted2107hi def link mailQuoteExp1 mailQuoted1108hi def link mailQuoteExp2 mailQuoted2109hi def link mailQuoteExp3 mailQuoted3110hi def link mailQuoteExp4 mailQuoted4111hi def link mailQuoteExp5 mailQuoted5112hi def link mailQuoteExp6 mailQuoted6113 114let b:current_syntax = "mail"115 116let &cpo = s:cpo_save117unlet s:cpo_save118 