mail.vim (6041B)
1 " Vim syntax file 2 " Language: Mail file 3 " 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: Wed 14 Aug 2013 08:24:52 AM PDT 6 7 " Quit when a syntax file was already loaded 8 if exists("b:current_syntax") 9 finish 10 endif 11 12 let s:cpo_save = &cpo 13 set cpo&vim 14 15 " Include markdown syntax 16 runtime! syntax/markdown.vim 17 18 " The mail header is recognized starting with a "keyword:" line and ending 19 " with an empty line or other line that can't be in the header. All lines of 20 " the header are highlighted. Headers of quoted messages (quoted with >) are 21 " also highlighted. 22 23 " Syntax clusters 24 syn cluster mailHeaderFields contains=mailHeaderKey,mailSubject,mailHeaderEmail,@mailLinks 25 syn cluster mailLinks contains=mailURL,mailEmail 26 syn cluster mailQuoteExps contains=mailQuoteExp1,mailQuoteExp2,mailQuoteExp3,mailQuoteExp4,mailQuoteExp5,mailQuoteExp6 27 28 syn case match 29 " For "From " matching case is required. The "From " is not matched in quoted 30 " emails 31 " According to RFC 2822 any printable ASCII character can appear in a field 32 " name, except ':'. 33 syn region mailHeader contains=@mailHeaderFields,@NoSpell start="^From .*\d\d\d\d$" skip="^\s" end="\v^[!-9;-~]*([^!-~]|$)"me=s-1 fold 34 syn match mailHeaderKey contained contains=mailEmail,@NoSpell "^From\s.*\d\d\d\d$" 35 36 " Nothing else depends on case. 37 syn case ignore 38 39 " Headers in properly quoted (with "> " or ">") emails are matched 40 syn 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 fold 41 42 " Usenet headers 43 syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(Newsgroups|Followup-To|Message-ID|Supersedes|Control):.*$" 44 45 46 syn region mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@mailQuoteExps,@NoSpell start="\v(^(\> ?)*)@<=(to|b?cc):" skip=",$" end="$" 47 syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(from|reply-to):.*$" fold 48 syn match mailHeaderKey contained contains=@NoSpell "\v(^(\> ?)*)@<=date:" 49 syn match mailSubject contained "\v^subject:.*$" fold 50 syn match mailSubject contained contains=@NoSpell "\v(^(\> ?)+)@<=subject:.*$" 51 52 " Anything in the header between < and > is an email address 53 syn match mailHeaderEmail contained contains=@NoSpell "<.\{-}>" 54 55 " Mail Signatures. (Begin with "-- ", end with change in quote level) 56 syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps start="^--\s$" end="^$" end="^\(> \?\)\+"me=s-1 fold 57 syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)\+\)--\s$" end="^\z1$" end="^\z1\@!"me=s-1 end="^\z1\(> \?\)\+"me=s-1 fold 58 59 " Treat verbatim Text special. 60 syn region mailVerbatim contains=@NoSpell keepend start="^#v+$" end="^#v-$" fold 61 syn region mailVerbatim contains=@mailQuoteExps,@NoSpell keepend start="^\z(\(> \?\)\+\)#v+$" end="\z1#v-$" fold 62 63 " URLs start with a known protocol or www,web,w3. 64 syn match mailURL contains=@NoSpell `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-z0-9/]` 65 syn match mailEmail contains=@NoSpell "\v[_=a-z\./+0-9-]+\@[a-z0-9._-]+\a{2}" 66 67 " Make sure quote markers in regions (header / signature) have correct color 68 syn match mailQuoteExp1 contained "\v^(\> ?)" 69 syn match mailQuoteExp2 contained "\v^(\> ?){2}" 70 syn match mailQuoteExp3 contained "\v^(\> ?){3}" 71 syn match mailQuoteExp4 contained "\v^(\> ?){4}" 72 syn match mailQuoteExp5 contained "\v^(\> ?){5}" 73 syn match mailQuoteExp6 contained "\v^(\> ?){6}" 74 75 " Even and odd quoted lines. Order is important here! 76 syn region mailQuoted6 keepend contains=mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{5}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold 77 syn region mailQuoted5 keepend contains=mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{4}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold 78 syn region mailQuoted4 keepend contains=mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{3}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold 79 syn region mailQuoted3 keepend contains=mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{2}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold 80 syn region mailQuoted2 keepend contains=mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{1}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold 81 syn region mailQuoted1 keepend contains=mailQuoted2,mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z([a-z]\+>\|[]|}>]\)" end="^\z1\@!" fold 82 83 " Need to sync on the header. Assume we can do that within 100 lines 84 if exists("mail_minlines") 85 exec "syn sync minlines=" . mail_minlines 86 else 87 syn sync minlines=100 88 endif 89 90 hi def link mailVerbatim Special 91 hi mailHeader guifg=#575b72 92 hi def link mailHeaderKey Type 93 hi def link mailSignature PreProc 94 hi def link mailHeaderEmail mailEmail 95 hi def link mailEmail Special 96 hi def link mailURL String 97 hi def link mailSubject Title 98 hi mailQuoted1 guifg=#40445c 99 hi mailQuoted2 guifg=#575b72 100 hi mailQuoted3 guifg=#777b8e 101 hi mailQuoted4 guifg=#a3a6b3 102 hi mailQuoted5 guifg=#c7cad9 103 hi mailQuoted6 guifg=#40445c 104 hi def link mailQuoteExp1 mailQuoted1 105 hi def link mailQuoteExp2 mailQuoted2 106 hi def link mailQuoteExp3 mailQuoted3 107 hi def link mailQuoteExp4 mailQuoted4 108 hi def link mailQuoteExp5 mailQuoted5 109 hi def link mailQuoteExp6 mailQuoted6 110 111 let b:current_syntax = "mail" 112 113 let &cpo = s:cpo_save 114 unlet s:cpo_save