xref: /vim-8.2.3635/runtime/ftplugin/mp.vim (revision 01a6c216)
1" Vim filetype plugin file
2" Language:           MetaPost
3" Maintainer:         Nicola Vitacolonna <[email protected]>
4" Former Maintainers: Nikolai Weibull <[email protected]>
5" Latest Revision:    2016 Oct 2
6
7if exists("b:did_ftplugin")
8  finish
9endif
10let b:did_ftplugin = 1
11
12let s:cpo_save = &cpo
13set cpo&vim
14
15let b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
16      \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
17
18setlocal 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'
25
26if exists(":FixBeginfigs") != 2
27  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
34
35let s:mp_regex = {
36      \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
37      \ 'endsection'   : '^\s*\%(enddef\|end\%(fig\|char\|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  call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
48endfunction
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\>,' .
73        \ '\<begin\%(logo\)\?char\>:\<endchar\>,' .
74        \ '\<beginglyph\>:\<endglyph\>,' .
75        \ '\<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
81let &cpo = s:cpo_save
82unlet s:cpo_save
83