xref: /vim-8.2.3635/runtime/ftplugin/mf.vim (revision 2ec618c9)
1" Vim filetype plugin file
2" Language:           METAFONT
3" Maintainer:         Nicola Vitacolonna <[email protected]>
4" Former Maintainers: Nikolai Weibull <[email protected]>
5" Latest Revision:    2016 Oct 1
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=.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\)\>',
28      \ 'endsection'   : '^\s*\%(enddef\|endchar\|endlogochar\)\>',
29      \ '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
38  for i in range(2, a:count)
39    call search(s:mp_regex[a:what], a:flags)
40  endfor
41endfunction
42
43
44" Move around macros.
45nnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:false) <CR>
46vnoremap <silent><buffer> [[ :<C-U>call <SID>move_around(v:count1, "beginsection", "bW", v:true)  <CR>
47nnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W",  v:false) <CR>
48vnoremap <silent><buffer> ]] :<C-U>call <SID>move_around(v:count1, "beginsection", "W",  v:true)  <CR>
49nnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection",   "bW", v:false) <CR>
50vnoremap <silent><buffer> [] :<C-U>call <SID>move_around(v:count1, "endsection",   "bW", v:true)  <CR>
51nnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection",   "W",  v:false) <CR>
52vnoremap <silent><buffer> ][ :<C-U>call <SID>move_around(v:count1, "endsection",   "W",  v:true)  <CR>
53nnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock",   "bW", v:false) <CR>
54vnoremap <silent><buffer> [{ :<C-U>call <SID>move_around(v:count1, "beginblock",   "bW", v:true)  <CR>
55nnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock",     "W",  v:false) <CR>
56vnoremap <silent><buffer> ]} :<C-U>call <SID>move_around(v:count1, "endblock",     "W",  v:true)  <CR>
57
58if exists("loaded_matchit")
59  let b:match_ignorecase = 0
60  let b:match_words =
61        \ '\<if\>:\<else\%[if]\>:\<fi\>,' .
62        \ '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' .
63        \ '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' .
64        \ '\<begingroup\>:\<endgroup\>,' .
65        \ '\<beginchar\>:\<endchar\>' .
66        \ '\<beginlogochar\>:\<endlogochar\>'
67  " Ignore comments and strings
68  let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
69        \ =~# "mf\\(Comment\\|String\\)$"'
70endif
71
72let &cpo = s:cpo_save
73unlet s:cpo_save
74