Created
September 6, 2011 02:56
-
-
Save eraserhd/1196466 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
augroup Kiwi | |
au! | |
autocmd BufNewFile,BufRead *Spec.m,*Spec.mm set foldmethod=expr foldexpr=KiwiFoldLevel(v:lnum) | |
augroup END | |
function! KiwiFoldLevel(lnum) | |
let line=getline(a:lnum) | |
if line=~'^\s\s*\(context\|describe\|it\)\s*(' | |
return ">" . (indent(a:lnum) / (&sts ? &sts : &ts)) | |
elseif line=~'^\s\s*});\s*$' && getline(a:lnum+1)!~'^\s*$' | |
return "<" . (indent(a:lnum) / (&sts ? &sts : &ts)) | |
elseif line=~'^\s*$' && getline(a:lnum-1)=~'^\s\s*});\s*$' | |
return "<" . (indent(a:lnum-1) / (&sts ? &sts : &ts)) | |
elseif line=~'{{'.'{[0-9][0-9]*' | |
return ">" . substitute(line, '^.*{{'.'{\([0-9]*\).*$', '\1', '') | |
elseif line=~('{{'.'{') | |
return 'a1' | |
elseif line=~'[0-9][0-9]*}'.'}}' | |
return "<" . substitute(line, '^.*\([0-9][0-9]*\)}'.'}}.*$', '\1', '') | |
elseif line=~'}'.'}}' | |
return 's1' | |
else | |
return '=' | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment