Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 1 | vim9script |
| 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 Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 8 | # 2024 Jan 14 by Vim Project (browsefilter) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | if exists("b:did_ftplugin") |
| 11 | finish |
| 12 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 13 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 14 | b:did_ftplugin = 1 |
| 15 | b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<" |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 16 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 17 | setlocal comments=:% |
| 18 | setlocal commentstring=%\ %s |
| 19 | setlocal formatoptions+=cjroql2 |
| 20 | setlocal formatoptions-=t |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 21 | setlocal omnifunc=syntaxcomplete#Complete |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 22 | setlocal suffixesadd=.mf |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 23 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 24 | &l:include = '\<input\>' |
| 25 | &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+' |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 26 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 27 | g:omni_syntax_group_include_mf = 'mf\w\+' |
| 28 | g:omni_syntax_group_exclude_mf = 'mfTodoComment' |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 29 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 30 | if 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 Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 39 | endif |
Bram Moolenaar | 0dc065e | 2005-07-04 22:49:24 +0000 | [diff] [blame] | 40 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 41 | if !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 |
| 75 | endif |
| 76 | |
| 77 | if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter') |
| 78 | b:browsefilter = "METAFONT Source Files (*.mf)\t*.mf\n" |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 79 | if has("win32") |
| 80 | b:browsefilter ..= "All Files (*.*)\t*\n" |
| 81 | else |
| 82 | b:browsefilter ..= "All Files (*)\t*\n" |
| 83 | endif |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 84 | b:undo_ftplugin ..= ' | unlet! b:browsefilter' |
| 85 | endif |
| 86 | |
| 87 | # vim: sw=2 fdm=marker |