From b5ea2fa88d4f165b7b6b2a8b038a1d2c6addf2e4 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Fri, 27 Mar 2009 16:22:37 -0400 Subject: [PATCH] Move guisp retrieval into a separate function. No idea why this is faster... but it is, profiling proves it. --- plugin/CSApprox.vim | 53 ++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/plugin/CSApprox.vim b/plugin/CSApprox.vim index f73762f..1bb96f7 100644 --- a/plugin/CSApprox.vim +++ b/plugin/CSApprox.vim @@ -194,24 +194,14 @@ function! s:Highlights(modes) let rv[i][where][attr] = synIDattr(i, attr, where) endfor - for attr in [ "fg", "bg", "sp" ] + for attr in [ "fg", "bg" ] let rv[i][where][attr] = synIDattr(i, attr.'#', where) endfor - if s:NeedRedirFallback() - redir => temp - exe 'sil hi ' . rv[i].name - redir END - let temp = matchstr(temp, where.'sp=\zs.*') - if len(temp) == 0 || temp[0] =~ '\s' - let temp = "" - else - " Make sure we can handle guisp='dark red' - let temp = substitute(temp, '[\x00].*', '', '') - let temp = substitute(temp, '\s*\(c\=term\|gui\).*', '', '') - let temp = substitute(temp, '\s*$', '', '') - endif - let rv[i][where]["sp"] = temp + if where == "gui" + let rv[i][where]["sp"] = s:SynGuiSp(i, rv[i].name) + else + let rv[i][where]["sp"] = -1 endif for attr in [ "fg", "bg", "sp" ] @@ -225,6 +215,39 @@ function! s:Highlights(modes) return rv endfunction +" {>2} Retrieve guisp + +" Get guisp using whichever method is specified by _redir_fallback +function! s:SynGuiSp(idx, name) + if !s:NeedRedirFallback() + return s:SynGuiSpAttr(a:idx) + else + return s:SynGuiSpRedir(a:name) + endif +endfunction + +" {>3} Implementation for retrieving guisp with redir hack +function! s:SynGuiSpRedir(name) + redir => temp + exe 'sil hi ' . a:name + redir END + let temp = matchstr(temp, 'guisp=\zs.*') + if len(temp) == 0 || temp[0] =~ '\s' + let temp = "" + else + " Make sure we can handle guisp='dark red' + let temp = substitute(temp, '[\x00].*', '', '') + let temp = substitute(temp, '\s*\(c\=term\|gui\).*', '', '') + let temp = substitute(temp, '\s*$', '', '') + endif + return temp +endfunction + +" {>3} Implementation for retrieving guisp with synIDattr() +function! s:SynGuiSpAttr(idx) + return synIDattr(a:idx, 'sp#', 'gui') +endfunction + " {>1} Handle color names " Place to store rgb.txt name to color mappings - lazy loaded if needed