Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 2 | " Language: ConTeXt typesetting engine |
| 3 | " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> |
| 4 | " Former Maintainers: Nikolai Weibull <now@bitwi.se> |
Bram Moolenaar | b4ada79 | 2016-10-30 21:55:26 +0100 | [diff] [blame] | 5 | " Latest Revision: 2016 Oct 30 |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 6 | |
| 7 | if exists("b:did_ftplugin") |
| 8 | finish |
| 9 | endif |
| 10 | let b:did_ftplugin = 1 |
| 11 | |
| 12 | let s:cpo_save = &cpo |
| 13 | set cpo&vim |
| 14 | |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 15 | if !exists('current_compiler') |
| 16 | compiler context |
| 17 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 18 | |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 19 | let b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<" |
| 20 | \ . "| unlet! b:match_ignorecase b:match_words b:match_skip" |
| 21 | |
| 22 | setlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2 |
| 23 | if get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) |
Bram Moolenaar | b4ada79 | 2016-10-30 21:55:26 +0100 | [diff] [blame] | 24 | setlocal omnifunc=contextcomplete#Complete |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 25 | let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+' |
| 26 | let g:omni_syntax_group_exclude_context = 'mfTodoComment' |
| 27 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 28 | |
| 29 | let &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 Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 34 | let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)' |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 35 | |
| 36 | setlocal suffixesadd=.tex |
| 37 | |
| 38 | if 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 Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 43 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 44 | |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 45 | let 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 | |
| 52 | function! 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)') |
| 58 | endfunction |
| 59 | |
| 60 | " Move around macros. |
| 61 | nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> |
| 62 | vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> |
| 63 | nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> |
| 64 | vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> |
| 65 | nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> |
| 66 | vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> |
| 67 | nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> |
| 68 | vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> |
| 69 | nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> |
| 70 | vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> |
| 71 | nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> |
| 72 | vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> |
| 73 | |
| 74 | " Other useful mappings |
| 75 | if 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$ |
| 94 | endif |
| 95 | |
| 96 | " Commands for asynchronous typesetting |
| 97 | command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>) |
| 98 | command! -nargs=0 ConTeXtJobStatus call context#job_status() |
| 99 | command! -nargs=0 ConTeXtStopJobs call context#stop_jobs() |
| 100 | |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 101 | let &cpo = s:cpo_save |
| 102 | unlet s:cpo_save |