142eeac35SBram Moolenaar" Vim filetype plugin file 242eeac35SBram Moolenaar" Language: ConTeXt typesetting engine 3*46fceaaaSBram Moolenaar" Maintainer: Nicola Vitacolonna <[email protected]> 4*46fceaaaSBram Moolenaar" Former Maintainers: Nikolai Weibull <[email protected]> 5*46fceaaaSBram Moolenaar" Latest Revision: 2016 Oct 14 642eeac35SBram Moolenaar 742eeac35SBram Moolenaarif exists("b:did_ftplugin") 842eeac35SBram Moolenaar finish 942eeac35SBram Moolenaarendif 1042eeac35SBram Moolenaarlet b:did_ftplugin = 1 1142eeac35SBram Moolenaar 1242eeac35SBram Moolenaarlet s:cpo_save = &cpo 1342eeac35SBram Moolenaarset cpo&vim 1442eeac35SBram Moolenaar 15*46fceaaaSBram Moolenaarif !exists('current_compiler') 16*46fceaaaSBram Moolenaar compiler context 17*46fceaaaSBram Moolenaarendif 1842eeac35SBram Moolenaar 19*46fceaaaSBram Moolenaarlet b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<" 20*46fceaaaSBram Moolenaar \ . "| unlet! b:match_ignorecase b:match_words b:match_skip" 21*46fceaaaSBram Moolenaar 22*46fceaaaSBram Moolenaarsetlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2 23*46fceaaaSBram Moolenaarif get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) 24*46fceaaaSBram Moolenaar setlocal omnifunc=context#complete 25*46fceaaaSBram Moolenaar let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+' 26*46fceaaaSBram Moolenaar let g:omni_syntax_group_exclude_context = 'mfTodoComment' 27*46fceaaaSBram Moolenaarendif 2842eeac35SBram Moolenaar 2942eeac35SBram Moolenaarlet &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\=' 3042eeac35SBram Moolenaar \ . 'def\|\\font\|\\\%(future\)\=let' 3142eeac35SBram Moolenaar \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write' 3242eeac35SBram Moolenaar \ . '\|fam\|insert\|if\)' 3342eeac35SBram Moolenaar 34*46fceaaaSBram Moolenaarlet &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)' 3542eeac35SBram Moolenaar 3642eeac35SBram Moolenaarsetlocal suffixesadd=.tex 3742eeac35SBram Moolenaar 3842eeac35SBram Moolenaarif exists("loaded_matchit") 3942eeac35SBram Moolenaar let b:match_ignorecase = 0 4042eeac35SBram Moolenaar let b:match_skip = 'r:\\\@<!\%(\\\\\)*%' 4142eeac35SBram Moolenaar let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' . 4242eeac35SBram Moolenaar \ '\\start\(\a\+\):\\stop\1' 43e37d50a5SBram Moolenaarendif 4442eeac35SBram Moolenaar 45*46fceaaaSBram Moolenaarlet s:context_regex = { 46*46fceaaaSBram Moolenaar \ 'beginsection' : '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', 47*46fceaaaSBram Moolenaar \ 'endsection' : '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', 48*46fceaaaSBram Moolenaar \ 'beginblock' : '\\\%(start\|setup\|define\)', 49*46fceaaaSBram Moolenaar \ 'endblock' : '\\\%(stop\|setup\|define\)' 50*46fceaaaSBram Moolenaar \ } 51*46fceaaaSBram Moolenaar 52*46fceaaaSBram Moolenaarfunction! s:move_around(count, what, flags, visual) 53*46fceaaaSBram Moolenaar if a:visual 54*46fceaaaSBram Moolenaar exe "normal! gv" 55*46fceaaaSBram Moolenaar endif 56*46fceaaaSBram Moolenaar call search(s:context_regex[a:what], a:flags.'s') " 's' sets previous context mark 57*46fceaaaSBram Moolenaar call map(range(2, a:count), 'search(s:context_regex[a:what], a:flags)') 58*46fceaaaSBram Moolenaarendfunction 59*46fceaaaSBram Moolenaar 60*46fceaaaSBram Moolenaar" Move around macros. 61*46fceaaaSBram Moolenaarnnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> 62*46fceaaaSBram Moolenaarvnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> 63*46fceaaaSBram Moolenaarnnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> 64*46fceaaaSBram Moolenaarvnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> 65*46fceaaaSBram Moolenaarnnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> 66*46fceaaaSBram Moolenaarvnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> 67*46fceaaaSBram Moolenaarnnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> 68*46fceaaaSBram Moolenaarvnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> 69*46fceaaaSBram Moolenaarnnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> 70*46fceaaaSBram Moolenaarvnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> 71*46fceaaaSBram Moolenaarnnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> 72*46fceaaaSBram Moolenaarvnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> 73*46fceaaaSBram Moolenaar 74*46fceaaaSBram Moolenaar" Other useful mappings 75*46fceaaaSBram Moolenaarif get(g:, 'context_mappings', 1) 76*46fceaaaSBram Moolenaar let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)' 77*46fceaaaSBram Moolenaar 78*46fceaaaSBram Moolenaar fun! s:tp() 79*46fceaaaSBram Moolenaar call cursor(search(s:tp_regex, 'bcW') + 1, 1) 80*46fceaaaSBram Moolenaar normal! V 81*46fceaaaSBram Moolenaar call cursor(search(s:tp_regex, 'W') - 1, 1) 82*46fceaaaSBram Moolenaar endf 83*46fceaaaSBram Moolenaar 84*46fceaaaSBram Moolenaar " Reflow paragraphs with commands like gqtp ("gq TeX paragraph") 85*46fceaaaSBram Moolenaar onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr> 86*46fceaaaSBram Moolenaar " Select TeX paragraph 87*46fceaaaSBram Moolenaar vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr> 88*46fceaaaSBram Moolenaar 89*46fceaaaSBram Moolenaar " $...$ text object 90*46fceaaaSBram Moolenaar onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr> 91*46fceaaaSBram Moolenaar onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr> 92*46fceaaaSBram Moolenaar vnoremap <buffer> i$ T$ot$ 93*46fceaaaSBram Moolenaar vnoremap <buffer> a$ F$of$ 94*46fceaaaSBram Moolenaarendif 95*46fceaaaSBram Moolenaar 96*46fceaaaSBram Moolenaar" Commands for asynchronous typesetting 97*46fceaaaSBram Moolenaarcommand! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>) 98*46fceaaaSBram Moolenaarcommand! -nargs=0 ConTeXtJobStatus call context#job_status() 99*46fceaaaSBram Moolenaarcommand! -nargs=0 ConTeXtStopJobs call context#stop_jobs() 100*46fceaaaSBram Moolenaar 10142eeac35SBram Moolenaarlet &cpo = s:cpo_save 10242eeac35SBram Moolenaarunlet s:cpo_save 103