Permalink
Browse files

Option to enable/disable toggling with the Load cmds

Also, rename some s:var's and reindent the script.
  • Loading branch information...
1 parent 45e270d commit 874367f41275d8dd43204f0c491157accc8b5f03 @kien committed May 1, 2012
Showing with 43 additions and 58 deletions.
  1. +39 −58 autoload/rainbow_parentheses.vim
  2. +4 −0 readme.md
@@ -4,54 +4,45 @@
" 2011-10-12: Use less code. Leave room for deeper levels.
"==============================================================================
-if !exists('g:rbpt_colorpairs')
- let s:colorpairs = [
- \ ['brown', 'RoyalBlue3'],
- \ ['Darkblue', 'SeaGreen3'],
- \ ['darkgray', 'DarkOrchid3'],
- \ ['darkgreen', 'firebrick3'],
- \ ['darkcyan', 'RoyalBlue3'],
- \ ['darkred', 'SeaGreen3'],
- \ ['darkmagenta', 'DarkOrchid3'],
- \ ['brown', 'firebrick3'],
- \ ['gray', 'RoyalBlue3'],
- \ ['black', 'SeaGreen3'],
- \ ['darkmagenta', 'DarkOrchid3'],
- \ ['Darkblue', 'firebrick3'],
- \ ['darkgreen', 'RoyalBlue3'],
- \ ['darkcyan', 'SeaGreen3'],
- \ ['darkred', 'DarkOrchid3'],
- \ ['red', 'firebrick3'],
- \ ]
-else
- let s:colorpairs = g:rbpt_colorpairs
- unl g:rbpt_colorpairs
-endif
-
-if !exists('g:rbpt_max')
- let s:max = len(s:colorpairs)
-else
- let s:max = g:rbpt_max
- unl g:rbpt_max
-endif
+let s:pairs = [
+ \ ['brown', 'RoyalBlue3'],
+ \ ['Darkblue', 'SeaGreen3'],
+ \ ['darkgray', 'DarkOrchid3'],
+ \ ['darkgreen', 'firebrick3'],
+ \ ['darkcyan', 'RoyalBlue3'],
+ \ ['darkred', 'SeaGreen3'],
+ \ ['darkmagenta', 'DarkOrchid3'],
+ \ ['brown', 'firebrick3'],
+ \ ['gray', 'RoyalBlue3'],
+ \ ['black', 'SeaGreen3'],
+ \ ['darkmagenta', 'DarkOrchid3'],
+ \ ['Darkblue', 'firebrick3'],
+ \ ['darkgreen', 'RoyalBlue3'],
+ \ ['darkcyan', 'SeaGreen3'],
+ \ ['darkred', 'DarkOrchid3'],
+ \ ['red', 'firebrick3'],
+ \ ]
+let s:pairs = exists('g:rbpt_colorpairs') ? g:rbpt_colorpairs : s:pairs
+let s:max = exists('g:rbpt_max') ? g:rbpt_max : max([len(s:pairs), 16])
+let s:loadtgl = exists('g:rbpt_loadcmd_toggle') ? g:rbpt_loadcmd_toggle : 0
+let s:types = [['(',')'],['\[','\]'],['{','}'],['<','>']]
func! s:extend()
- if s:max > len(s:colorpairs)
- cal extend(s:colorpairs, s:colorpairs)
+ if s:max > len(s:pairs)
+ cal extend(s:pairs, s:pairs)
cal s:extend()
- elseif s:max < len(s:colorpairs)
- cal remove(s:colorpairs, s:max, -1)
+ elseif s:max < len(s:pairs)
+ cal remove(s:pairs, s:max, -1)
endif
endfunc
cal s:extend()
func! rainbow_parentheses#activate()
- let id = 1
- for [ctermfg, guifg] in s:colorpairs
+ let [id, s:active] = [1, 1]
+ for [ctermfg, guifg] in s:pairs
exe 'hi default level'.id.'c ctermfg='.ctermfg.' guifg='.guifg
let id += 1
endfor
- let s:active = 1
endfunc
func! rainbow_parentheses#clear()
@@ -65,18 +56,15 @@ func! rainbow_parentheses#toggle()
if !exists('s:active')
cal rainbow_parentheses#load(0)
endif
- if exists('s:active') && s:active
- cal rainbow_parentheses#clear()
- else
- cal rainbow_parentheses#activate()
- endif
+ let afunc = exists('s:active') && s:active ? 'clear' : 'activate'
+ cal call('rainbow_parentheses#'.afunc, [])
endfunc
func! rainbow_parentheses#toggleall()
if !exists('s:active')
cal rainbow_parentheses#load(0)
- cal rainbow_parentheses#load(1)
- cal rainbow_parentheses#load(2)
+ cal rainbow_parentheses#load(1)
+ cal rainbow_parentheses#load(2)
endif
if exists('s:active') && s:active
cal rainbow_parentheses#clear()
@@ -86,29 +74,22 @@ func! rainbow_parentheses#toggleall()
endfunc
func! s:cluster()
- let levels = ''
- for each in range(1, s:max)
- let levels .= ',level'.each
- endfor
- exe 'syn cluster rainbow_parentheses contains=@TOP'.levels.',NoInParens'
+ let levels = join(map(range(1, s:max), '"level".v:val'), ',')
+ exe 'sy cluster rainbow_parentheses contains=@TOP'.levels.',NoInParens'
endfunc
cal s:cluster()
-let s:types = [['(',')'],['\[','\]'],['{','}'],['<','>']]
-
func! rainbow_parentheses#load(...)
- let [level, grp, alllvls, type] = ['', '', [], s:types[a:1]]
- for each in range(1, s:max)
- cal add(alllvls, 'level'.each)
- endfor
+ let [level, grp, type] = ['', '', s:types[a:1]]
+ let alllvls = map(range(1, s:max), '"level".v:val')
if !exists('b:loaded')
let b:loaded = [0,0,0,0]
endif
- let b:loaded[a:1] = b:loaded[a:1] ? 0 : 1
+ let b:loaded[a:1] = s:loadtgl && b:loaded[a:1] ? 0 : 1
for each in range(1, s:max)
- let region = b:loaded[a:1] ? 'level'.each : 'level'.each.'none'
+ let region = 'level'. each .(b:loaded[a:1] ? '' : 'none')
let grp = b:loaded[a:1] ? 'level'.each.'c' : 'Normal'
- let cmd = 'syn region %s matchgroup=%s start=/%s/ end=/%s/ contains=TOP,%s,NoInParens'
+ let cmd = 'sy region %s matchgroup=%s start=/%s/ end=/%s/ contains=TOP,%s,NoInParens'
exe printf(cmd, region, grp, type[0], type[1], join(alllvls, ','))
cal remove(alllvls, 0)
endfor
View
@@ -27,6 +27,10 @@ let g:rbpt_colorpairs = [
let g:rbpt_max = 16
```
+```vim
+let g:rbpt_loadcmd_toggle = 0
+```
+
### Commands:
```vim

0 comments on commit 874367f

Please sign in to comment.