annotate runtime/indent/dylan.vim @ 0:76efa0be13f1

Initial revision
author atsuki
date Sat, 10 Nov 2007 15:07:22 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
1 " Vim indent file
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
2 " Language: Dylan
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
3 " Version: 0.01
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
4 " Last Change: 2003 Feb 04
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
5 " Maintainer: Brent A. Fulgham <bfulgham@debian.org>
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
6
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
8 if exists("b:did_indent")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
9 finish
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
10 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
11 let b:did_indent = 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
12
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
13 setlocal indentkeys+==~begin,=~block,=~case,=~cleanup,=~define,=~end,=~else,=~elseif,=~exception,=~for,=~finally,=~if,=~otherwise,=~select,=~unless,=~while
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
14
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
15 " Define the appropriate indent function but only once
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
16 setlocal indentexpr=DylanGetIndent()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
17 if exists("*DylanGetIndent")
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
18 finish
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
19 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
20
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
21 function DylanGetIndent()
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
22 " Get the line to be indented
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
23 let cline = getline(v:lnum)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
24
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
25 " Don't reindent comments on first column
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
26 if cline =~ '^/\[/\*]'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
27 return 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
28 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
29
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
30 "Find the previous non-blank line
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
31 let lnum = prevnonblank(v:lnum - 1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
32 "Use zero indent at the top of the file
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
33 if lnum == 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
34 return 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
35 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
36
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
37 let prevline=getline(lnum)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
38 let ind = indent(lnum)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
39 let chg = 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
40
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
41 " If previous line was a comment, use its indent
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
42 if prevline =~ '^\s*//'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
43 return ind
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
44 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
45
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
46 " If previous line was a 'define', indent
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
47 if prevline =~? '\(^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)\|\s*\S*\s*=>$\)'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
48 let chg = &sw
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
49 " local methods indent the shift-width, plus 6 for the 'local'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
50 elseif prevline =~? '^\s*local'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
51 let chg = &sw + 6
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
52 " If previous line was a let with no closing semicolon, indent
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
53 elseif prevline =~? '^\s*let.*[^;]\s*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
54 let chg = &sw
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
55 " If previous line opened a parenthesis, and did not close it, indent
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
56 elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
57 return = match( prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
58 "elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
59 elseif prevline =~ '^[^(]*)\s*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
60 " This line closes a parenthesis. Find opening
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
61 let curr_line = prevnonblank(lnum - 1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
62 while curr_line >= 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
63 let str = getline(curr_line)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
64 if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
65 let curr_line = prevnonblank(curr_line - 1)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
66 else
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
67 break
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
68 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
69 endwhile
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
70 if curr_line < 0
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
71 return -1
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
72 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
73 let ind = indent(curr_line)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
74 " Although we found the closing parenthesis, make sure this
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
75 " line doesn't start with an indentable command:
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
76 let curr_str = getline(curr_line)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
77 if curr_str =~? '^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
78 let chg = &sw
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
79 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
80 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
81
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
82 " If a line starts with end, un-indent (even if we just indented!)
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
83 if cline =~? '^\s*\(cleanup\|end\|else\|elseif\|exception\|finally\|otherwise\)'
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
84 let chg = chg - &sw
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
85 endif
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
86
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
87 return ind + chg
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
88 endfunction
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
89
76efa0be13f1 Initial revision
atsuki
parents:
diff changeset
90 " vim:sw=2 tw=130