blob: 6c11166afabce164592f607bb4d3b6bfab7307cd [file] [log] [blame]
Bram Moolenaar42eeac32005-06-29 22:40:58 +00001" Vim filetype plugin file
Bram Moolenaar46fceaa2016-10-23 21:21:08 +02002" Language: ConTeXt typesetting engine
3" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
4" Former Maintainers: Nikolai Weibull <now@bitwi.se>
5" Latest Revision: 2016 Oct 14
Bram Moolenaar42eeac32005-06-29 22:40:58 +00006
7if exists("b:did_ftplugin")
8 finish
9endif
10let b:did_ftplugin = 1
11
12let s:cpo_save = &cpo
13set cpo&vim
14
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020015if !exists('current_compiler')
16 compiler context
17endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000018
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020019let b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
20 \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
21
22setlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2
23if get(b:, 'context_metapost', get(g:, 'context_metapost', 1))
24 setlocal omnifunc=context#complete
25 let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+'
26 let g:omni_syntax_group_exclude_context = 'mfTodoComment'
27endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000028
29let &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
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020034let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
Bram Moolenaar42eeac32005-06-29 22:40:58 +000035
36setlocal suffixesadd=.tex
37
38if exists("loaded_matchit")
39 let b:match_ignorecase = 0
40 let b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
41 let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' .
42 \ '\\start\(\a\+\):\\stop\1'
Bram Moolenaare37d50a2008-08-06 17:06:04 +000043endif
Bram Moolenaar42eeac32005-06-29 22:40:58 +000044
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020045let s:context_regex = {
46 \ 'beginsection' : '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
47 \ 'endsection' : '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
48 \ 'beginblock' : '\\\%(start\|setup\|define\)',
49 \ 'endblock' : '\\\%(stop\|setup\|define\)'
50 \ }
51
52function! s:move_around(count, what, flags, visual)
53 if a:visual
54 exe "normal! gv"
55 endif
56 call search(s:context_regex[a:what], a:flags.'s') " 's' sets previous context mark
57 call map(range(2, a:count), 'search(s:context_regex[a:what], a:flags)')
58endfunction
59
60" Move around macros.
61nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
62vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
63nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
64vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
65nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
66vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
67nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
68vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
69nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
70vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
71nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
72vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
73
74" Other useful mappings
75if get(g:, 'context_mappings', 1)
76 let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
77
78 fun! s:tp()
79 call cursor(search(s:tp_regex, 'bcW') + 1, 1)
80 normal! V
81 call cursor(search(s:tp_regex, 'W') - 1, 1)
82 endf
83
84 " Reflow paragraphs with commands like gqtp ("gq TeX paragraph")
85 onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr>
86 " Select TeX paragraph
87 vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr>
88
89 " $...$ text object
90 onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr>
91 onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr>
92 vnoremap <buffer> i$ T$ot$
93 vnoremap <buffer> a$ F$of$
94endif
95
96" Commands for asynchronous typesetting
97command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>)
98command! -nargs=0 ConTeXtJobStatus call context#job_status()
99command! -nargs=0 ConTeXtStopJobs call context#stop_jobs()
100
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000101let &cpo = s:cpo_save
102unlet s:cpo_save