Skip to content

Commit 6941fc3

Browse files
committed
split matchadd() loop into separate function
1 parent 0966cde commit 6941fc3

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

autoload/css_color.vim

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,8 @@ function! s:create_syn_match()
209209
return ''
210210
endfunction
211211

212-
let s:_funcname = '\(rgb\|hsl\)a\?' " submatch 1
213-
let s:_numval = '\(\d\{1,3}%\?\)' " submatch 2,3,4
214-
let s:_ws_ = '\s*'
215-
let s:_listsep = s:_ws_ . ',' . s:_ws_
216-
let s:_otherargs_ = '\%(,[^)]*\)\?'
217-
let s:_funcexpr = s:_funcname . '[(]' . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_ws_ . s:_otherargs_ . '[)]'
218-
let s:_hexcolor = '#\(\x\{3}\|\x\{6}\)\>' " submatch 5
219-
let s:_grammar = s:_funcexpr . '\|' . s:_hexcolor
220-
function! css_color#parse_screen()
221-
" N.B. this substitute() call is here just for the side effect
222-
" of invoking s:create_syn_match during substitution -- because
223-
" match() and friends do not allow finding all matches in a single
224-
" scan without examining the start of the string over and over
225-
call substitute( join( getline('w0','w$'), "\n" ), s:_grammar, '\=s:create_syn_match()', 'g' )
226-
212+
function! s:update_matches()
213+
" adds matches based that duplicate the highlighted colors on the current line
227214
let lnr = line('.')
228215
let group = ''
229216
let groupstart = 0
@@ -241,3 +228,20 @@ function! css_color#parse_screen()
241228
let groupstart = col
242229
endfor
243230
endfunction
231+
232+
let s:_funcname = '\(rgb\|hsl\)a\?' " submatch 1
233+
let s:_numval = '\(\d\{1,3}%\?\)' " submatch 2,3,4
234+
let s:_ws_ = '\s*'
235+
let s:_listsep = s:_ws_ . ',' . s:_ws_
236+
let s:_otherargs_ = '\%(,[^)]*\)\?'
237+
let s:_funcexpr = s:_funcname . '[(]' . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_ws_ . s:_otherargs_ . '[)]'
238+
let s:_hexcolor = '#\(\x\{3}\|\x\{6}\)\>' " submatch 5
239+
let s:_grammar = s:_funcexpr . '\|' . s:_hexcolor
240+
function! css_color#parse_screen()
241+
" N.B. this substitute() call is here just for the side effect
242+
" of invoking s:create_syn_match during substitution -- because
243+
" match() and friends do not allow finding all matches in a single
244+
" scan without examining the start of the string over and over
245+
call substitute( join( getline('w0','w$'), "\n" ), s:_grammar, '\=s:create_syn_match()', 'g' )
246+
call s:update_matches()
247+
endfunction

0 commit comments

Comments
 (0)