blob: 3a0a3d029881e37c6b9eee1c36da5debe351da59 [file] [log] [blame]
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00001" Vim filetype plugin file
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02002" Language: MetaPost
3" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
4" Former Maintainers: Nikolai Weibull <now@bitwi.se>
Bram Moolenaardc083282016-10-11 08:57:33 +02005" Latest Revision: 2016 Oct 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007if exists("b:did_ftplugin")
8 finish
9endif
10let b:did_ftplugin = 1
11
Bram Moolenaare37d50a2008-08-06 17:06:04 +000012let s:cpo_save = &cpo
13set cpo&vim
14
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020015let b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
16 \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000017
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020018setlocal comments=:% commentstring=%\ %s formatoptions-=t formatoptions+=cjroql2
19setlocal suffixesadd=.mp,.mpiv
20let &l:include = '\<\%(input\|loadmodule\)\>' " loadmodule is in MetaFun
21let &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
22setlocal omnifunc=syntaxcomplete#Complete
23let g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+'
24let g:omni_syntax_group_exclude_mp = 'mfTodoComment'
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000025
Bram Moolenaar10c56952007-05-10 18:38:52 +000026if exists(":FixBeginfigs") != 2
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000027 command -nargs=0 FixBeginfigs call s:fix_beginfigs()
28
29 function! s:fix_beginfigs()
30 let i = 1
31 g/^beginfig(\d*);$/s//\='beginfig('.i.');'/ | let i = i + 1
32 endfunction
33endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +000034
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020035let s:mp_regex = {
36 \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
Bram Moolenaardc083282016-10-11 08:57:33 +020037 \ 'endsection' : '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>',
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020038 \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
39 \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>'
40 \ }
41
42function! s:move_around(count, what, flags, visual)
43 if a:visual
44 exe "normal! gv"
45 endif
46 call search(s:mp_regex[a:what], a:flags.'s') " 's' sets previous context mark
Bram Moolenaardc083282016-10-11 08:57:33 +020047 call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020048endfunction
49
50
51" Move around macros.
52nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
53vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
54nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
55vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
56nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
57vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
58nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
59vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
60nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
61vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
62nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
63vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
64
65if exists("loaded_matchit")
66 let b:match_ignorecase = 0
67 let b:match_words =
68 \ '\<if\>:\<else\%[if]\>:\<fi\>,' .
69 \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' .
70 \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' .
71 \ '\<beginfig\>:\<endfig\>,' .
72 \ '\<begingroup\>:\<endgroup\>,' .
Bram Moolenaardc083282016-10-11 08:57:33 +020073 \ '\<begin\%(logo\)\?char\>:\<endchar\>,' .
74 \ '\<beginglyph\>:\<endglyph\>,' .
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020075 \ '\<begingraph\>:\<endgraph\>'
76 " Ignore comments and strings
77 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
78 \ =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'
79endif
80
Bram Moolenaare37d50a2008-08-06 17:06:04 +000081let &cpo = s:cpo_save
82unlet s:cpo_save