Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 2 | " Language: MetaPost |
| 3 | " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> |
| 4 | " Former Maintainers: Nikolai Weibull <now@bitwi.se> |
Bram Moolenaar | dc08328 | 2016-10-11 08:57:33 +0200 | [diff] [blame] | 5 | " Latest Revision: 2016 Oct 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6 | |
Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 7 | if exists("b:did_ftplugin") |
| 8 | finish |
| 9 | endif |
| 10 | let b:did_ftplugin = 1 |
| 11 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 12 | let s:cpo_save = &cpo |
| 13 | set cpo&vim |
| 14 | |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 15 | let b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<" |
| 16 | \ . "| unlet! b:match_ignorecase b:match_words b:match_skip" |
Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 17 | |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 18 | setlocal comments=:% commentstring=%\ %s formatoptions-=t formatoptions+=cjroql2 |
| 19 | setlocal suffixesadd=.mp,.mpiv |
| 20 | let &l:include = '\<\%(input\|loadmodule\)\>' " loadmodule is in MetaFun |
| 21 | let &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+' |
| 22 | setlocal omnifunc=syntaxcomplete#Complete |
| 23 | let g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+' |
| 24 | let g:omni_syntax_group_exclude_mp = 'mfTodoComment' |
Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 25 | |
Bram Moolenaar | 10c5695 | 2007-05-10 18:38:52 +0000 | [diff] [blame] | 26 | if exists(":FixBeginfigs") != 2 |
Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 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 |
| 33 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 34 | |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 35 | let s:mp_regex = { |
| 36 | \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>', |
Bram Moolenaar | dc08328 | 2016-10-11 08:57:33 +0200 | [diff] [blame] | 37 | \ 'endsection' : '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>', |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 38 | \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>', |
| 39 | \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>' |
| 40 | \ } |
| 41 | |
| 42 | function! 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 Moolenaar | dc08328 | 2016-10-11 08:57:33 +0200 | [diff] [blame] | 47 | call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)') |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 48 | endfunction |
| 49 | |
| 50 | |
| 51 | " Move around macros. |
| 52 | nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> |
| 53 | vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> |
| 54 | nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> |
| 55 | vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> |
| 56 | nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> |
| 57 | vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> |
| 58 | nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> |
| 59 | vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> |
| 60 | nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> |
| 61 | vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> |
| 62 | nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> |
| 63 | vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> |
| 64 | |
| 65 | if 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 Moolenaar | dc08328 | 2016-10-11 08:57:33 +0200 | [diff] [blame] | 73 | \ '\<begin\%(logo\)\?char\>:\<endchar\>,' . |
| 74 | \ '\<beginglyph\>:\<endglyph\>,' . |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 75 | \ '\<begingraph\>:\<endgraph\>' |
| 76 | " Ignore comments and strings |
| 77 | let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") |
| 78 | \ =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"' |
| 79 | endif |
| 80 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 81 | let &cpo = s:cpo_save |
| 82 | unlet s:cpo_save |