Skip to content

Commit 967d226

Browse files
zeertzjqdlejay
andcommitted
vim-patch:f165798: runtime(m4): update syntax script
This change does the following to the M4 syntax script: - In M4 there are no "strings" in the usual sense. Instead, M4 has quotes, but the text inside a quoted region is rescanned just like outside, and quotes can be nested. - The old m4String region was misleading and removed. A new m4Quoted region reflects proper quoting semantics. - Removed a duplicate highlight rule. - Fixed a typo in a highlight group name (m4builtin → m4Builtin). - Added a reference link to the POSIX M4 specification. - Removed outdated maintainer URL. closes: vim/vim#18192 vim/vim@f165798 Co-authored-by: Damien Lejay <[email protected]>
1 parent c4c9daf commit 967d226

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

runtime/syntax/m4.vim

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
" Vim syntax file
2-
" Language: M4
2+
" Language: M4
33
" Maintainer: Claudio Fleiner ([email protected])
4-
" URL: http://www.fleiner.com/vim/syntax/m4.vim
5-
" (outdated)
64
" Last Change: 2022 Jun 12
5+
" 2025 Sep 2 by Vim project: fix a few syntax issues #18192
76

87
" This file will highlight user function calls if they use only
98
" capital letters and have at least one argument (i.e. the '('
@@ -18,6 +17,23 @@ if !exists("main_syntax")
1817
let main_syntax='m4'
1918
endif
2019

20+
" Reference: The Open Group Base Specifications, M4
21+
" https://pubs.opengroup.org/onlinepubs/9799919799/
22+
23+
" Quoting in M4:
24+
" – Quotes are nestable;
25+
" – The delimiters can be redefined with changequote(); here we only handle
26+
" the default pair: ` ... ';
27+
" – Quoted text in M4 is rescanned, not treated as a literal string;
28+
" Therefore the region is marked transparent so contained items retain
29+
" their normal highlighting.
30+
syn region m4Quoted
31+
\ matchgroup=m4QuoteDelim
32+
\ start=+`+
33+
\ end=+'+
34+
\ contains=@m4Top
35+
\ transparent
36+
2137
" define the m4 syntax
2238
syn match m4Variable contained "\$\d\+"
2339
syn match m4Special contained "$[@*#]"
@@ -30,28 +46,26 @@ syn region m4Paren matchgroup=m4Delimiter start="(" end=")" contained contain
3046
syn region m4Command matchgroup=m4Function start="\<\(m4_\)\=\(define\|defn\|pushdef\)(" end=")" contains=@m4Top
3147
syn region m4Command matchgroup=m4Preproc start="\<\(m4_\)\=\(include\|sinclude\)("he=e-1 end=")" contains=@m4Top
3248
syn region m4Command matchgroup=m4Statement start="\<\(m4_\)\=\(syscmd\|esyscmd\|ifdef\|ifelse\|indir\|builtin\|shift\|errprint\|m4exit\|changecom\|changequote\|changeword\|m4wrap\|debugfile\|divert\|undivert\)("he=e-1 end=")" contains=@m4Top
33-
syn region m4Command matchgroup=m4builtin start="\<\(m4_\)\=\(len\|index\|regexp\|substr\|translit\|patsubst\|format\|incr\|decr\|eval\|maketemp\)("he=e-1 end=")" contains=@m4Top
49+
syn region m4Command matchgroup=m4Builtin start="\<\(m4_\)\=\(len\|index\|regexp\|substr\|translit\|patsubst\|format\|incr\|decr\|eval\|maketemp\)("he=e-1 end=")" contains=@m4Top
3450
syn keyword m4Statement divert undivert
3551
syn region m4Command matchgroup=m4Type start="\<\(m4_\)\=\(undefine\|popdef\)("he=e-1 end=")" contains=@m4Top
3652
syn region m4Function matchgroup=m4Type start="\<[_A-Z][_A-Z0-9]*("he=e-1 end=")" contains=@m4Top
37-
syn region m4String start="`" end="'" contains=SpellErrors
38-
syn cluster m4Top contains=m4Comment,m4Constants,m4Special,m4Variable,m4String,m4Paren,m4Command,m4Statement,m4Function
53+
syn cluster m4Top contains=m4Comment,m4Constants,m4Special,m4Variable,m4Paren,m4Command,m4Statement,m4Function,m4Quoted
3954

4055
" Define the default highlighting.
4156
" Only when an item doesn't have highlighting yet
42-
hi def link m4Delimiter Delimiter
43-
hi def link m4Comment Comment
44-
hi def link m4Function Function
45-
hi def link m4Keyword Keyword
46-
hi def link m4Special Special
47-
hi def link m4String String
48-
hi def link m4Statement Statement
49-
hi def link m4Preproc PreProc
50-
hi def link m4Type Type
51-
hi def link m4Special Special
52-
hi def link m4Variable Special
53-
hi def link m4Constants Constant
54-
hi def link m4Builtin Statement
57+
hi def link m4QuoteDelim Delimiter
58+
hi def link m4Delimiter Delimiter
59+
hi def link m4Comment Comment
60+
hi def link m4Function Function
61+
hi def link m4Keyword Keyword
62+
hi def link m4Special Special
63+
hi def link m4Statement Statement
64+
hi def link m4Preproc PreProc
65+
hi def link m4Type Type
66+
hi def link m4Variable Special
67+
hi def link m4Constants Constant
68+
hi def link m4Builtin Statement
5569

5670
let b:current_syntax = "m4"
5771

0 commit comments

Comments
 (0)