[t] Convert some exception tests
[parrot.git] / editor / indent_pir.vim
blob87c231c387ef5d08333fd8292014b00757f3ef59
1 " Description:  PIR indenter
2 " Author:   Andrew Rodland <arodland@entermail.net>
3 " Maintainer: Jimmy Zhuo <zhuomingliang@yahoo.com.cn>
4 " Last Change: 2009 Jan 16
6 " As usual, we want to be alone
7 if exists("b:did_indent")
8     finish
9 endif
10 let b:did_indent=1
12 setlocal indentexpr=PIRIndent()
13 setlocal indentkeys=o,O,*<Return>,<bs>,:,=.end,0#
15 fun! InPOD(lnum)
16     return synIDattr(synID(a:lnum, 1, 1), "name") =~? '^myPod$\|^pod[A-Z]'
17 endfun
19 fun! PIRIndent()
20     let thisline = getline(v:lnum)
22     let POD_START = '^=[a-z]'
24     if thisline =~? POD_START
25         return 0
26     endif
29     if InPOD(v:lnum)
30         return -1
31     endif
33     let COMMENT = '^#'
34     if thisline =~? COMMENT
35         return 0
36     endif
38     let lnum=v:lnum
39     while lnum > 0
40         let lnum = prevnonblank(lnum-1)
41         let prevline = getline(lnum)
43         if prevline !~? COMMENT
44             if !InPOD(lnum)
45                 break
46             endif
47         endif
48     endwhile
50     if lnum < 1
51         return 0
52     endif
54     let ind = indent(lnum)
56     let SUB = '^\s*\.pcc_sub\s\+\|^\s*\.sub\s\+\|^\s*\.macro\s\+'
57     let RETURNBLOCK = '\s*\.begin_return\s*$'
58     let END = '^\s*\.end\s*$\|^\s*\.end_return\s*\|^\s*\.endm$'
59     let LABEL = '^\s*\k\+:'
61     if prevline =~? SUB
62         let ind = ind + &sw
63     endif
65     if prevline =~? RETURNBLOCK
66         let ind = ind + &sw
67     endif
69     if prevline =~? LABEL
70         let ind = ind + 2
71     endif
73     if thisline =~? END
74         let ind = ind - &sw
75     endif
77     if thisline =~? LABEL
78         let ind = ind - 2
79     endif
81     return ind
83 endfun