Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created September 6, 2011 02:56
Show Gist options
  • Save eraserhd/1196466 to your computer and use it in GitHub Desktop.
Save eraserhd/1196466 to your computer and use it in GitHub Desktop.
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