mf.vim 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. " Vim filetype plugin file
  2. " Language: METAFONT
  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=.mf
  16. let &l:include = '\<input\>'
  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_mf = 'mf\w\+'
  20. let g:omni_syntax_group_exclude_mf = 'mfTodoComment'
  21. let s:mp_regex = {
  22. \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|beginchar\|beginlogochar\)\>',
  23. \ 'endsection' : '^\s*\%(enddef\|endchar\)\>',
  24. \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
  25. \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>'
  26. \ }
  27. function! s:move_around(count, what, flags, visual)
  28. if a:visual
  29. exe "normal! gv"
  30. endif
  31. call search(s:mp_regex[a:what], a:flags.'s') " 's' sets previous context mark
  32. call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
  33. endfunction
  34. " Move around macros.
  35. nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
  36. vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
  37. nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
  38. vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
  39. nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
  40. vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
  41. nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
  42. vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
  43. nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
  44. vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
  45. nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
  46. vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
  47. if exists("loaded_matchit")
  48. let b:match_ignorecase = 0
  49. let b:match_words =
  50. \ '\<if\>:\<else\%[if]\>:\<fi\>,' .
  51. \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' .
  52. \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' .
  53. \ '\<begingroup\>:\<endgroup\>,' .
  54. \ '\<begin\%(logo\)\?char\>:\<endchar\>'
  55. " Ignore comments and strings
  56. let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
  57. \ =~# "mf\\(Comment\\|String\\)$"'
  58. endif
  59. let &cpo = s:cpo_save
  60. unlet s:cpo_save