" Vim syntax file" Language: X Pixmap v2" Maintainer: Steve Wall (hitched97@velnet.com)" Last Change: 2001 Apr 25" Version: 5.8"" Made from xpm.vim by Ronald Schild <rs@scutum.de>" For version 5.x: Clear all syntax items" For version 6.x: Quit when a syntax file was already loadedif version < 600syntax clearelseif exists("b:current_syntax")finishendifsyn region xpm2PixelString start="^" end="$" contains=@xpm2Colorssyn keyword xpm2Todo TODO FIXME XXX containedsyn match xpm2Comment "\!.*$" contains=xpm2Todoif version < 508command -nargs=+ HiLink hi link <args>command -nargs=+ Hi hi <args>elsecommand -nargs=+ HiLink hi def link <args>command -nargs=+ Hi hi def <args>endifif has("gui_running")let color = ""let chars = ""let colors = 0let cpp = 0let n = 0let i = 1while i <= line("$") " scanning all lineslet s = getline(i)if match(s,"\!.*$") != -1let s = matchstr(s, "^[^\!]*")endifif s != "" " does line contain a string?if n == 0 " first string is the Values string" get the 3rd value: colors = number of colorslet colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')" get the 4th value: cpp = number of character per pixellet cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')" highlight the Values string as normal string (no pixel string)exe 'syn match xpm2Values /'.s.'/'HiLink xpm2Values Statementlet n = 1 " n = color indexelseif n <= colors " string is a color specification" get chars = <cpp> length string representing the pixels" (first incl. the following whitespace)let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '')" now get color, first try 'c' key if any (color visual)let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '')if color == s" no 'c' key, try 'g' key (grayscale with more than 4 levels)let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '')if color == s" next try: 'g4' key (4-level grayscale)let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '')if color == s" finally try 'm' key (mono visual)let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '')if color == slet color = ""endifendifendifendif" Vim cannot handle RGB codes with more than 6 hex digitsif color =~ '#\x\{10,}$'let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')elseif color =~ '#\x\{7,}$'let color = substitute(color, '\(\x\x\)\x', '\1', 'g')" nor with 3 digitselseif color =~ '#\x\{3}$'let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')endif" escape meta characters in patternslet s = escape(s, '/\*^$.~[]')let chars = escape(chars, '/\*^$.~[]')" change whitespace to "\s\+"let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g")let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g")" now create syntax items" highlight the color string as normal string (no pixel string)exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef'exe 'HiLink xpm2Col'.n.'Def Constant'" but highlight the first whitespace after chars in its colorexe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained'exe 'HiLink xpm2Col'.n.'inDef xpm2Color'.n" remove the following whitespace from charslet chars = substitute(chars, '\\s\\+$', '', '')" and create the syntax item contained in the pixel stringsexe 'syn match xpm2Color'.n.' /'.chars.'/ contained'exe 'syn cluster xpm2Colors add=xpm2Color'.n" if no color or color = "None" show backgroundif color == "" || substitute(color, '.*', '\L&', '') == 'none'exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE'elseexe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'"endiflet n = n + 1elsebreak " no more color stringendifendiflet i = i + 1endwhileunlet color chars colors cpp n i sendif " has("gui_running")" Define the default highlighting." For version 5.7 and earlier: only when not done already" For version 5.8 and later: only when an item doesn't have highlighting yetif version >= 508 || !exists("did_xpm2_syntax_inits")if version < 508let did_xpm2_syntax_inits = 1endif" The default highlighting.HiLink xpm2Type TypeHiLink xpm2StorageClass StorageClassHiLink xpm2Todo TodoHiLink xpm2Comment CommentHiLink xpm2PixelString Stringendifdelcommand HiLinkdelcommand Hilet b:current_syntax = "xpm2"" vim: ts=8:sw=2:noet: