@@ -10,35 +10,6 @@ for i in range(0, 255)
1010 let s: hex [ printf ( ' %02x' , i ) ] = i
1111endfor
1212
13- function ! s: FGforBG (bg )
14- " takes a 6hex color code and returns a matching color that is visible
15- let rgb = matchlist (tolower (a: bg ),' ^#\(\x\x\)\(\x\x\)\(\x\x\)$' )
16- if len ( rgb ) == 0 | return ' #cccccc' | endif
17- let [r ,g ,b ] = rgb[1 :3 ]
18- return s: hex [r ]* 30 + s: hex [g ]* 59 + s: hex [b ]* 11 > 12000 ? ' #000000' : ' #ffffff'
19- endfunction
20-
21- function ! s: SetMatcher (clr,pat)
22- let group = ' cssColor' .tolower (matchstr (a: clr ,' ^#\zs.*' ))
23- redir = > s: currentmatch
24- silent ! exe ' syn list' group
25- redir END
26- if s: currentmatch !~ a: pat .' \/'
27- exe ' syn match' group ' /' .a: pat .' / contained'
28- exe ' syn cluster cssColors add=' .group
29- if has (' gui_running' )
30- exe ' hi' group ' guifg=' .s: FGforBG (a: clr )
31- exe ' hi' group ' guibg=' .a: clr
32- elseif &t_Co == 256
33- exe ' hi' group ' ctermfg=' .s: Rgb2xterm (s: FGforBG (a: clr ))
34- exe ' hi' group ' ctermbg=' .s: Rgb2xterm (a: clr )
35- endif
36- return 1
37- else
38- return 0
39- endif
40- endfunction
41-
4213" xterm color table
4314" 16 vt100 colors preset
4415let s: colortable= [
@@ -119,6 +90,35 @@ function! s:Rgb2xterm(color)
11990 return best_match
12091endfunction
12192
93+ function ! s: FGforBG (bg )
94+ " takes a 6hex color code and returns a matching color that is visible
95+ let rgb = matchlist (tolower (a: bg ),' ^#\(\x\x\)\(\x\x\)\(\x\x\)$' )
96+ if len ( rgb ) == 0 | return ' #cccccc' | endif
97+ let [r ,g ,b ] = rgb[1 :3 ]
98+ return s: hex [r ]* 30 + s: hex [g ]* 59 + s: hex [b ]* 11 > 12000 ? ' #000000' : ' #ffffff'
99+ endfunction
100+
101+ function ! s: SetMatcher (clr,pat)
102+ let group = ' cssColor' .tolower (matchstr (a: clr ,' ^#\zs.*' ))
103+ redir = > s: currentmatch
104+ silent ! exe ' syn list' group
105+ redir END
106+ if s: currentmatch !~ a: pat .' \/'
107+ exe ' syn match' group ' /' .a: pat .' / contained'
108+ exe ' syn cluster cssColors add=' .group
109+ if has (' gui_running' )
110+ exe ' hi' group ' guifg=' .s: FGforBG (a: clr )
111+ exe ' hi' group ' guibg=' .a: clr
112+ elseif &t_Co == 256
113+ exe ' hi' group ' ctermfg=' .s: Rgb2xterm (s: FGforBG (a: clr ))
114+ exe ' hi' group ' ctermbg=' .s: Rgb2xterm (a: clr )
115+ endif
116+ return 1
117+ else
118+ return 0
119+ endif
120+ endfunction
121+
122122function ! s: SetNamedColor (clr,name)
123123 let group = ' cssColor' .tolower (matchstr (a: clr ,' ^#\zs.*' ))
124124 exe ' syn keyword' group a: name ' contained'
0 commit comments