0
0
mirror of https://github.com/vim/vim.git synced 2025-07-24 10:45:12 -04:00
vim/runtime/ftplugin/context.vim

116 lines
4.3 KiB
VimL
Raw Normal View History

2022-08-15 18:51:32 +01:00
vim9script
# Vim filetype plugin 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:did_ftplugin")
finish
endif
2022-08-15 18:51:32 +01:00
import autoload '../autoload/context.vim'
b:did_ftplugin = 1
2005-06-29 22:40:58 +00:00
2016-10-23 21:21:08 +02:00
if !exists('current_compiler')
compiler context
endif
2022-08-15 18:51:32 +01:00
b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
setlocal comments=b:%D,b:%C,b:%M,:%
setlocal commentstring=%\ %s
setlocal formatoptions+=tjcroql2
setlocal omnifunc=context.Complete
setlocal suffixesadd=.tex,.mkxl,.mkvi,.mkiv,.mkii
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
&l:define = '\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
.. 'def\|\\font\|\\\%(future\)\=let'
.. '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
.. '\|fam\|insert\|if\)'
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
&l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
if exists("g:loaded_matchit") && !exists("b:match_words")
b:match_ignorecase = 0
b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],\\start\(\a\+\):\\stop\1'
b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
2008-08-06 17:06:04 +00:00
endif
2005-06-29 22:40:58 +00:00
2022-08-15 18:51:32 +01:00
if !get(g:, 'no_context_maps', 0) && !get(g:, 'no_plugin_maps', 0)
const context_regex = {
'beginsection': '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
'endsection': '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
'beginblock': '\\\%(start\|setup\|define\)',
'endblock': '\\\%(stop\|setup\|define\)',
}
def UndoMap(mapping: string, modes: string)
for mode in modes
b:undo_ftplugin ..= printf(" | silent! execute '%sunmap <buffer> %s'", mode, mapping)
endfor
enddef
def MoveAround(count: number, what: string, flags: string)
search(context_regex[what], flags .. 's') # 's' sets previous context mark
var i = 2
while i <= count
search(context_regex[what], flags)
i += 1
endwhile
enddef
# Macros to move around
nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
for mapping in ['[[', ']]', '[]', '][', '[{', ']}']
UndoMap(mapping, 'nv')
endfor
# Other useful mappings
const tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
def TeXPar()
cursor(search(tp_regex, 'bcW') + 1, 1)
2016-10-23 21:21:08 +02:00
normal! V
2022-08-15 18:51:32 +01:00
cursor(search(tp_regex, 'W') - 1, 1)
enddef
# Reflow paragraphs with mappings like gqtp ("gq TeX paragraph")
onoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
# Select TeX paragraph
vnoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
# $...$ text object
onoremap <silent><buffer> i$ <scriptcmd>normal! T$vt$<cr>
onoremap <silent><buffer> a$ <scriptcmd>normal! F$vf$<cr>
vnoremap <buffer> i$ T$ot$
vnoremap <buffer> a$ F$of$
for mapping in ['tp', 'i$', 'a$']
UndoMap(mapping, 'ov')
endfor
2016-10-23 21:21:08 +02:00
endif
2022-08-15 18:51:32 +01:00
# Commands for asynchronous typesetting
command! -buffer -nargs=? -complete=buffer ConTeXt context.Typeset(<q-args>)
command! -buffer -nargs=0 ConTeXtLog context.Log('%')
command! -nargs=0 ConTeXtJobStatus context.JobStatus()
command! -nargs=0 ConTeXtStopJobs context.StopJobs()
2016-10-23 21:21:08 +02:00
2022-08-15 18:51:32 +01:00
# vim: sw=2 fdm=marker