robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
139ffd91de
master
1" Vim syntax file 2" Language: Makefile 3" Maintainer: This runtime file is looking for a new maintainer. 4" Previous Maintainer: Claudio Fleiner <claudio@fleiner.com>, Roland Hieber <https://github.com/rohieb> 5" URL: https://github.com/vim/vim/blob/master/runtime/syntax/make.vim 6" Last Change: 2026 Aug 05 7" 2025 Apr 15 by Vim project: rework Make flavor detection (#17089) 8" 2025 Oct 12 by Vim project: update makeDefine highlighting (#18403) 9" 2025 Oct 25 by Vim project: update makeTargetinDefine highlighting (#18570) 10" 2025 Dec 23 by Vim project: fix too greedy match (#18938) 11" 2025 Dec 23 by Vim project: wrong highlight with paranthesis inside quotes (#18818) 12" 2026 Apr 17 by Vim project: wrong highlight $ inside quotes (#19986) 13" 2026 Aug 05 by Vim project: highlight variables in non-empty target lists 14 15" quit when a syntax file was already loaded 16if exists ( "b:current_syntax" ) 17finish 18endif 19 20let s: cpo_save = & cpo 21set cpo & vim 22 23" enable GNU extension when b:make_flavor is not set—detection failed or Makefile is POSIX-compliant 24let s: make_flavor = 'gnu' 25 26" some special characters 27syn match makeSpecial "^\s * [ @+- ] \+ " 28syn match makeNextLine "\\\n\s * " 29 30" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend 31syn region makeDefine start = "^\s * define\s "end = "^\s * endef\s * \(#. * \)\?$ " 32 \contains = makeStatement , makeIdent , makePreCondit , makeDefine , makeComment , makeTargetinDefine 33 34if get ( b:, 'make_flavor' , s: make_flavor ) == 'microsoft' 35" Microsoft Makefile specials 36syn case ignore 37syn match makeInclude "^!\s * include\s. * $ " 38syn match makePreCondit "^!\s * \(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s * if\|else\s * ifdef\|else\s * ifndef\|endif\|undef\)\> " 39syn case match 40endif 41 42" identifiers; treat $$X like $X inside makeDefine 43syn match makeIdent "\$\$\w * " 44syn match makeIdent "\$\$\$\$\w * "containedin = makeDefine 45syn match makeIdent "\$ [ ^({ ] " 46syn match makeIdent "\$\$ [ ^({\"' ] "containedin = makeDefine 47if get ( b:, 'make_flavor' , s: make_flavor ) == 'microsoft' 48syn region makeIdent start = "\$( "end = ") "contains = makeStatement , makeIdent , makeDString , makeSString 49syn region makeIdent start = "\${ "end = "} "contains = makeStatement , makeIdent , makeDString , makeSString 50syn region makeIdent start = "\$\$( "end = ") "containedin = makeDefine contains = makeStatement , makeIdent , makeDString , makeSString 51syn region makeIdent start = "\$\${ "end = "} "containedin = makeDefine contains = makeStatement , makeIdent , makeDString , makeSString 52else 53syn region makeIdent start = "\$( "skip = "\\)\|\\\\ "end = ") "contains = makeStatement , makeIdent , makeDString , makeSString 54syn region makeIdent start = "\${ "skip = "\\}\|\\\\ "end = "} "contains = makeStatement , makeIdent , makeDString , makeSString 55syn region makeIdent start = "\$\$( "skip = "\\)\|\\\\ "end = ") "containedin = makeDefine contains = makeStatement , makeIdent , makeDString , makeSString 56syn region makeIdent start = "\$\${ "skip = "\\}\|\\\\ "end = "} "containedin = makeDefine contains = makeStatement , makeIdent , makeDString , makeSString 57endif 58syn match makeIdent "^ * [ ^:#= \t ] * \s * [ :+?!* ] = "me= e-2 59syn match makeIdent "^ * [ ^:#= \t ] * \s * ::= "me= e-3 60syn match makeIdent "^ * [ ^:#= \t ] * \s * = "me= e-1 61syn match makeIdent "% " 62 63" Makefile.in variables 64syn match makeConfig "@ [ A-Za-z0-9_ ] \+@ " 65 66" make targets 67syn match makeImplicit "^\. [ A-Za-z0-9_./\t - ] \+\s * :$ "me= e-1 68syn match makeImplicit "^\. [ A-Za-z0-9_./\t - ] \+\s * : [ ^= ] "me= e-2 69 70syn match makeTargetinDefine "^ [ ~A-Za-z0-9_./$(){}%- ][ A-Za-z0-9_./\t ${}()%- ] * &\?:\?:\{1,2}\ze [ ^:= ] " 71 \contains = makeIdent , makeSpecTarget , makeComment 72syn match makeTargetinDefine "^ [ ~A-Za-z0-9_./$(){}%*@- ][ A-Za-z0-9_./\t $(){}%*@- ] * &\?::\=\s * $ " 73 \contains = makeIdent , makeSpecTarget , makeComment 74 75" Match prerequisites separately so identifiers can match inside target lists. 76syn region makePrerequisites contained transparent 77 \start = ". "rs= e-1 78 \end = "[ ^\\ ] $ " 79 \keepend contains = makeIdent , makeSpecTarget , makeNextLine , makeComment , makeDString 80 \skipnl nextGroup=makeCommands 81syn match makeTarget "^ [ ~A-Za-z0-9_./$(){}%- ][ A-Za-z0-9_./\t ${}()%- ] * &\?:\?:\{1,2}\ze [ ^:= ] " 82 \contains = makeIdent , makeSpecTarget , makeComment 83 \nextgroup = makePrerequisites skipwhite 84syn match makeTarget "^ [ ~A-Za-z0-9_./$(){}%*@- ][ A-Za-z0-9_./\t $(){}%*@- ] * &\?::\=\s * $ " 85 \contains = makeIdent , makeSpecTarget , makeComment 86 \skipnl nextgroup = makeCommands , makeCommandError 87 88syn region makeSpecTarget transparent matchgroup = makeSpecTarget 89 \start = "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|NOTPARALLEL\|POSIX\)\>\s * :\{1,2} [ ^:= ] "rs= e-1 90 \end = "[ ^\\ ] $ "keepend 91 \contains = makeIdent , makeSpecTarget , makeNextLine , makeComment skipnl nextGroup=makeCommands 92syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|NOTPARALLEL\|POSIX\)\>\s * ::\=\s * $ " 93 \contains = makeIdent , makeComment 94 \skipnl nextgroup = makeCommands , makeCommandError 95 96if get ( b:, 'make_flavor' , s: make_flavor ) == 'bsd' 97syn region makeSpecTarget transparent matchgroup = makeSpecTarget 98 \start = "^\.DELETE_ON_ERROR\>\s * :\{1,2} [ ^:= ] "rs= e-1 99 \end = "[ ^\\ ] $ "keepend 100 \contains = makeIdent , makeSpecTarget , makeNextLine , makeComment skipnl nextGroup=makeCommands 101syn match makeSpecTarget "^\.DELETE_ON_ERROR\>\s * ::\=\s * $ " 102 \contains = makeIdent , makeComment 103 \skipnl nextgroup = makeCommands , makeCommandError 104elseif get ( b:, 'make_flavor' , s: make_flavor ) == 'gnu' 105syn region makeSpecTarget transparent matchgroup = makeSpecTarget 106 \start = "^\.\(EXPORT_ALL_VARIABLES\|DELETE_ON_ERROR\|INTERMEDIATE\|KEEP_STATE\|LIBPATTERNS\|ONESHELL\|SECONDARY\)\>\s * :\{1,2} [ ^:= ] "rs= e-1 107 \end = "[ ^\\ ] $ "keepend 108 \contains = makeIdent , makeSpecTarget , makeNextLine , makeComment skipnl nextGroup=makeCommands 109syn match makeSpecTarget "^\.\(EXPORT_ALL_VARIABLES\|DELETE_ON_ERROR\|INTERMEDIATE\|KEEP_STATE\|LIBPATTERNS\|ONESHELL\|SECONDARY\)\>\s * ::\=\s * $ " 110 \contains = makeIdent , makeComment 111 \skipnl nextgroup = makeCommands , makeCommandError 112endif 113 114syn match makeCommandError "^\s\+\S. * "contained 115syn region makeCommands contained start = "; "hs= s+1start = "^\t " 116 \end = "^ [ ^\t# ] "me= e-1, re= e-1end = "^$ " 117 \contains = makeCmdNextLine , makeSpecial , makeComment , makeIdent , makePreCondit , makeDefine , makeDString , makeSString 118 \nextgroup = makeCommandError 119syn match makeCmdNextLine "\\\n. "he= e-1contained 120 121" some directives 122syn match makeInclude "^ * [ -s ] \=include\s. * $ " 123syn match makeExport "^ * \(export\|unexport\)\> " 124if get ( b:, 'make_flavor' , s: make_flavor ) == 'gnu' 125" Statements / Functions (GNU make) 126syn match makePreCondit "^ * \(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\) " 127syn match makeStatement "^ * vpath\> " 128syn match makeOverride "^ * override\> " 129syn match makeStatement contained "[ ({ ] \(abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|file\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|guile\|if\|info\|intcmp\|join\|lastword\|let\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|subst\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\> "ms= s+1 130endif 131 132" Comment 133if ! exists ( "make_no_comments" ) 134if get ( b:, 'make_flavor' , s: make_flavor ) == 'microsoft' 135syn match makeComment "#. * "contains = @Spell , makeTodo 136else 137syn region makeComment start = "# "end = "^$ "end = "[ ^\\ ] $ "keepend contains = @Spell , makeTodo 138syn match makeComment "#$ "contains = @Spell 139endif 140endif 141syn keyword makeTodo TODO FIXME XXX contained 142 143" match escaped quotes and any other escaped character 144" except for $, as a backslash in front of a $ does 145" not make it a standard character, but instead it will 146" still act as the beginning of a variable 147" The escaped char is not highlightet currently 148syn match makeEscapedChar "\\ [ ^$ ] " 149 150 151syn region makeDString start = +\(\\\)\@<!" +skip = +\\. +end = +" +contained contains = makeIdent 152syn region makeSString start = +\(\\\)\@<!' +skip = +\\. +end = +' +contained contains = makeIdent 153syn region makeBString start = +\(\\\)\@<!` +skip = +\\. +end = +` +contains = makeIdent , makeSString , makeDString , makeNextLine 154 155" Syncing 156syn sync minlines= 20 maxlines=200 157 158" Sync on Make command block region: When searching backwards hits a line that 159" can't be a command or a comment, use makeCommands if it looks like a target, 160" NONE otherwise. 161syn syncmatch makeCommandSync groupthereNONE "^ [ ^\t# ] " 162syn syncmatch makeCommandSync grouptheremakeCommands "^ [ A-Za-z0-9_./$()%- ][ A-Za-z0-9_./\t $()%- ] * :\{1,2} [ ^:= ] " 163syn syncmatch makeCommandSync grouptheremakeCommands "^ [ A-Za-z0-9_./$()%- ][ A-Za-z0-9_./\t $()%- ] * :\{1,2}\s * $ " 164 165" Define the default highlighting. 166" Only when an item doesn't have highlighting yet 167 168hi def link makeNextLine makeSpecial 169hi def link makeCmdNextLine makeSpecial 170hi link makeOverride makeStatement 171hi link makeExport makeStatement 172 173hi def link makeSpecTarget Statement 174if ! exists ( "make_no_commands" ) 175hi def link makeCommands Number 176endif 177hi def link makeImplicit Function 178hi def link makeTarget Function 179hi def link makeTargetinDefine Function 180hi def link makeInclude Include 181hi def link makePreCondit PreCondit 182hi def link makeStatement Statement 183hi def link makeIdent Identifier 184hi def link makeSpecial Special 185hi def link makeComment Comment 186hi def link makeDString String 187hi def link makeSString String 188hi def link makeBString Function 189hi def link makeError Error 190hi def link makeTodo Todo 191hi def link makeDefine Define 192hi def link makeCommandError Error 193hi def link makeConfig PreCondit 194 195let b: current_syntax = "make" 196 197let & cpo = s: cpo_save 198unlet s: cpo_save 199" vim: ts=8