Permalink
Browse files

Organizing more plugins into bundles

  • Loading branch information...
1 parent cdbdbcd commit ababc5f6c2b28120e70f01aeffa3edf474f57846 @akitaonrails akitaonrails committed Apr 22, 2010
View
@@ -43,3 +43,6 @@
[submodule "bundle/syntastic"]
path = bundle/syntastic
url = git://github.com/scrooloose/syntastic.git
+[submodule "bundle/pastie"]
+ path = bundle/pastie
+ url = git://github.com/tpope/vim-pastie.git
File renamed without changes.
@@ -80,18 +80,6 @@ NOTE: Although :CSApproxSnapshot can be used in both GVim and terminal Vim,
running in a terminal than running in the GUI, and there's no way for
terminal Vim to figure out what color would have been used in GVim.
- *:CSApprox*
-A command is also provided to run the approximation manually. This might be
-useful if some colors were set outside of a colorscheme file, for instance.
-By default, it will not change any colors unless no highlight group is set to
-a color above 15, which is CSApprox's normal behavior. This probably isn't
-useful in most use cases, though. On the other hand, if a ! is provided,
-CSApprox will skip that test and update the cterm value for every highlight
-group from the corresponding gui color. Syntax:
->
- :CSApprox[!]
-<
-
==============================================================================
2. Requirements *csapprox-requirements*
@@ -440,14 +428,6 @@ Transparently adapting schemes is slow.
NOTE: As of CSApprox 3.50, the overhead is down to about 0.10 seconds on my
test machine.
-It isn't possible to approximate only a particular set of groups.
-
- Unfortunately, the :CSApprox command will always update all groups, even if
- only a small set of groups has changed. A future improvement would be to
- provide a function called, say, CSApprox(), that takes an optional list of
- highlight groups (default: all) and only does approximation for those
- groups.
-
==============================================================================
6. Appendix - Terminals and Palettes *csapprox-terminal-list*
@@ -54,15 +54,20 @@
" Quit if the user doesn't want or need us or is missing the gui feature. We
" need +gui to be able to check the gui color settings; vim doesn't bother to
" store them if it is not built with +gui.
-if exists('g:CSApprox_loaded')
- finish
-elseif ! has('gui')
- " Warn unless the user set g:CSApprox_verbose_level to zero.
- if get(g:, 'CSApprox_verbose_level', 1)
+if !has('gui') || exists('g:CSApprox_loaded')
+ " XXX This depends upon knowing the default for g:CSApprox_verbose_level
+ let s:verbose = 1
+ if exists("g:CSApprox_verbose_level")
+ let s:verbose = g:CSApprox_verbose_level
+ endif
+
+ if ! has('gui') && s:verbose > 0
echomsg "CSApprox needs gui support - not loading."
echomsg " See :help |csapprox-+gui| for possible workarounds."
endif
+ unlet s:verbose
+
finish
endif
@@ -72,6 +77,110 @@ let g:CSApprox_loaded = 1
let s:savecpo = &cpo
set cpo&vim
+" {>1} Built-in approximation algorithm
+
+" {>2} Cube definitions
+let s:xterm_colors = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ]
+let s:eterm_colors = [ 0x00, 0x2A, 0x55, 0x7F, 0xAA, 0xD4 ]
+let s:konsole_colors = [ 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF ]
+let s:xterm_greys = [ 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A,
+ \ 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
+ \ 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2,
+ \ 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE ]
+
+let s:urxvt_colors = [ 0x00, 0x8B, 0xCD, 0xFF ]
+let s:urxvt_greys = [ 0x2E, 0x5C, 0x73, 0x8B,
+ \ 0xA2, 0xB9, 0xD0, 0xE7 ]
+
+" {>2} Integer comparator
+" Used to sort the complete list of possible colors
+function! s:IntCompare(i1, i2)
+ return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
+endfunc
+
+" {>2} Approximator
+" Takes 3 decimal values for r, g, and b, and returns the closest cube number.
+" Uses &term to determine which cube should be used, though if &term is set to
+" "xterm" or begins with "screen", the variables g:CSApprox_eterm and
+" g:CSApprox_konsole can be used to select a different palette.
+"
+" This approximator considers closeness based upon the individiual components.
+" For each of r, g, and b, it finds the closest cube component available on
+" the cube. If the three closest matches can combine to form a valid color,
+" this color is used, otherwise we repeat the search with the greys removed,
+" meaning that the three new matches must make a valid color when combined.
+function! s:ApproximatePerComponent(r,g,b)
+ let hex = printf("%02x%02x%02x", a:r, a:g, a:b)
+
+ let greys = (&t_Co == 88 ? s:urxvt_greys : s:xterm_greys)
+
+ if &t_Co == 88
+ let colors = s:urxvt_colors
+ let type = 'urxvt'
+ elseif ((&term ==# 'xterm' || &term =~# '^screen' || &term==# 'builtin_gui')
+ \ && exists('g:CSApprox_konsole') && g:CSApprox_konsole)
+ \ || &term =~? '^konsole'
+ let colors = s:konsole_colors
+ let type = 'konsole'
+ elseif ((&term ==# 'xterm' || &term =~# '^screen' || &term==# 'builtin_gui')
+ \ && exists('g:CSApprox_eterm') && g:CSApprox_eterm)
+ \ || &term =~? '^eterm'
+ let colors = s:eterm_colors
+ let type = 'eterm'
+ else
+ let colors = s:xterm_colors
+ let type = 'xterm'
+ endif
+
+ if !exists('s:approximator_cache_'.type)
+ let s:approximator_cache_{type} = {}
+ endif
+
+ let rv = get(s:approximator_cache_{type}, hex, -1)
+ if rv != -1
+ return rv
+ endif
+
+ " Only obtain sorted list once
+ if !exists("s:".type."_greys_colors")
+ let s:{type}_greys_colors = sort(greys + colors, "s:IntCompare")
+ endif
+
+ let greys_colors = s:{type}_greys_colors
+
+ let r = s:NearestElemInList(a:r, greys_colors)
+ let g = s:NearestElemInList(a:g, greys_colors)
+ let b = s:NearestElemInList(a:b, greys_colors)
+
+ let len = len(colors)
+ if (r == g && g == b && index(greys, r) != -1)
+ let rv = 16 + len * len * len + index(greys, r)
+ else
+ let r = s:NearestElemInList(a:r, colors)
+ let g = s:NearestElemInList(a:g, colors)
+ let b = s:NearestElemInList(a:b, colors)
+ let rv = index(colors, r) * len * len
+ \ + index(colors, g) * len
+ \ + index(colors, b)
+ \ + 16
+ endif
+
+ let s:approximator_cache_{type}[hex] = rv
+ return rv
+endfunction
+
+" {>2} Color comparator
+" Finds the nearest element to the given element in the given list
+function! s:NearestElemInList(elem, list)
+ let len = len(a:list)
+ for i in range(len-1)
+ if (a:elem <= (a:list[i] + a:list[i+1]) / 2)
+ return a:list[i]
+ endif
+ endfor
+ return a:list[len-1]
+endfunction
+
" {>1} Collect info for the set highlights
" {>2} Determine if synIDattr is usable
@@ -410,11 +519,6 @@ function! s:FixupCtermInfo(highlights)
endfor
endfunction
-" {>2} Kludge around inability to reference autoload functions
-function! s:DefaultApproximator(...)
- return call('csapprox#per_component#Approximate', a:000)
-endfunction
-
" {>2} Set cterm colors for a highlight group
" Given the information for a single highlight group (ie, the value of
" one of the items in s:Highlights() already normalized with s:FixupCtermInfo
@@ -427,7 +531,7 @@ function! s:SetCtermFromGui(hl)
" Set up the default approximator function, if needed
if !exists("g:CSApprox_approximator_function")
- let g:CSApprox_approximator_function = function("s:DefaultApproximator")
+ let g:CSApprox_approximator_function=function("s:ApproximatePerComponent")
endif
" Clear existing highlights
@@ -589,15 +693,8 @@ endfunction
" main function. This allows us to default to a message whenever any error,
" even a recoverable one, occurs, meaning the user quickly finds out when
" something's wrong, but makes it very easy for the user to make us silent.
-function! s:CSApprox(...)
+function! s:CSApprox()
try
- if a:0 == 1 && a:1
- if !exists('s:inhibit_hicolor_test')
- let s:inhibit_hicolor_test = 0
- endif
- let s:inhibit_hicolor_test += 1
- endif
-
let savelz = &lz
set lz
@@ -647,13 +744,6 @@ function! s:CSApprox(...)
endif
let &lz = savelz
-
- if a:0 == 1 && a:1
- let s:inhibit_hicolor_test -= 1
- if s:inhibit_hicolor_test == 0
- unlet s:inhibit_hicolor_test
- endif
- endif
endtry
endfunction
@@ -873,9 +963,6 @@ endfunction
command! -bang -nargs=1 -complete=file -bar CSApproxSnapshot
\ call s:CSApproxSnapshot(<f-args>, strlen("<bang>"))
-" {>2} Manual updates
-command -bang -bar CSApprox call s:CSApprox(strlen("<bang>"))
-
" {>1} Hooks
" {>2} Autocmds
Submodule pastie added at 549355
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit ababc5f

Please sign in to comment.