From 96e7aebcb7f16be03e6f84b3d0d58beb744ce2c7 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Mon, 19 Jul 2010 23:50:05 -0400 Subject: [PATCH] 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. --- plugin/CSApprox.vim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/CSApprox.vim b/plugin/CSApprox.vim index b762404..4ed336b 100644 --- a/plugin/CSApprox.vim +++ b/plugin/CSApprox.vim @@ -116,7 +116,7 @@ function! s:Highlights(modes) for where in a:modes 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) endfor @@ -284,6 +284,11 @@ endfunction " {>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 " Allow the user to override a specified attribute with another attribute. " 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 new = filter(a:map, '0') - let valid_attrs = [ 'bg', 'fg', 'sp', 'bold', 'italic', - \ 'reverse', 'underline', 'undercurl' ] + let valid_attrs = [ 'bg', 'fg', 'sp' ] + s:PossibleAttributes() let colorattrs = [ 'fg', 'bg', 'sp' ] @@ -374,7 +378,7 @@ function! s:FixupCtermInfo(highlights) endif " 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] = '' if hl.gui[attr] == 1 if s:attr_map(attr) != '' @@ -482,7 +486,7 @@ function! s:SetCtermFromGui(hl) endfor " Finally, set the attributes - let attrs = [ 'bold', 'italic', 'reverse', 'underline', 'undercurl' ] + let attrs = s:PossibleAttributes() call filter(attrs, 'hl.cterm[v:val] == 1') if !empty(attrs) @@ -848,7 +852,7 @@ function! s:CSApproxSnapshot(file, overwrite) let hl = highlights[hlnum] let line = ' CSAHi ' . hl.name 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') let line .= ' ' . type . '=' . (empty(attrs) ? 'NONE' : join(attrs, ',')) if type != 'term'