mp.vim 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. " Vim filetype plugin file
  2. " Language: MetaPost
  3. " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
  4. " Former Maintainers: Nikolai Weibull <now@bitwi.se>
  5. " Latest Revision: 2016 Oct 2
  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< fo< sua< inc< def< ofu<"
  13. \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
  14. setlocal comments=:% commentstring=%\ %s formatoptions-=t formatoptions+=cjroql2
  15. setlocal suffixesadd=.mp,.mpiv
  16. let &l:include = '\<\%(input\|loadmodule\)\>' " loadmodule is in MetaFun
  17. let &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
  18. setlocal omnifunc=syntaxcomplete#Complete
  19. let g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+'
  20. let g:omni_syntax_group_exclude_mp = 'mfTodoComment'
  21. if exists(":FixBeginfigs") != 2
  22. command -nargs=0 FixBeginfigs call s:fix_beginfigs()
  23. function! s:fix_beginfigs()
  24. let i = 1
  25. g/^beginfig(\d*);$/s//\='beginfig('.i.');'/ | let i = i + 1
  26. endfunction
  27. endif
  28. let s:mp_regex = {
  29. \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
  30. \ 'endsection' : '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>',
  31. \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
  32. \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>'
  33. \ }
  34. function! s:move_around(count, what, flags, visual)
  35. if a:visual
  36. exe "normal! gv"
  37. endif
  38. call search(s:mp_regex[a:what], a:flags.'s') " 's' sets previous context mark
  39. call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
  40. endfunction
  41. " Move around macros.
  42. nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
  43. vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
  44. nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
  45. vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
  46. nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
  47. vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
  48. nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
  49. vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
  50. nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
  51. vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
  52. nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
  53. vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
  54. if exists("loaded_matchit")
  55. let b:match_ignorecase = 0
  56. let b:match_words =
  57. \ '\<if\>:\<else\%[if]\>:\<fi\>,' .
  58. \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' .
  59. \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' .
  60. \ '\<beginfig\>:\<endfig\>,' .
  61. \ '\<begingroup\>:\<endgroup\>,' .
  62. \ '\<begin\%(logo\)\?char\>:\<endchar\>,' .
  63. \ '\<beginglyph\>:\<endglyph\>,' .
  64. \ '\<begingraph\>:\<endgraph\>'
  65. " Ignore comments and strings
  66. let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
  67. \ =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'
  68. endif
  69. let &cpo = s:cpo_save
  70. unlet s:cpo_save