context.vim 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: 2016 Oct 30
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. let s:cpo_save = &cpo
  11. set cpo&vim
  12. if !exists('current_compiler')
  13. compiler context
  14. endif
  15. let b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"
  16. \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
  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. let &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
  24. \ . 'def\|\\font\|\\\%(future\)\=let'
  25. \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
  26. \ . '\|fam\|insert\|if\)'
  27. let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
  28. setlocal suffixesadd=.tex
  29. if exists("loaded_matchit")
  30. let b:match_ignorecase = 0
  31. let b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
  32. let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' .
  33. \ '\\start\(\a\+\):\\stop\1'
  34. endif
  35. let s:context_regex = {
  36. \ 'beginsection' : '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
  37. \ 'endsection' : '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>',
  38. \ 'beginblock' : '\\\%(start\|setup\|define\)',
  39. \ 'endblock' : '\\\%(stop\|setup\|define\)'
  40. \ }
  41. function! s:move_around(count, what, flags, visual)
  42. if a:visual
  43. exe "normal! gv"
  44. endif
  45. call search(s:context_regex[a:what], a:flags.'s') " 's' sets previous context mark
  46. call map(range(2, a:count), 'search(s:context_regex[a:what], a:flags)')
  47. endfunction
  48. " Move around macros.
  49. nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
  50. vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
  51. nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
  52. vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
  53. nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
  54. vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
  55. nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
  56. vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
  57. nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
  58. vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
  59. nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
  60. vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
  61. " Other useful mappings
  62. if get(g:, 'context_mappings', 1)
  63. let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
  64. fun! s:tp()
  65. call cursor(search(s:tp_regex, 'bcW') + 1, 1)
  66. normal! V
  67. call cursor(search(s:tp_regex, 'W') - 1, 1)
  68. endf
  69. " Reflow paragraphs with commands like gqtp ("gq TeX paragraph")
  70. onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr>
  71. " Select TeX paragraph
  72. vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr>
  73. " $...$ text object
  74. onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr>
  75. onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr>
  76. vnoremap <buffer> i$ T$ot$
  77. vnoremap <buffer> a$ F$of$
  78. endif
  79. " Commands for asynchronous typesetting
  80. command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>)
  81. command! -nargs=0 ConTeXtJobStatus call context#job_status()
  82. command! -nargs=0 ConTeXtStopJobs call context#stop_jobs()
  83. let &cpo = s:cpo_save
  84. unlet s:cpo_save