xref: /vim-8.2.3635/runtime/ftplugin/context.vim (revision 2286304c)
142eeac35SBram Moolenaar" Vim filetype plugin file
242eeac35SBram Moolenaar" Language:           ConTeXt typesetting engine
346fceaaaSBram Moolenaar" Maintainer:         Nicola Vitacolonna <[email protected]>
446fceaaaSBram Moolenaar" Former Maintainers: Nikolai Weibull <[email protected]>
5*2286304cSBram Moolenaar" Latest Revision:    2021 Oct 15
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
1546fceaaaSBram Moolenaarif !exists('current_compiler')
1646fceaaaSBram Moolenaar  compiler context
1746fceaaaSBram Moolenaarendif
1842eeac35SBram Moolenaar
1946fceaaaSBram Moolenaarlet b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
2046fceaaaSBram Moolenaar
2146fceaaaSBram Moolenaarsetlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2
2246fceaaaSBram Moolenaarif get(b:, 'context_metapost', get(g:, 'context_metapost', 1))
23b4ada79aSBram Moolenaar  setlocal omnifunc=contextcomplete#Complete
2446fceaaaSBram Moolenaar  let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+'
2546fceaaaSBram Moolenaar  let g:omni_syntax_group_exclude_context = 'mfTodoComment'
2646fceaaaSBram Moolenaarendif
2742eeac35SBram Moolenaar
2842eeac35SBram Moolenaarlet &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
2942eeac35SBram Moolenaar        \ .     'def\|\\font\|\\\%(future\)\=let'
3042eeac35SBram Moolenaar        \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
3142eeac35SBram Moolenaar        \ .     '\|fam\|insert\|if\)'
3242eeac35SBram Moolenaar
3346fceaaaSBram Moolenaarlet &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
3442eeac35SBram Moolenaar
3542eeac35SBram Moolenaarsetlocal suffixesadd=.tex
3642eeac35SBram Moolenaar
37*2286304cSBram Moolenaarif exists("loaded_matchit") && !exists("b:match_words")
3842eeac35SBram Moolenaar  let b:match_ignorecase = 0
3942eeac35SBram Moolenaar  let b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
4042eeac35SBram Moolenaar  let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' .
4142eeac35SBram Moolenaar        \ '\\start\(\a\+\):\\stop\1'
42*2286304cSBram Moolenaar  let b:undo_ftplugin .= " | unlet! b:match_ignorecase b:match_words b:match_skip"
43e37d50a5SBram Moolenaarendif
4442eeac35SBram Moolenaar
4546fceaaaSBram Moolenaarlet s:context_regex = {
4646fceaaaSBram Moolenaar      \ 'beginsection' : '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
4746fceaaaSBram Moolenaar      \ 'endsection'   : '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
4846fceaaaSBram Moolenaar      \ 'beginblock'   : '\\\%(start\|setup\|define\)',
4946fceaaaSBram Moolenaar      \ 'endblock'     : '\\\%(stop\|setup\|define\)'
5046fceaaaSBram Moolenaar      \ }
5146fceaaaSBram Moolenaar
5246fceaaaSBram Moolenaarfunction! s:move_around(count, what, flags, visual)
5346fceaaaSBram Moolenaar  if a:visual
5446fceaaaSBram Moolenaar    exe "normal! gv"
5546fceaaaSBram Moolenaar  endif
5646fceaaaSBram Moolenaar  call search(s:context_regex[a:what], a:flags.'s') " 's' sets previous context mark
5746fceaaaSBram Moolenaar  call map(range(2, a:count), 'search(s:context_regex[a:what], a:flags)')
5846fceaaaSBram Moolenaarendfunction
5946fceaaaSBram Moolenaar
60*2286304cSBram Moolenaarif !exists("no_plugin_maps") && !exists("no_context_maps")
6146fceaaaSBram Moolenaar  " Move around macros.
6246fceaaaSBram Moolenaar  nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
6346fceaaaSBram Moolenaar  vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true)  <CR>
6446fceaaaSBram Moolenaar  nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W",  v:false) <CR>
6546fceaaaSBram Moolenaar  vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W",  v:true)  <CR>
6646fceaaaSBram Moolenaar  nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection",   "bW", v:false) <CR>
6746fceaaaSBram Moolenaar  vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection",   "bW", v:true)  <CR>
6846fceaaaSBram Moolenaar  nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection",   "W",  v:false) <CR>
6946fceaaaSBram Moolenaar  vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection",   "W",  v:true)  <CR>
7046fceaaaSBram Moolenaar  nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock",   "bW", v:false) <CR>
7146fceaaaSBram Moolenaar  vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock",   "bW", v:true)  <CR>
7246fceaaaSBram Moolenaar  nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock",     "W",  v:false) <CR>
7346fceaaaSBram Moolenaar  vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock",     "W",  v:true)  <CR>
7446fceaaaSBram Moolenaar
75*2286304cSBram Moolenaar  let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" .
76*2286304cSBram Moolenaar	\                " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" .
77*2286304cSBram Moolenaar	\                " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" .
78*2286304cSBram Moolenaar	\                " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['" .
79*2286304cSBram Moolenaar	\                " | sil! exe 'nunmap <buffer> [{' | sil! exe 'vunmap <buffer> [{'" .
80*2286304cSBram Moolenaar	\                " | sil! exe 'nunmap <buffer> ]}' | sil! exe 'vunmap <buffer> ]}'"
81*2286304cSBram Moolenaarend
82*2286304cSBram Moolenaar
8346fceaaaSBram Moolenaar" Other useful mappings
8446fceaaaSBram Moolenaarif get(g:, 'context_mappings', 1)
8546fceaaaSBram Moolenaar  let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
8646fceaaaSBram Moolenaar
8746fceaaaSBram Moolenaar  fun! s:tp()
8846fceaaaSBram Moolenaar    call cursor(search(s:tp_regex, 'bcW') + 1, 1)
8946fceaaaSBram Moolenaar    normal! V
9046fceaaaSBram Moolenaar    call cursor(search(s:tp_regex, 'W') - 1, 1)
9146fceaaaSBram Moolenaar  endf
9246fceaaaSBram Moolenaar
93*2286304cSBram Moolenaar  if !exists("no_plugin_maps") && !exists("no_context_maps")
9446fceaaaSBram Moolenaar    " Reflow paragraphs with commands like gqtp ("gq TeX paragraph")
9546fceaaaSBram Moolenaar    onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr>
9646fceaaaSBram Moolenaar    " Select TeX paragraph
9746fceaaaSBram Moolenaar    vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr>
9846fceaaaSBram Moolenaar
9946fceaaaSBram Moolenaar    " $...$ text object
10046fceaaaSBram Moolenaar    onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr>
10146fceaaaSBram Moolenaar    onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr>
10246fceaaaSBram Moolenaar    vnoremap <buffer> i$ T$ot$
10346fceaaaSBram Moolenaar    vnoremap <buffer> a$ F$of$
104*2286304cSBram Moolenaar
105*2286304cSBram Moolenaar    let b:undo_ftplugin .= " | sil! exe 'ounmap <buffer> tp' | sil! exe 'vunmap <buffer> tp'" .
106*2286304cSBram Moolenaar	  \                " | sil! exe 'ounmap <buffer> i$' | sil! exe 'vunmap <buffer> i$'" .
107*2286304cSBram Moolenaar	  \                " | sil! exe 'ounmap <buffer> a$' | sil! exe 'vunmap <buffer> a$'"
108*2286304cSBram Moolenaar    endif
10946fceaaaSBram Moolenaarendif
11046fceaaaSBram Moolenaar
11146fceaaaSBram Moolenaar" Commands for asynchronous typesetting
11246fceaaaSBram Moolenaarcommand! -buffer -nargs=? -complete=file ConTeXt          call context#typeset(<q-args>)
11346fceaaaSBram Moolenaarcommand!         -nargs=0                ConTeXtJobStatus call context#job_status()
11446fceaaaSBram Moolenaarcommand!         -nargs=0                ConTeXtStopJobs  call context#stop_jobs()
11546fceaaaSBram Moolenaar
11642eeac35SBram Moolenaarlet &cpo = s:cpo_save
11742eeac35SBram Moolenaarunlet s:cpo_save
118