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