Skip to content

Commit ce06493

Browse files
dkearnschrisbra
authored andcommitted
runtime(vim): Update base-syntax, add legacy header folding
Allow for syntax-based folding of Vim9 script legacy header regions. This is enabled with the "H" flag of the g:vimsyn_folding config variable. closes: #14530 Signed-off-by: Christian Brabandt <cb@256bit.org> Signed-off-by: Doug Kearns <dougkearns@gmail.com>
1 parent 5a9f7e6 commit ce06493

6 files changed

Lines changed: 93 additions & 15 deletions

File tree

runtime/doc/syntax.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.1. Last change: 2024 Apr 09
1+
*syntax.txt* For Vim version 9.1. Last change: 2024 Apr 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3764,12 +3764,15 @@ Some folding is now supported with syntax/vim.vim: >
37643764
g:vimsyn_folding == 0 or doesn't exist: no syntax-based folding
37653765
g:vimsyn_folding =~ 'a' : augroups
37663766
g:vimsyn_folding =~ 'f' : fold functions
3767+
g:vimsyn_folding =~ 'h' : fold heredocs
3768+
g:vimsyn_folding =~ 'H' : fold Vim9-script legacy headers
37673769
g:vimsyn_folding =~ 'l' : fold lua script
37683770
g:vimsyn_folding =~ 'm' : fold mzscheme script
37693771
g:vimsyn_folding =~ 'p' : fold perl script
37703772
g:vimsyn_folding =~ 'P' : fold python script
37713773
g:vimsyn_folding =~ 'r' : fold ruby script
37723774
g:vimsyn_folding =~ 't' : fold tcl script
3775+
let g:vimsyn_folding = 'acfhlmpPrt'
37733776
<
37743777
*g:vimsyn_noerror*
37753778
Not all error highlighting that syntax/vim.vim does may be correct; Vim script

runtime/syntax/generator/vim.vim.base

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <dougkearns@gmail.com>
55
" URL: https://github.com/vim-jp/syntax-vim-ex
6-
" Last Change: 2024 Apr 09
6+
" Last Change: 2024 Apr 12
77
" Former Maintainer: Charles E. Campbell
88

99
" DO NOT CHANGE DIRECTLY.
@@ -79,7 +79,7 @@ syn case match
7979
" Special Vim Highlighting (not automatic) {{{1
8080

8181
" Set up folding commands for this syntax highlighting file {{{2
82-
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhlmpPrt]'
82+
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]'
8383
if g:vimsyn_folding =~# 'a'
8484
com! -nargs=* VimFolda <args> fold
8585
else
@@ -95,6 +95,11 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhlmpPrt]'
9595
else
9696
com! -nargs=* VimFoldh <args>
9797
endif
98+
if g:vimsyn_folding =~# 'H'
99+
com! -nargs=* VimFoldH <args> fold
100+
else
101+
com! -nargs=* VimFoldH <args>
102+
endif
98103
if g:vimsyn_folding =~# 'l'
99104
com! -nargs=* VimFoldl <args> fold
100105
else
@@ -129,6 +134,7 @@ else
129134
com! -nargs=* VimFolda <args>
130135
com! -nargs=* VimFoldf <args>
131136
com! -nargs=* VimFoldh <args>
137+
com! -nargs=* VimFoldH <args>
132138
com! -nargs=* VimFoldl <args>
133139
com! -nargs=* VimFoldm <args>
134140
com! -nargs=* VimFoldp <args>
@@ -827,11 +833,11 @@ syn region vimGlobal matchgroup=Statement start='\<v\%[global]!\=/' skip='\\.' e
827833
" ==================
828834

829835
if s:vim9script
830-
syn cluster vimLegacyTop contains=TOP,vimPreVim9script,vim9Comment,vim9LineComment
831-
syn region vimPreVim9script start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment
836+
syn cluster vimLegacyTop contains=TOP,vim9LegacyHeader,vim9Comment,vim9LineComment
837+
VimFoldH syn region vim9LegacyHeader start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment
832838

