changeset 34513:97fc56ee7ca7

runtime(vim): Update base-syntax, improve :map highlighting (#14141) Commit: https://github.com/vim/vim/commit/5d67aef3060d6d3aa14d273c39f23d8a90c4cef1 Author: dkearns <dougkearns@gmail.com> Date: Sun Mar 10 04:01:22 2024 +1100 runtime(vim): Update base-syntax, improve :map highlighting (https://github.com/vim/vim/issues/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 <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 09 Mar 2024 18:15:04 +0100
parents f68c5e30c2d4
children 728675946924
files runtime/syntax/generator/vim.vim.base runtime/syntax/testdir/dumps/vim_ex_map_01.dump runtime/syntax/testdir/dumps/vim_ex_map_02.dump runtime/syntax/testdir/dumps/vim_ex_map_03.dump runtime/syntax/testdir/dumps/vim_ex_map_04.dump runtime/syntax/testdir/dumps/vim_ex_map_99.dump runtime/syntax/testdir/input/vim_ex_map.vim runtime/syntax/vim.vim
diffstat 8 files changed, 178 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/syntax/generator/vim.vim.base
+++ b/runtime/syntax/generator/vim.vim.base
@@ -467,11 +467,13 @@ syn match	vimMap		"\<map!"	  contains=vi
 " GEN_SYN_VIM: vimCommand mapclear, START_STR='syn keyword vimMap', END_STR='skipwhite nextgroup=vimMapMod'
 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 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
@@ -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
new file mode 100644
--- /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|%| 
new file mode 100644
--- /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|%| 
new file mode 100644
--- /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|%| 
new file mode 100644
--- /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|%| 
--- 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
+|"+0#0000e05&| |I|s@1|u|e| @1|#|1|2|6|7|2| +0#0000000&@59
 @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
+|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
-|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|>|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| 
--- a/runtime/syntax/testdir/input/vim_ex_map.vim
+++ b/runtime/syntax/testdir/input/vim_ex_map.vim
@@ -19,3 +19,69 @@ imapclear <buffer>
 lmapclear <buffer>
 cmapclear <buffer>
 tmapclear <buffer>
+
+
+" :help map-bar
+
+" <Bar>     '<' is not in 'cpoptions'
+map _l :!ls <Bar> more^M:echo "rhs"<CR>
+" \|        'b' is not in 'cpoptions'
+map _l :!ls \| more^M:echo "rhs"<CR>
+" ^V|       always, in Vim and Vi
+map _l :!ls | more^M:echo "rhs"<CR>
+
+map lhs :search('foo\\|bar')<CR>:echo "rhs"<CR>
+
+
+" multiline RHS
+
+map <leader>baz 
+  \ :echo (<bar>
+  \
+  \'bar')<cr>
+  "\ 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 <leader>foo :echo call(
+  "\ comment
+  \ {x->x},
+  \ ['foo'])<cr>
+
+nnoremap <leader>bar :echo (
+  \
+  \ 'bar')<cr>
+
+
+" Example:
+"   /autoload/netrw.vim
+
+if !hasmapto('<Plug>NetrwOpenFile')          |nmap <buffer> <silent> <nowait> %	<Plug>NetrwOpenFile|endif
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -511,11 +511,13 @@ syn keyword vimMap cmapc[lear] imapc[lea
 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