7
|
1 " Vim indent file
|
|
2 " Language: Dylan
|
|
3 " Version: 0.01
|
|
4 " Last Change: 2003 Feb 04
|
|
5 " Maintainer: Brent A. Fulgham <bfulgham@debian.org>
|
|
6
|
|
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
|
|
12
|
|
13 setlocal indentkeys+==~begin,=~block,=~case,=~cleanup,=~define,=~end,=~else,=~elseif,=~exception,=~for,=~finally,=~if,=~otherwise,=~select,=~unless,=~while
|
|
14
|
|
15 " Define the appropriate indent function but only once
|
|
16 setlocal indentexpr=DylanGetIndent()
|
|
17 if exists("*DylanGetIndent")
|
|
18 finish
|
|
19 endif
|
|
20
|
|
21 function DylanGetIndent()
|
|
22 " Get the line to be indented
|
|
23 let cline = getline(v:lnum)
|
|
24
|
|
25 " Don't reindent comments on first column
|
|
26 if cline =~ '^/\[/\*]'
|
|
27 return 0
|
|
28 endif
|
|
29
|
|
30 "Find the previous non-blank line
|
|
31 let lnum = prevnonblank(v:lnum - 1)
|
|
32 "Use zero indent at the top of the file
|
|
33 if lnum == 0
|
|
34 return 0
|
|
35 endif
|
|
36
|
|
37 let prevline=getline(lnum)
|
|
38 let ind = indent(lnum)
|
|
39 let chg = 0
|
|
40
|
|
41 " If previous line was a comment, use its indent
|
|
42 if prevline =~ '^\s*//'
|
|
43 return ind
|
|
44 endif
|
|
45
|
|
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*=>$\)'
|
|
48 let chg = &sw
|
|
49 " local methods indent the shift-width, plus 6 for the 'local'
|
|
50 elseif prevline =~? '^\s*local'
|
|
51 let chg = &sw + 6
|
|
52 " If previous line was a let with no closing semicolon, indent
|
|
53 elseif prevline =~? '^\s*let.*[^;]\s*$'
|
|
54 let chg = &sw
|
|
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)
|
|
62 while curr_line >= 0
|
|
63 let str = getline(curr_line)
|
|
64 if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
|
|
65 let curr_line = prevnonblank(curr_line - 1)
|
|
66 else
|
|
67 break
|
|
68 endif
|
|
69 endwhile
|
|
70 if curr_line < 0
|
|
71 return -1
|
|
72 endif
|
|
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\)'
|
|
78 let chg = &sw
|
|
79 endif
|
|
80 endif
|
|
81
|
|
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\)'
|
|
84 let chg = chg - &sw
|
|
85 endif
|
|
86
|
|
87 return ind + chg
|
|
88 endfunction
|
|
89
|
|
90 " vim:sw=2 tw=130
|