vim/ftplugin/clojure/clojurefolding.vim @ ff5bff57a284

Uncomment docstring foldtext mappings.
author Steve Losh <steve@stevelosh.com>
date Tue, 17 Jan 2012 11:37:57 -0500
parents 7f2c706a6945
children f47fa6183dd6
if exists('loaded_clojurefolding') || &cp
    finish
endif
let loaded_clojurefolding=1

" ---------------------------------------------------------------------------
"  Automagic Clojure folding on defn's and defmacro's
"
function GetClojureFold()
      if getline(v:lnum) =~ '^\s*(defn.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(def .*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defmacro.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(ns.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defmethod.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defpage.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defpartial.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(deftest.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*$'
            let my_cljnum = v:lnum
            let my_cljmax = line("$")

            while (1)
                  let my_cljnum = my_cljnum + 1
                  if my_cljnum > my_cljmax
                        return "<1"
                  endif

                  let my_cljdata = getline(my_cljnum)

                  " If we match an empty line, stop folding
                  if my_cljdata =~ '^$'
                        return "<1"
                  else
                        return "="
                  endif
            endwhile
      else
            return "="
      endif
endfunction

function TurnOnClojureFolding()
      setlocal foldexpr=GetClojureFold()
      setlocal foldmethod=expr
endfunction