4 " Last Change: 2003 Feb 04
5 " Maintainer: Brent A. Fulgham <bfulgham@debian.org>
7 " Only load this indent file when no other was loaded.
8 if exists("b:did_indent")
13 setlocal indentkeys+==~begin,=~block,=~case,=~cleanup,=~define,=~end,=~else,=~elseif,=~exception,=~for,=~finally,=~if,=~otherwise,=~select,=~unless,=~while
15 " Define the appropriate indent function but only once
16 setlocal indentexpr=DylanGetIndent()
17 if exists("*DylanGetIndent")
21 function DylanGetIndent()
22 " Get the line to be indented
23 let cline = getline(v:lnum)
25 " Don't reindent comments on first column
26 if cline =~ '^/\[/\*]'
30 "Find the previous non-blank line
31 let lnum = prevnonblank(v:lnum - 1)
32 "Use zero indent at the top of the file
37 let prevline=getline(lnum)
38 let ind = indent(lnum)
41 " If previous line was a comment, use its indent
42 if prevline =~ '^\s*//'
46 " If previous line was a 'define', indent
47 if prevline =~? '\(^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)\|\s*\S*\s*=>$\)'
49 " local methods indent the shift-width, plus 6 for the 'local'
50 elseif prevline =~? '^\s*local'
52 " If previous line was a let with no closing semicolon, indent
53 elseif prevline =~? '^\s*let.*[^;]\s*$'
55 " If previous line opened a parenthesis, and did not close it, indent
56 elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
57 return = match( prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
58 "elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
59 elseif prevline =~ '^[^(]*)\s*$'
60 " This line closes a parenthesis. Find opening
61 let curr_line = prevnonblank(lnum - 1)
63 let str = getline(curr_line)
64 if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
65 let curr_line = prevnonblank(curr_line - 1)
73 let ind = indent(curr_line)
74 " Although we found the closing parenthesis, make sure this
75 " line doesn't start with an indentable command:
76 let curr_str = getline(curr_line)
77 if curr_str =~? '^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)'
82 " If a line starts with end, un-indent (even if we just indented!)
83 if cline =~? '^\s*\(cleanup\|end\|else\|elseif\|exception\|finally\|otherwise\)'