codekingpro/portable-devtools
114k
1vim9script2 3# Vim filetype plugin file4# Language: MetaPost5# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>6# Former Maintainers: Nikolai Weibull <now@bitwi.se>7# Latest Revision: 2026 Jan 108 9if exists("b:did_ftplugin")10 finish11endif12 13b:did_ftplugin = 114b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"15 16setlocal comments=:%17setlocal commentstring=%\ %s18setlocal formatoptions+=cjroql219setlocal formatoptions-=t20setlocal omnifunc=syntaxcomplete#Complete21setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl22 23&l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun24&l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'25 26g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+'27g:omni_syntax_group_exclude_mp = 'mfTodoComment'28 29var fignum: number30 31def FixBeginfigs()32 fignum = 133 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum34enddef35 36command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs()37 38if exists("g:loaded_matchit") && !exists("b:match_words")39 b:match_ignorecase = 040 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'41 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,'42 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,'43 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,'44 .. '\<begin\(\a\+\)\>:end\1,'45 .. '\<beginlogochar\>:\<endchar\>'46 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"47endif48 49if !get(g:, 'no_mp_maps', 0) && !get(g:, 'no_plugin_maps', 0)50 const mp_regex = {51 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',52 'endsection': '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>',53 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',54 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'}55 56 def MoveAround(count: number, what: string, flags: string)57 search(mp_regex[what], flags .. 's') # 's' sets previous context mark58 var i = 259 while i <= count60 search(mp_regex[what], flags)61 i += 162 endwhile63 enddef64 65 # Macros to move around66 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>67 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>68 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>69 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>70 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>71 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>72 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>73 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>74 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>75 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>76 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>77 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>78 79 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"]80 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping)81 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping)82 endfor83endif84 85if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')86 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n"87 if has("win32")88 b:browsefilter ..= "All Files (*.*)\t*\n"89 else90 b:browsefilter ..= "All Files (*)\t*\n"91 endif92 b:undo_ftplugin ..= ' | unlet! b:browsefilter'93endif94 95# vim: sw=2 fdm=marker96 