Mercurial > vim
annotate runtime/ftplugin/mp.vim @ 30023:87063bfe81cd v9.0.0349
patch 9.0.0349: filetype of *.sil files not well detected
Commit: https://github.com/vim/vim/commit/be807d582499acbe314ead3891481cba6ca136df
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 1 15:01:25 2022 +0100
patch 9.0.0349: filetype of *.sil files not well detected
Problem: Filetype of *.sil files not well detected.
Solution: Inspect the file contents to guess the filetype.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 01 Sep 2022 16:15:03 +0200 |
parents | 2acb87ee55fc |
children | 8ae680be2a51 |
rev | line source |
---|---|
29756 | 1 vim9script |
2 | |
3 # Vim filetype plugin file | |
4 # Language: MetaPost | |
5 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> | |
6 # Former Maintainers: Nikolai Weibull <now@bitwi.se> | |
7 # Latest Revision: 2022 Aug 12 | |
389 | 8 |
9 if exists("b:did_ftplugin") | |
10 finish | |
11 endif | |
29756 | 12 |
13 b:did_ftplugin = 1 | |
14 b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<" | |
7 | 15 |
29756 | 16 setlocal comments=:% |
17 setlocal commentstring=%\ %s | |
18 setlocal formatoptions+=cjroql2 | |
19 setlocal formatoptions-=t | |
20 setlocal omnifunc=syntaxcomplete#Complete | |
21 setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl | |
1698 | 22 |
29756 | 23 &l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun |
24 &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+' | |
25 | |
26 g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+' | |
27 g:omni_syntax_group_exclude_mp = 'mfTodoComment' | |
389 | 28 |
29756 | 29 var fignum: number |
30 | |
31 def FixBeginfigs() | |
32 fignum = 1 | |
33 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum | |
34 enddef | |
35 | |
36 command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs() | |
389 | 37 |
29756 | 38 if exists("g:loaded_matchit") && !exists("b:match_words") |
39 b:match_ignorecase = 0 | |
40 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"' | |
41 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,' | |
42 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' | |
43 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' | |
44 .. '\<begin\(\a\+\)\>:end\1,' | |
45 .. '\<beginlogochar\>:\<endchar\>' | |
46 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip" | |
389 | 47 endif |
1698 | 48 |
29756 | 49 if !get(g:, 'no_mp_maps', 0) && !get(g:, 'no_plugin_maps', 0) |
50 const mp_regex = { | |
51 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>', | |
52 'endsection': '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>', | |
53 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>', | |
54 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'} | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
55 |
29756 | 56 def MoveAround(count: number, what: string, flags: string) |
57 search(mp_regex[what], flags .. 's') # 's' sets previous context mark | |
58 var i = 2 | |
59 while i <= count | |
60 search(mp_regex[what], flags) | |
61 i += 1 | |
62 endwhile | |
63 enddef | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
64 |
29756 | 65 # Macros to move around |
66 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> | |
67 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> | |
68 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> | |
69 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> | |
70 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> | |
71 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> | |
72 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> | |
73 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> | |
74 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> | |
75 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> | |
76 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr> | |
77 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr> | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
78 |
29756 | 79 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"] |
80 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping) | |
81 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping) | |
82 endfor | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
83 endif |
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
84 |
29756 | 85 if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter') |
86 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n" | |
87 .. "All Files (*.*)\t*.*\n" | |
88 b:undo_ftplugin ..= ' | unlet! b:browsefilter' | |
89 endif | |
90 | |
91 # vim: sw=2 fdm=marker |