changeset 33800:dd4dd8e83b1f

runtime(vim): Improve keymap file highlighting (#13550) Commit: https://github.com/vim/vim/commit/69866449ddb20e329f4bc5250312fbfb4a773986 Author: dkearns <dougkearns@gmail.com> Date: Wed Nov 22 05:43:40 2023 +1100 runtime(vim): Improve keymap file highlighting (https://github.com/vim/vim/issues/13550) - Match :loadkeymap to EOF as a region and contain only allowed items. - Add highlighting for <Char- notation. - add basic syntax highlighting tests Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 21 Nov 2023 19:45:05 +0100
parents 93b27fc986fb
children d9576e67ab4b
files runtime/syntax/testdir/dumps/vim_00.dump runtime/syntax/testdir/dumps/vim_01.dump runtime/syntax/testdir/dumps/vim_99.dump runtime/syntax/testdir/input/vim.vim runtime/syntax/vim.vim
diffstat 5 files changed, 103 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/vim_00.dump
@@ -0,0 +1,20 @@
+>"+0#0000e05#ffffff0| |V|i|m| |K|e|y|m|a|p| |f|i|l|e| |f|o|r| |s|y|n|t|a|x| |t|e|s|t|i|n|g| @38
+@75
+@75
+@46| +0#0000000&@28
+@75
+@75
+|"+0#0000e05&| +0#0000000&|M+0#e000e06&|a|i|n|t|a|i|n|e|r|:| +0#0000e05&@2|D|o|u|g| |K|e|a|r|n|s| |<|d|o|u|g|k|e|a|r|n|s|@|g|m|a|i|l|.|c|o|m|>| @24
+@60| +0#0000000&@14
+|"+0#0000e05&| +0#0000000&|L+0#e000e06&|a|s|t| |C|h|a|n|g|e|d|:| +0#0000e05&|2|0|2|3| |N|o|v| |2|1| @47
+@75
+@75
+@46| +0#0000000&@28
+@75
+@75
+@75
+@75
+|s+0#af5f00255&|c|r|i|p|t|e|n|c|o|d|i|n|g| +0#0000000&|u|t|f|-+0#af5f00255&|8+0#e000002&| +0#0000000&@54
+@75
+|@+0#4040ff13&@2| @71
+|"+0#0000000&|i|n|p|u|t|/|v|i|m|.|v|i|m|"| |2|6|L|,| |3|9@1|2|B| @30|1|,|1| @10|T|o|p| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/vim_01.dump
@@ -0,0 +1,20 @@
+| +0&#ffffff0@74
+@75
+|a| |A| @3|B+0#0000e05&|a|s|i|c| |m|a|p@1|i|n|g| @38| +0#0000000&@15
+|'|a| |á| @2|M+0#0000e05&|o|r|e| |t|h|a|n| |o|n|e| |c|h|a|r| |i|n| |f|i|r|s|t| |c|o|l|u|m|n| @10| +0#0000000&@22
+@75
+>"+0#0000e05&| |S|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| @56
+@60| +0#0000000&@14
+|<+0#e000e06&|c|h|a|r|-|6|2|>| +0#0000000&@5|B| @14|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |L|H|S| |-| |d|e|c|i|m|a|l| @2
+@75
+@75
+@46| +0#0000000&@28
+|c| @13|<+0#e000e06&|c|h|a|r|-|0|1|0|3|>| +0#0000000&@4|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |R|H|S| |-| |o|c|t|a|l| @4
+@60| +0#0000000&@14
+|<+0#e000e06&|c|h|a|r|-|0|x|0@1|6|4|>| +0#0000000&@1|<+0#e000e06&|c|h|a|r|-|0|x|0@1|4@1|>| +0#0000000&@2|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |L|H|S| |a|n|d| |R|H|S| |-| |h|e
+|x|a|d|e|c|i|m|a|l| @50| +0#0000000&@14
+@75
+|"+0#0000e05&| |V|i|m|-|s|c|r|i|p|t| |c|o|m@1|e|n|t| |c|h|a|r|a|c|t|e|r|s| @30| +0#0000000&@12
+|#| |<+0#e000e06&|c|h|a|r|-|0|x|0@1|a|3|>| +0#0000000&@15|L+0#0000e05&|i|n|e| |s|h|o|u|l|d| |n|o|t| |m|a|t|c|h| |a|s| |a| |V|i|m|9|-|s|c|r|i|p|t| |c|o|m@1|e
+|n|t| +0#0000000&@72
+@57|1|9|,|1| @9|9|3|%| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/vim_99.dump
@@ -0,0 +1,20 @@
+|a+0&#ffffff0| |A| @3|B+0#0000e05&|a|s|i|c| |m|a|p@1|i|n|g| @38| +0#0000000&@15
+|'|a| |á| @2|M+0#0000e05&|o|r|e| |t|h|a|n| |o|n|e| |c|h|a|r| |i|n| |f|i|r|s|t| |c|o|l|u|m|n| @10| +0#0000000&@22
+@75
+|"+0#0000e05&| |S|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| @56
+@60| +0#0000000&@14
+|<+0#e000e06&|c|h|a|r|-|6|2|>| +0#0000000&@5|B| @14|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |L|H|S| |-| |d|e|c|i|m|a|l| @2
+@75
+@75
+@46| +0#0000000&@28
+|c| @13|<+0#e000e06&|c|h|a|r|-|0|1|0|3|>| +0#0000000&@4|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |R|H|S| |-| |o|c|t|a|l| @4
+@60| +0#0000000&@14
+|<+0#e000e06&|c|h|a|r|-|0|x|0@1|6|4|>| +0#0000000&@1|<+0#e000e06&|c|h|a|r|-|0|x|0@1|4@1|>| +0#0000000&@2|S+0#0000e05&|p|e|c|i|a|l| |n|o|t|a|t|i|o|n| |a|l@1|o|w|e|d| |i|n| |L|H|S| |a|n|d| |R|H|S| |-| |h|e
+|x|a|d|e|c|i|m|a|l| @50| +0#0000000&@14
+@75
+|"+0#0000e05&| |V|i|m|-|s|c|r|i|p|t| |c|o|m@1|e|n|t| |c|h|a|r|a|c|t|e|r|s| @30| +0#0000000&@12
+|#| |<+0#e000e06&|c|h|a|r|-|0|x|0@1|a|3|>| +0#0000000&@15|L+0#0000e05&|i|n|e| |s|h|o|u|l|d| |n|o|t| |m|a|t|c|h| |a|s| |a| |V|i|m|9|-|s|c|r|i|p|t| |c|o|m@1|e
+|n|t| +0#0000000&@72
+>\|"| |“| @18|L+0#0000e05&|i|n|e| |s|h|o|u|l|d| |n|o|t| |m|a|t|c|h| |a|s| |a| |l|e|g|a|c|y|-|s|c|r|i|p|t| |c|o|m@1|e|n|t| | +0#0000000&@2
+|~+0#4040ff13&| @73
+| +0#0000000&@56|2|6|,|1| @9|B|o|t| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/input/vim.vim
@@ -0,0 +1,26 @@
+" Vim Keymap file for syntax testing                                                                                                                                                                                                                                           
+                                                                                                                                       
+" Maintainer:   Doug Kearns <dougkearns@gmail.com>                                                                                     
+" Last Changed: 2023 Nov 21                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                               
+scriptencoding utf-8                                                                                                                                                                                                                                                           
+                                                                                                                                       
+let b:keymap_name = "syntax-test"                                                                                                      
+                                                                                                                                                                                                                                                                               
+loadkeymap                                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                               
+" Line comment                                                                                                                         
+                                                                                                                                       
+  " Another line comment                
+                                                                                                                                       
+a A    Basic mapping                                       
+'a á   More than one char in first column           
+                                          
+" Special notation                                                                                                                     
+<char-62>      B               Special notation allowed in LHS - decimal                                                                                                                                                                                                       
+c              <char-0103>     Special notation allowed in RHS - octal                                                                 
+<char-0x0064>  <char-0x0044>   Special notation allowed in LHS and RHS - hexadecimal                                                   
+                                         
+" Vim-script comment characters                               
+# <char-0x00a3>                Line should not match as a Vim9-script comment
+\" “                   Line should not match as a legacy-script comment 
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -2,8 +2,8 @@
 " Language:	Vim 9.0 script
 " Maintainer:	Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
 " Last Change:	May 09, 2023
-" 	2023 Sep 14 by Vim Project (all :loadkeymap variants)
 " 	2023 Nov 12 by Vim Project (:let-heredoc improvements)
+" 	2023 Nov 20 by Vim Project (:loadkeymap improvements)
 " Version:	9.0-25
 " URL:	http://www.drchip.org/astronaut/vim/index.html#SYNTAX_VIM
 " Automatically generated keyword lists: {{{1
@@ -31,10 +31,6 @@ syn keyword vimCommand contained	al[l] a
 syn match   vimCommand contained	"\<z[-+^.=]\=\>"
 syn keyword vimStdPlugin contained	Arguments Asm Break Cfilter Clear Continue DiffOrig Evaluate Finish Gdb Lfilter Man N[ext] Over P[rint] Program Run S Source Step Stop Termdebug TermdebugCommand TOhtml Until Winbar XMLent XMLns
 
-" :loadkeymap command (Vim Project Addition) {{{3
-" TODO: this needs to be folded into the autogenerated keyword list above
-syn keyword vimCommand contained loadk[eymap]
-
 " vimOptions are caught only when contained in a vimSet {{{2
 syn keyword vimOption contained	acd ambw arshape aw backupskip beval bk bri bufhidden cdh ci cinsd cms commentstring conceallevel cpt cscopetagorder csto cursorlineopt dg dir ed enc equalprg expandtab fdls fex fileignorecase fml foldlevel formatexpr gcr gli guifont guitabtooltip hidden hlg imactivatefunc imi inc inex isident keymap langmap linebreak lm lsp makeencoding maxmem mh mmp more mousemoveevent mzq numberwidth opfunc patchexpr pfn pp printfont pumwidth pythonthreehome re restorescreen ro rulerformat scl scs sft shellslash shortmess showtabline slm smoothscroll spell spl srr statusline sw sxq tag tal tenc termwintype tgst titleold tpm ttm tw udir ur verbose viminfofile warn wfh wildchar wim winminheight wmh write
 syn keyword vimOption contained	ai anti asd awa balloondelay bevalterm bkc briopt buflisted cdhome cin cinw co compatible confirm crb cscopeverbose csverb cwh dict directory edcompatible encoding errorbells exrc fdm ff filetype fmr foldlevelstart formatlistpat gd go guifontset helpfile highlight hls imactivatekey iminsert include inf isk keymodel langmenu lines lmap luadll makeprg maxmempattern mis mmt mouse mouses mzquantum nuw osfiletype patchmode ph preserveindent printheader pvh pyx readonly revins rop runtimepath scr sect sh shelltemp shortname shq sloc sms spellcapcheck splitbelow ss stl swapfile syn tagbsearch tb term terse thesaurus titlestring tr tty twk ul ut verbosefile virtualedit wb wfw wildcharm winaltkeys winminwidth wmnu writeany
@@ -270,6 +266,19 @@ syn keyword	vimPattern   contained	start
 " vimTypes : new for vim9
 syn match	vimType	":\s*\zs\<\(bool\|number\|float\|string\|blob\|list<\|dict<\|job\|channel\|func\)\>"
 
+" Keymaps: (Vim Project Addition) {{{2
+" =======
+
+" TODO: autogenerated vimCommand keyword list does not handle all abbreviations
+"     : handle Vim9 script comments when something like #13104 is merged
+syn match  vimKeymapStart	"^"	contained skipwhite nextgroup=vimKeymapLhs,vimKeymapLineComment
+syn match  vimKeymapLhs	"\S\+"	contained skipwhite nextgroup=vimKeymapRhs contains=vimNotation
+syn match  vimKeymapRhs	"\S\+"	contained skipwhite nextgroup=vimKeymapTailComment contains=vimNotation
+syn match  vimKeymapTailComment	"\S.*"	contained
+syn match  vimKeymapLineComment	+".*+	contained contains=@vimCommentGroup,vimCommentString,vimCommentTitle
+
+syn region vimKeymap matchgroup=vimCommand start="\<loadk\%[eymap]\>" end="\%$" contains=vimKeymapStart
+
 " Special Filenames, Modifiers, Extension Removal: {{{2
 " ===============================================
 syn match	vimSpecFile	"<c\(word\|WORD\)>"	nextgroup=vimSpecFileMod,vimSubst
@@ -468,6 +477,7 @@ syn match	vimNotation	"\%#=1\(\\\|<lt>\)
 syn match	vimNotation	'\(\\\|<lt>\)\=<C-R>[0-9a-z"%#:.\-=]'he=e-1				contains=vimBracket
 syn match	vimNotation	'\%#=1\(\\\|<lt>\)\=<\%(q-\)\=\(line[12]\|count\|bang\|reg\|args\|mods\|f-args\|f-mods\|lt\)>'	contains=vimBracket
 syn match	vimNotation	"\%#=1\(\\\|<lt>\)\=<\([cas]file\|abuf\|amatch\|cword\|cWORD\|client\)>"		contains=vimBracket
+syn match	vimNotation	"\%#=1\(\\\|<lt>\)\=<\%([scamd]-\)\{0,4}char-\%(\d\+\|0\o\+\|0x\x\+\)>"			contains=vimBracket
 syn match	vimBracket contained	"[\\<>]"
 syn case match
 
@@ -941,6 +951,8 @@ if !exists("skip_vim_syntax_inits")
  hi def link vimInsert	vimString
  hi def link vimIskSep	Delimiter
  hi def link vimKeyCode	vimSpecFile
+ hi def link vimKeymapLineComment	vimComment
+ hi def link vimKeymapTailComment	vimComment
  hi def link vimKeyword	Statement
  hi def link vimLet	vimCommand
  hi def link vimLetHereDoc	vimString