833-
syn keyword vim9ScriptArg noclear
834-
syn keyword vimCommand vim9s[cript] nextgroup=vim9ScriptArg skipwhite
839+
syn keyword vim9Vim9ScriptArg noclear contained
840+
syn keyword vim9Vim9Script vim9s[cript] nextgroup=vim9Vim9ScriptArg skipwhite
835841
endif
836842

837843
" Embedded Scripts: {{{2
@@ -1041,7 +1047,7 @@ if !exists("skip_vim_syntax_inits")
10411047
hi def link vimBufnrWarn vimWarn
10421048
endif
10431049

1044-
hi def link vim9ScriptArg Special
1050+
hi def link vim9Vim9ScriptArg Special
10451051
hi def link vimAbb vimCommand
10461052
hi def link vimAddress vimMark
10471053
hi def link vimAugroupBang vimBang
@@ -1171,6 +1177,7 @@ if !exists("skip_vim_syntax_inits")
11711177
hi def link vimSetMod vimOption
11721178
hi def link vimSetSep Statement
11731179
hi def link vimSetString vimString
1180+
hi def link vim9Vim9Script vimCommand
11741181
hi def link vimSpecFile Identifier
11751182
hi def link vimSpecFileMod vimSpecFile
11761183
hi def link vimSpecial Type
@@ -1235,6 +1242,8 @@ let b:current_syntax = "vim"
12351242
" Cleanup: {{{1
12361243
delc VimFolda
12371244
delc VimFoldf
1245+
delc VimFoldh
1246+
delc VimFoldH
12381247
delc VimFoldl
12391248
delc VimFoldm
12401249
delc VimFoldp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
>++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |"| |V|I|M|_|T|E|S|T|_|S|E|T|U|P| |l|e|t| |g|:|v|i|m|s|y|n|_|f|o|l|d|i|n|g| |=| |"|H|"| ||| |s|e|t| |f|d|m|=|s|y|n|t|a|x|-
2+
|v+0#af5f00255#ffffff0|i|m|9|s|c|r|i|p|t| +0#0000000&|n+0#e000e06&|o|c|l|e|a|r| +0#0000000&@56
3+
@75
4+
|#+0#0000e05&| |c|o|m@1|e|n|t| +0#0000000&@65
5+
@75
6+
| +0#0000e05&|#| |s|t|r|i|n|g| |o|n|l|y| |r|e|c|o|g|n|i|s|e|d| |w|i|t|h| |l|e|a|d|i|n|g| |c|h|a|r| +0#0000000&@31
7+
@1|"+0#e000002&|u|s|e|l|e|s@1| |s|t|r|i|n|g|"| +0#0000000&@57
8+
|~+0#4040ff13&| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|~| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|~| @73
20+
| +0#0000000&@56|1|,|1| @10|A|l@1|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |"| |V|I|M|_|T|E|S|T|_|S|E|T|U|P| |l|e|t| |g|:|v|i|m|s|y|n|_|f|o|l|d|i|n|g| |=| |"|H|"| ||| |s|e|t| |f|d|m|=|s|y|n|t|a|x|-
2+
|v+0#af5f00255#ffffff0|i|m|9|s|c|r|i|p|t| +0#0000000&|n+0#e000e06&|o|c|l|e|a|r| +0#0000000&@56
3+
@75
4+
|#+0#0000e05&| |c|o|m@1|e|n|t| +0#0000000&@65
5+
@75
6+
| +0#0000e05&|#| |s|t|r|i|n|g| |o|n|l|y| |r|e|c|o|g|n|i|s|e|d| |w|i|t|h| |l|e|a|d|i|n|g| |c|h|a|r| +0#0000000&@31
7+
@1>"+0#e000002&|u|s|e|l|e|s@1| |s|t|r|i|n|g|"| +0#0000000&@57
8+
|~+0#4040ff13&| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|~| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|~| @73
20+
| +0#0000000&@56|1|7|,|2| @9|A|l@1|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
" VIM_TEST_SETUP let g:vimsyn_folding = "H" | set fdm=syntax
2+
" comment
3+
4+
if !has('vim9script')
5+
# 42 " comment
6+
source foo.vim
7+
finish
8+
endif
9+
10+
" comment
11+
12+
vim9script noclear
13+
14+
# comment
15+
16+
# string only recognised with leading char
17+
"useless string"

