vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

icalendar.vim (4966B)


      1 " Vim syntax file
      2 " Language:             iCalendar
      3 " Maintainer:           Anakin Childerhose <anakin@childerhose.ca>
      4 " Latest Change:        2026 Sept 22
      5 " License:              Vim (see :h license)
      6 
      7 if exists("b:current_syntax")
      8   finish
      9 endif
     10 
     11 let s:cpo_save = &cpo
     12 set cpo&vim
     13 
     14 syntax sync minlines=150
     15 
     16 " component delineating content lines {{{
     17 "
     18 "  BEGIN:VCALENDAR
     19 "  ^^^^^ icalendarComponentBegin
     20 "       ^ icalendarComponentSeparator
     21 "        ^^^^^^^^^ icalendarComponentType
     22 "  END:VCALENDAR
     23 "  ^^^ icalendarComponentEnd
     24 "     ^ icalendarComponentSeparator
     25 "      ^^^^^^^^^ icalendarComponentType
     26 "
     27 " Line folding in these lines is technically valid but rare so it is ignored to
     28 " keep the following lines simpler
     29 syntax keyword icalendarComponentBegin BEGIN nextgroup=icalendarComponentSeparator
     30 syntax keyword icalendarComponentEnd END nextgroup=icalendarComponentSeparator
     31 syntax match icalendarComponentSeparator ":" contained nextgroup=icalendarComponentType
     32 syntax match icalendarComponentType "\w\+" contained
     33 " component delineating content lines }}}
     34 
     35 
     36 " property content lines {{{
     37 "
     38 "  TRIGGER;RELATED=START:-PT10M
     39 "  ^^^^^^^ icalendarPropertyName
     40 "         ^ icalendarParamSeparator
     41 "          ^^^^^^^ icalendarPropertyParamName
     42 "                 ^ icalendarParamEquals
     43 "                  ^^^^^ icalendarPropertyParamValue
     44 "                       ^ icalendarPropertySeparator
     45 "                        ^^^^^^ icalendarPropertyValue
     46 "
     47 " Line folding can occur between any two characters so practically every match
     48 " needs to support possible folds
     49 
     50 let s:fold = '\n[ \t]'
     51 let s:prop_chars = '[A-Za-z0-9-]'
     52 let s:name_regex = $'\({s:prop_chars}\|{s:fold}\)*'
     53 let s:safe_chars = '[^";:,]'
     54 
     55 execute $'syntax match icalendarPropertyName "^{s:name_regex}" nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
     56 execute $'syntax match icalendarParamSeparator ";\({s:fold}\)*" contained nextgroup=icalendarPropertyParamName'
     57 execute $'syntax match icalendarPropertyParamName "{s:name_regex}" contained nextgroup=icalendarParamEquals'
     58 execute $'syntax match icalendarParamEquals "=\({s:fold}\)*" contained nextgroup=icalendarPropertyParamValue'
     59 " collect safe chars and folds
     60 execute $'syntax match icalendarPropertyParamValue "\({s:safe_chars}\|{s:fold}\)\+" contained nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
     61 " unsafe chars need to be quoted:
     62 " if a value starts with a double quote, ", collect all characters upto the next
     63 " double quote, [^"]*, including newlines, \_ followed by zero or more folds
     64 execute $'syntax match icalendarPropertyParamValue "\"\_[^\"]*\"\({s:fold}\)*" contained nextgroup=icalendarParamSeparator,icalendarPropertySeparator'
     65 execute $'syntax match icalendarPropertySeparator ":\({s:fold}\)*" contained nextgroup=icalendarPropertyValue'
     66 execute $'syntax match icalendarPropertyValue "\([^\n]\|{s:fold}\)*" contained'
     67 " property content lines }}}
     68 
     69 
     70 " recurring rules {{{
     71 "
     72 "  RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU
     73 "  ^^^^^ icalendarRrule
     74 "       ^ icalendarRruleSeparator
     75 "        ^^^^ icalendarRruleParamName
     76 "            ^ icalendarRruleEquals
     77 "             ^^^^^^ icalendarRruleParamValue
     78 "                   ^ icalendarRruleParamSeparator
     79 "
     80 let s:rrule_chars = '[A-Za-z0-9-+,]'
     81 
     82 syntax keyword icalendarRrule RRULE nextgroup=icalendarRruleSeparator
     83 execute $'syntax match icalendarRruleSeparator ":\({s:fold}\)*" contained nextgroup=icalendarRruleParamName'
     84 execute $'syntax match icalendarRruleParamName "{s:name_regex}" contained nextgroup=icalendarRruleEquals'
     85 execute $'syntax match icalendarRruleEquals "=\({s:fold}\)*" contained nextgroup=icalendarRruleParamValue'
     86 execute $'syntax match icalendarRruleParamValue "\({s:rrule_chars}\|{s:fold}\)\+" contained nextgroup=icalendarRruleParamSeparator'
     87 execute $'syntax match icalendarRruleParamSeparator ";\({s:fold}\)*" contained nextgroup=icalendarRruleParamName'
     88 " recurring rules }}}
     89 
     90 highlight default link icalendarComponentBegin Structure
     91 highlight default link icalendarComponentEnd Structure
     92 highlight default link icalendarComponentSeparator Operator
     93 highlight default link icalendarComponentType Type
     94 
     95 highlight default link icalendarPropertyName Identifier
     96 highlight default link icalendarParamSeparator Operator
     97 highlight default link icalendarPropertyParamName Type
     98 highlight default link icalendarParamEquals Operator
     99 highlight default link icalendarPropertyParamValue String
    100 highlight default link icalendarPropertySeparator Operator
    101 highlight default link icalendarPropertyValue Constant
    102 
    103 highlight default link icalendarRrule Identifier
    104 highlight default link icalendarRruleSeparator Operator
    105 highlight default link icalendarRruleParamName Type
    106 highlight default link icalendarRruleEquals Operator
    107 highlight default link icalendarRruleParamValue String
    108 highlight default link icalendarRruleParamSeparator Operator
    109 
    110 let b:current_syntax = "icalendar"
    111 
    112 let &cpo = s:cpo_save
    113 unlet s:cpo_save
    114 
    115 " vim: fdm=marker