Skip to content
This repository
tag: RELEASE_4_2_0
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (62 sloc) 1.583 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
" Description: PIR indenter
" Author: Andrew Rodland <arodland@entermail.net>
" Maintainer: Jimmy Zhuo <zhuomingliang@yahoo.com.cn>
" Last Change: 2009 Jan 16

" As usual, we want to be alone
if exists("b:did_indent")
    finish
endif
let b:did_indent=1

setlocal indentexpr=PIRIndent()
setlocal indentkeys=o,O,*<Return>,<bs>,:,=.end,0#

fun! InPOD(lnum)
    return synIDattr(synID(a:lnum, 1, 1), "name") =~? '^myPod$\|^pod[A-Z]'
endfun

fun! PIRIndent()
    let thisline = getline(v:lnum)

    let POD_START = '^=[a-z]'

    if thisline =~? POD_START
        return 0
    endif


    if InPOD(v:lnum)
        return -1
    endif

    let COMMENT = '^#'
    if thisline =~? COMMENT
        return 0
    endif

    let lnum=v:lnum
    while lnum > 0
        let lnum = prevnonblank(lnum-1)
        let prevline = getline(lnum)

        if prevline !~? COMMENT
            if !InPOD(lnum)
                break
            endif
        endif
    endwhile

    if lnum < 1
        return 0
    endif

    let ind = indent(lnum)

    let SUB = '^\s*\.pcc_sub\s\+\|^\s*\.sub\s\+\|^\s*\.macro\s\+'
    let RETURNBLOCK = '\s*\.begin_return\s*$'
    let END = '^\s*\.end\s*$\|^\s*\.end_return\s*\|^\s*\.endm$'
    let LABEL = '^\s*\k\+:'

    if prevline =~? SUB
        let ind = ind + &sw
    endif

    if prevline =~? RETURNBLOCK
        let ind = ind + &sw
    endif

    if prevline =~? LABEL
        let ind = ind + 2
    endif

    if thisline =~? END
        let ind = ind - &sw
    endif

    if thisline =~? LABEL
        let ind = ind - 2
    endif

    return ind

endfun
Something went wrong with that request. Please try again.