blob: b39a306d73e60877584f8fef3532c830f3a45fab [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>
Konfekt7c3f9af2024-10-05 17:26:46 +02007# Latest Revision: 2024 Oct 04
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 Moolenaare1f3fd12022-08-15 18:51:32 +010017b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020018
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010019setlocal comments=b:%D,b:%C,b:%M,:%
20setlocal commentstring=%\ %s
21setlocal formatoptions+=tjcroql2
22setlocal omnifunc=context.Complete
23setlocal suffixesadd=.tex,.mkxl,.mkvi,.mkiv,.mkii
24
25&l:define = '\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
26.. 'def\|\\font\|\\\%(future\)\=let'
27.. '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
28.. '\|fam\|insert\|if\)'
29
30&l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
31
32if exists("g:loaded_matchit") && !exists("b:match_words")
33 b:match_ignorecase = 0
34 b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
35 b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],\\start\(\a\+\):\\stop\1'
36 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020037endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000038
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010039if !get(g:, 'no_context_maps', 0) && !get(g:, 'no_plugin_maps', 0)
40 const context_regex = {
41 'beginsection': '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
42 'endsection': '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
43 'beginblock': '\\\%(start\|setup\|define\)',
44 'endblock': '\\\%(stop\|setup\|define\)',
45 }
Bram Moolenaar42eeac32005-06-29 22:40:58 +000046
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010047 def UndoMap(mapping: string, modes: string)
48 for mode in modes
49 b:undo_ftplugin ..= printf(" | silent! execute '%sunmap <buffer> %s'", mode, mapping)
50 endfor
51 enddef
Bram Moolenaar42eeac32005-06-29 22:40:58 +000052
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010053 def MoveAround(count: number, what: string, flags: string)
54 search(context_regex[what], flags .. 's') # 's' sets previous context mark
55 var i = 2
56 while i <= count
57 search(context_regex[what], flags)
58 i += 1
59 endwhile
60 enddef
Bram Moolenaar42eeac32005-06-29 22:40:58 +000061
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010062 # Macros to move around
63 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
64 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
65 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
66 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
67 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
68 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
69 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
70 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
71 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
72 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
73 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
74 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
Bram Moolenaar42eeac32005-06-29 22:40:58 +000075
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010076 for mapping in ['[[', ']]', '[]', '][', '[{', ']}']
77 UndoMap(mapping, 'nv')
78 endfor
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020079
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010080 # Other useful mappings
81 const tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020082
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010083 def TeXPar()
84 cursor(search(tp_regex, 'bcW') + 1, 1)
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020085 normal! V
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010086 cursor(search(tp_regex, 'W') - 1, 1)
87 enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020088
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010089 # Reflow paragraphs with mappings like gqtp ("gq TeX paragraph")
90 onoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
91 # Select TeX paragraph
92 vnoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020093
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010094 # $...$ text object
95 onoremap <silent><buffer> i$ <scriptcmd>normal! T$vt$<cr>
96 onoremap <silent><buffer> a$ <scriptcmd>normal! F$vf$<cr>
97 vnoremap <buffer> i$ T$ot$
98 vnoremap <buffer> a$ F$of$
Bram Moolenaar22863042021-10-16 15:23:36 +010099
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100100 for mapping in ['tp', 'i$', 'a$']
101 UndoMap(mapping, 'ov')
102 endfor
Bram Moolenaar46fceaa2016-10-23 21:21:08 +0200103endif
104
Konfekt7c3f9af2024-10-05 17:26:46 +0200105if !exists('current_compiler')
106 b:undo_ftplugin ..= "| compiler make"
107 compiler context
108endif
109
110b:undo_ftplugin ..= "| sil! delc -buffer ConTeXt | sil! delc -buffer ConTeXtLog | sil! delc -buffer ConTeXtJobStatus | sil! delc -buffer ConTeXtStopJobs"
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100111# Commands for asynchronous typesetting
112command! -buffer -nargs=? -complete=buffer ConTeXt context.Typeset(<q-args>)
113command! -buffer -nargs=0 ConTeXtLog context.Log('%')
114command! -nargs=0 ConTeXtJobStatus context.JobStatus()
115command! -nargs=0 ConTeXtStopJobs context.StopJobs()
Bram Moolenaar46fceaa2016-10-23 21:21:08 +0200116
Bram Moolenaare1f3fd12022-08-15 18:51:32 +0100117# vim: sw=2 fdm=marker