Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Mail file |
| 3 | " Previous Maintainer: Felix von Leitner <leitner@math.fu-berlin.de> |
| 4 | " Maintainer: Gautam Iyer <gautam@math.uchicago.edu> |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 5 | " Last Change: Thu 10 Feb 2005 09:46:26 AM CST |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
| 25 | syn region mailHeader contains=@mailHeaderFields start="^From " skip="^\s" end="\v^[-A-Za-z0-9]*([^-A-Za-z0-9:]|$)"me=s-1 |
| 26 | syn match mailHeaderKey contained contains=mailEmail "^From\s.*$" |
| 27 | |
| 28 | syn case ignore |
| 29 | " Nothing else depends on case. Headers in properly quoted (with "> " or ">") |
| 30 | " emails are matched |
| 31 | syn region mailHeader keepend contains=@mailHeaderFields,@mailQuoteExps start="^\z(\(> \?\)*\)\v(newsgroups|from|((in-)?reply-)?to|b?cc|subject|return-path|received|date|replied):" skip="^\z1\s" end="\v^\z1[-a-z0-9]*([^-a-z0-9:]|$)"me=s-1 end="\v^\z1@!"me=s-1 end="\v^\z1(\> ?)+"me=s-1 |
| 32 | |
| 33 | syn region mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@mailQuoteExps start="\v(^(\> ?)*)@<=(to|b?cc):" skip=",$" end="$" |
| 34 | syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail "\v(^(\> ?)*)@<=(from|reply-to):.*$" |
| 35 | syn match mailHeaderKey contained "\v(^(\> ?)*)@<=date:" |
| 36 | syn match mailSubject contained "\v(^(\> ?)*)@<=subject:.*$" contains=@Spell |
| 37 | |
| 38 | " Anything in the header between < and > is an email address |
| 39 | syn match mailHeaderEmail contained "<.\{-}>" |
| 40 | |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 41 | " Mail Signatures. (Begin with "-- ", end with change in quote level) |
| 42 | syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps start="^\z(\(> \?\)*\)-- $" end="^\z1$" end="^\z1\@!"me=s-1 end="^\z1\(> \?\)\+"me=s-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 43 | |
| 44 | " URLs start with a known protocol or www,web,w3. |
| 45 | syn match mailURL `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-z0-9/]` |
| 46 | syn match mailEmail "\v[_=a-z\./+0-9-]+\@[a-z0-9._-]+\a{2}" |
| 47 | |
| 48 | " Make sure quote markers in regions (header / signature) have correct color |
| 49 | syn match mailQuoteExp1 contained "\v^(\> ?)" |
| 50 | syn match mailQuoteExp2 contained "\v^(\> ?){2}" |
| 51 | syn match mailQuoteExp3 contained "\v^(\> ?){3}" |
| 52 | syn match mailQuoteExp4 contained "\v^(\> ?){4}" |
| 53 | syn match mailQuoteExp5 contained "\v^(\> ?){5}" |
| 54 | syn match mailQuoteExp6 contained "\v^(\> ?){6}" |
| 55 | |
| 56 | " Even and odd quoted lines. order is imporant here! |
| 57 | syn match mailQuoted1 contains=mailHeader,@mailLinks,mailSignature "^\([a-z]\+>\|[]|}>]\).*$" |
| 58 | syn match mailQuoted2 contains=mailHeader,@mailLinks,mailSignature "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{2}.*$" |
| 59 | syn match mailQuoted3 contains=mailHeader,@mailLinks,mailSignature "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{3}.*$" |
| 60 | syn match mailQuoted4 contains=mailHeader,@mailLinks,mailSignature "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{4}.*$" |
| 61 | syn match mailQuoted5 contains=mailHeader,@mailLinks,mailSignature "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{5}.*$" |
| 62 | syn match mailQuoted6 contains=mailHeader,@mailLinks,mailSignature "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{6}.*$" |
| 63 | |
| 64 | " Need to sync on the header. Assume we can do that within 100 lines |
| 65 | if exists("mail_minlines") |
| 66 | exec "syn sync minlines=" . mail_minlines |
| 67 | else |
| 68 | syn sync minlines=100 |
| 69 | endif |
| 70 | |
| 71 | " Define the default highlighting. |
| 72 | hi def link mailHeader Statement |
| 73 | hi def link mailHeaderKey Type |
| 74 | hi def link mailSignature PreProc |
| 75 | hi def link mailHeaderEmail mailEmail |
| 76 | hi def link mailEmail Special |
| 77 | hi def link mailURL String |
| 78 | hi def link mailSubject LineNR |
| 79 | hi def link mailQuoted1 Comment |
| 80 | hi def link mailQuoted3 mailQuoted1 |
| 81 | hi def link mailQuoted5 mailQuoted1 |
| 82 | hi def link mailQuoted2 Identifier |
| 83 | hi def link mailQuoted4 mailQuoted2 |
| 84 | hi def link mailQuoted6 mailQuoted2 |
| 85 | hi def link mailQuoteExp1 mailQuoted1 |
| 86 | hi def link mailQuoteExp2 mailQuoted2 |
| 87 | hi def link mailQuoteExp3 mailQuoted3 |
| 88 | hi def link mailQuoteExp4 mailQuoted4 |
| 89 | hi def link mailQuoteExp5 mailQuoted5 |
| 90 | hi def link mailQuoteExp6 mailQuoted6 |
| 91 | |
| 92 | let b:current_syntax = "mail" |