Mercurial > vim
annotate runtime/ftplugin/mp.vim @ 34540:9e093c96dff6 v9.1.0172
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Commit: https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Mar 12 21:50:32 2024 +0100
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: #14183
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Mar 2024 22:00:04 +0100 |
parents | 8ae680be2a51 |
children |
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 | |
34134
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
8 # 2024 Jan 14 by Vim Project (browsefilter) |
389 | 9 |
10 if exists("b:did_ftplugin") | |
11 finish | |
12 endif | |
29756 | 13 |
14 b:did_ftplugin = 1 | |
15 b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<" | |
7 | 16 |
29756 | 17 setlocal comments=:% |
18 setlocal commentstring=%\ %s | |
19 setlocal formatoptions+=cjroql2 | |
20 setlocal formatoptions-=t | |
21 setlocal omnifunc=syntaxcomplete#Complete | |
22 setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl | |
1698 | 23 |
29756 | 24 &l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun |
25 &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+' | |
26 | |
27 g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+' | |
28 g:omni_syntax_group_exclude_mp = 'mfTodoComment' | |
389 | 29 |
29756 | 30 var fignum: number |
31 | |
32 def FixBeginfigs() | |
33 fignum = 1 | |
34 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum | |
35 enddef | |
36 | |
37 command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs() | |
389 | 38 |
29756 | 39 if exists("g:loaded_matchit") && !exists("b:match_words") |
40 b:match_ignorecase = 0 | |
41 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"' | |
42 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,' | |
43 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,' | |
44 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,' | |
45 .. '\<begin\(\a\+\)\>:end\1,' | |
46 .. '\<beginlogochar\>:\<endchar\>' | |
47 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip" | |
389 | 48 endif |
1698 | 49 |
29756 | 50 if !get(g:, 'no_mp_maps', 0) && !get(g:, 'no_plugin_maps', 0) |
51 const mp_regex = { | |
52 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>', | |
53 'endsection': '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>', | |
54 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>', | |
55 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'} | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
56 |
29756 | 57 def MoveAround(count: number, what: string, flags: string) |
58 search(mp_regex[what], flags .. 's') # 's' sets previous context mark | |
59 var i = 2 | |
60 while i <= count | |
61 search(mp_regex[what], flags) | |
62 i += 1 | |
63 endwhile | |
64 enddef | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
65 |
29756 | 66 # Macros to move around |
67 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> | |
68 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> | |
69 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> | |
70 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> | |
71 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> | |
72 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> | |
73 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> | |
74 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> | |
75 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> | |
76 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> | |
77 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr> | |
78 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
|
79 |
29756 | 80 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"] |
81 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping) | |
82 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping) | |
83 endfor | |
10244
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
84 endif |
876fbdd84e52
commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents:
1698
diff
changeset
|
85 |
29756 | 86 if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter') |
87 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n" | |
34134
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
88 if has("win32") |
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
89 b:browsefilter ..= "All Files (*.*)\t*\n" |
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
90 else |
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
91 b:browsefilter ..= "All Files (*)\t*\n" |
8ae680be2a51
runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents:
29756
diff
changeset
|
92 endif |
29756 | 93 b:undo_ftplugin ..= ' | unlet! b:browsefilter' |
94 endif | |
95 | |
96 # vim: sw=2 fdm=marker |