mail.vim 5.9 KB

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