vim/ftplugin/lisp/lispfolding.vim @ b44883779e1b bpollack/use-command-to-explicitly-call-ag-and-us-1442506830050

Close branch
author Steve Losh <steve@stevelosh.com>
date Thu, 17 Sep 2015 16:37:39 +0000
parents 54484a3a4dfd
children ddcca1ccfdf3
if exists('loaded_lispfolding') || &cp
    finish
endif
let loaded_lispfolding=1

" ---------------------------------------------------------------------------
"  Automagic Lisp folding on defn's and defmacro's
"
function GetLispFold()
      if getline(v:lnum) =~ '^\s*(defun.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defmacro.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defparameter.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defvar.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defclass.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*(defstruct.*\s'
            return ">1"
      elseif getline(v:lnum) =~ '^\s*$'
            let my_lispnum = v:lnum
            let my_lispmax = line("$")

            while (1)
                  let my_lispnum = my_lispnum + 1
                  if my_lispnum > my_lispmax
                        return "<1"
                  endif

                  let my_lispdata = getline(my_lispnum)

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

function TurnOnLispFolding()
      setlocal foldexpr=GetLispFold()
      setlocal foldmethod=expr
endfunction