blob: 341f5f950ea270a5c2f945336b2af627eb4bf1bc [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: RPL/2
3" Version: 0.2
4" Last Change: 2002 August 16
5" Maintainer: BERTRAND Joël <rpl2@free.fr>
6
7" Only load this indent file when no other was loaded.
8if exists("b:did_indent")
9 finish
10endif
11let b:did_indent = 1
12
13setlocal indentkeys+==~end,=~case,=~if,=~then,=~else,=~do,=~until,=~while,=~repeat,=~select,=~default,=~for,=~start,=~next,=~step,<<>,<>>
14
15" Define the appropriate indent function but only once
16setlocal indentexpr=RplGetFreeIndent()
17if exists("*RplGetFreeIndent")
18 finish
19endif
20
21function RplGetIndent(lnum)
22 let ind = indent(a:lnum)
23 let prevline=getline(a:lnum)
24 " Strip tail comment
25 let prevstat=substitute(prevline, '!.*$', '', '')
26
27 " Add a shiftwidth to statements following if, iferr, then, else, elseif,
28 " case, select, default, do, until, while, repeat, for, start
29 if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>'
30 elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)'
31 elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)'
32 let ind = ind + &sw
33 endif
34
35 " Subtract a shiftwidth from then, else, elseif, end, until, repeat, next,
36 " step
37 let line = getline(v:lnum)
38 if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>'
39 let ind = ind - &sw
40 elseif line =~? '^\s*>>\($\|\s\+\)'
41 let ind = ind - &sw
42 endif
43
44 return ind
45endfunction
46
47function RplGetFreeIndent()
48 " Find the previous non-blank line
49 let lnum = prevnonblank(v:lnum - 1)
50
51 " Use zero indent at the top of the file
52 if lnum == 0
53 return 0
54 endif
55
56 let ind=RplGetIndent(lnum)
57 return ind
58endfunction
59
60" vim:sw=2 tw=130