blob: 7c9a8a12833fd1c29f13a9bc20d0956ee26553a9 [file] [log] [blame]
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00001" Vim filetype plugin file
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02002" Language: METAFONT
3" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
4" Former Maintainers: Nikolai Weibull <now@bitwi.se>
Bram Moolenaardc083282016-10-11 08:57:33 +02005" Latest Revision: 2016 Oct 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar071d4272004-06-13 20:20:40 +00007if exists("b:did_ftplugin")
8 finish
9endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010let 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=.mf
20let &l:include = '\<input\>'
21let &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
22setlocal omnifunc=syntaxcomplete#Complete
23let g:omni_syntax_group_include_mf = 'mf\w\+'
24let g:omni_syntax_group_exclude_mf = 'mfTodoComment'
25
26let s:mp_regex = {
27 \ 'beginsection' : '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|beginchar\|beginlogochar\)\>',
Bram Moolenaardc083282016-10-11 08:57:33 +020028 \ 'endsection' : '^\s*\%(enddef\|endchar\)\>',
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020029 \ 'beginblock' : '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
30 \ 'endblock' : '^\s*\%(endgroup\|fi\|endfor\)\>'
31 \ }
32
33function! 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
Bram Moolenaardc083282016-10-11 08:57:33 +020038 call map(range(2, a:count), 'search(s:mp_regex[a:what], a:flags)')
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020039endfunction
40
41
42" Move around macros.
43nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
44vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true) <CR>
45nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:false) <CR>
46vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W", v:true) <CR>
47nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:false) <CR>
48vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection", "bW", v:true) <CR>
49nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:false) <CR>
50vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection", "W", v:true) <CR>
51nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:false) <CR>
52vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock", "bW", v:true) <CR>
53nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:false) <CR>
54vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock", "W", v:true) <CR>
55
56if 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\>,' .
Bram Moolenaardc083282016-10-11 08:57:33 +020063 \ '\<begin\%(logo\)\?char\>:\<endchar\>'
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020064 " Ignore comments and strings
65 let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
66 \ =~# "mf\\(Comment\\|String\\)$"'
67endif
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000068
Bram Moolenaare37d50a2008-08-06 17:06:04 +000069let &cpo = s:cpo_save
70unlet s:cpo_save