@@ -138,21 +138,17 @@ function! s:create_syn_match()
138138 let rgb_color = get ( s: pattern_color , pattern, ' ' )
139139
140140 if ! strlen ( rgb_color )
141- let hexcolor = submatch (1 )
141+ let hex = submatch (1 )
142142 let funcname = submatch (2 )
143143
144- if funcname == ' rgb'
145- let rgb_color = s: rgb2color (submatch (3 ),submatch (4 ),submatch (5 ))
146- elseif funcname == ' hsl'
147- let rgb_color = s: hsl2color (submatch (3 ),submatch (4 ),submatch (5 ))
148- elseif strlen (hexcolor) == 6
149- let rgb_color = tolower (hexcolor)
150- elseif strlen (hexcolor) == 3
151- let rgb_color = substitute (tolower (hexcolor), ' \(.\)' , ' \1\1' , ' g' )
152- else
153- throw ' css_color: create_syn_match invoked on bad match data'
154- endif
144+ let rgb_color
145+ \ = funcname == ' rgb' ? s: rgb2color (submatch (3 ),submatch (4 ),submatch (5 ))
146+ \ : funcname == ' hsl' ? s: hsl2color (submatch (3 ),submatch (4 ),submatch (5 ))
147+ \ : strlen (hex) == 6 ? tolower (hex)
148+ \ : strlen (hex) == 3 ? tolower (hex[0 ].hex[0 ].hex[1 ].hex[1 ].hex[2 ].hex[2 ])
149+ \ : ' '
155150
151+ if rgb_color == ' ' | throw ' css_color: create_syn_match invoked on bad match data' | endif
156152 let s: pattern_color [pattern] = rgb_color
157153 endif
158154
@@ -202,7 +198,7 @@ function! s:create_matches()
202198 endfor
203199endfunction
204200
205- let s: _hexcolor = ' #\(\x\{3}\|\x\{6}\)\> ' " submatch 1
201+ let s: _hexcolor = ' #\(\x\{3}\%(\>\ |\x\{3}\>\)\) ' " submatch 1
206202let s: _funcname = ' \(rgb\|hsl\)a\?' " submatch 2
207203let s: _ws_ = ' \s*'
208204let s: _numval = s: _ws_ . ' \(\d\{1,3}%\?\)' " submatch 3,4,5
0 commit comments