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 | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 5 | " Latest Revision: 2021 Oct 15 |
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<" |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 20 | |
| 21 | setlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2 |
| 22 | if get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) |
Bram Moolenaar | b4ada79 | 2016-10-30 21:55:26 +0100 | [diff] [blame] | 23 | setlocal omnifunc=contextcomplete#Complete |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 24 | let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+' |
| 25 | let g:omni_syntax_group_exclude_context = 'mfTodoComment' |
| 26 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 27 | |
| 28 | let &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\=' |
| 29 | \ . 'def\|\\font\|\\\%(future\)\=let' |
| 30 | \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write' |
| 31 | \ . '\|fam\|insert\|if\)' |
| 32 | |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 33 | let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)' |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 34 | |
| 35 | setlocal suffixesadd=.tex |
| 36 | |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 37 | if exists("loaded_matchit") && !exists("b:match_words") |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 38 | let b:match_ignorecase = 0 |
| 39 | let b:match_skip = 'r:\\\@<!\%(\\\\\)*%' |
| 40 | let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' . |
| 41 | \ '\\start\(\a\+\):\\stop\1' |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 42 | let b:undo_ftplugin .= " | unlet! b:match_ignorecase b:match_words b:match_skip" |
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 | |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 60 | if !exists("no_plugin_maps") && !exists("no_context_maps") |
| 61 | " Move around macros. |
| 62 | nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> |
| 63 | vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> |
| 64 | nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> |
| 65 | vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> |
| 66 | nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> |
| 67 | vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> |
| 68 | nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> |
| 69 | vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> |
| 70 | nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> |
| 71 | vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> |
| 72 | nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> |
| 73 | vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> |
| 74 | |
| 75 | let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" . |
| 76 | \ " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" . |
| 77 | \ " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" . |
| 78 | \ " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['" . |
| 79 | \ " | sil! exe 'nunmap <buffer> [{' | sil! exe 'vunmap <buffer> [{'" . |
| 80 | \ " | sil! exe 'nunmap <buffer> ]}' | sil! exe 'vunmap <buffer> ]}'" |
| 81 | end |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 82 | |
| 83 | " Other useful mappings |
| 84 | if get(g:, 'context_mappings', 1) |
| 85 | let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)' |
| 86 | |
| 87 | fun! s:tp() |
| 88 | call cursor(search(s:tp_regex, 'bcW') + 1, 1) |
| 89 | normal! V |
| 90 | call cursor(search(s:tp_regex, 'W') - 1, 1) |
| 91 | endf |
| 92 | |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 93 | if !exists("no_plugin_maps") && !exists("no_context_maps") |
| 94 | " Reflow paragraphs with commands like gqtp ("gq TeX paragraph") |
| 95 | onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr> |
| 96 | " Select TeX paragraph |
| 97 | vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr> |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 98 | |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 99 | " $...$ text object |
| 100 | onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr> |
| 101 | onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr> |
| 102 | vnoremap <buffer> i$ T$ot$ |
| 103 | vnoremap <buffer> a$ F$of$ |
| 104 | |
| 105 | let b:undo_ftplugin .= " | sil! exe 'ounmap <buffer> tp' | sil! exe 'vunmap <buffer> tp'" . |
| 106 | \ " | sil! exe 'ounmap <buffer> i$' | sil! exe 'vunmap <buffer> i$'" . |
| 107 | \ " | sil! exe 'ounmap <buffer> a$' | sil! exe 'vunmap <buffer> a$'" |
| 108 | endif |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 109 | endif |
| 110 | |
| 111 | " Commands for asynchronous typesetting |
| 112 | command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>) |
| 113 | command! -nargs=0 ConTeXtJobStatus call context#job_status() |
| 114 | command! -nargs=0 ConTeXtStopJobs call context#stop_jobs() |
| 115 | |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 116 | let &cpo = s:cpo_save |
| 117 | unlet s:cpo_save |