blob: bc5116eb3a6a4f5fac52f9ac1ffa7be551855c4c [file] [log] [blame]
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01001vim9script
2
3# Vim filetype plugin file
4# Language: MetaPost
5# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
6# Former Maintainers: Nikolai Weibull <now@bitwi.se>
7# Latest Revision: 2022 Aug 12
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009if exists("b:did_ftplugin")
10 finish
11endif
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000012
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010013b:did_ftplugin = 1
14b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
Bram Moolenaare37d50a2008-08-06 17:06:04 +000015
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010016setlocal comments=:%
17setlocal commentstring=%\ %s
18setlocal formatoptions+=cjroql2
19setlocal formatoptions-=t
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020020setlocal omnifunc=syntaxcomplete#Complete
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010021setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000022
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010023&l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun
24&l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000025
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010026g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+'
27g:omni_syntax_group_exclude_mp = 'mfTodoComment'
28
29var fignum: number
30
31def FixBeginfigs()
32 fignum = 1
33 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum
34enddef
35
36command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs()
37
38if exists("g:loaded_matchit") && !exists("b:match_words")
39 b:match_ignorecase = 0
40 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"
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000047endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +000048
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010049if !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\)\>'}
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020055
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010056 def MoveAround(count: number, what: string, flags: string)
57 search(mp_regex[what], flags .. 's') # 's' sets previous context mark
58 var i = 2
59 while i <= count
60 search(mp_regex[what], flags)
61 i += 1
62 endwhile
63 enddef
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020064
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010065 # Macros to move around
66 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>
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020078
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010079 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 endfor
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020083endif
84
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010085if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
86 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n"
87 .. "All Files (*.*)\t*.*\n"
88 b:undo_ftplugin ..= ' | unlet! b:browsefilter'
89endif
90
91# vim: sw=2 fdm=marker