annotate runtime/indent/dylan.vim @ 1969:2e915ea7110f v7.2.266

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