Skip to content

Commit

Permalink
Toggle individual types
Browse files Browse the repository at this point in the history
Run the Load cmd again to toggle each type.
Close #3.
  • Loading branch information
kien committed Oct 26, 2011
1 parent 5aa885e commit 8f70517
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
19 changes: 12 additions & 7 deletions autoload/rainbow_parentheses.vim
Expand Up @@ -47,8 +47,8 @@ cal s:extend()

func! rainbow_parentheses#activate()
let id = 1
for [ctermbg, guibg] in s:colorpairs
exe printf('hi default level%dc ctermfg=%s guifg=%s', id, ctermbg, guibg)
for [ctermfg, guifg] in s:colorpairs
exe 'hi default level'.id.'c ctermfg='.ctermfg.' guifg='.guifg
let id += 1
endfor
let s:active = 1
Expand All @@ -63,7 +63,7 @@ endfunc

func! rainbow_parentheses#toggle()
if !exists('s:active')
cal rainbow_parentheses#load('(',')')
cal rainbow_parentheses#load(0)
endif
if exists('s:active') && s:active
cal rainbow_parentheses#clear()
Expand All @@ -81,15 +81,20 @@ func! s:cluster()
endfunc
cal s:cluster()

func! rainbow_parentheses#load(br1, br2)
let [level, grp, alllvls] = ['', '', []]
let [br1, br2] = [escape(a:br1, '['), escape(a:br2, ']')]
let s:types = [['(',')'],['\[','\]'],['{','}'],['<','>']]
let s:loaded = [0,0,0,0]

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 s:loaded[a:1] = s:loaded[a:1] ? 0 : 1
for each in range(1, s:max)
let region = s:loaded[a:1] ? 'level'.each : 'level'.each.'none'
let grp = s:loaded[a:1] ? 'level'.each.'c' : 'Normal'
let cmd = 'syn region %s matchgroup=%s start=/%s/ end=/%s/ contains=TOP,%s,NoInParens'
exe printf(cmd, 'level'.each, 'level'.each.'c', br1, br2, join(alllvls, ','))
exe printf(cmd, region, grp, type[0], type[1], join(alllvls, ','))
cal remove(alllvls, 0)
endfor
endfunc
Expand Down
8 changes: 4 additions & 4 deletions plugin/rainbow_parentheses.vim
Expand Up @@ -5,7 +5,7 @@
" GetLatestVimScripts: 3772 1 :AutoInstall: rainbow_parentheses.zip

com! RainbowParenthesesToggle cal rainbow_parentheses#toggle()
com! RainbowParenthesesLoadSquare cal rainbow_parentheses#load('[',']')
com! RainbowParenthesesLoadRound cal rainbow_parentheses#load('(',')')
com! RainbowParenthesesLoadBraces cal rainbow_parentheses#load('{','}')
com! RainbowParenthesesLoadChevrons cal rainbow_parentheses#load('<','>')
com! RainbowParenthesesLoadRound cal rainbow_parentheses#load(0)
com! RainbowParenthesesLoadSquare cal rainbow_parentheses#load(1)
com! RainbowParenthesesLoadBraces cal rainbow_parentheses#load(2)
com! RainbowParenthesesLoadChevrons cal rainbow_parentheses#load(3)
10 changes: 10 additions & 0 deletions readme.md
Expand Up @@ -36,3 +36,13 @@ let g:rbpt_max = 16
:RainbowParenthesesLoadBraces " {}
:RainbowParenthesesLoadChevrons " <>
```

### Always On:

```vim
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
au Syntax * RainbowParenthesesLoadChevrons
```

0 comments on commit 8f70517

Please sign in to comment.