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