context.vim (5589B)
1 " Vim filetype plugin file 2 " Language: ConTeXt typesetting engine 3 " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> 4 " Former Maintainers: Nikolai Weibull <now@bitwi.se> 5 " Latest Revision: 2021 Oct 15 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 15 let b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<" 16 17 setlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2 18 if get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) 19 setlocal omnifunc=contextcomplete#Complete 20 let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+' 21 let g:omni_syntax_group_exclude_context = 'mfTodoComment' 22 endif 23 24 let &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\=' 25 \ . 'def\|\\font\|\\\%(future\)\=let' 26 \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write' 27 \ . '\|fam\|insert\|if\)' 28 29 let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)' 30 31 setlocal suffixesadd=.tex 32 33 if exists("loaded_matchit") && !exists("b:match_words") 34 let b:match_ignorecase = 0 35 let b:match_skip = 'r:\\\@<!\%(\\\\\)*%' 36 let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' . 37 \ '\\start\(\a\+\):\\stop\1' 38 let b:undo_ftplugin .= " | unlet! b:match_ignorecase b:match_words b:match_skip" 39 endif 40 41 let s:context_regex = { 42 \ 'beginsection' : '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', 43 \ 'endsection' : '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', 44 \ 'beginblock' : '\\\%(start\|setup\|define\)', 45 \ 'endblock' : '\\\%(stop\|setup\|define\)' 46 \ } 47 48 function! s:move_around(count, what, flags, visual) 49 if a:visual 50 exe "normal! gv" 51 endif 52 call search(s:context_regex[a:what], a:flags.'s') " 's' sets previous context mark 53 call map(range(2, a:count), 'search(s:context_regex[a:what], a:flags)') 54 endfunction 55 56 if !exists("no_plugin_maps") && !exists("no_context_maps") 57 " Move around macros. 58 nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> 59 vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> 60 nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> 61 vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> 62 nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> 63 vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> 64 nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> 65 vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> 66 nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> 67 vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> 68 nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> 69 vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> 70 71 let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" . 72 \ " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" . 73 \ " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" . 74 \ " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['" . 75 \ " | sil! exe 'nunmap <buffer> [{' | sil! exe 'vunmap <buffer> [{'" . 76 \ " | sil! exe 'nunmap <buffer> ]}' | sil! exe 'vunmap <buffer> ]}'" 77 end 78 79 " Other useful mappings 80 if get(g:, 'context_mappings', 1) 81 let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)' 82 83 fun! s:tp() 84 call cursor(search(s:tp_regex, 'bcW') + 1, 1) 85 normal! V 86 call cursor(search(s:tp_regex, 'W') - 1, 1) 87 endf 88 89 if !exists("no_plugin_maps") && !exists("no_context_maps") 90 " Reflow paragraphs with commands like gqtp ("gq TeX paragraph") 91 onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr> 92 " Select TeX paragraph 93 vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr> 94 95 " $...$ text object 96 onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr> 97 onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr> 98 vnoremap <buffer> i$ T$ot$ 99 vnoremap <buffer> a$ F$of$ 100 101 let b:undo_ftplugin .= " | sil! exe 'ounmap <buffer> tp' | sil! exe 'vunmap <buffer> tp'" . 102 \ " | sil! exe 'ounmap <buffer> i$' | sil! exe 'vunmap <buffer> i$'" . 103 \ " | sil! exe 'ounmap <buffer> a$' | sil! exe 'vunmap <buffer> a$'" 104 endif 105 endif 106 107 if !exists('current_compiler') 108 let b:undo_ftplugin ..= "| compiler make" 109 compiler context 110 endif 111 112 let b:undo_ftplugin ..= "| sil! delc -buffer ConTeXt | sil! delc -buffer ConTeXtLog | sil! delc -buffer ConTeXtJobStatus | sil! delc -buffer ConTeXtStopJobs" 113 " Commands for asynchronous typesetting 114 command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>) 115 command! -nargs=0 ConTeXtJobStatus call context#job_status() 116 command! -nargs=0 ConTeXtStopJobs call context#stop_jobs() 117 118 let &cpo = s:cpo_save 119 unlet s:cpo_save