Install vim74
[msysgit.git] / share / vim / vim74 / syntax / xpm2.vim
blob74b3c66af25e25d01b3d511046af2b36455e8ea7
1 " Vim syntax file
2 " Language:     X Pixmap v2
3 " Maintainer:   Steve Wall (hitched97@velnet.com)
4 " Last Change:  2012 Jun 01
5 "               (Dominique Pelle added @Spell)
6 " Version:      5.8
8 " Made from xpm.vim by Ronald Schild <rs@scutum.de>
10 " For version 5.x: Clear all syntax items
11 " For version 6.x: Quit when a syntax file was already loaded
12 if version < 600
13   syntax clear
14 elseif exists("b:current_syntax")
15   finish
16 endif
18 let s:cpo_save = &cpo
19 set cpo&vim
21 syn region  xpm2PixelString     start="^"  end="$"  contains=@xpm2Colors
22 syn keyword xpm2Todo            TODO FIXME XXX  contained
23 syn match   xpm2Comment         "\!.*$"  contains=@Spell,xpm2Todo
26 if version < 508
27   command -nargs=+ HiLink hi link <args>
28   command -nargs=+ Hi hi <args>
29 else
30   command -nargs=+ HiLink hi def link <args>
31   command -nargs=+ Hi hi def <args>
32 endif
34 if has("gui_running")
36   let color  = ""
37   let chars  = ""
38   let colors = 0
39   let cpp    = 0
40   let n      = 0
41   let i      = 1
43   while i <= line("$")          " scanning all lines
45     let s = getline(i)
46     if match(s,"\!.*$") != -1
47       let s = matchstr(s, "^[^\!]*")
48     endif
49     if s != ""                  " does line contain a string?
51       if n == 0                 " first string is the Values string
53         " get the 3rd value: colors = number of colors
54         let colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')
55         " get the 4th value: cpp = number of character per pixel
56         let cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')
57         if cpp =~ '[^0-9]'
58           break  " if cpp is not made of digits there must be something wrong
59         endif
61         " Highlight the Values string as normal string (no pixel string).
62         " Only when there is no slash, it would terminate the pattern.
63         if s !~ '/'
64           exe 'syn match xpm2Values /' . s . '/'
65         endif
66         HiLink xpm2Values Statement
68         let n = 1                       " n = color index
70       elseif n <= colors                " string is a color specification
72         " get chars = <cpp> length string representing the pixels
73         " (first incl. the following whitespace)
74         let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '')
76         " now get color, first try 'c' key if any (color visual)
77         let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '')
78         if color == s
79           " no 'c' key, try 'g' key (grayscale with more than 4 levels)
80           let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '')
81           if color == s
82             " next try: 'g4' key (4-level grayscale)
83             let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '')
84             if color == s
85               " finally try 'm' key (mono visual)
86               let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '')
87               if color == s
88                 let color = ""
89               endif
90             endif
91           endif
92         endif
94         " Vim cannot handle RGB codes with more than 6 hex digits
95         if color =~ '#\x\{10,}$'
96           let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')
97         elseif color =~ '#\x\{7,}$'
98           let color = substitute(color, '\(\x\x\)\x', '\1', 'g')
99         " nor with 3 digits
100         elseif color =~ '#\x\{3}$'
101           let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')
102         endif
104         " escape meta characters in patterns
105         let s = escape(s, '/\*^$.~[]')
106         let chars = escape(chars, '/\*^$.~[]')
108         " change whitespace to "\s\+"
109         let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g")
110         let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g")
112         " now create syntax items
113         " highlight the color string as normal string (no pixel string)
114         exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef'
115         exe 'HiLink xpm2Col'.n.'Def Constant'
117         " but highlight the first whitespace after chars in its color
118         exe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained'
119         exe 'HiLink xpm2Col'.n.'inDef xpm2Color'.n
121         " remove the following whitespace from chars
122         let chars = substitute(chars, '\\s\\+$', '', '')
124         " and create the syntax item contained in the pixel strings
125         exe 'syn match xpm2Color'.n.' /'.chars.'/ contained'
126         exe 'syn cluster xpm2Colors add=xpm2Color'.n
128         " if no color or color = "None" show background
129         if color == ""  ||  substitute(color, '.*', '\L&', '') == 'none'
130           exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE'
131         elseif color !~ "'"
132           exe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'"
133         endif
134         let n = n + 1
135       else
136         break                   " no more color string
137       endif
138     endif
139     let i = i + 1
140   endwhile
142   unlet color chars colors cpp n i s
144 endif           " has("gui_running")
146 " Define the default highlighting.
147 " For version 5.7 and earlier: only when not done already
148 " For version 5.8 and later: only when an item doesn't have highlighting yet
149 if version >= 508 || !exists("did_xpm2_syntax_inits")
150   if version < 508
151     let did_xpm2_syntax_inits = 1
152   endif
154   " The default highlighting.
155   HiLink xpm2Type               Type
156   HiLink xpm2StorageClass       StorageClass
157   HiLink xpm2Todo               Todo
158   HiLink xpm2Comment            Comment
159   HiLink xpm2PixelString        String
160 endif
161 delcommand HiLink
162 delcommand Hi
164 let b:current_syntax = "xpm2"
166 let &cpo = s:cpo_save
167 unlet s:cpo_save
168 " vim: ts=8:sw=2:noet: