annotate runtime/indent/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 f00c56ee8118
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
1 vim9script
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
2
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
3 # Language: ConTeXt typesetting engine
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
4 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
f00c56ee8118 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: 29885
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
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 if exists("b:did_indent")
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 finish
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 endif
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
12 # Load MetaPost indentation script (this will also set b:did_indent)
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 runtime! indent/mp.vim
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
15 setlocal indentexpr=ConTeXtIndent()
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
16
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
17 b:undo_indent = "setl indentexpr<"
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
19 def PrevNotComment(l: number): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
20 var prevlnum = prevnonblank(l)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
21
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
22 while prevlnum > 0 && getline(prevlnum) =~# '^\s*%'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
23 prevlnum = prevnonblank(prevlnum - 1)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
24 endwhile
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
26 return prevlnum
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
27 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
29 def FindPair(pstart: string, pmid: string, pend: string): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
30 cursor(v:lnum, 1)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
31 return indent(searchpair(pstart, pmid, pend, 'bWn',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
32 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
33 enddef
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
34
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
35 def ConTeXtIndent(): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
36 # Use MetaPost rules inside MetaPost graphic environments
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 if len(synstack(v:lnum, 1)) > 0 &&
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
38 synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
39 return g:MetaPostIndent()
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 endif
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
41
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
42 const prevlnum = PrevNotComment(v:lnum - 1)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
43 const prevind = indent(prevlnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
44 const prevline = getline(prevlnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
45 const currline = getline(v:lnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
46
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
47 # If the current line starts with ], match indentation.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
48 if currline =~# '^\s*\]'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
49 return FindPair('\[', '', '\]')
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
50 endif
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
51
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
52 # If the current line starts with }, match indentation.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
53 if currline =~# '^\s*}'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
54 return FindPair('{', '', '}')
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
55 endif
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
56
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
57 # If the previous line ends with [ or { (possibly followed by a comment) then indent.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
58 if prevline =~# '[{[]\s*\%(%.*\)\=$'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
59 return prevind + shiftwidth()
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
60 endif
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
61
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 return -1
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
63 enddef
10301
07d2b5a3b7cc commit https://github.com/vim/vim/commit/46fceaaa8d1447a9588736d86eb4908214187b08
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10301
diff changeset
65 # vim: sw=2 fdm=marker