annotate runtime/indent/pascal.vim @ 349:028158b1362b v7.0090

updated for version 7.0090
author vimboss
date Wed, 22 Jun 2005 22:37:09 +0000
parents 18f024844150
children 289b19a6f2ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
333
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
1 " Vim indent file
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
2 " Language: Pascal
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
3 " Maintainer: Neil Carter <n.carter@swansea.ac.uk>
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
4 " Created: 2004 Jul 13
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
5 " Last Change: 2005 Jun 15
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
6
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
7
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
8 if exists("b:did_indent")
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
9 finish
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
10 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
11 let b:did_indent = 1
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
12
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
13 setlocal indentexpr=GetPascalIndent(v:lnum)
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
14 setlocal indentkeys&
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
15 setlocal indentkeys+==end;,==const,==type,==var,==begin,==repeat,==until,==for
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
16 setlocal indentkeys+==program,==function,==procedure,==object,==private
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
17 setlocal indentkeys+==record,==if,==else,==case
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
18
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
19 if exists("*GetPascalIndent")
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
20 finish
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
21 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
22
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
23
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
24 function! s:GetPrevNonCommentLineNum( line_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
25
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
26 " Skip lines starting with a comment
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
27 let SKIP_LINES = '^\s*\(\((\*\)\|\(\*\ \)\|\(\*)\)\|{\|}\)'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
28
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
29 let nline = a:line_num
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
30 while nline > 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
31 let nline = prevnonblank(nline-1)
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
32 if getline(nline) !~? SKIP_LINES
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
33 break
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
34 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
35 endwhile
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
36
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
37 return nline
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
38 endfunction
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
39
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
40
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
41 function! GetPascalIndent( line_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
42 " Line 0 always goes at column 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
43 if a:line_num == 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
44 return 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
45 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
46
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
47 let this_codeline = getline( a:line_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
48
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
49 " If in the middle of a three-part comment
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
50 if this_codeline =~ '^\s*\*'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
51 return indent( a:line_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
52 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
53
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
54 let prev_codeline_num = s:GetPrevNonCommentLineNum( a:line_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
55 let prev_codeline = getline( prev_codeline_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
56 let indnt = indent( prev_codeline_num )
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
57
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
58 " Compiler directives should always go in column zero.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
59 if this_codeline =~ '^\s*{\(\$IFDEF\|\$ELSE\|\$ENDIF\)'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
60 return 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
61 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
62
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
63 " These items have nothing before or after (not even a comment), and
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
64 " go on column 0. Make sure that the ^\s* is followed by \( to make
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
65 " ORs work properly, and not include the start of line (this must
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
66 " always appear).
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
67 " The bracketed expression with the underline is a routine
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
68 " separator. This is one case where we do indent comment lines.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
69 if this_codeline =~ '^\s*\((\*\ _\+\ \*)\|\<\(const\|var\)\>\)$'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
70 return 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
71 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
72
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
73 " These items may have text after them, and go on column 0 (in most
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
74 " cases). The problem is that "function" and "procedure" keywords
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
75 " should be indented if within a class declaration.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
76 if this_codeline =~ '^\s*\<\(program\|type\|uses\|procedure\|function\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
77 return 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
78 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
79
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
80 " BEGIN
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
81 " If the begin does not come after "if", "for", or "else", then it
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
82 " goes in column 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
83 if this_codeline =~ '^\s*begin\>' && prev_codeline !~ '^\s*\<\(if\|for\|else\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
84 return 0
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
85 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
86
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
87 " These keywords are indented once only.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
88 if this_codeline =~ '^\s*\<\(private\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
89 return &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
90 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
91
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
92 " If the PREVIOUS LINE contained these items, the current line is
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
93 " always indented once.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
94 if prev_codeline =~ '^\s*\<\(type\|uses\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
95 return &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
96 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
97
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
98 " These keywords are indented once only. Possibly surrounded by
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
99 " other chars.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
100 if this_codeline =~ '^.\+\<\(object\|record\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
101 return &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
102 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
103
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
104 " If the previous line was indenting...
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
105 if prev_codeline =~ '^\s*\<\(for\|if\|case\|else\|end\ else\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
106 " then indent.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
107 let indnt = indnt + &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
108 " BUT... if this is the start of a multistatement block then we
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
109 " need to align the begin with the previous line.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
110 if this_codeline =~ '^\s*begin\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
111 return indnt - &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
112 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
113
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
114 " We also need to keep the indentation level constant if the
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
115 " whole if-then statement was on one line.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
116 if prev_codeline =~ '\<then\>.\+'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
117 let indnt = indnt - &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
118 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
119 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
120
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
121 " PREVIOUS-LINE BEGIN
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
122 " If the previous line was an indenting keyword then indent once...
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
123 if prev_codeline =~ '^\s*\<\(const\|var\|begin\|repeat\|private\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
124 " But only if this is another var in a list.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
125 if this_codeline !~ '^\s*var\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
126 return indnt + &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
127 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
128 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
129
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
130 " PREVIOUS-LINE BEGIN
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
131 " Indent code after a case statement begin
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
132 if prev_codeline =~ '\:\ begin\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
133 return indnt + &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
134 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
135
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
136 " These words may have text before them on the line (hence the .*)
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
137 " but are followed by nothing. Always indent once only.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
138 if prev_codeline =~ '^\(.*\|\s*\)\<\(object\|record\)\>$'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
139 return indnt + &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
140 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
141
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
142 " If we just closed a bracket that started on a previous line, then
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
143 " unindent. But don't return yet -- we need to check for further
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
144 " unindentation (for end/until/else)
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
145 if prev_codeline =~ '^[^(]*[^*])'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
146 let indnt = indnt - &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
147 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
148
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
149 " At the end of a block, we have to unindent both the current line
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
150 " (the "end" for instance) and the newly-created line.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
151 if this_codeline =~ '^\s*\<\(end\|until\|else\)\>'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
152 return indnt - &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
153 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
154
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
155 " If we have opened a bracket and it continues over one line,
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
156 " then indent once.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
157 "
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
158 " RE = an opening bracket followed by any amount of anything other
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
159 " than a closing bracket and then the end-of-line.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
160 "
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
161 " If we didn't include the end of line, this RE would match even
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
162 " closed brackets, since it would match everything up to the closing
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
163 " bracket.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
164 "
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
165 " This test isn't clever enough to handle brackets inside strings or
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
166 " comments.
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
167 if prev_codeline =~ '([^*]\=[^)]*$'
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
168 return indnt + &shiftwidth
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
169 endif
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
170
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
171 return indnt
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
172 endfunction
18f024844150 updated for version 7.0086
vimboss
parents: 315
diff changeset
173