spec.vim (13298B)
1 " Filename: spec.vim 2 " Purpose: Vim syntax file 3 " Language: SPEC: Build/install scripts for Linux RPM packages 4 " Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com 5 " Former Maintainer: Donovan Rebbechi elflord@panix.com (until March 2014) 6 " Last Change: 2020 May 25 7 " 2024 Sep 10 by Vim Project: add file triggers support, #15569 8 " 2025 May 05 by Vim Project: update for rpm 4.2 #17258 9 " 2025 Nov 09 by Vim Project: support for more distributions and tags #18703 10 11 " quit when a syntax file was already loaded 12 if exists("b:current_syntax") 13 finish 14 endif 15 16 syn sync minlines=1000 17 18 syn match specSpecialChar contained '[][!$()\\|>^;:{}]' 19 syn match specColon contained ':' 20 syn match specPercent contained '%' 21 22 syn match specVariables contained '\$\h\w*' contains=specSpecialVariablesNames,specSpecialChar 23 syn match specVariables contained '\${\w*}' contains=specSpecialVariablesNames,specSpecialChar 24 25 syn match specMacroIdentifier contained '%\h\w*' contains=specMacroNameLocal,specMacroNameOther,specPercent 26 syn match specMacroIdentifier contained '%{?\?\w*}' contains=specMacroNameLocal,specMacroNameOther,specPercent,specSpecialChar 27 28 syn match specSpecialVariables contained '\$[0-9]\|\${[0-9]}' 29 syn match specCommandOpts contained '\s\(-\w\+\|--\w[a-zA-Z_-]\+\)'ms=s+1 30 syn match specComment '^\s*#.*$' 31 32 33 syn case match 34 35 36 "matches with no highlight 37 syn match specNoNumberHilite 'X11\|X11R6\|[a-zA-Z]*\.\d\|[a-zA-Z][-/]\d' 38 syn match specManpageFile '[a-zA-Z]\.1' 39 40 "Day, Month and most used license acronyms 41 syn keyword specLicense contained GPL LGPL BSD MIT GNU 42 syn keyword specWeekday contained Mon Tue Wed Thu Fri Sat Sun 43 syn keyword specMonth contained Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec 44 syn keyword specMonth contained January February March April May June July August September October November December 45 46 "#, @, www 47 syn match specNumber '\(^-\=\|[ \t]-\=\|-\)[0-9.-]*[0-9]' 48 syn match specEmail contained "<\=\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\+\>>\=" 49 syn match specURL contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#-]\+\>' 50 syn match specURLMacro contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#%{}-]\+\>' contains=specMacroIdentifier 51 52 "TODO take specSpecialVariables out of the cluster for the sh* contains (ALLBUT) 53 "Special system directories 54 syn match specListedFilesPrefix contained '/\(usr\|local\|opt\|X11R6\|X11\)/'me=e-1 55 syn match specListedFilesBin contained '/s\=bin/'me=e-1 56 syn match specListedFilesLib contained '/\(lib\|include\)/'me=e-1 57 syn match specListedFilesDoc contained '/\(man\d*\|doc\|info\)\>' 58 syn match specListedFilesEtc contained '/etc/'me=e-1 59 syn match specListedFilesShare contained '/share/'me=e-1 60 syn cluster specListedFiles contains=specListedFilesBin,specListedFilesLib,specListedFilesDoc,specListedFilesEtc,specListedFilesShare,specListedFilesPrefix,specVariables,specSpecialChar 61 62 "specCommands 63 syn match specConfigure contained '\./configure' 64 syn match specTarCommand contained '\<tar\s\+[cxvpzIjf]\{,5}\s*' 65 syn keyword specCommandSpecial contained root 66 syn keyword specCommand contained make xmkmf mkdir chmod ln find sed rm strip moc echo grep ls rm mv mkdir install cp pwd cat tail then else elif cd gzip rmdir ln eval export touch bzip2 bunzip2 gunzip 67 syn cluster specCommands contains=specCommand,specTarCommand,specConfigure,specCommandSpecial 68 69 "frequently used rpm env vars 70 syn keyword specSpecialVariablesNames contained RPM_BUILD_ROOT RPM_BUILD_DIR RPM_SOURCE_DIR RPM_OPT_FLAGS LDFLAGS CC CC_FLAGS CPPNAME CFLAGS CXX CXXFLAGS CPPFLAGS 71 72 "valid macro names from /usr/lib/rpm/macros 73 syn keyword specMacroNameOther contained buildroot buildsubdir distribution disturl ix86 name nil optflags perl_sitearch release requires_eq vendor version dist fedora rhel rocky rhl centos 74 syn match specMacroNameOther contained '\<\(PATCH\|SOURCE\|el\|fc\)\d*\>' 75 76 "valid _macro names from /usr/lib/rpm/macros 77 syn keyword specMacroNameLocal contained _arch _binary_payload _bindir _build _build_alias _build_cpu _build_os _build_vendor _builddir _buildshell _buildsubdir _bzip2bin _datadir _dbpath _dbpath_rebuild _defaultdocdir _defaultlicensedir _docdir _excludedocs _exec_prefix _fixgroup _fixowner _fixperms _ftpport _ftpproxy _gpg_path _group_path _gzipbin _host _host_alias _host_cpu _host_os _host_vendor _httpport _httpproxy _iconsdir _includedir _infodir _install_langs _install_script_path _instchangelog _keyring _keyringpath _langpatt _lib _libdir _libexecdir _localstatedir _mandir _netsharedpath _oldincludedir _os _passwd_path _pgp_path _pgpbin _preScriptEnvironment _prefix _provides _rpmconfigdir _rpmdir _rpmfilename _rpmformat _rpmluadir _rpmmacrodir _sbindir _sharedstatedir _signature _source_payload _sourcedir _specdir _srcrpmdir _sysconfdir _sysusersdir _target _target_alias _target_cpu _target_os _target_platform _target_vendor _timecheck _tmppath _topdir _unitdir _usr _usrsrc _var _vendor 78 79 80 "------------------------------------------------------------------------------ 81 " here's is all the spec sections definitions: PreAmble, Description, Package, 82 " Scripts, Files and Changelog 83 84 "One line macros - valid in all ScriptAreas 85 "tip: remember do include new items on specScriptArea's skip section 86 syn region specSectionMacroArea oneline matchgroup=specSectionMacro start='^%\(define\|global\|patch\d*\|setup\|autosetup\|autopatch\|configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\|include\)\>' end='$' contains=specCommandOpts,specMacroIdentifier 87 syn region specSectionMacroBracketArea oneline matchgroup=specSectionMacro start='^%{\(configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\)}' end='$' contains=specCommandOpts,specMacroIdentifier 88 89 "%% Files Section %% 90 "TODO %config valid parameters: missingok\|noreplace 91 "TODO %verify valid parameters: \(not\)\= \(md5\|atime\|...\) 92 syn region specFilesArea matchgroup=specSection start='^%[Ff][Ii][Ll][Ee][Ss]\>' skip='%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|license\|verify\|ghost\|exclude\)\>' end='^%[a-zA-Z]'me=e-2 contains=specFilesOpts,specFilesDirective,@specListedFiles,specComment,specCommandSpecial,specMacroIdentifier 93 "tip: remember to include new items in specFilesArea above 94 syn match specFilesDirective contained '%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|license\|verify\|ghost\|exclude\)\>' 95 96 "valid options for certain section headers 97 syn match specDescriptionOpts contained '\s-[ln]\s*\a'ms=s+1,me=e-1 98 syn match specPackageOpts contained '\s-n\s*\w'ms=s+1,me=e-1 99 syn match specFilesOpts contained '\s-f\s*\w'ms=s+1,me=e-1 100 101 102 syn case ignore 103 104 105 "%% PreAmble Section %% 106 "Copyright and Serial were deprecated by License and Epoch 107 syn region specPreAmbleDeprecated oneline matchgroup=specError start='^\(Copyright\|Serial\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier 108 syn region specPreAmble oneline matchgroup=specCommand start='^\(Prereq\|Summary\|Name\|Version\|Packager\|Requires\|Recommends\|Suggests\|Supplements\|Enhances\|Icon\|URL\|SourceLicense\|Source\d*\|Patch\d*\|Prefix\|Packager\|Group\|License\|Release\|BuildRoot\|Distribution\|DistTag\|Vendor\|Provides\|ExclusiveArch\|ExcludeArch\|ExclusiveOS\|Obsoletes\|BuildArch\|BuildArchitectures\|BuildRequires\|BuildConflicts\|BuildPreReq\|Conflicts\|AutoRequires\|AutoReq\|AutoReqProv\|AutoProv\|Epoch\|ModularityLabel\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier 109 110 "%% Description Section %% 111 syn region specDescriptionArea matchgroup=specSection start='^%description' end='^%'me=e-1 contains=specDescriptionOpts,specEmail,specURL,specNumber,specMacroIdentifier,specComment 112 113 "%% Package Section %% 114 syn region specPackageArea matchgroup=specSection start='^%package' end='^%'me=e-1 contains=specPackageOpts,specPreAmble,specComment 115 116 "%% Scripts Section %% 117 syn region specScriptArea matchgroup=specSection start='^%\(prep\|generate_buildrequires\|conf\|build\|install\|clean\|check\|pre\|postun\|preun\|post\|posttrans\|filetriggerin\|filetriggerun\|filetriggerpostun\|transfiletriggerin\|transfiletriggerun\|transfiletriggerpostun\)\>' skip='^%{\|^%\(define\|patch\d*\|configure\|GNUconfigure\|setup\|autosetup\|autopatch\|find_lang\|make_build\|makeinstall\|make_install\)\>' end='^%'me=e-1 contains=specSpecialVariables,specVariables,@specCommands,specVariables,shDo,shFor,shCaseEsac,specNoNumberHilite,specCommandOpts,shComment,shIf,specSpecialChar,specMacroIdentifier,specSectionMacroArea,specSectionMacroBracketArea,shOperator,shQuote1,shQuote2 118 119 "%% Changelog Section %% 120 syn region specChangelogArea matchgroup=specSection start='^%changelog' end='^%'me=e-1 contains=specEmail,specURL,specWeekday,specMonth,specNumber,specComment,specLicense 121 122 123 124 "------------------------------------------------------------------------------ 125 "here's the shell syntax for all the Script Sections 126 127 128 syn case match 129 130 131 "sh-like comment stile, only valid in script part 132 syn match shComment contained '#.*$' 133 134 syn region dnlComment matchgroup=specComment start=+%dnl+ end=+$+ 135 136 syn region shQuote1 contained matchgroup=shQuoteDelim start=+'+ skip=+\\'+ end=+'+ contains=specMacroIdentifier 137 syn region shQuote2 contained matchgroup=shQuoteDelim start=+"+ skip=+\\"+ end=+"+ contains=specVariables,specMacroIdentifier 138 139 syn match shOperator contained '[><|!&;]\|[!=]=' 140 syn region shDo transparent matchgroup=specBlock start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase,specPreAmble,@specListedFiles 141 142 syn region specIf matchgroup=specBlock start="%ifosf\|%ifos\|%ifnos\|%ifarch\|%ifnarch\|%else" end='%endif' contains=ALLBUT, specIfError, shCase 143 144 syn region shIf transparent matchgroup=specBlock start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase,@specListedFiles 145 146 syn region shFor matchgroup=specBlock start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase,@specListedFiles 147 148 syn region shCaseEsac transparent matchgroup=specBlock start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError,@specListedFiles nextgroup=shCaseEsac 149 syn region shCaseEsac matchgroup=specBlock start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError,@specListedFilesBin 150 syn region shCase matchgroup=specBlock contained start=")" end=";;" contains=ALLBUT,shFunction,shCaseError,shCase,@specListedFiles 151 152 syn sync match shDoSync grouphere shDo "\<do\>" 153 syn sync match shDoSync groupthere shDo "\<done\>" 154 syn sync match shIfSync grouphere shIf "\<if\>" 155 syn sync match shIfSync groupthere shIf "\<fi\>" 156 syn sync match specIfSync grouphere specIf "%ifarch\|%ifos\|%ifnos" 157 syn sync match specIfSync groupthere specIf "%endIf" 158 syn sync match shForSync grouphere shFor "\<for\>" 159 syn sync match shForSync groupthere shFor "\<in\>" 160 syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>" 161 syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>" 162 163 " Define the default highlighting. 164 " Only when an item doesn't have highlighting yet 165 166 "main types color definitions 167 hi def link specSection Structure 168 hi def link specSectionMacro Macro 169 hi def link specWWWlink PreProc 170 hi def link specOpts Operator 171 172 "yes, it's ugly, but white is sooo cool 173 if &background == "dark" 174 hi def specGlobalMacro ctermfg=white 175 else 176 hi def link specGlobalMacro Identifier 177 endif 178 179 "sh colors 180 hi def link shComment Comment 181 hi def link dnlComment Comment 182 hi def link shIf Statement 183 hi def link shOperator Special 184 hi def link shQuote1 String 185 hi def link shQuote2 String 186 hi def link shQuoteDelim Statement 187 188 "spec colors 189 hi def link specBlock Function 190 hi def link specColon Special 191 hi def link specCommand Statement 192 hi def link specCommandOpts specOpts 193 hi def link specCommandSpecial Special 194 hi def link specComment Comment 195 hi def link specConfigure specCommand 196 hi def link specDate String 197 hi def link specDescriptionOpts specOpts 198 hi def link specEmail specWWWlink 199 hi def link specError Error 200 hi def link specFilesDirective specSectionMacro 201 hi def link specFilesOpts specOpts 202 hi def link specLicense String 203 hi def link specMacroNameLocal specGlobalMacro 204 hi def link specMacroNameOther specGlobalMacro 205 hi def link specManpageFile NONE 206 hi def link specMonth specDate 207 hi def link specNoNumberHilite NONE 208 hi def link specNumber Number 209 hi def link specPackageOpts specOpts 210 hi def link specPercent Special 211 hi def link specSpecialChar Special 212 hi def link specSpecialVariables specGlobalMacro 213 hi def link specSpecialVariablesNames specGlobalMacro 214 hi def link specTarCommand specCommand 215 hi def link specURL specWWWlink 216 hi def link specURLMacro specWWWlink 217 hi def link specVariables Identifier 218 hi def link specWeekday specDate 219 hi def link specListedFilesBin Statement 220 hi def link specListedFilesDoc Statement 221 hi def link specListedFilesEtc Statement 222 hi def link specListedFilesLib Statement 223 hi def link specListedFilesPrefix Statement 224 hi def link specListedFilesShare Statement 225 226 227 let b:current_syntax = "spec" 228 229 " vim: ts=8