Limit calls to synIDattr() in s:Highlights()

Modify s:Highlights() to only check modes it's explicitly told to.
s:CSApproxImpl() needs only gui colors, s:CSApproxSnapshot() needs gui,
cterm, and term.
This commit is contained in:
Matt Wozniski 2009-03-27 15:42:35 -04:00
parent df73d5e798
commit 7522e9b3d7

View File

@ -168,7 +168,7 @@ endfunction
" numbers for keys and values that are dictionaries with four keys each, " numbers for keys and values that are dictionaries with four keys each,
" 'name', 'term', 'cterm', and 'gui'. 'name' holds the group name, and each " 'name', 'term', 'cterm', and 'gui'. 'name' holds the group name, and each
" of the others holds highlight information for that particular mode. " of the others holds highlight information for that particular mode.
function! s:Highlights() function! s:Highlights(modes)
let rv = {} let rv = {}
let i = 0 let i = 0
@ -188,7 +188,7 @@ function! s:Highlights()
let rv[i] = {} let rv[i] = {}
let rv[i].name = synIDattr(i, "name") let rv[i].name = synIDattr(i, "name")
for where in [ "term", "cterm", "gui" ] for where in a:modes
let rv[i][where] = {} let rv[i][where] = {}
for attr in [ "bold", "italic", "reverse", "underline", "undercurl" ] for attr in [ "bold", "italic", "reverse", "underline", "undercurl" ]
let rv[i][where][attr] = synIDattr(i, attr, where) let rv[i][where][attr] = synIDattr(i, attr, where)
@ -385,6 +385,10 @@ endfunction
function! s:FixupCtermInfo(highlights) function! s:FixupCtermInfo(highlights)
for hl in values(a:highlights) for hl in values(a:highlights)
if !has_key(hl, 'cterm')
let hl["cterm"] = {}
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 [ "bold", "italic", "reverse", "underline", "undercurl" ]
let hl.cterm[attr] = '' let hl.cterm[attr] = ''
@ -669,7 +673,7 @@ function! s:CSApproxImpl()
endif endif
" Get the current highlight colors " Get the current highlight colors
let highlights = s:Highlights() let highlights = s:Highlights(["gui"])
let hinums = keys(highlights) let hinums = keys(highlights)
@ -681,17 +685,17 @@ function! s:CSApproxImpl()
" XXX: s:inhibit_hicolor_test allows this test to be skipped for snapshots " XXX: s:inhibit_hicolor_test allows this test to be skipped for snapshots
if !exists("s:inhibit_hicolor_test") || !s:inhibit_hicolor_test if !exists("s:inhibit_hicolor_test") || !s:inhibit_hicolor_test
for hlid in hinums for hlid in hinums
let val = highlights[hlid] for type in [ 'bg', 'fg' ]
if ( val.cterm.bg > 15 let color = synIDattr(hlid, type, 'cterm')
\ && index(s:presets_{&t_Co}, str2nr(val.cterm.bg)) < 0)
\ || ( val.cterm.fg > 15 if color > 15 && index(s:presets_{&t_Co}, str2nr(color)) < 0
\ && index(s:presets_{&t_Co}, str2nr(val.cterm.fg)) < 0) " The value is set above 15, and wasn't set by vim.
" The value is set above 15, and wasn't set by vim. if &verbose >= 2
if &verbose >= 2 echomsg 'CSApprox: Exiting - high' type 'color found for' highlights[hlid].name
echomsg 'CSApprox: Exiting - high color found for' val.name endif
return
endif endif
return endfor
endif
endfor endfor
endif endif
@ -797,7 +801,8 @@ function! s:CSApproxSnapshot(file, overwrite)
endif endif
call s:CSApprox() call s:CSApprox()
let highlights = s:Highlights()
let highlights = s:Highlights(["term", "cterm", "gui"])
call s:FixupGuiInfo(highlights) call s:FixupGuiInfo(highlights)
if round == 'konsole' || round == 'eterm' if round == 'konsole' || round == 'eterm'