runtime/syntax/vim.vim

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <dougkearns@gmail.com>
55
" URL: https://github.com/vim-jp/syntax-vim-ex
6-
" Last Change: 2024 Apr 11
6+
" Last Change: 2024 Apr 13
77
" Former Maintainer: Charles E. Campbell
88

99
" DO NOT CHANGE DIRECTLY.
@@ -116,7 +116,7 @@ syn keyword vimFuncName contained test_mswin_event test_null_blob test_null_chan
116116
" Special Vim Highlighting (not automatic) {{{1
117117

118118
" Set up folding commands for this syntax highlighting file {{{2
119-
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhlmpPrt]'
119+
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]'
120120
if g:vimsyn_folding =~# 'a'
121121
com! -nargs=* VimFolda <args> fold
122122
else
@@ -132,6 +132,11 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhlmpPrt]'
132132
else
133133
com! -nargs=* VimFoldh <args>
134134
endif
135+
if g:vimsyn_folding =~# 'H'
136+
com! -nargs=* VimFoldH <args> fold
137+
else
138+
com! -nargs=* VimFoldH <args>
139+
endif
135140
if g:vimsyn_folding =~# 'l'
136141
com! -nargs=* VimFoldl <args> fold
137142
else
@@ -166,6 +171,7 @@ else
166171
com! -nargs=* VimFolda <args>
167172
com! -nargs=* VimFoldf <args>
168173
com! -nargs=* VimFoldh <args>
174+
com! -nargs=* VimFoldH <args>
169175
com! -nargs=* VimFoldl <args>
170176
com! -nargs=* VimFoldm <args>
171177
com! -nargs=* VimFoldp <args>
@@ -871,11 +877,11 @@ syn region vimGlobal matchgroup=Statement start='\<v\%[global]!\=/' skip='\\.' e
871877
" ==================
872878

873879
if s:vim9script
874-
syn cluster vimLegacyTop contains=TOP,vimPreVim9script,vim9Comment,vim9LineComment
875-
syn region vimPreVim9script start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment
880+
syn cluster vimLegacyTop contains=TOP,vim9LegacyHeader,vim9Comment,vim9LineComment
881+
VimFoldH syn region vim9LegacyHeader start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment
876882

877-
syn keyword vim9ScriptArg noclear
878-
syn keyword vimCommand vim9s[cript] nextgroup=vim9ScriptArg skipwhite
883+
syn keyword vim9Vim9ScriptArg noclear contained
884+
syn keyword vim9Vim9Script vim9s[cript] nextgroup=vim9Vim9ScriptArg skipwhite
879885
endif
880886

881887
" Embedded Scripts: {{{2
@@ -1085,7 +1091,7 @@ if !exists("skip_vim_syntax_inits")
10851091
hi def link vimBufnrWarn vimWarn
10861092
endif
10871093

1088-
hi def link vim9ScriptArg Special
1094+
hi def link vim9Vim9ScriptArg Special
10891095
hi def link vimAbb vimCommand
10901096
hi def link vimAddress vimMark
10911097
hi def link vimAugroupBang vimBang
@@ -1215,6 +1221,7 @@ if !exists("skip_vim_syntax_inits")
12151221
hi def link vimSetMod vimOption
12161222
hi def link vimSetSep Statement
12171223
hi def link vimSetString vimString
1224+
hi def link vim9Vim9Script vimCommand
12181225
hi def link vimSpecFile Identifier
12191226
hi def link vimSpecFileMod vimSpecFile
12201227
hi def link vimSpecial Type
@@ -1279,6 +1286,8 @@ let b:current_syntax = "vim"
12791286
" Cleanup: {{{1
12801287
delc VimFolda
12811288
delc VimFoldf
1289+
delc VimFoldh
1290+
delc VimFoldH
12821291
delc VimFoldl
12831292
delc VimFoldm
12841293
delc VimFoldp

0 commit comments

Comments
 (0)