vim/ftplugin/lisp/lispfolding.vim @ 0ab8b4c9ac2a

Update subrepository state.
author Steve Losh <steve@stevelosh.com>
date Sun, 10 Apr 2016 21:54:52 +0000
parents 70a831232f0f
children f13a2b1ddedf
if exists('loaded_lispfolding') || &cp
    finish
endif
let loaded_lispfolding=1

" ---------------------------------------------------------------------------
"  Automagic Lisp folding on defn's and defmacro's
"

function! GetLispFold()
    let inline_fn_comment_re = '\v^ *;;( .*)?$'

    if getline(v:lnum) =~ '^;;;; '
        return "0"
    elseif getline(v:lnum) =~ '^;;; '
        return "1"
    elseif getline(v:lnum) =~ inline_fn_comment_re
        if getline(v:lnum + 1) =~ inline_fn_comment_re
            return "2"
        else
            return "<2"
        endif
    elseif getline(v:lnum) =~ '^; '
        return "0"
    elseif getline(v:lnum) =~ '^(let[*]? '
        " let over lambda
        return ">1"
    elseif getline(v:lnum) =~ '^(test '
        return ">1"
    elseif getline(v:lnum) =~ '^(def\S\+ '
        " fuck it just fold everything that looks kinda deffy
        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