Little bit of refactoring

I noticed that the list of possible attributes was written out
repeatedly, so I'm encapsulating the list in a function.
This commit is contained in:
Matt Wozniski 2010-07-19 23:50:05 -04:00
parent 63e636157a
commit 96e7aebcb7

View File

@ -116,7 +116,7 @@ function! s:Highlights(modes)
for where in a:modes for where in a:modes
let rv[i][where] = {} let rv[i][where] = {}
for attr in [ "bold", "italic", "reverse", "underline", "undercurl" ] for attr in s:PossibleAttributes()
let rv[i][where][attr] = synIDattr(i, attr, where) let rv[i][where][attr] = synIDattr(i, attr, where)
endfor endfor
@ -284,6 +284,11 @@ endfunction
" {>1} Derive and set cterm attributes " {>1} Derive and set cterm attributes
" {>2} List of all possible attributes
function! s:PossibleAttributes()
return [ "bold", "italic", "reverse", "underline", "undercurl" ]
endfunction
" {>2} Attribute overrides " {>2} Attribute overrides
" Allow the user to override a specified attribute with another attribute. " Allow the user to override a specified attribute with another attribute.
" For example, the default is to map 'italic' to 'underline' (since many " For example, the default is to map 'italic' to 'underline' (since many
@ -305,8 +310,7 @@ function! s:NormalizeAttrMap(map)
let old = copy(a:map) let old = copy(a:map)
let new = filter(a:map, '0') let new = filter(a:map, '0')
let valid_attrs = [ 'bg', 'fg', 'sp', 'bold', 'italic', let valid_attrs = [ 'bg', 'fg', 'sp' ] + s:PossibleAttributes()
\ 'reverse', 'underline', 'undercurl' ]
let colorattrs = [ 'fg', 'bg', 'sp' ] let colorattrs = [ 'fg', 'bg', 'sp' ]
@ -374,7 +378,7 @@ function! s:FixupCtermInfo(highlights)
endif endif
" Find attributes to be set in the terminal " Find attributes to be set in the terminal
for attr in [ "bold", "italic", "reverse", "underline", "undercurl" ] for attr in s:PossibleAttributes()
let hl.cterm[attr] = '' let hl.cterm[attr] = ''
if hl.gui[attr] == 1 if hl.gui[attr] == 1
if s:attr_map(attr) != '' if s:attr_map(attr) != ''
@ -482,7 +486,7 @@ function! s:SetCtermFromGui(hl)
endfor endfor
" Finally, set the attributes " Finally, set the attributes
let attrs = [ 'bold', 'italic', 'reverse', 'underline', 'undercurl' ] let attrs = s:PossibleAttributes()
call filter(attrs, 'hl.cterm[v:val] == 1') call filter(attrs, 'hl.cterm[v:val] == 1')
if !empty(attrs) if !empty(attrs)
@ -848,7 +852,7 @@ function! s:CSApproxSnapshot(file, overwrite)
let hl = highlights[hlnum] let hl = highlights[hlnum]
let line = ' CSAHi ' . hl.name let line = ' CSAHi ' . hl.name
for type in [ 'term', 'cterm', 'gui' ] for type in [ 'term', 'cterm', 'gui' ]
let attrs = [ 'bold', 'italic', 'reverse', 'underline', 'undercurl' ] let attrs = s:PossibleAttributes()
call filter(attrs, 'hl[type][v:val] == 1') call filter(attrs, 'hl[type][v:val] == 1')
let line .= ' ' . type . '=' . (empty(attrs) ? 'NONE' : join(attrs, ',')) let line .= ' ' . type . '=' . (empty(attrs) ? 'NONE' : join(attrs, ','))
if type != 'term' if type != 'term'