blob: 87ad9f8de4aa6fd2852d1d7c09541449fa0df382 [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
Doug Kearns93197fd2024-01-14 20:59:02 +01008# 2024 Jan 14 by Vim Project (browsefilter)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000010if exists("b:did_ftplugin")
11 finish
12endif
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000013
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010014b:did_ftplugin = 1
15b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
Bram Moolenaare37d50a2008-08-06 17:06:04 +000016
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010017setlocal comments=:%
18setlocal commentstring=%\ %s
19setlocal formatoptions+=cjroql2
20setlocal formatoptions-=t
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020021setlocal omnifunc=syntaxcomplete#Complete
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010022setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000023
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010024&l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun
25&l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000026
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010027g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+'
28g:omni_syntax_group_exclude_mp = 'mfTodoComment'
29
30var fignum: number
31
32def FixBeginfigs()
33 fignum = 1
34 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum
35enddef
36
37command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs()
38
39if exists("g:loaded_matchit") && !exists("b:match_words")
40 b:match_ignorecase = 0
41 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'
42 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,'
43 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,'
44 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,'
45 .. '\<begin\(\a\+\)\>:end\1,'
46 .. '\<beginlogochar\>:\<endchar\>'
47 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000048endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +000049
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010050if !get(g:, 'no_mp_maps', 0) && !get(g:, 'no_plugin_maps', 0)
51 const mp_regex = {
52 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
53 'endsection': '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>',
54 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
55 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'}
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020056
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010057 def MoveAround(count: number, what: string, flags: string)
58 search(mp_regex[what], flags .. 's') # 's' sets previous context mark
59 var i = 2
60 while i <= count
61 search(mp_regex[what], flags)
62 i += 1
63 endwhile
64 enddef
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020065
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010066 # Macros to move around
67 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
68 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
69 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
70 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
71 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
72 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
73 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
74 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
75 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
76 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
77 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
78 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020079
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010080 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"]
81 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping)
82 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping)
83 endfor
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020084endif
85
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010086if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
87 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n"
Doug Kearns93197fd2024-01-14 20:59:02 +010088 if has("win32")
89 b:browsefilter ..= "All Files (*.*)\t*\n"
90 else
91 b:browsefilter ..= "All Files (*)\t*\n"
92 endif
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010093 b:undo_ftplugin ..= ' | unlet! b:browsefilter'
94endif
95
96# vim: sw=2 fdm=marker