* docs/pmc.pod:
[parrot.git] / editor / indent_pir.vim
blob29dd9f6be3eb39667902de3308bbc5643a0f544a
1 " Description:  imcc indenter
2 " Author:       Andrew Rodland <arodland@entermail.net>
3 " Last Change: 2004 Aug 3
5 " As usual, we want to be alone
6 if exists("b:did_indent")
7         finish
8 endif
9 let b:did_indent=1
11 setlocal indentexpr=PIRIndent()
12 setlocal indentkeys=o,O,*<Return>,<bs>,:,=.end,0#
14 fun! InPOD(lnum)
15         return synIDattr(synID(a:lnum, 1, 1), "name") =~? '^myPod$\|^pod[A-Z]'
16 endfun
18 fun! PIRIndent()
19         let thisline = getline(v:lnum)
21         let POD_START = '^=[a-z]'
23         if thisline =~? POD_START
24                 return 0
25         endif
27         
28         if InPOD(v:lnum)
29                 return -1
30         endif
32         let LABEL_OR_COMMENT = '^\s*\k\+:\s*$\|^#'
33         if thisline =~? LABEL_OR_COMMENT
34                 return 0
35         endif
37         let lnum=v:lnum
38         while lnum > 0
39                 let lnum = prevnonblank(lnum-1)
40                 let prevline = getline(lnum)
41                 
42                 if prevline !~? LABEL_OR_COMMENT
43                         if !InPOD(lnum)
44                                 break
45                         endif
46                 endif
47         endwhile
49         if lnum < 1
50                 return 0
51         endif
53         let ind = indent(lnum)
54         
55         let SUB = '^\s*\.pcc_sub\s\+\|^\s*\.sub\s\+'
56         let RETURNBLOCK = '\s*\.pcc_begin_return\s*$'
57         let END = '^\s*\.end\s*$\|^\s*\.pcc_end_return\s*$'
59         if prevline =~? SUB
60                 let ind = ind + &sw
61         endif
63         if prevline =~? RETURNBLOCK
64                 let ind = ind + &sw
65         endif
67         if thisline =~? END
68                 let ind = ind - &sw
69         endif
71         return ind
73 endfun