mf.vim (3249B)
1 " Vim filetype plugin file 2 " Language: METAFONT 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=.mf 20 let &l:include = '\<input\>' 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_mf = 'mf\w\+' 24 let g:omni_syntax_group_exclude_mf = 'mfTodoComment' 25 26 let s:mp_regex = { 27 \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|beginchar\|beginlogochar\)\>', 28 \ 'endsection' : '^\s*\%(enddef\|endchar\)\>', 29 \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>', 30 \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>' 31 \ } 32 33 function! s:move_around(count, what, flags, visual) 34 if a:visual 35 exe "normal! gv" 36 endif 37 call search(s:mp_regex[a:what], a:flags.'s') " 's' sets previous context mark 38 call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)') 39 endfunction 40 41 42 " Move around macros. 43 nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR> 44 vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR> 45 nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR> 46 vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR> 47 nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR> 48 vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR> 49 nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR> 50 vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR> 51 nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR> 52 vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR> 53 nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR> 54 vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR> 55 56 if exists("loaded_matchit") 57 let b:match_ignorecase = 0 58 let b:match_words = 59 \ '\<if\>:\<else\%[if]\>:\<fi\>,' . 60 \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' . 61 \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' . 62 \ '\<begingroup\>:\<endgroup\>,' . 63 \ '\<begin\%(logo\)\?char\>:\<endchar\>' 64 " Ignore comments and strings 65 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") 66 \ =~# "mf\\(Comment\\|String\\)$"' 67 endif 68 69 let &cpo = s:cpo_save 70 unlet s:cpo_save