mf.vim 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. vim9script
  2. # Vim filetype plugin file
  3. # Language: METAFONT
  4. # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
  5. # Former Maintainers: Nikolai Weibull <now@bitwi.se>
  6. # Latest Revision: 2022 Aug 12
  7. if exists("b:did_ftplugin")
  8. finish
  9. endif
  10. b:did_ftplugin = 1
  11. b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
  12. setlocal comments=:%
  13. setlocal commentstring=%\ %s
  14. setlocal formatoptions+=cjroql2
  15. setlocal formatoptions-=t
  16. setlocal omnifunc=syntaxcomplete#Complete
  17. setlocal suffixesadd=.mf
  18. &l:include = '\<input\>'
  19. &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
  20. g:omni_syntax_group_include_mf = 'mf\w\+'
  21. g:omni_syntax_group_exclude_mf = 'mfTodoComment'
  22. if exists("g:loaded_matchit") && !exists("b:match_words")
  23. b:match_ignorecase = 0
  24. b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "mf\\(Comment\\|String\\)$"'
  25. b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,'
  26. .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,'
  27. .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,'
  28. .. '\<begingroup\>:\<endgroup\>,'
  29. .. '\<begin\%(logo\)\?char\>:\<endchar\>'
  30. b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
  31. endif
  32. if !get(g:, 'no_mf_maps', 0) && !get(g:, 'no_plugin_maps', 0)
  33. const mf_regex = {
  34. 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|beginchar\|beginlogochar\)\>',
  35. 'endsection': '^\s*\%(enddef\|endchar\)\>',
  36. 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
  37. 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'}
  38. def MoveAround(count: number, what: string, flags: string)
  39. search(mf_regex[what], flags .. 's') # 's' sets previous context mark
  40. var i = 2
  41. while i <= count
  42. search(mf_regex[what], flags)
  43. i += 1
  44. endwhile
  45. enddef
  46. # Macros to move around
  47. nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
  48. vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
  49. nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
  50. vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
  51. nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
  52. vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
  53. nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
  54. vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
  55. nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
  56. vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
  57. nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
  58. vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
  59. for mapping in ["[[", "]]", "[]", "][", "[{", "]}"]
  60. b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping)
  61. b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping)
  62. endfor
  63. endif
  64. if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
  65. b:browsefilter = "METAFONT Source Files (*.mf)\t*.mf\n"
  66. .. "All Files (*.*)\t*.*\n"
  67. b:undo_ftplugin ..= ' | unlet! b:browsefilter'
  68. endif
  69. # vim: sw=2 fdm=marker