context.vim 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. 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. setlocal comments=b:%D,b:%C,b:%M,:% commentstring=%\ %s formatoptions+=tjcroql2
  17. if get(b:, 'context_metapost', get(g:, 'context_metapost', 1))
  18. setlocal omnifunc=contextcomplete#Complete
  19. let g:omni_syntax_group_include_context = 'mf\w\+,mp\w\+'
  20. let g:omni_syntax_group_exclude_context = 'mfTodoComment'
  21. endif
  22. let &l:define='\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
  23. \ . 'def\|\\font\|\\\%(future\)\=let'
  24. \ . '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
  25. \ . '\|fam\|insert\|if\)'
  26. let &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)'
  27. setlocal suffixesadd=.tex
  28. if exists("loaded_matchit") && !exists("b:match_words")
  29. let b:match_ignorecase = 0
  30. let b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
  31. let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' .
  32. \ '\\start\(\a\+\):\\stop\1'
  33. let b:undo_ftplugin .= " | unlet! b:match_ignorecase b:match_words b:match_skip"
  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. if !exists("no_plugin_maps") && !exists("no_context_maps")
  49. " Move around macros.
  50. nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
  51. vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
  52. nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
  53. vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
  54. nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
  55. vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
  56. nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
  57. vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
  58. nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
  59. vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
  60. nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
  61. vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
  62. let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" .
  63. \ " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" .
  64. \ " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" .
  65. \ " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['" .
  66. \ " | sil! exe 'nunmap <buffer> [{' | sil! exe 'vunmap <buffer> [{'" .
  67. \ " | sil! exe 'nunmap <buffer> ]}' | sil! exe 'vunmap <buffer> ]}'"
  68. end
  69. " Other useful mappings
  70. if get(g:, 'context_mappings', 1)
  71. let s:tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'
  72. fun! s:tp()
  73. call cursor(search(s:tp_regex, 'bcW') + 1, 1)
  74. normal! V
  75. call cursor(search(s:tp_regex, 'W') - 1, 1)
  76. endf
  77. if !exists("no_plugin_maps") && !exists("no_context_maps")
  78. " Reflow paragraphs with commands like gqtp ("gq TeX paragraph")
  79. onoremap <silent><buffer> tp :<c-u>call <sid>tp()<cr>
  80. " Select TeX paragraph
  81. vnoremap <silent><buffer> tp <esc>:<c-u>call <sid>tp()<cr>
  82. " $...$ text object
  83. onoremap <silent><buffer> i$ :<c-u>normal! T$vt$<cr>
  84. onoremap <silent><buffer> a$ :<c-u>normal! F$vf$<cr>
  85. vnoremap <buffer> i$ T$ot$
  86. vnoremap <buffer> a$ F$of$
  87. let b:undo_ftplugin .= " | sil! exe 'ounmap <buffer> tp' | sil! exe 'vunmap <buffer> tp'" .
  88. \ " | sil! exe 'ounmap <buffer> i$' | sil! exe 'vunmap <buffer> i$'" .
  89. \ " | sil! exe 'ounmap <buffer> a$' | sil! exe 'vunmap <buffer> a$'"
  90. endif
  91. endif
  92. " Commands for asynchronous typesetting
  93. command! -buffer -nargs=? -complete=file ConTeXt call context#typeset(<q-args>)
  94. command! -nargs=0 ConTeXtJobStatus call context#job_status()
  95. command! -nargs=0 ConTeXtStopJobs call context#stop_jobs()
  96. let &cpo = s:cpo_save
  97. unlet s:cpo_save