02a3b8f4d0f969dc4f43b013c1ad4e9c72798504
[profile.git] / .vim / colors / iain.vim
1 " $Id$
2 " Mangling for terminal code ripped from desert256.
3
4 if version > 580
5     " no guarantees for version 5.8 and below, but this makes it stop
6     " complaining
7     "hi clear
8     if exists("syntax_on")
9         syntax reset
10     endif
11 endif
12 let g:colors_name="iain"
13
14 if has("gui_running") || &t_Co == 88 || &t_Co == 256
15     " functions {{{
16     " returns an approximate grey index for the given grey level
17     fun! <SID>grey_number(x)
18         if &t_Co == 88
19             if a:x < 23
20                 return 0
21             elseif a:x < 69
22                 return 1
23             elseif a:x < 103
24                 return 2
25             elseif a:x < 127
26                 return 3
27             elseif a:x < 150
28                 return 4
29             elseif a:x < 173
30                 return 5
31             elseif a:x < 196
32                 return 6
33             elseif a:x < 219
34                 return 7
35             elseif a:x < 243
36                 return 8
37             else
38                 return 9
39             endif
40         else
41             if a:x < 14
42                 return 0
43             else
44                 let l:n = (a:x - 8) / 10
45                 let l:m = (a:x - 8) % 10
46                 if l:m < 5
47                     return l:n
48                 else
49                     return l:n + 1
50                 endif
51             endif
52         endif
53     endfun
54
55     " returns the actual grey level represented by the grey index
56     fun! <SID>grey_level(n)
57         if &t_Co == 88
58             if a:n == 0
59                 return 0
60             elseif a:n == 1
61                 return 46
62             elseif a:n == 2
63                 return 92
64             elseif a:n == 3
65                 return 115
66             elseif a:n == 4
67                 return 139
68             elseif a:n == 5
69                 return 162
70             elseif a:n == 6
71                 return 185
72             elseif a:n == 7
73                 return 208
74             elseif a:n == 8
75                 return 231
76             else
77                 return 255
78             endif
79         else
80             if a:n == 0
81                 return 0
82             else
83                 return 8 + (a:n * 10)
84             endif
85         endif
86     endfun
87
88     " returns the palette index for the given grey index
89     fun! <SID>grey_color(n)
90         if &t_Co == 88
91             if a:n == 0
92                 return 16
93             elseif a:n == 9
94                 return 79
95             else
96                 return 79 + a:n
97             endif
98         else
99             if a:n == 0
100                 return 16
101             elseif a:n == 25
102                 return 231
103             else
104                 return 231 + a:n
105             endif
106         endif
107     endfun
108
109     " returns an approximate color index for the given color level
110     fun! <SID>rgb_number(x)
111         if &t_Co == 88
112             if a:x < 69
113                 return 0
114             elseif a:x < 172
115                 return 1
116             elseif a:x < 230
117                 return 2
118             else
119                 return 3
120             endif
121         else
122             if a:x < 75
123                 return 0
124             else
125                 let l:n = (a:x - 55) / 40
126                 let l:m = (a:x - 55) % 40
127                 if l:m < 20
128                     return l:n
129                 else
130                     return l:n + 1
131                 endif
132             endif
133         endif
134     endfun
135
136     " returns the actual color level for the given color index
137     fun! <SID>rgb_level(n)
138         if &t_Co == 88
139             if a:n == 0
140                 return 0
141             elseif a:n == 1
142                 return 139
143             elseif a:n == 2
144                 return 205
145             else
146                 return 255
147             endif
148         else
149             if a:n == 0
150                 return 0
151             else
152                 return 55 + (a:n * 40)
153             endif
154         endif
155     endfun
156
157     " returns the palette index for the given R/G/B color indices
158     fun! <SID>rgb_color(x, y, z)
159         if &t_Co == 88
160             return 16 + (a:x * 16) + (a:y * 4) + a:z
161         else
162             return 16 + (a:x * 36) + (a:y * 6) + a:z
163         endif
164     endfun
165
166     " returns the palette index to approximate the given R/G/B color levels
167     fun! <SID>color(r, g, b)
168         " get the closest grey
169         let l:gx = <SID>grey_number(a:r)
170         let l:gy = <SID>grey_number(a:g)
171         let l:gz = <SID>grey_number(a:b)
172
173         " get the closest color
174         let l:x = <SID>rgb_number(a:r)
175         let l:y = <SID>rgb_number(a:g)
176         let l:z = <SID>rgb_number(a:b)
177
178         if l:gx == l:gy && l:gy == l:gz
179             " there are two possibilities
180             let l:dgr = <SID>grey_level(l:gx) - a:r
181             let l:dgg = <SID>grey_level(l:gy) - a:g
182             let l:dgb = <SID>grey_level(l:gz) - a:b
183             let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
184             let l:dr = <SID>rgb_level(l:gx) - a:r
185             let l:dg = <SID>rgb_level(l:gy) - a:g
186             let l:db = <SID>rgb_level(l:gz) - a:b
187             let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
188             if l:dgrey < l:drgb
189                 " use the grey
190                 return <SID>grey_color(l:gx)
191             else
192                 " use the color
193                 return <SID>rgb_color(l:x, l:y, l:z)
194             endif
195         else
196             " only one possibility
197             return <SID>rgb_color(l:x, l:y, l:z)
198         endif
199     endfun
200
201     " returns the palette index to approximate the 'rrggbb' hex string
202     fun! <SID>rgb(rgb)
203         let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
204         let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
205         let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
206
207         return <SID>color(l:r, l:g, l:b)
208     endfun
209
210     " sets the highlighting for the given group
211     fun! <SID>X(group, fg, bg, attr)
212         if a:fg != ""
213             if a:fg =~ '^#'
214                 let l:fg = <SID>rgb(substitute(a:fg, '^#', '', ''))
215             else
216                 let l:fg=a:fg
217             endif
218             exec "hi " . a:group . " guifg=" . a:fg . " ctermfg=" . l:fg
219         endif
220         if a:bg != ""
221             if a:bg =~ '^#'
222                 let l:bg = <SID>rgb(substitute(a:bg, '^#', '', ''))
223             else
224                 let l:bg=a:bg
225             endif
226             exec "hi " . a:group . " guibg=" . a:bg . " ctermbg=" . l:bg
227         endif
228         if a:attr != ""
229             exec "hi " . a:group . " gui=" . a:attr . " cterm=" . a:attr
230         endif
231     endfun
232     " }}}
233     " From darkblue.
234     call <SID>X("ErrorMsg", "#ffffff", "#287eff", "")
235     call <SID>X("Visual", "#ffffff", "#8080ff", "")
236     call <SID>X("VisualNOS", "", "#8080ff", "underline")
237     "call <SID>X("Todo", "#d14a14", "#1248d1", "")
238     call <SID>X("Search", "#ffffff", "#2050d0", "")
239     call <SID>X("IncSearch", "#b0ffff", "#2050d0", "")
240     "call <SID>X("SpecialKey", "#00ffff", "", "")
241     call <SID>X("Directory", "#00ffff", "", "")
242     call <SID>X("Title", "#ff00ff", "", "none")
243     call <SID>X("WarningMsg", "#ff0000", "", "")
244     "call <SID>X("WildMenu", "#ffff00", "#000000", "")
245     call <SID>X("ModeMsg", "#22cce2", "", "")
246     call <SID>X("Question", "#00ff00", "", "none")
247     "call <SID>X("NonText", "#0030ff", "", "")
248     call <SID>X("VertSplit", "#000000", "#a9a9a9", "none")
249     call <SID>X("Folded", "#808080", "#000040", "")
250     call <SID>X("FoldColumn", "#808080", "#000040", "")
251     call <SID>X("LineNr", "#90f020", "", "")
252     call <SID>X("DiffAdd", "#00008b", "", "")
253     call <SID>X("DiffChange", "#8b008b", "", "")
254     call <SID>X("DiffDelete", "#0000ff", "#008b8b", "bold")
255     call <SID>X("DiffText", "", "#ff0000", "bold")
256     call <SID>X("Cursor", "#000000", "#ffff00", "")
257     call <SID>X("lCursor", "#000000", "#ffffff", "")
258     "call <SID>X("Comment", "#80a0ff", "", "")
259     "call <SID>X("Constant", "#ffa0a0", "", "")
260     "call <SID>X("Special", "#ffa500", "", "")
261     "call <SID>X("Identifier", "#40ffff", "", "")
262     "call <SID>X("Statement", "#ffff60", "", "none")
263     "call <SID>X("PreProc", "#ff80ff", "", "none")
264     "call <SID>X("Type", "#60ff60", "", "none")
265     call <SID>X("Ignore", "#ffffff", "", "")
266
267     " My stuff.
268     call <SID>X("WildMenu", "blue", "white", "bold")
269     call <SID>X("Todo", "black", "green", "bold")
270     call <SID>X("MoreMsg", "#00ff00", "", "none")
271
272     call <SID>X("Repeat", "yellow", "", "none")
273     call <SID>X("Label", "#90f020", "", "none")
274     call <SID>X("Conditional", "#ffff60", "", "none")
275     call <SID>X("Operator", "#e0e000", "", "none")
276     call <SID>X("Statement", "#ffff00", "", "none")
277
278     hi Comment ctermfg=lightblue cterm=none guifg=#80a0ff gui=none
279
280     call <SID>X("Function", "darkgreen", "", "none")
281     call <SID>X("Identifier", "#40ffff", "", "none")
282
283     hi Character ctermfg=darkmagenta cterm=bold guifg=magenta gui=bold
284     hi String ctermfg=darkmagenta cterm=none guifg=magenta gui=none
285     call <SID>X("Float", "magenta", "", "none")
286     call <SID>X("Number", "magenta", "", "bold")
287     call <SID>X("Boolean", "darkred", "", "bold")
288     call <SID>X("Constant", "darkmagenta", "", "bold")
289     hi NonText ctermfg=blue cterm=none guifg=blue gui=none
290
291     call <SID>X("SpecialChar", "#ff0000", "", "none")
292     hi SpecialKey ctermfg=blue cterm=none guifg=blue gui=none
293     call <SID>X("Special", "#ff0000", "", "none")
294
295     call <SID>X("Include", "red", "", "none")
296     call <SID>X("Macro", "red", "", "none")
297     call <SID>X("PreCondit", "darkred", "", "none")
298     call <SID>X("PreProc", "darkred", "", "bold")
299
300     hi StorageClass ctermfg=green cterm=none guifg=lightgreen gui=none
301     hi Structure ctermfg=darkgreen cterm=bold guifg=green gui=bold
302     hi Type ctermfg=darkgreen cterm=none guifg=green gui=none
303
304     " Fix up shell stuff. XXX: Should this go in ~/.vim/after/syntax/sh.vim?
305     hi link shShellVariables Identifier
306
307     " Fix up Perl stuff.
308 endif
309
310 " vim: set fdl=0 fdm=marker: