blob: a3c9af342b03714961c57e8c4fb93f29f8e98935 [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>
5" Latest Revision: 2016 Oct 1
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\)\)\>',
37 \ 'endsection' : '^\s*\%(enddef\|end\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
38 \ '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
47 for i in range(2, a:count)
48 call search(s:mp_regex[a:what], a:flags)
49 endfor
50endfunction
51
52
53" Move around macros.
54nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
55vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
56nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
57vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
58nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
59vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
60nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
61vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
62nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
63vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
64nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
65vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
66
67if exists("loaded_matchit")
68 let b:match_ignorecase = 0
69 let b:match_words =
70 \ '\<if\>:\<else\%[if]\>:\<fi\>,' .
71 \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' .
72 \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' .
73 \ '\<beginfig\>:\<endfig\>,' .
74 \ '\<begingroup\>:\<endgroup\>,' .
75 \ '\<beginchar\>:\<endchar\>' .
76 \ '\<beginlogochar\>:\<endlogochar\>' .
77 \ '\<beginglyph\>:\<endglyph\>' .
78 \ '\<begingraph\>:\<endgraph\>'
79 " Ignore comments and strings
80 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
81 \ =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'
82endif
83
Bram Moolenaare37d50a2008-08-06 17:06:04 +000084let &cpo = s:cpo_save
85unlet s:cpo_save