blob: 7e7dfa7dca5460ca61b2fb137588d3e536c9efed [file] [log] [blame]
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01001vim9script
2
3# Vim filetype plugin file
4# Language: METAFONT
5# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
6# Former Maintainers: Nikolai Weibull <now@bitwi.se>
7# Latest Revision: 2022 Aug 12
Doug Kearns93197fd2024-01-14 20:59:02 +01008# 2024 Jan 14 by Vim Project (browsefilter)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar071d4272004-06-13 20:20:40 +000010if exists("b:did_ftplugin")
11 finish
12endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010014b:did_ftplugin = 1
15b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
Bram Moolenaare37d50a2008-08-06 17:06:04 +000016
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010017setlocal comments=:%
18setlocal commentstring=%\ %s
19setlocal formatoptions+=cjroql2
20setlocal formatoptions-=t
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020021setlocal omnifunc=syntaxcomplete#Complete
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010022setlocal suffixesadd=.mf
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020023
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010024&l:include = '\<input\>'
25&l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020026
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010027g:omni_syntax_group_include_mf = 'mf\w\+'
28g:omni_syntax_group_exclude_mf = 'mfTodoComment'
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020029
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010030if exists("g:loaded_matchit") && !exists("b:match_words")
31 b:match_ignorecase = 0
32 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "mf\\(Comment\\|String\\)$"'
33 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,'
34 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,'
35 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,'
36 .. '\<begingroup\>:\<endgroup\>,'
37 .. '\<begin\%(logo\)\?char\>:\<endchar\>'
38 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar2ec618c2016-10-01 14:47:05 +020039endif
Bram Moolenaar0dc065e2005-07-04 22:49:24 +000040
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010041if !get(g:, 'no_mf_maps', 0) && !get(g:, 'no_plugin_maps', 0)
42 const mf_regex = {
43 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|beginchar\|beginlogochar\)\>',
44 'endsection': '^\s*\%(enddef\|endchar\)\>',
45 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
46 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'}
47
48 def MoveAround(count: number, what: string, flags: string)
49 search(mf_regex[what], flags .. 's') # 's' sets previous context mark
50 var i = 2
51 while i <= count
52 search(mf_regex[what], flags)
53 i += 1
54 endwhile
55 enddef
56
57 # Macros to move around
58 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
59 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
60 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
61 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
62 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
63 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
64 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
65 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
66 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
67 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
68 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
69 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
70
71 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"]
72 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping)
73 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping)
74 endfor
75endif
76
77if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
78 b:browsefilter = "METAFONT Source Files (*.mf)\t*.mf\n"
Doug Kearns93197fd2024-01-14 20:59:02 +010079 if has("win32")
80 b:browsefilter ..= "All Files (*.*)\t*\n"
81 else
82 b:browsefilter ..= "All Files (*)\t*\n"
83 endif
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010084 b:undo_ftplugin ..= ' | unlet! b:browsefilter'
85endif
86
87# vim: sw=2 fdm=marker