m4.vim (4526B)
1 " Vim syntax file 2 " Language: M4 3 " Maintainer: Claudio Fleiner (claudio@fleiner.com) 4 " Last Change: 2022 Jun 12 5 " 2025 Sep 2 by Vim project: fix a few syntax issues #18192 6 " 2025 Sep 5 by Vim project: introduce m4Disabled region #18200 7 " 2025 Sep 6 by Vim project: remove m4Function heuristics #18211 8 " 2025 Sep 6 by Vim project: remove m4Type and m4Function #18223 9 " 2025 Sep 15 by Vim project: highlight m4Parameters #18306 10 11 " quit when a syntax file was already loaded 12 if !exists("main_syntax") 13 if exists("b:current_syntax") 14 finish 15 endif 16 " we define it here so that included files can test for it 17 let main_syntax='m4' 18 endif 19 20 " Reference: The Open Group Base Specifications, M4 21 " https://pubs.opengroup.org/onlinepubs/9799919799/ 22 23 " Early definition of a cluster 24 syn cluster m4Top contains=NONE 25 26 " Quoting in M4: 27 " – Quotes are nestable; 28 " – The delimiters can be redefined with changequote(); here we only handle 29 " the default pair: ` ... '; 30 " – Quoted text in M4 is rescanned, not treated as a literal string. 31 " Therefore the region is marked transparent so contained items retain 32 " their normal highlighting. 33 syn region m4Quoted 34 \ matchgroup=m4QuoteDelim 35 \ start=+`+ 36 \ end=+'+ 37 \ contains=@m4Top 38 \ transparent 39 syn cluster m4Top add=m4Quoted 40 41 " Comments in M4: 42 " – According to the Open Group Base Specification, comments start with 43 " a <number-sign> (#) and end at <newline>, unless redefined with changecom(). 44 " We only handle the default here. 45 " – Comments in M4 are not like in most languages: they do not remove the text, 46 " they simply prevent any macros from being expanded, while the text remains 47 " in the output. This region therefore disables any other matches. 48 " – Comments themselves are disabled when quoted. 49 syn region m4Disabled start=+#+ end=+$+ containedin=ALLBUT,m4Quoted,m4ParamCount 50 51 " Macros in M4: 52 " – Name tokens consist of the longest possible sequence of letters, digits, 53 " and underscores, where the first character is not a digit. 54 " – In GNU M4, this can be altered with changeword(). 55 " – Any name token may be defined as a macro and quoting prevents expansion. 56 " Thus correct highlighting requires running M4. 57 58 " Parameters in M4: 59 " $0 = macro name; $1..$9 = positional (single digit only); $# = count; 60 " $* = args comma-joined; $@ = args quoted+comma; "${" = unspecified. 61 syn match m4ParamZero contained "\$0" 62 syn match m4ParamPos contained "\$[1-9]" 63 syn match m4ParamCount contained "\$#" 64 syn match m4ParamAll contained "\$[@*]" 65 syn match m4ParamBad contained '\${' 66 syn cluster m4Top add=m4ParamZero,m4ParamPos,m4ParamCount,m4ParamAll,m4ParamBad 67 68 " define the rest of M4 syntax 69 syn match m4Comment "\<\(m4_\)\=dnl\>.*" contains=SpellErrors 70 syn match m4Constants "\<\(m4_\)\=__file__" 71 syn match m4Constants "\<\(m4_\)\=__line__" 72 syn keyword m4Constants divnum sysval m4_divnum m4_sysval 73 syn region m4Paren matchgroup=m4Delimiter start="(" end=")" contained contains=@m4Top 74 syn region m4Command matchgroup=m4Define start="\<\(m4_\)\=\(define\|defn\|pushdef\)(" end=")" contains=@m4Top 75 syn region m4Command matchgroup=m4Preproc start="\<\(m4_\)\=\(include\|sinclude\)("he=e-1 end=")" contains=@m4Top 76 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 77 syn region m4Command matchgroup=m4Builtin start="\<\(m4_\)\=\(len\|index\|regexp\|substr\|translit\|patsubst\|format\|incr\|decr\|eval\|maketemp\)("he=e-1 end=")" contains=@m4Top 78 syn keyword m4Statement divert undivert 79 syn region m4Command matchgroup=m4Define start="\<\(m4_\)\=\(undefine\|popdef\)("he=e-1 end=")" contains=@m4Top 80 syn cluster m4Top add=m4Comment,m4Constants,m4Paren,m4Command,m4Statement 81 82 " Define the default highlighting. 83 " Only when an item doesn't have highlighting yet 84 hi def link m4QuoteDelim Delimiter 85 hi def link m4Delimiter Delimiter 86 hi def link m4Comment Comment 87 hi def link m4ParamZero Macro 88 hi def link m4ParamPos Special 89 hi def link m4ParamCount Keyword 90 hi def link m4ParamAll Keyword 91 hi def link m4ParamBad Error 92 hi def link m4Keyword Keyword 93 hi def link m4Define Define 94 hi def link m4Statement Statement 95 hi def link m4Preproc PreProc 96 hi def link m4Constants Constant 97 hi def link m4Builtin Statement 98 99 let b:current_syntax = "m4" 100 101 if main_syntax == 'm4' 102 unlet main_syntax 103 endif 104 105 " vim: ts=4