annotate runtime/indent/pascal.vim @ 1312:b4b1b5324380 v7.1.026

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