annotate runtime/autoload/context.vim @ 34018:d81556766132

runtime(context): update ConTeXt keywords and other minor fixes (#13778) Commit: https://github.com/vim/vim/commit/0bca4a00188ccde335e0d6a7b7c093998e09182f Author: Lifepillar <lifepillar@users.noreply.github.com> Date: Wed Dec 27 18:49:50 2023 +0100 runtime(context): update ConTeXt keywords and other minor fixes (https://github.com/vim/vim/issues/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>
author Christian Brabandt <cb@256bit.org>
date Wed, 27 Dec 2023 19:00:06 +0100
parents 1e91e26ceebf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
1 vim9script
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
3 # Language: ConTeXt typesetting engine
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
4 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
5 # Former Maintainers: Nikolai Weibull <now@bitwi.se>
34018
d81556766132 runtime(context): update ConTeXt keywords and other minor fixes (#13778)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
6 # Latest Revision: 2023 Dec 26
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
8 # Typesetting {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
9 import autoload './typeset.vim'
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
11 export def ConTeXtCmd(path: string): list<string>
30547
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
12 var cmd = ['mtxrun', '--script', 'context', '--nonstopmode', '--autogenerate']
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
13 if !empty(get(g:, 'context_extra_options', ''))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
14 cmd += g:context_extra_options
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
15 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
16 cmd->add(path)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 29756
diff changeset
17 return cmd
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
18 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
20 export def Typeset(bufname: string, env = {}, Cmd = ConTeXtCmd): bool
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
21 return typeset.TypesetBuffer(bufname, Cmd, env, 'ConTeXt')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
22 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
24 export def JobStatus()
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
25 typeset.JobStatus('ConTeXt')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
26 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
28 export def StopJobs()
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
29 typeset.StopJobs('ConTeXt')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
30 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
32 export def Log(bufname: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
33 execute 'edit' typeset.LogPath(bufname)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
34 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
35 # }}}
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
37 # Completion {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
38 def BinarySearch(base: string, keywords: list<string>): list<string>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
39 const pat = '^' .. base
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
40 const len = len(keywords)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
41 var res = []
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
42 var lft = 0
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
43 var rgt = len
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
45 # Find the leftmost index matching base
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
46 while lft < rgt
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
47 var i = (lft + rgt) / 2
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
48 if keywords[i] < base
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
49 lft = i + 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
50 else
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
51 rgt = i
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
52 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
53 endwhile
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
55 while lft < len && keywords[lft] =~ pat
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
56 add(res, keywords[lft])
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
57 lft += 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
58 endwhile
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
60 return res
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
61 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
63 var isMetaPostBlock = false
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
65 var MP_KEYWORDS: list<string> = []
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
66 var CTX_KEYWORDS: list<string> = []
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
68 # Complete only MetaPost keywords in MetaPost blocks, and complete only
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
69 # ConTeXt keywords otherwise.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
70 export def Complete(findstart: number, base: string): any
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
71 if findstart == 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
72 if len(synstack(line("."), 1)) > 0 && synIDattr(synstack(line("."), 1)[0], "name") ==# 'contextMPGraphic'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
73 isMetaPostBlock = true
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
74 return match(getline('.'), '\S\+\%' .. col('.') .. 'c')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
75 endif
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
77 # Complete only \commands starting with a backslash
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
78 isMetaPostBlock = false
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
79 var pos = match(getline('.'), '\\\zs\S\+\%' .. col('.') .. 'c')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
80 return (pos == -1) ? -3 : pos
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 endif
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
82
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
83 if isMetaPostBlock
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
84 if empty(MP_KEYWORDS)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
85 MP_KEYWORDS = sort(syntaxcomplete#OmniSyntaxList(['mf\w\+', 'mp\w\+']))
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
86 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
87 return BinarySearch(base, MP_KEYWORDS)
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 endif
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
90 if empty(CTX_KEYWORDS)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
91 CTX_KEYWORDS = sort(syntaxcomplete#OmniSyntaxList([
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
92 'context\w\+', 'texAleph', 'texEtex', 'texLuatex', 'texOmega',
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
93 'texPdftex', 'texTex', 'texXeTeX'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
94 ]))
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
95 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
96 return BinarySearch(base, CTX_KEYWORDS)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
97 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
98 # }}}
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
100 # vim: sw=2 fdm=marker