neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

mp.vim (3712B)


      1 " Vim filetype plugin file
      2 " Language:           MetaPost
      3 " Maintainer:         Nicola Vitacolonna <nvitacolonna@gmail.com>
      4 " Former Maintainers: Nikolai Weibull <now@bitwi.se>
      5 " Latest Revision:    2016 Oct 2
      6 
      7 if exists("b:did_ftplugin")
      8  finish
      9 endif
     10 let b:did_ftplugin = 1
     11 
     12 let s:cpo_save = &cpo
     13 set cpo&vim
     14 
     15 let b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
     16      \ . "| unlet! b:match_ignorecase b:match_words b:match_skip"
     17 
     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'
     25 
     26 if 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
     33 endif
     34 
     35 let 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 
     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
     47  call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
     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\>,' .
     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$"'
     79 endif
     80 
     81 let &cpo = s:cpo_save
     82 unlet s:cpo_save