context.vim (6199B)
1 " Vim syntax file 2 " Language: ConTeXt typesetting engine 3 " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> 4 " Former Maintainers: Nikolai Weibull <now@bitwi.se> 5 " Latest Revision: 2016 Oct 16 6 7 if exists("b:current_syntax") 8 finish 9 endif 10 11 runtime! syntax/plaintex.vim 12 unlet b:current_syntax 13 14 let s:cpo_save = &cpo 15 set cpo&vim 16 17 " Dictionary of (filetype, group) pairs to highlight between \startGROUP \stopGROUP. 18 let s:context_include = get(b:, 'context_include', get(g:, 'context_include', {'xml': 'XML'})) 19 20 " For backward compatibility (g:context_include used to be a List) 21 if type(s:context_include) ==# type([]) 22 let g:context_metapost = (index(s:context_include, 'mp') != -1) 23 let s:context_include = filter( 24 \ {'c': 'C', 'javascript': 'JS', 'ruby': 'Ruby', 'xml': 'XML'}, 25 \ { k,_ -> index(s:context_include, k) != -1 } 26 \ ) 27 endif 28 29 syn iskeyword @,48-57,a-z,A-Z,192-255 30 31 syn spell toplevel 32 33 " ConTeXt options, i.e., [...] blocks 34 syn region contextOptions matchgroup=contextDelimiter start='\[' end=']\|\ze\\stop' skip='\\\[\|\\\]' contains=ALLBUT,contextBeginEndLua,@Spell 35 36 " Highlight braces 37 syn match contextDelimiter '[{}]' 38 39 " Comments 40 syn match contextComment '\\\@<!\%(\\\\\)*\zs%.*$' display contains=initexTodo 41 syn match contextComment '^\s*%[CDM].*$' display contains=initexTodo 42 43 syn match contextBlockDelim '\\\%(start\|stop\)\a\+' contains=@NoSpell 44 45 syn region contextEscaped matchgroup=contextPreProc start='\\type\%(\s*\|\n\)*\z([^A-Za-z%]\)' end='\z1' 46 syn region contextEscaped matchgroup=contextPreProc start='\\type\=\%(\s\|\n\)*{' end='}' 47 syn region contextEscaped matchgroup=contextPreProc start='\\type\=\%(\s*\|\n\)*<<' end='>>' 48 syn region contextEscaped matchgroup=contextPreProc 49 \ start='\\start\z(\a*\%(typing\|typen\)\)' 50 \ end='\\stop\z1' contains=plaintexComment keepend 51 syn region contextEscaped matchgroup=contextPreProc start='\\\h\+Type\%(\s\|\n\)*{' end='}' 52 syn region contextEscaped matchgroup=contextPreProc start='\\Typed\h\+\%(\s\|\n\)*{' end='}' 53 54 syn match contextBuiltin display contains=@NoSpell 55 \ '\\\%(unprotect\|protect\|unexpanded\)\>' 56 57 syn match contextPreProc '^\s*\\\%(start\|stop\)\=\%(component\|environment\|project\|product\)\>' 58 \ contains=@NoSpell 59 60 if get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) 61 let b:mp_metafun_macros = 1 " Highlight MetaFun keywords 62 syn include @mpTop syntax/mp.vim 63 unlet b:current_syntax 64 65 syn region contextMPGraphic matchgroup=contextBlockDelim 66 \ start='\\start\z(MP\%(clip\|code\|definitions\|drawing\|environment\|extensions\|inclusions\|initializations\|page\|\)\)\>.*$' 67 \ end='\\stop\z1' 68 \ contains=@mpTop,@NoSpell 69 syn region contextMPGraphic matchgroup=contextBlockDelim 70 \ start='\\start\z(\%(\%[re]usable\|use\|unique\|static\)MPgraphic\|staticMPfigure\|uniqueMPpagegraphic\)\>.*$' 71 \ end='\\stop\z1' 72 \ contains=@mpTop,@NoSpell 73 endif 74 75 if get(b:, 'context_lua', get(g:, 'context_lua', 1)) 76 syn include @luaTop syntax/lua.vim 77 unlet b:current_syntax 78 79 syn region contextLuaCode matchgroup=contextBlockDelim 80 \ start='\\startluacode\>' 81 \ end='\\stopluacode\>' keepend 82 \ contains=@luaTop,@NoSpell 83 84 syn match contextDirectLua "\\\%(directlua\|ctxlua\)\>\%(\s*%.*$\)\=" 85 \ nextgroup=contextBeginEndLua skipwhite skipempty 86 \ contains=initexComment 87 syn region contextBeginEndLua matchgroup=contextSpecial 88 \ start="{" end="}" skip="\\[{}]" 89 \ contained contains=@luaTop,@NoSpell 90 endif 91 92 for synname in keys(s:context_include) 93 execute 'syn include @' . synname . 'Top' 'syntax/' . synname . '.vim' 94 unlet b:current_syntax 95 execute 'syn region context' . s:context_include[synname] . 'Code' 96 \ 'matchgroup=contextBlockDelim' 97 \ 'start=+\\start' . s:context_include[synname] . '+' 98 \ 'end=+\\stop' . s:context_include[synname] . '+' 99 \ 'contains=@' . synname . 'Top,@NoSpell' 100 endfor 101 102 syn match contextSectioning '\\\%(start\|stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>' 103 \ contains=@NoSpell 104 105 syn match contextSpecial '\\crlf\>\|\\par\>\|-\{2,3}\||[<>/]\=|' 106 \ contains=@NoSpell 107 syn match contextSpecial /\\[`'"]/ 108 syn match contextSpecial +\\char\%(\d\{1,3}\|'\o\{1,3}\|"\x\{1,2}\)\>+ 109 \ contains=@NoSpell 110 syn match contextSpecial '\^\^.' 111 syn match contextSpecial '`\%(\\.\|\^\^.\|.\)' 112 113 syn match contextStyle '\\\%(em\|ss\|hw\|cg\|mf\)\>' 114 \ contains=@NoSpell 115 syn match contextFont '\\\%(CAP\|Cap\|cap\|Caps\|kap\|nocap\)\>' 116 \ contains=@NoSpell 117 syn match contextFont '\\\%(Word\|WORD\|Words\|WORDS\)\>' 118 \ contains=@NoSpell 119 syn match contextFont '\\\%(vi\{1,3}\|ix\|xi\{0,2}\)\>' 120 \ contains=@NoSpell 121 syn match contextFont '\\\%(tf\|b[si]\|s[cl]\|os\)\%(xx\|[xabcd]\)\=\>' 122 \ contains=@NoSpell 123 124 hi def link contextOptions Typedef 125 hi def link contextComment Comment 126 hi def link contextBlockDelim Keyword 127 hi def link contextBuiltin Keyword 128 hi def link contextDelimiter Delimiter 129 hi def link contextEscaped String 130 hi def link contextPreProc PreProc 131 hi def link contextSectioning PreProc 132 hi def link contextSpecial Special 133 hi def link contextType Type 134 hi def link contextStyle contextType 135 hi def link contextFont contextType 136 hi def link contextDirectLua Keyword 137 138 let b:current_syntax = "context" 139 140 let &cpo = s:cpo_save 141 unlet s:cpo_save