Permalink
Browse files

self-modify code to avoid the GUI-or-256term check

  • Loading branch information...
1 parent abd0a4f commit 3ad55a6e66a465e450a88c4865cf41b11a2d9209 @ap committed May 20, 2011
Showing with 15 additions and 10 deletions.
  1. +15 −10 after/syntax/css.vim
View
@@ -99,25 +99,30 @@ function! s:SetMatcher(color, pattern)
if currentmatch =~ a:pattern.'\/' | return 0 | endif
exe 'syn match' group '/'.a:pattern.'/ contained'
exe 'syn cluster cssColors add='.group
- if has('gui_running')
- exe 'hi' group 'guibg=#'.a:color 'guifg=#'.s:FGforBG(a:color)
- elseif &t_Co == 256
- exe 'hi' group 'ctermbg='.s:Rgb2xterm(a:color) 'ctermfg='.s:Rgb2xterm(s:FGforBG(a:color))
- endif
+ exe 'hi' group 'guibg=#'.(a:color) 'guifg=#'.(s:FGforBG(a:color))
return 1
endfunction
function! s:SetNamedColor(color, name)
let group = 'cssColor' . tolower(a:color)
exe 'syn keyword' group a:name 'contained'
exe 'syn cluster cssColors add='.group
- if has('gui_running')
- exe 'hi' group 'guibg=#'.a:color 'guifg=#'.s:FGforBG(a:color)
- elseif &t_Co == 256
- exe 'hi' group 'ctermbg='.s:Rgb2xterm(a:color) 'ctermfg='.s:Rgb2xterm(s:FGforBG(a:color))
- endif
+ exe 'hi' group 'guibg=#'.(a:color) 'guifg=#'.(s:FGforBG(a:color))
endfunction
+if ( ! has('gui_running') ) && &t_Co == 256
+ " on xterm, recompile code with applicable changes
+ " this avoids having any conditionals on a critical execution path
+ redir => source
+ silent! function s:SetMatcher
+ silent! function s:SetNamedColor
+ redir END
+ let source = substitute( source, '\n[0-9]\+', "\n", 'g' )
+ let source = substitute( source, ' \zsfunction\ze ', 'function!', 'g' )
+ let source = substitute( source, 'gui\([bf]g\)=#''.(', 'cterm\1=''.s:Rgb2xterm(', 'g' )
+ exe source
+endif
+
function! s:PreviewCSSColorInLine()
" TODO use cssColor matchdata
let n = 0

0 comments on commit 3ad55a6

Please sign in to comment.