1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-21 17:25:11 +01:00
vim/runtime/syntax/context.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
6.2 KiB
VimL
Raw Permalink Normal View History

2022-08-15 18:51:32 +01:00
vim9script
# Vim syntax file
# Language: ConTeXt typesetting engine
# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
# Former Maintainers: Nikolai Weibull <now@bitwi.se>
runtime(context): update ConTeXt keywords and other minor fixes (#13778) Update to the ConTeXt runtime files. Changes: 1. shared syntax files updated with `mtxrun --script interface --vim` using the latest ConTeXt LMTX. 2. fixed reference to `make` tag in the help file. 3. added `keepend` to mitigate issues with embedded Lua syntax (see below). 4. the latest revision date of each ConTeXt runtime file has been updated to the date of this commit. The issue about embedded Lua was reported by a user: >Take the following valid ConTeXt file: > \starttext > \ctxlua{context("Text generated from Lua.")} > \ctxlua{context("Another text generated from Lua.")} > \stoptext >On my Vim installation (including when I start Vim with `--clean`), the >closing bracket and curly braces on line 2 are highlighted red and the >syntax highlighting after that is off. >I was trying to dig a little bit into what was going on, using the >`synID()` and `synIDattr()` functions. It appears that the closing >bracket on line 2 is matched as a `luaParentError` instead of the end >of the `luaParen` region. Therefore, the `luaParen` region continues >all the way to the end of the file. The closing curly brace on line >2 is matched as a `luaError`, the 2nd `\ctxlua` on line 3 as >`luaParen`, etc. >This issue doesn't occur in a plain Lua file, where the closing bracket >is correctly matched as the end of the `luaParen` region. So it seems >that something goes wrong when the Lua syntax file is included in the >ConTeXt one. By adding `keepend`, the right parenthesis for some reason is still highlighted as a `luaParenError`, but at least the right curly brace should correctly end the Lua block. From what I've seen, I think it is very difficult to embed Lua syntax properly without help from the Lua syntax file (that is, without patching it). It has global rules such as: syn match luaParenError ")" syn match luaError "}" which make it difficult, if not impossible, to contain Lua syntax without `keepend` (and its limitations). Signed-off-by: Lifepillar <lifepillar@lifepillar.me> Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-12-27 18:49:50 +01:00
# Latest Revision: 2023 Dec 26
2005-06-29 22:40:58 +00:00
if exists("b:current_syntax")
finish
endif
2022-08-15 18:51:32 +01:00
# Dictionary of (filetype, group) pairs to highlight between \startGROUP \stopGROUP.
var context_include = get(b:, 'context_include', get(g:, 'context_include', {'xml': 'XML'}))
2006-04-21 22:12:41 +00:00
2022-08-15 18:51:32 +01:00
# Deprecation warning
if type(context_include) ==# type([])
echomsg "[ConTeXt] b:context_include/g:context_include must be Dictionaries."
context_include = {'xml': 'XML'}
endif
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
syn iskeyword @,48-57,_,!,?,a-z,A-Z,192-255
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
syn spell toplevel
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
runtime! syntax/shared/context-data-context.vim
runtime! syntax/shared/context-data-interfaces.vim
runtime! syntax/shared/context-data-tex.vim
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
syn match contextCommand '\\\k\+\>' display contains=@NoSpell
2007-05-10 19:06:20 +00:00
2022-08-15 18:51:32 +01:00
# ConTeXt options, i.e., [...] blocks
syn region contextOptions matchgroup=contextDelimiter start='\[' end=']\|\ze\\stop' skip='\\\[\|\\\]' contains=TOP,@Spell
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
# Highlight braces
2016-10-23 21:21:08 +02:00
syn match contextDelimiter '[{}]'
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
# Comments
syn match contextComment '\%(\_^\|[^\\]\)\%(\\\\\)*\zs%.*$' display contains=contextTodo,contextMagicLine
syn match contextComment '^\s*%[CDM].*$' display contains=contextTodo,contextMagicLine
syn keyword contextTodo TODO FIXME XXX NOTE contained
syn match contextMagicLine '^\s*%\s*!TEX.*$' contained
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
syn match contextBlockDelim '\\\%(start\|stop\)\k\+' contains=@NoSpell
2016-10-23 21:21:08 +02:00
syn region contextEscaped matchgroup=contextPreProc start='\\type\%(\s*\|\n\)*\z([^A-Za-z%]\)' end='\z1'
syn region contextEscaped matchgroup=contextPreProc start='\\type\=\%(\s\|\n\)*{' end='}'
syn region contextEscaped matchgroup=contextPreProc start='\\type\=\%(\s*\|\n\)*<<' end='>>'
2005-06-29 22:40:58 +00:00
syn region contextEscaped matchgroup=contextPreProc
\ start='\\start\z(\a*\%(typing\|typen\)\)'
2022-08-15 18:51:32 +01:00
\ end='\\stop\z1' contains=contextComment keepend
2016-10-23 21:21:08 +02:00
syn region contextEscaped matchgroup=contextPreProc start='\\\h\+Type\%(\s\|\n\)*{' end='}'
syn region contextEscaped matchgroup=contextPreProc start='\\Typed\h\+\%(\s\|\n\)*{' end='}'
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
syn match contextBuiltin '\\unexpanded\>' display contains=@NoSpell
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
# \unprotect... \protect regions
syn region contextUnprotect matchgroup=contextBuiltin start='\\unprotect' end='\\protect' contains=TOP
syn match contextSequence '\\[a-zA-Z]*[@_!?]\+[a-zA-Z@_!?]*' contains=@NoSpell contained containedin=contextUnprotect
2006-04-21 22:12:41 +00:00
2022-08-15 18:51:32 +01:00
# Math
syn match contextMathCmd '\\m\%(ath\%(ematics\)\=\)\=\>'
syn region contextInlineMath matchgroup=contextMathDelim start='\$' skip='\\\\\|\\\$' end='\$'
syn region contextDisplayMath matchgroup=contextMathDelim start='\$\$' skip='\\\\\|\\\$' end='\$\$' keepend
syn region contextDisplayMath matchgroup=contextBlockDelim start='\\startformula' end='\\stopformula' contains=TOP
2006-04-21 22:12:41 +00:00
2022-08-15 18:51:32 +01:00
# MetaFun
b:mp_metafun = 1
syn include @mpTop syntax/mp.vim
unlet b:current_syntax
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
syn region contextMPGraphic matchgroup=contextBlockDelim
\ start='\\start\z(MP\%(clip\|code\|definitions\|drawing\|environment\|extensions\|inclusions\|initializations\|page\|\)\)\>.*$'
\ end='\\stop\z1'
\ contains=@mpTop,@NoSpell
syn region contextMPGraphic matchgroup=contextBlockDelim
\ start='\\start\z(\%(\%[re]usable\|use\|unique\|static\)MPgraphic\|staticMPfigure\|uniqueMPpagegraphic\)\>.*$'
\ end='\\stop\z1'
\ contains=@mpTop,@NoSpell
# Lua
syn include @luaTop syntax/lua.vim
unlet b:current_syntax
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
syn region contextLuaCode matchgroup=contextBlockDelim
\ start='\\startluacode\>'
\ end='\\stopluacode\>' keepend
\ contains=@luaTop,@NoSpell
syn match contextDirectLua "\\\%(directlua\|ctxlua\)\>\%(\s*%.*$\)\="
\ nextgroup=contextBeginEndLua skipwhite skipempty
\ contains=contextComment
syn region contextBeginEndLua matchgroup=contextSpecial
runtime(context): update ConTeXt keywords and other minor fixes (#13778) Update to the ConTeXt runtime files. Changes: 1. shared syntax files updated with `mtxrun --script interface --vim` using the latest ConTeXt LMTX. 2. fixed reference to `make` tag in the help file. 3. added `keepend` to mitigate issues with embedded Lua syntax (see below). 4. the latest revision date of each ConTeXt runtime file has been updated to the date of this commit. The issue about embedded Lua was reported by a user: >Take the following valid ConTeXt file: > \starttext > \ctxlua{context("Text generated from Lua.")} > \ctxlua{context("Another text generated from Lua.")} > \stoptext >On my Vim installation (including when I start Vim with `--clean`), the >closing bracket and curly braces on line 2 are highlighted red and the >syntax highlighting after that is off. >I was trying to dig a little bit into what was going on, using the >`synID()` and `synIDattr()` functions. It appears that the closing >bracket on line 2 is matched as a `luaParentError` instead of the end >of the `luaParen` region. Therefore, the `luaParen` region continues >all the way to the end of the file. The closing curly brace on line >2 is matched as a `luaError`, the 2nd `\ctxlua` on line 3 as >`luaParen`, etc. >This issue doesn't occur in a plain Lua file, where the closing bracket >is correctly matched as the end of the `luaParen` region. So it seems >that something goes wrong when the Lua syntax file is included in the >ConTeXt one. By adding `keepend`, the right parenthesis for some reason is still highlighted as a `luaParenError`, but at least the right curly brace should correctly end the Lua block. From what I've seen, I think it is very difficult to embed Lua syntax properly without help from the Lua syntax file (that is, without patching it). It has global rules such as: syn match luaParenError ")" syn match luaError "}" which make it difficult, if not impossible, to contain Lua syntax without `keepend` (and its limitations). Signed-off-by: Lifepillar <lifepillar@lifepillar.me> Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-12-27 18:49:50 +01:00
\ start="{" end="}" skip="\\[{}]" keepend
2022-08-15 18:51:32 +01:00
\ contained contains=@luaTop,@NoSpell
for synname in keys(context_include)
execute 'syn include @' .. synname .. 'Top' 'syntax/' .. synname .. '.vim'
2016-10-23 21:21:08 +02:00
unlet b:current_syntax
2022-08-15 18:51:32 +01:00
execute 'syn region context' .. context_include[synname] .. 'Code'
2016-10-23 21:21:08 +02:00
\ 'matchgroup=contextBlockDelim'
2022-08-15 18:51:32 +01:00
\ 'start=+\\start' .. context_include[synname] .. '\w*+'
\ 'end=+\\stop' .. context_include[synname] .. '\w*+'
\ 'contains=@' .. synname .. 'Top,@NoSpell'
2016-10-23 21:21:08 +02:00
endfor
2022-08-15 18:51:32 +01:00
syn match contextSectioning '\\\%(start\|stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>' contains=@NoSpell
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
syn match contextSpecial '\\par\>\|-\{2,3}\||[<>/]\=|' contains=@NoSpell
2006-04-21 22:12:41 +00:00
syn match contextSpecial /\\[`'"]/
2022-08-15 18:51:32 +01:00
syn match contextSpecial +\\char\%(\d\{1,3}\|'\o\{1,3}\|"\x\{1,2}\)\>+ contains=@NoSpell
2005-06-29 22:40:58 +00:00
syn match contextSpecial '\^\^.'
syn match contextSpecial '`\%(\\.\|\^\^.\|.\)'
2022-08-15 18:51:32 +01:00
syn match contextStyle '\\\%(em\|ss\|hw\|cg\|mf\)\>' contains=@NoSpell
syn match contextFont '\\\%(CAP\|Cap\|cap\|Caps\|kap\|nocap\)\>' contains=@NoSpell
syn match contextFont '\\\%(Word\|WORD\|Words\|WORDS\)\>' contains=@NoSpell
syn match contextFont '\\\%(vi\{1,3}\|ix\|xi\{0,2}\)\>' contains=@NoSpell
syn match contextFont '\\\%(tf\|b[si]\|s[cl]\|os\)\%(xx\|[xabcd]\)\=\>' contains=@NoSpell
2005-06-29 22:40:58 +00:00
hi def link contextBlockDelim Keyword
hi def link contextBuiltin Keyword
2022-08-15 18:51:32 +01:00
hi def link contextCommand Keyword
hi def link contextComment Comment
2005-06-29 22:40:58 +00:00
hi def link contextDelimiter Delimiter
2022-08-15 18:51:32 +01:00
hi def link contextDirectLua Keyword
2016-10-23 21:21:08 +02:00
hi def link contextEscaped String
2022-08-15 18:51:32 +01:00
hi def link contextFont contextType
hi def link contextKeyword Keyword
hi def link contextInlineMath String
hi def link contextMagicLine PreProc
hi def link contextMathCmd Identifier
hi def link contextMathDelim Delimiter
hi def link contextOptions Typedef
2005-06-29 22:40:58 +00:00
hi def link contextPreProc PreProc
hi def link contextSectioning PreProc
2022-08-15 18:51:32 +01:00
hi def link contextSequence Identifier
2005-06-29 22:40:58 +00:00
hi def link contextSpecial Special
hi def link contextStyle contextType
2022-08-15 18:51:32 +01:00
hi def link contextTodo Todo
hi def link contextType Type
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
b:current_syntax = 'context'
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
# vim: sw=2 fdm=marker