From 5d67aef3060d6d3aa14d273c39f23d8a90c4cef1 Mon Sep 17 00:00:00 2001 From: dkearns Date: Sun, 10 Mar 2024 04:01:22 +1100 Subject: runtime(vim): Update base-syntax, improve :map highlighting (#14141) Improve :map command highlighting. - Fix multiline RHS matching, allow continued lines and comments. - Allow ^V-escaped whitespace in LHS. - Handle map-bar properly and allow trailing commands. Fixes issue #12672. Signed-off-by: Doug Kearns Signed-off-by: Christian Brabandt --- runtime/syntax/generator/vim.vim.base | 12 +++-- runtime/syntax/testdir/dumps/vim_ex_map_01.dump | 20 ++++++++ runtime/syntax/testdir/dumps/vim_ex_map_02.dump | 20 ++++++++ runtime/syntax/testdir/dumps/vim_ex_map_03.dump | 20 ++++++++ runtime/syntax/testdir/dumps/vim_ex_map_04.dump | 20 ++++++++ runtime/syntax/testdir/dumps/vim_ex_map_99.dump | 36 +++++++------- runtime/syntax/testdir/input/vim_ex_map.vim | 66 +++++++++++++++++++++++++ runtime/syntax/vim.vim | 12 +++-- 8 files changed, 178 insertions(+), 28 deletions(-) create mode 100644 runtime/syntax/testdir/dumps/vim_ex_map_01.dump create mode 100644 runtime/syntax/testdir/dumps/vim_ex_map_02.dump create mode 100644 runtime/syntax/testdir/dumps/vim_ex_map_03.dump create mode 100644 runtime/syntax/testdir/dumps/vim_ex_map_04.dump (limited to 'runtime/syntax') diff --git a/runtime/syntax/generator/vim.vim.base b/runtime/syntax/generator/vim.vim.base index 5fc0d089e2..fe87119908 100644 --- a/runtime/syntax/generator/vim.vim.base +++ b/runtime/syntax/generator/vim.vim.base @@ -467,11 +467,13 @@ syn match vimMap "\" contains=vimMapModKey,vimMapModErr skipwhite nextgroup=vimMapMod,vimMapLhs -syn match vimMapRhs contained ".*" contains=vimNotation,vimCtrlChar skipnl nextgroup=vimMapRhsExtend -syn match vimMapRhsExtend contained "^\s*\\.*$" contains=vimContinue +syn region vimMapRhs contained start="\S" skip=+\\|\|\@1<=|\|\n\s*\\\|\n\s*"\\ + end="|" end="$" contains=@vimContinue,vimCtrlChar,vimNotation skipnl nextgroup=vimMapRhsContinue +" assume a continuation comment introduces the RHS +syn region vimMapRhsContinue contained start=+^\s*\%(\\\|"\\ \)+ skip=+\\|\|\@1<=|\|\n\s*\\\|\n\s*"\\ + end="|" end="$" contains=@vimContinue,vimCtrlChar,vimNotation syn case ignore syn keyword vimMapModKey contained buffer expr leader localleader nowait plug script sid silent unique syn case match @@ -1137,4 +1139,4 @@ delc VimFoldr delc VimFoldt let &cpo = s:keepcpo unlet s:keepcpo -" vim:ts=18 fdm=marker +" vim:ts=18 fdm=marker ft=vim diff --git a/runtime/syntax/testdir/dumps/vim_ex_map_01.dump b/runtime/syntax/testdir/dumps/vim_ex_map_01.dump new file mode 100644 index 0000000000..7b4353382d --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_ex_map_01.dump @@ -0,0 +1,20 @@ +|v+0#af5f00255#ffffff0|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|x+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|s+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|o+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|i+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +>l+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|c+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +|t+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 +@75 +@75 +|"+0#0000e05&| |:|h|e|l|p| |m|a|p|-|b|a|r| +0#0000000&@59 +@75 +|"+0#0000e05&| |<|B|a|r|>| @4|'|<|'| |i|s| |n|o|t| |i|n| |'|c|p|o|p|t|i|o|n|s|'| +0#0000000&@37 +|m+0#af5f00255&|a|p| +0#0000000&|_|l| |:|!|l|s| |<+0#e000e06&|B|a|r|>| +0#0000000&|m|o|r|e|^|M|:|e|c|h|o| |"|r|h|s|"|<+0#e000e06&|C|R|>| +0#0000000&@35 +|"+0#0000e05&| |\||| @7|'|b|'| |i|s| |n|o|t| |i|n| |'|c|p|o|p|t|i|o|n|s|'| +0#0000000&@37 +|m+0#af5f00255&|a|p| +0#0000000&|_|l| |:|!|l|s| |\||| |m|o|r|e|^|M|:|e|c|h|o| |"|r|h|s|"|<+0#e000e06&|C|R|>| +0#0000000&@38 +|"+0#0000e05&| |^|V||| @6|a|l|w|a|y|s|,| |i|n| |V|i|m| |a|n|d| |V|i| +0#0000000&@41 +|m+0#af5f00255&|a|p| +0#0000000&|_|l| |:|!|l|s| |^+0#0000e05&|V||+0#0000000&| |m|o|r|e|^|M|:|e|c|h|o| |"|r|h|s|"|<+0#e000e06&|C|R|>| +0#0000000&@37 +@75 +@57|1|9|,|1| @9|1|9|%| diff --git a/runtime/syntax/testdir/dumps/vim_ex_map_02.dump b/runtime/syntax/testdir/dumps/vim_ex_map_02.dump new file mode 100644 index 0000000000..c598781d6a --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_ex_map_02.dump @@ -0,0 +1,20 @@ +| +0&#ffffff0@74 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| |:|s|e|a|r|c|h|(|'|f|o@1|\@1|||b|a|r|'|)|<+0#e000e06&|C|R|>|:+0#0000000&|e|c|h|o| |"|r|h|s|"|<+0#e000e06&|C|R|>| +0#0000000&@27 +@75 +@75 +|"+0#0000e05&| |m|u|l|t|i|l|i|n|e| |R|H|S| +0#0000000&@59 +> @74 +|m+0#af5f00255&|a|p| +0#0000000&|<+0#e000e06&|l|e|a|d|e|r|>|b+0#0000000&|a|z| @59 +@2|\+0#e000e06&| +0#0000000&|:|e|c|h|o| |(|<+0#e000e06&|b|a|r|>| +0#0000000&@58 +@2|\+0#e000e06&| +0#0000000&@71 +@2|\+0#e000e06&|'+0#0000000&|b|a|r|'|)|<+0#e000e06&|c|r|>| +0#0000000&@61 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| @67 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| @67 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +@57|3|7|,|0|-|1| @7|4|5|%| diff --git a/runtime/syntax/testdir/dumps/vim_ex_map_03.dump b/runtime/syntax/testdir/dumps/vim_ex_map_03.dump new file mode 100644 index 0000000000..4ad6e82e27 --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_ex_map_03.dump @@ -0,0 +1,20 @@ +| +0&#ffffff0@1|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s|^+0#0000e05&|V| +0#0000000&@65 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +> @74 +|m+0#af5f00255&|a|p| +0#0000000&|l|^+0#0000e05&|V| +0#0000000&|h|s| @64 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|^+0#0000e05&|V| +0#0000000&|h|s| @64 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|e|c|h|o| |"|f|o@1|"| @60 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| |r|h|s| @63 +|m+0#af5f00255&|a|p| +0#0000000&|l|^+0#0000e05&|V| +0#0000000&|h|^+0#0000e05&|V| +0#0000000&|s|^+0#0000e05&|V| +0#0000000&@1|r|h|s| @54 +@75 +|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| @67 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| |(|m|a|t|c|h|e|s| |a|s| |R|H|S| |b|u|t| |h|a|r|m|l|e|s@1|)| +0#0000000&@32 +@57|5@1|,|0|-|1| @7|7|2|%| diff --git a/runtime/syntax/testdir/dumps/vim_ex_map_04.dump b/runtime/syntax/testdir/dumps/vim_ex_map_04.dump new file mode 100644 index 0000000000..254fc91179 --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_ex_map_04.dump @@ -0,0 +1,20 @@ +| +0&#ffffff0@1|"+0#0000e05&|\| |c|o|m@1|e|n|t| |(|m|a|t|c|h|e|s| |a|s| |R|H|S| |b|u|t| |h|a|r|m|l|e|s@1|)| +0#0000000&@32 +|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|c|l|e|a|r|"| +0#0000000&@62 +@75 +@75 +|"+0#0000e05&| |I|s@1|u|e| @1|#|1|2|6|7|2| +0#0000000&@59 +> @74 +|n+0#af5f00255&@1|o|r|e|m|a|p| +0#0000000&|<+0#e000e06&|l|e|a|d|e|r|>|f+0#0000000&|o@1| |:|e|c|h|o| |c|a|l@1|(| @42 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|{|x|-|>|x|}|,| @63 +@2|\+0#e000e06&| +0#0000000&|[|'|f|o@1|'|]|)|<+0#e000e06&|c|r|>| +0#0000000&@58 +@75 +|n+0#af5f00255&@1|o|r|e|m|a|p| +0#0000000&|<+0#e000e06&|l|e|a|d|e|r|>|b+0#0000000&|a|r| |:|e|c|h|o| |(| @46 +@2|\+0#e000e06&| +0#0000000&@71 +@2|\+0#e000e06&| +0#0000000&|'|b|a|r|'|)|<+0#e000e06&|c|r|>| +0#0000000&@60 +@75 +@75 +|"+0#0000e05&| +0#0000000&|E+0#e000e06&|x|a|m|p|l|e|:| +0#0000000&@64 +|"+0#0000e05&| @2|/|a|u|t|o|l|o|a|d|/|n|e|t|r|w|.|v|i|m| +0#0000000&@51 +@75 +@57|7|3|,|0|-|1| @7|9|8|%| diff --git a/runtime/syntax/testdir/dumps/vim_ex_map_99.dump b/runtime/syntax/testdir/dumps/vim_ex_map_99.dump index fa5a0d7ea5..37ee7cf982 100644 --- a/runtime/syntax/testdir/dumps/vim_ex_map_99.dump +++ b/runtime/syntax/testdir/dumps/vim_ex_map_99.dump @@ -1,20 +1,20 @@ -|m+0#af5f00255#ffffff0|a|p|!| +0#0000000&@70 -|m+0#af5f00255&|a|p|!| +0#0000000&|l|h|s| |r|h|s| @62 -|m+0#af5f00255&|a|p| +0#0000000&@71 -|m+0#af5f00255&|a|p| +0#0000000&|l|h|s| |r|h|s| @63 +| +0&#ffffff0@74 @75 -|c+0#af5f00255&|a|l@1| +0#0000000&|m+0#00e0e07&|a|p|(+0#e000e06&|l+0#00e0e07&|i|s|t|,+0#0000000&| |'+0#e000002&|v|:|v|a|l|'|)+0#e000e06&| +0#0000000&@51 -|c+0#af5f00255&|a|l@1| +0#0000000&|m+0#00e0e07&|a|p| +0#0000000&|(+0#e000e06&|l+0#00e0e07&|i|s|t|,+0#0000000&| |'+0#e000002&|v|:|v|a|l|'|)+0#e000e06&| +0#0000000&@50 +|"+0#0000e05&| |I|s@1|u|e| @1|#|1|2|6|7|2| +0#0000000&@59 @75 -|m+0#af5f00255&|a|p|c|l|e|a|r| +0#0000000&@1|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|m+0#af5f00255&|a|p|c|l|e|a|r|!| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|n+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|v+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|x+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|s+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|o+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|i+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|l+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -|c+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 ->t+0#af5f00255&|m|a|p|c|l|e|a|r| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&@56 -@57|2|1|,|1| @9|B|o|t| +|n+0#af5f00255&@1|o|r|e|m|a|p| +0#0000000&|<+0#e000e06&|l|e|a|d|e|r|>|f+0#0000000&|o@1| |:|e|c|h|o| |c|a|l@1|(| @42 +@2|"+0#0000e05&|\| |c|o|m@1|e|n|t| +0#0000000&@62 +@2|\+0#e000e06&| +0#0000000&|{|x|-|>|x|}|,| @63 +@2|\+0#e000e06&| +0#0000000&|[|'|f|o@1|'|]|)|<+0#e000e06&|c|r|>| +0#0000000&@58 +@75 +|n+0#af5f00255&@1|o|r|e|m|a|p| +0#0000000&|<+0#e000e06&|l|e|a|d|e|r|>|b+0#0000000&|a|r| |:|e|c|h|o| |(| @46 +@2|\+0#e000e06&| +0#0000000&@71 +@2|\+0#e000e06&| +0#0000000&|'|b|a|r|'|)|<+0#e000e06&|c|r|>| +0#0000000&@60 +@75 +@75 +|"+0#0000e05&| +0#0000000&|E+0#e000e06&|x|a|m|p|l|e|:| +0#0000000&@64 +|"+0#0000e05&| @2|/|a|u|t|o|l|o|a|d|/|n|e|t|r|w|.|v|i|m| +0#0000000&@51 +@75 +>i+0#af5f00255&|f| +0#0000000&|!+0#af5f00255&|h+0#00e0e07&|a|s|m|a|p|t|o|(+0#e000e06&|'+0#e000002&|<|P|l|u|g|>|N|e|t|r|w|O|p|e|n|F|i|l|e|'|)+0#e000e06&| +0#0000000&@9|||n+0#af5f00255&|m|a|p| +0#0000000&|<+0#e000e06&|b|u|f@1|e|r|>| +0#0000000&|<+0#e000e06&|s|i|l|e|n|t|>| +0#0000000&|<+0#e000e06&|n|o|w|a|i +|t|>| +0#0000000&|%| |<+0#e000e06&|P|l|u|g|>|N+0#0000000&|e|t|r|w|O|p|e|n|F|i|l|e|||e+0#af5f00255&|n|d|i|f| +0#0000000&@44 +@57|8|7|,|1| @9|B|o|t| diff --git a/runtime/syntax/testdir/input/vim_ex_map.vim b/runtime/syntax/testdir/input/vim_ex_map.vim index 81fe84cc93..95f42922e3 100644 --- a/runtime/syntax/testdir/input/vim_ex_map.vim +++ b/runtime/syntax/testdir/input/vim_ex_map.vim @@ -19,3 +19,69 @@ imapclear lmapclear cmapclear tmapclear + + +" :help map-bar + +" '<' is not in 'cpoptions' +map _l :!ls more^M:echo "rhs" +" \| 'b' is not in 'cpoptions' +map _l :!ls \| more^M:echo "rhs" +" ^V| always, in Vim and Vi +map _l :!ls | more^M:echo "rhs" + +map lhs :search('foo\\|bar'):echo "rhs" + + +" multiline RHS + +map baz + \ :echo ( + \ + \'bar') + "\ comment + +map lhs + "\ comment + \ echo "foo" + +map lhs + "\ comment + \ echo "foo" + +map lhs + "\ comment + \ echo "foo" + +map l hs + "\ comment + \ echo "foo" + +map l hs + "\ comment + \ echo "foo" + +map lhs rhs +map l h s rhs + +map lhs + "\ comment (matches as RHS but harmless) +echo "clear" + + +" Issue #12672 + +nnoremap foo :echo call( + "\ comment + \ {x->x}, + \ ['foo']) + +nnoremap bar :echo ( + \ + \ 'bar') + + +" Example: +" /autoload/netrw.vim + +if !hasmapto('NetrwOpenFile') |nmap % NetrwOpenFile|endif diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index 32933fd698..5d6db23f2a 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -511,11 +511,13 @@ syn keyword vimMap cmapc[lear] imapc[lear] lmapc[lear] nmapc[lear] omapc[lear] s syn keyword vimMap mapc[lear] skipwhite nextgroup=vimMapBang,vimMapMod " GEN_SYN_VIM: vimCommand unmap, START_STR='syn keyword vimUnmap', END_STR='skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs' syn keyword vimUnmap cu[nmap] iu[nmap] lu[nmap] nun[map] ou[nmap] sunm[ap] tunma[p] unm[ap] vu[nmap] xu[nmap] skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs -syn match vimMapLhs contained "\S\+" contains=vimNotation,vimCtrlChar skipwhite nextgroup=vimMapRhs -syn match vimMapBang contained "\a\@1<=!" skipwhite nextgroup=vimMapMod,vimMapLhs +syn match vimMapLhs contained "\%(.\|\S\)\+" contains=vimCtrlChar,vimNotation skipwhite nextgroup=vimMapRhs +syn match vimMapLhs contained "\%(.\|\S\)\+\ze\s*$" contains=vimCtrlChar,vimNotation skipwhite skipnl nextgroup=vimMapRhsContinue +syn match vimMapBang contained "\a\@1<=!" skipwhite nextgroup=vimMapMod,vimMapLhs syn match vimMapMod contained "\%#=1\c<\(buffer\|expr\|\(local\)\=leader\|nowait\|plug\|script\|sid\|unique\|silent\)\+>" contains=vimMapModKey,vimMapModErr skipwhite nextgroup=vimMapMod,vimMapLhs -syn match vimMapRhs contained ".*" contains=vimNotation,vimCtrlChar skipnl nextgroup=vimMapRhsExtend -syn match vimMapRhsExtend contained "^\s*\\.*$" contains=vimContinue +syn region vimMapRhs contained start="\S" skip=+\\|\|\@1<=|\|\n\s*\\\|\n\s*"\\ + end="|" end="$" contains=@vimContinue,vimCtrlChar,vimNotation skipnl nextgroup=vimMapRhsContinue +" assume a continuation comment introduces the RHS +syn region vimMapRhsContinue contained start=+^\s*\%(\\\|"\\ \)+ skip=+\\|\|\@1<=|\|\n\s*\\\|\n\s*"\\ + end="|" end="$" contains=@vimContinue,vimCtrlChar,vimNotation syn case ignore syn keyword vimMapModKey contained buffer expr leader localleader nowait plug script sid silent unique syn case match @@ -1182,4 +1184,4 @@ delc VimFoldr delc VimFoldt let &cpo = s:keepcpo unlet s:keepcpo -" vim:ts=18 fdm=marker +" vim:ts=18 fdm=marker ft=vim -- cgit v1.2.3