blob: 0070f854251641d22c57d2b449af5dfa13eb9a92 [file] [log] [blame]
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01001vim9script
2
3# Vim filetype plugin file
4# Language: ConTeXt typesetting engine
5# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
6# Former Maintainers: Nikolai Weibull <now@bitwi.se>
Lifepillar0bca4a02023-12-27 18:49:50 +01007# Latest Revision: 2023 Dec 26
Bram Moolenaar42eeac32005-06-29 22:40:58 +00008
9if exists("b:did_ftplugin")
10 finish
11endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000012
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010013import autoload '../autoload/context.vim'
14
15b:did_ftplugin = 1
Bram Moolenaar42eeac32005-06-29 22:40:58 +000016
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020017if !exists('current_compiler')
18 compiler context
19endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000020
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010021b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020022
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010023setlocal comments=b:%D,b:%C,b:%M,:%
24setlocal commentstring=%\ %s
25setlocal formatoptions+=tjcroql2
26setlocal omnifunc=context.Complete
27setlocal suffixesadd=.tex,.mkxl,.mkvi,.mkiv,.mkii
28
29&l:define = '\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
30.. 'def\|\\font\|\\\%(future\)\=let'
31.. '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
32.. '\|fam\|insert\|if\)'
33
34&l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
35
36if exists("g:loaded_matchit") && !exists("b:match_words")
37 b:match_ignorecase = 0
38 b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
39 b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],\\start\(\a\+\):\\stop\1'
40 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020041endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000042
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010043if !get(g:, 'no_context_maps', 0) && !get(g:, 'no_plugin_maps', 0)
44 const context_regex = {
45 'beginsection': '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
46 'endsection': '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
47 'beginblock': '\\\%(start\|setup\|define\)',
48 'endblock': '\\\%(stop\|setup\|define\)',
49 }
Bram Moolenaar42eeac32005-06-29 22:40:58 +000050
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010051 def UndoMap(mapping: string, modes: string)
52 for mode in modes
53 b:undo_ftplugin ..= printf(" | silent! execute '%sunmap <buffer> %s'", mode, mapping)
54 endfor
55 enddef
Bram Moolenaar42eeac32005-06-29 22:40:58 +000056
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010057 def MoveAround(count: number, what: string, flags: string)
58 search(context_regex[what], flags .. 's') # 's' sets previous context mark
59 var i = 2
60 while i <= count
61 search(context_regex[what], flags)
62 i += 1
63 endwhile
64 enddef
Bram Moolenaar42eeac32005-06-29 22:40:58 +000065
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010066 # Macros to move around
67 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
68 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
69 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
70 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
71 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
72 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
73 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
74 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
75 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
76 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
77 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
78 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
Bram Moolenaar42eeac32005-06-29 22:40:58 +000079
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010080 for mapping in ['[[', ']]', '[]', '][', '[{', ']}']
81 UndoMap(mapping, 'nv')
82 endfor
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020083
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010084 # Other useful mappings
85 const tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020086
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010087 def TeXPar()
88 cursor(search(tp_regex, 'bcW') + 1, 1)
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020089 normal! V
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010090 cursor(search(tp_regex, 'W') - 1, 1)
91 enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020092
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010093 # Reflow paragraphs with mappings like gqtp ("gq TeX paragraph")
94 onoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
95 # Select TeX paragraph
96 vnoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020097
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010098 # $...$ text object
99 onoremap <silent><buffer> i$ <scriptcmd>normal! T$vt$<cr>
100 onoremap <silent><buffer> a$ <scriptcmd>normal! F$vf$<cr>
101 vnoremap <buffer> i$ T$ot$
102 vnoremap <buffer> a$ F$of$
Bram Moolenaar22863042021-10-16 15:23:36 +0100103
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100104 for mapping in ['tp', 'i$', 'a$']
105 UndoMap(mapping, 'ov')
106 endfor
Bram Moolenaar46fceaa2016-10-23 21:21:08 +0200107endif
108
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100109# Commands for asynchronous typesetting
110command! -buffer -nargs=? -complete=buffer ConTeXt context.Typeset(<q-args>)
111command! -buffer -nargs=0 ConTeXtLog context.Log('%')
112command! -nargs=0 ConTeXtJobStatus context.JobStatus()
113command! -nargs=0 ConTeXtStopJobs context.StopJobs()
Bram Moolenaar46fceaa2016-10-23 21:21:08 +0200114
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100115# vim: sw=2 fdm=marker