1" Vim syntax file 2" Language: Makefile 3" Maintainer: Claudio Fleiner <[email protected]> 4" URL: http://www.fleiner.com/vim/syntax/make.vim 5" Last Change: 2015 Feb 28 6 7" quit when a syntax file was already loaded 8if exists("b:current_syntax") 9 finish 10endif 11 12let s:cpo_save = &cpo 13set cpo&vim 14 15 16" some special characters 17syn match makeSpecial "^\s*[@+-]\+" 18syn match makeNextLine "\\\n\s*" 19 20" some directives 21syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)" 22syn match makeInclude "^ *[-s]\=include" 23syn match makeStatement "^ *vpath" 24syn match makeExport "^ *\(export\|unexport\)\>" 25syn match makeOverride "^ *override" 26hi link makeOverride makeStatement 27hi link makeExport makeStatement 28 29" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend 30syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine 31 32" Microsoft Makefile specials 33syn case ignore 34syn match makeInclude "^! *include" 35syn match makePreCondit "! *\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|elseif\|else if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>" 36syn case match 37 38" identifiers 39syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString 40syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString 41syn match makeIdent "\$\$\w*" 42syn match makeIdent "\$[^({]" 43syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2 44syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1 45syn match makeIdent "%" 46 47" Makefile.in variables 48syn match makeConfig "@[A-Za-z0-9_]\+@" 49 50" make targets 51" syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>" 52syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource 53syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource 54 55syn region makeTarget transparent matchgroup=makeTarget start="^[~A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"rs=e-1 end=";"re=e-1,me=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands 56syn match makeTarget "^[~A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget,makeComment skipnl nextgroup=makeCommands,makeCommandError 57 58syn region makeSpecTarget transparent matchgroup=makeSpecTarget start="^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*:\{1,2}[^:=]"rs=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands 59syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*::\=\s*$" contains=makeIdent,makeComment skipnl nextgroup=makeCommands,makeCommandError 60 61syn match makeCommandError "^\s\+\S.*" contained 62syn region makeCommands start=";"hs=s+1 start="^\t" end="^[^\t#]"me=e-1,re=e-1 end="^$" contained contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString nextgroup=makeCommandError 63syn match makeCmdNextLine "\\\n."he=e-1 contained 64 65 66" Statements / Functions (GNU make) 67syn match makeStatement contained "(\(subst\|abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1 68 69" Comment 70if exists("make_microsoft") 71 syn match makeComment "#.*" contains=@Spell,makeTodo 72elseif !exists("make_no_comments") 73 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo 74 syn match makeComment "#$" contains=@Spell 75endif 76syn keyword makeTodo TODO FIXME XXX contained 77 78" match escaped quotes and any other escaped character 79" except for $, as a backslash in front of a $ does 80" not make it a standard character, but instead it will 81" still act as the beginning of a variable 82" The escaped char is not highlightet currently 83syn match makeEscapedChar "\\[^$]" 84 85 86syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent 87syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent 88syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine 89 90" Syncing 91syn sync minlines=20 maxlines=200 92 93" Sync on Make command block region: When searching backwards hits a line that 94" can't be a command or a comment, use makeCommands if it looks like a target, 95" NONE otherwise. 96syn sync match makeCommandSync groupthere NONE "^[^\t#]" 97syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]" 98syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$" 99 100" Define the default highlighting. 101" Only when an item doesn't have highlighting yet 102 103hi def link makeNextLine makeSpecial 104hi def link makeCmdNextLine makeSpecial 105hi def link makeSpecTarget Statement 106if !exists("make_no_commands") 107hi def link makeCommands Number 108endif 109hi def link makeImplicit Function 110hi def link makeTarget Function 111hi def link makeInclude Include 112hi def link makePreCondit PreCondit 113hi def link makeStatement Statement 114hi def link makeIdent Identifier 115hi def link makeSpecial Special 116hi def link makeComment Comment 117hi def link makeDString String 118hi def link makeSString String 119hi def link makeBString Function 120hi def link makeError Error 121hi def link makeTodo Todo 122hi def link makeDefine Define 123hi def link makeCommandError Error 124hi def link makeConfig PreCondit 125 126let b:current_syntax = "make" 127 128let &cpo = s:cpo_save 129unlet s:cpo_save 130" vim: ts=8 131