On 23:35 Mon 07 May , Aaron Griffin wrote:
On 5/7/07, Alessio 'mOLOk' Bolognino <themolok.ml@gmail.com> wrote:
On 19:04 Mon 07 May , Dan McGee wrote:
On 5/7/07, Alessio 'mOLOk' Bolognino <themolok.ml@gmail.com> wrote:
On 08:33 Sun 06 May , Alessio 'mOLOk' Bolognino wrote:
Hi Guys, I spent an insane amount of time (last night) writing this (I hope so) useful thing: it's a vim syntax file for PKGBUILDs, to use it you should put it in ~/.vim/syntax/ and add this line at the bottom of your ~/.vimrc:
autocmd BufReadPost PKGBUILD set filetype=PKGBUILD
The colors are more or less random, but it does (cool?) things like check for wrong pkgname, pkgver, pkgrel, it complains if the pkgdesc is too long, and other stuff. This is my first syntax file (and I hope it'll be the last :) I'm not a regex guru so many things could be buggy, but well, feel free to improve it and add your name in the headers. Cheers,
Here is the patch: [...]
Well, I improved it a bit, the new patch is based on the current repo (not on the old patch), so, if you want to try it, apply this one only. Here is a little feature list: it marks: invalid pkgname (strange or >32 chars); pkgrel (containing hyphens or other shit); pkgrel (everything but digits); pkgdesc too long (>80 chars) and pkgdesc containing "foobar is a" that is a common error (800+ packages in the AUR begins with this description...); wrong url (without http:// and others); wrong licenses (everything but the common ones and custom:foobar) wrong arch (not i686 || x86_64 || ppc) non standard .install file (i.e. without the .install suffix ) specific sourceforge mirror in the source array (very common error too) md5sums != 32 chars sha1sums != 40 chars wrong options (and marks "no" in nooption in yellow because it is deprecated); In the build() it is used the sh.vim syntax-file.
I think this syntax file is very useful while checking users' packages and avoids some common errors. Enjoy it VIMmers :)
First of all, thanks for the suggestions
Just tried it out and I like it, and I have a few suggestions as well. * I noticed you tried to vary the colors used for pkgname, pkgver, conflicts, replaces, etc. This may seem bright and colorful, but I personally don't like it at all. I would rather everything on the right side of the equals sign be the same color (the only exception being things in quotes or things not in quotes).
OK, I can keep it more sober. I'll change the colors to look like sh.vim (the shell syntax-file)
Done, now it uses much less colors, very similar to sh.vim
* I couldn't get the illegal md5sum/sha1sum highlighting to ever work.
Mmm... Strangely enough here it works, this is the intended behaviour: if the hash is <32 chars, it should be marked all red (well, the color changes according with your vimrc, but it is usually red), if the hash is
32chars, the chars after the 32nd should be marked red. (A couple of people tested it and it works on their machine too)
* Multi-line arrays without a '\' on end of lines do not highlight properly.
It's not a bug, it's a feature! :D Seriously, I think you noticed this in the source array, it highlights the remote files only, not the local ones.
* There are a lot of commented out lines in the file; I think it would be much clearer if anything unnecessary is removed.
Well, you're right :)
I cleaned it a lot
Although I said a lot there, it is good enough to find a place in my GIT tree. <http://code.toofishes.net/gitweb.cgi?p=pacman.git;a=commit;h=d45f977e0657881a542586f688e675c2b010a894>
I'll improve it in my spare time and I'll send here patches.
Except for Dan's comments about the varying colors, I like it. Next update I'll stick it in the contrib dir.
New patch (based on the current pacman repo). Here you are the "colorphobic" version (much less colors :) --- contrib/PKGBUILD.vim | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 238 insertions(+), 0 deletions(-) create mode 100644 contrib/PKGBUILD.vim diff --git a/contrib/PKGBUILD.vim b/contrib/PKGBUILD.vim new file mode 100644 index 0000000..6843814 --- /dev/null +++ b/contrib/PKGBUILD.vim @@ -0,0 +1,238 @@ +" Vim syntax file +" Language: PKGBUILD +" Maintainer: Alessio 'mOLOk' Bolognino <themolok@gmail.com> +" Last Change: 2007/05/08 +" Version Info: PKGBUILD-0.2 (colorphobic) + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +let b:main_syntax = "sh" +runtime! syntax/sh.vim + +" case on +syn case match + +" pkgname +" FIXME if '=' is in the pkgname/pkgver, it highlight all the pkgname, not only the '=' +syn keyword pb_k_pkgname pkgname contained +syn match pbValidPkgname /\([[:alnum:]]\|+\|-\|_\){,32}/ contained contains=pbIllegalPkgname +syn match pbIllegalPkgname /[[:upper:]]\|[^[:alnum:]-+_=]\|=.*=\|=['"]\?.\{33,\}['"]\?/ contained +syn match pbPkgnameGroup /^pkgname=.*/ contains=pbIllegalPkgname,pb_k_pkgname,shDoubleQuote,shSingleQuote + +" pkgver +syn keyword pb_k_pkgver pkgver contained +syn match pbValidPkgver /\([[:alnum:]]\|\.\|+\|_\)/ contained contains=pbIllegalPkgver +syn match pbIllegalPkgver /[^[:alnum:]+=\.\_]\|=.*=/ contained +syn match pbPkgverGroup /^pkgver=.*/ contains=pbIllegalPkgver,pbValidPkgver,pb_k_pkgver,shDoubleQuote,shSingleQuote + +" pkgrel +syn keyword pb_k_pkgrel pkgrel contained +syn match pbValidPkgrel /[[:digit:]]*/ contained contains=pbIllegalPkgver +syn match pbIllegalPkgrel /[^[:digit:]=]\|=.*=/ contained +syn match pbPkgrelGroup /^pkgrel=.*/ contains=pbIllegalPkgrel,pbValidPkgrel,pb_k_pkgrel,shDoubleQuote,shSingleQuote + +" pkgdesc +syn keyword pb_k_desc pkgdesc contained +" 90 chars: 80 for description, 8 for pkgdesc and 2 for '' +syn match pbIllegalPkgdesc /.\{90,}\|=['"]\?.*['" ]\+[iI][sS] [aA]/ contained contains=pbPkgdescSign +syn match pbValidPkgdesc /[^='"]\.\{,80}/ contained contains=pbIllegalPkgdesc +syn match pbPkgdescGroup /^pkgdesc=.*/ contains=pbIllegalPkgdesc,pb_k_desc,pbValidPkgdesc,shDoubleQuote,shSingleQuote +syn match pbPkgdescSign /[='"]/ contained + +" url +syn keyword pb_k_url url contained +syn match pbValidUrl /['"]*\(https\|http\|ftp\)\:\/.*\.\+.*/ contained + +syn match pbIllegalUrl /[^=]/ contained contains=pbValidUrl +syn match pbUrlGroup /^url=.*/ contains=pbValidUrl,pb_k_url,pbIllegalUrl,shDoubleQuote,shSingleQuote + +" license +syn keyword pb_k_license license contained +syn keyword pbLicense APACHE CDDL EPL FDL GPL LGPL MPL PHP RUBY ZLIB ISC MIT BSD contained +syn match pbLicenseCustom /custom\(:[[:alnum:]]*\)*/ contained +syn match pbIllegalLicense /[^='"() ]/ contained contains=pbLicenseCustom,pbLicense +syn match pbLicenseGroup /^license=.*/ contains=pb_k_license,pbLicenseCustom,pbLicense,pbIllegalLicense,shDoubleQuote,shSingleQuote + +" backup +syn keyword pb_k_backup backup contained +syn match pbValidBackup /\.\?[[:alpha:]]*\/[[:alnum:]\{\}+._$-]*]*/ contained +syn match pbBackupGroup /^backup=.*/ contains=pb_k_backup,pbValidBackup,shDoubleQuote,shSingleQuote + +" arch +syn keyword pb_k_arch arch contained +syn keyword pbArch i686 x86_64 ppc contained +syn match pbIllegalArch /[^='() ]/ contained contains=pbArch +syn match pbArchGroup /^arch=.*/ contains=pb_k_arch,pbArch,pbIllegalArch,shDoubleQuote,shSingleQuote + +" makedepends +syn keyword pb_k_makedepends makedepends contained +syn match pbValidMakedepends /\([[:alnum:]]\|+\|-\|_\)*/ contained +syn region pbMakedependsGroup start=/^makedepends=(/ end=/)/ contains=pb_k_makedepends,pbValidMakedepends,shDoubleQuote,shSingleQuote + +" depends +syn keyword pb_k_depends depends contained +syn match pbValidDepends /\([[:alnum:]]\|+\|-\|_\)*/ contained +syn region pbDependsGroup start=/^depends=(/ end=/)/ contains=pb_k_depends,pbValidDepends,shDoubleQuote,shSingleQuote + +" XXX little hack to color conflicts/provides/replaces keyword even without =() +syn match pbkw /^\(conflicts\|provides\|replaces\)/ contains=pb_k_conflicts,pb_k_provides,pb_k_replaces +hi link pbkw keyword + +" conflicts +syn keyword pb_k_conflicts conflicts contained +syn match pbValidConflicts /\([[:alnum:]]\|+\|-\|_\)*/ contained +syn region pbConflictsGroup start=/^conflicts=(/ end=/)/ contains=pb_k_conflicts,pbValidConflicts,shDoubleQuote,shSingleQuote + +" provides +syn keyword pb_k_provides provides contained +syn match pbValidProvides /\([[:alnum:]]\|+\|-\|_\)*/ contained +syn region pbProvidesGroup start=/^provides=(/ end=/)/ contains=pb_k_provides,pbValidProvides,shDoubleQuote,shSingleQuote + +" replaces +syn keyword pb_k_replaces replaces contained +syn match pbValidReplaces /\([[:alnum:]]\|+\|-\|_\)*/ contained +syn region pbReplacesGroup start=/^replaces=(/ end=/)/ contains=pb_k_replaces,pbValidReplaces,shDoubleQuote,shSingleQuote + +" install +" XXX remove install from bashStatement, fix strage bug +syn clear bashStatement +syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep less ls mkdir mv rm rmdir rpm sed sleep sort strip tail touch + +syn keyword pb_k_install install contained +syn match pbValidInstall /\([[:alnum:]]\|\$\|+\|-\|_\)*\.install/ contained +syn match pbIllegalInstall /[^=]/ contained contains=pbValidInstall +syn match pbInstallGroup /^install=.*/ contains=pb_k_install,pbValidInstall,pbIllegalInstall,shDeref,shDoubleQuote,shSingleQuote + +" source: +" XXX remove source from shStatement, fixstrange bug +syn clear shStatement +syn keyword shStatement xxx wait getopts return autoload whence printf true popd nohup enable r trap readonly fc fg kill ulimit umask disown stop pushd read history logout times local exit test pwd time eval integer suspend dirs shopt hash false newgrp bg print jobs continue functions exec help cd break unalias chdir type shift builtin let bind + +syn keyword pb_k_source source contained +syn match pbIllegalSource /\(http\|ftp\|https\).*\.\+\(dl\|download.\?\)\.\(sourceforge\|sf\).net/ +syn region pbSourceGroup start=/^source=(/ end=/)/ contains=pb_k_source,pbIllegalSource,shNumber,shDoubleQuote,shSingleQuote,pbDerefEmulation +syn match pbDerefEmulation /\$[{]\?[[:alnum:]_]*[}]\?/ contained +hi link pbDerefEmulation PreProc + +" md5sums + +syn keyword pb_k_md5sums md5sums contained +syn match pbIllegalMd5sums /[^='"()\/ ]/ contained contains=pbValidMd5sums +syn match pbValidMd5sums /[[:alnum:]]\{32\}/ contained +syn region pbMd5sumsGroup start=/^md5sums/ end=/)/ contains=pb_k_md5sums,pbMd5Quotes,pbMd5Hash,pbIllegalMd5sums +syn match pbMd5Quotes /'.*'\|".*"/ contained contains=pbMd5Hash,pbIllegalMd5sums +syn match pbMd5Hash /[[:alnum:]]\+/ contained contains=pbValidMd5sums +hi link pbMd5Quotes Keyword +hi link pbMd5Hash Error +hi link pbValidMd5sums Number + +" sha1sums +syn keyword pb_k_sha1sums sha1sums contained +syn match pbIllegalSha1sums /[^='"()\/ ]/ contained contains=pbValidSha1sums +syn match pbValidSha1sums /[[:alnum:]]\{40\}/ contained +syn region pbSha1sumsGroup start=/^sha1sums/ end=/)/ contains=pb_k_sha1sums,pbSha1Quotes,pbSha1Hash,pbIllegalSha1sums +syn match pbSha1Quotes /'.*'\|".*"/ contained contains=pbSha1Hash,pbIllegalSha1sums +syn match pbSha1Hash /[[:alnum:]]\+/ contained contains=pbValidSha1sums +hi link pbSha1Quotes Keyword +hi link pbSha1Hash Error +hi link pbValidSha1sums Number + +" options +syn keyword pb_k_options options contained +syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|ccache\|distcc\|makeflags\|force\)/ contained +syn match pbOptionsNeg /\!/ contained +syn match pbOptionsDeprec /no/ contained +syn region pbOptionsGroup start=/^options=(/ end=/)/ contains=pb_k_options,pbOptions,pbOptionsNeg,pbOptionsDeprec,pbIllegalOption,shDoubleQuote,shSingleQuote +syn match pbIllegalOption /[^!"'()= ]/ contained contains=pbOptionsDeprec,pbOptions + +" noextract +syn match pbNoextract /[[:alnum:]+._${}-]\+/ contained +syn keyword pb_k_noextract noextract contained +syn region pbNoextractGroup start=/^noextract=(/ end=/)/ contains=pb_k_noextract,pbNoextract,shDoubleQuote,shSingleQuote + +" comments +syn keyword pb_k_maintainer Maintainer Contributor contained +syn match pbMaintainerGroup /Maintainer.*/ contains=pbMaintainer contained + +syn match pbDate /[0-9]\{4}\/[0-9]\{2}\/[0-9]\{2}/ contained + +syn cluster pbCommentGroup contains=pbTodo,pb_k_maintainer,pbMaintainerGroup,pbDate +syn keyword pbTodo contained COMBAK FIXME TODO XXX +syn match pbComment "^#.*$" contains=@pbCommentGroup +syn match pbComment "[^0-9]#.*$" contains=@pbCommentGroup + +" quote +syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial contained +syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial,@Spell contained +syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell contained +syn match shStringSpecial "[^[:print:]]" contained +syn match shSpecial "\\[\\\"\'`$()#]" contained + +hi link pbComment Comment +hi link pbTodo Todo + +hi link pbIllegalPkgname Error +hi link pb_k_pkgname pbKeywords + +hi link pbIllegalPkgver Error +hi link pb_k_pkgver pbKeywords + +hi link pbIllegalPkgrel Error +hi link pb_k_pkgrel pbKeywords + +hi link pbIllegalPkgdesc Error +hi link pb_k_desc pbKeywords + +hi link pbIllegalUrl Error +hi link pb_k_url pbKeywords + +hi link pb_k_license pbKeywords +hi link pbIllegalLicense Error + +hi link pb_k_backup pbKeywords + +hi link pb_k_arch pbKeywords +hi link pbIllegalArch Error + +hi link pb_k_makedepends pbKeywords +hi link pb_k_depends pbKeywords +hi link pb_k_replaces pbKeywords +hi link pb_k_conflicts pbKeywords +hi link pb_k_provides pbKeywords + +hi link pbIllegalInstall Error +hi link pb_k_install pbKeywords + +hi link pb_k_source pbKeywords +hi link pbIllegalSource Error + +hi link pb_k_md5sums pbKeywords +hi link pbIllegalMd5sums Error + +hi link pb_k_sha1sums pbKeywords +hi link pbIllegalSha1sums Error + +hi link pb_k_options pbKeywords +hi link pbOptionsDeprec Todo +hi link pbIllegalOption Error + +hi link pb_k_noextract pbKeywords +hi link pbNoextract Normal + +hi link pb_k_maintainer pbKeywords + +hi link pbKeywords Keyword + +hi link pbDate Special + +"syntax include @SHELL syntax/sh.vim +"syntax region BUILD start=/^build()/ end=/^}/ contains=@SHELL +"let b:current_syntax = "PKGBUILD" + +" vim: ft=vim -- 1.5.1.3 -- Alessio 'mOLOk' Bolognino Arch Linux Trusted User Public Key @ http://themolok.netsons.org/uploads/themolok.asc Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB