Merge branch 'MacVim'
[MacVim/KaoriYa.git] / runtime / indent / hamster.vim
blob93e7db486eee10ea4d277fd627c11aa5d0ccb442
1 " Vim indent file
2 " Language:    Hamster Script 
3 " Version:     2.0.6.0
4 " Last Change: Wed Nov 08 2006 12:02:42 PM
5 " Maintainer:  David Fishburn <fishburn@ianywhere.com>
7 " Only load this indent file when no other was loaded.
8 if exists("b:did_indent")
9   finish
10 endif
11 let b:did_indent = 1
13 setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
14 setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
15 setlocal indentkeys+==~sub,=~endsub
17 " Define the appropriate indent function but only once
18 setlocal indentexpr=HamGetFreeIndent()
19 if exists("*HamGetFreeIndent")
20   finish
21 endif
23 function HamGetIndent(lnum)
24   let ind = indent(a:lnum)
25   let prevline=getline(a:lnum)
27   " Add a shiftwidth to statements following if,  else, elseif,
28   " case, select, default, do, until, while, for, start
29   if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>' 
30     let ind = ind + &sw
31   endif
33   " Subtract a shiftwidth from else, elseif, end(if|while|for), until
34   let line = getline(v:lnum)
35   if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
36     let ind = ind - &sw
37   endif
39   return ind
40 endfunction
42 function HamGetFreeIndent()
43   " Find the previous non-blank line
44   let lnum = prevnonblank(v:lnum - 1)
46   " Use zero indent at the top of the file
47   if lnum == 0
48     return 0
49   endif
51   let ind=HamGetIndent(lnum)
52   return ind
53 endfunction
55 " vim:sw=2 tw=80