context.vim 5.5 KB

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