annotate runtime/indent/ada.vim @ 22707:9ff187b1652e v8.2.1902

patch 8.2.1902: default option values changed with :badd for existing buffer Commit: https://github.com/vim/vim/commit/e974fa7b2b98e53a59d5ef16a6a1291f12a32e33 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 25 15:02:51 2020 +0100 patch 8.2.1902: default option values changed with :badd for existing buffer Problem: Default option values are changed when using :badd for an existing buffer. Solution: When calling buflist_new() pass a zero line number. (closes #7195)
author Bram Moolenaar <Bram@vim.org>
date Sun, 25 Oct 2020 15:15:03 +0100
parents 63b0b7b79b25
children 11b656e74444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
1 "------------------------------------------------------------------------------
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
2 " Description: Vim Ada indent file
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
3 " Language: Ada (2005)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1668
diff changeset
4 " $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
5 " Copyright: Copyright (C) 2006 Martin Krischik
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
6 " Maintainer: Martin Krischik <krischik@users.sourceforge.net>
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
7 " Neil Bird <neil@fnxweb.com>
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
8 " Ned Okie <nokie@radford.edu>
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1668
diff changeset
9 " $Author: krischik $
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1668
diff changeset
10 " $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
11 " Version: 4.6
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1668
diff changeset
12 " $Revision: 887 $
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
13 " $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/indent/ada.vim $
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
14 " History: 24.05.2006 MK Unified Headers
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
15 " 16.07.2006 MK Ada-Mode as vim-ball
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
16 " 15.10.2006 MK Bram's suggestion for runtime integration
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
17 " 05.11.2006 MK Bram suggested to save on spaces
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
18 " 19.09.2007 NO g: missing before ada#Comment
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
19 " Help Page: ft-vim-indent
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
20 "------------------------------------------------------------------------------
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " ToDo:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Verify handling of multi-line exprs. and recovery upon the final ';'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Correctly find comments given '"' and "" ==> " syntax.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " Combine the two large block-indent functions into one?
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
25 "------------------------------------------------------------------------------
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Only load this indent file when no other was loaded.
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
28 if exists("b:did_indent") || version < 700
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endif
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
31
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
32 let b:did_indent = 45
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 setlocal indentexpr=GetAdaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 setlocal indentkeys-=0{,0}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 setlocal indentkeys+=0=~then,0=~end,0=~elsif,0=~when,0=~exception,0=~begin,0=~is,0=~record
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " Only define the functions once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 if exists("*GetAdaIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endif
3507
8201108e9cf0 More runtime file fixes for 'compatible' mode.
Bram Moolenaar <bram@vim.org>
parents: 3496
diff changeset
42 let s:keepcpo= &cpo
8201108e9cf0 More runtime file fixes for 'compatible' mode.
Bram Moolenaar <bram@vim.org>
parents: 3496
diff changeset
43 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
45 if exists("g:ada_with_gnat_project_files")
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
46 let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|project\>\|then\>\|when\>\|is\>\)'
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
47 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
48 let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|then\>\|when\>\|is\>\)'
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
49 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
51 " Section: s:MainBlockIndent {{{1
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
52 "
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
53 " Try to find indent of the block we're in
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 " prev_indent = the previous line's indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " prev_lnum = previous line (to start looking on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " blockstart = expr. that indicates a possible start of this block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " stop_at = if non-null, if a matching line is found, gives up!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " No recursive previous block analysis: simply look for a valid line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " with a lesser or equal indent than we currently (on prev_lnum) have.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " This shouldn't work as well as it appears to with lines that are currently
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 " nowhere near the correct indent (e.g., start of line)!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " Seems to work OK as it 'starts' with the indent of the /previous/ line.
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
63 function s:MainBlockIndent (prev_indent, prev_lnum, blockstart, stop_at)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let lnum = a:prev_lnum
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
65 let line = substitute( getline(lnum), g:ada#Comment, '', '' )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 while lnum > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if a:stop_at != '' && line =~ '^\s*' . a:stop_at && indent(lnum) < a:prev_indent
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
68 return a:prev_indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 elseif line =~ '^\s*' . a:blockstart
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
70 let ind = indent(lnum)
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
71 if ind < a:prev_indent
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
72 return ind
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
73 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " Get previous non-blank/non-comment-only line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 while 1
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
79 let line = substitute( getline(lnum), g:ada#Comment, '', '' )
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
80 if line !~ '^\s*$' && line !~ '^\s*#'
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
81 break
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
82 endif
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
83 let lnum = prevnonblank(lnum - 1)
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
84 if lnum <= 0
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
85 return a:prev_indent
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
86 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " Fallback - just move back one
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
90 return a:prev_indent - shiftwidth()
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
91 endfunction MainBlockIndent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
93 " Section: s:EndBlockIndent {{{1
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
94 "
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 " Try to find indent of the block we're in (and about to complete),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " including handling of nested blocks. Works on the 'end' of a block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 " prev_indent = the previous line's indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 " prev_lnum = previous line (to start looking on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 " blockstart = expr. that indicates a possible start of this block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 " blockend = expr. that indicates a possible end of this block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 function s:EndBlockIndent( prev_indent, prev_lnum, blockstart, blockend )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 let lnum = a:prev_lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 let ends = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 while lnum > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 if getline(lnum) =~ '^\s*' . a:blockstart
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 let ind = indent(lnum)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
108 if ends <= 0
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
109 if ind < a:prev_indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 return ind
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
111 endif
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
112 else
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
113 let ends = ends - 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 elseif getline(lnum) =~ '^\s*' . a:blockend
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
116 let ends = ends + 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 " Get previous non-blank/non-comment-only line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 let line = getline(lnum)
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
123 let line = substitute( line, g:ada#Comment, '', '' )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if line !~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 if lnum <= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 return a:prev_indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 " Fallback - just move back one
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
134 return a:prev_indent - shiftwidth()
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
135 endfunction EndBlockIndent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
137 " Section: s:StatementIndent {{{1
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
138 "
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
139 " Return indent of previous statement-start
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 " (after we've indented due to multi-line statements).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 " This time, we start searching on the line *before* the one given (which is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 " the end of a statement - we want the previous beginning).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 function s:StatementIndent( current_indent, prev_lnum )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let lnum = a:prev_lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 let prev_lnum = lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 " Get previous non-blank/non-comment-only line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 while 1
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
150 let line = substitute( getline(lnum), g:ada#Comment, '', '' )
6238
47b1887483da Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3507
diff changeset
151
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
152 if line !~ '^\s*$' && line !~ '^\s*#'
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
153 break
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
154 endif
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
155 let lnum = prevnonblank(lnum - 1)
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
156 if lnum <= 0
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
157 return a:current_indent
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
158 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 " Leave indent alone if our ';' line is part of a ';'-delineated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 " aggregate (e.g., procedure args.) or first line after a block start.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 if line =~ s:AdaBlockStart || line =~ '(\s*$'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
163 return a:current_indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 if line !~ '[.=(]\s*$'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
166 let ind = indent(prev_lnum)
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
167 if ind < a:current_indent
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
168 return ind
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
169 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 " Fallback - just use current one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 return a:current_indent
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
174 endfunction StatementIndent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
177 " Section: GetAdaIndent {{{1
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
178 "
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 " Find correct indent of a new line based upon what went before
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
180 "
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 function GetAdaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 let package_line = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 " Get previous non-blank/non-comment-only/non-cpp line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 while 1
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
189 let line = substitute( getline(lnum), g:ada#Comment, '', '' )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 if line !~ '^\s*$' && line !~ '^\s*#'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
191 break
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 if lnum <= 0
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
195 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 " Get default indent (from prev. line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 let ind = indent(lnum)
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
201 let initind = ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 " Now check what's on the previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 if line =~ s:AdaBlockStart || line =~ '(\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 " Check for false matches to AdaBlockStart
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 let false_match = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 if line =~ '^\s*\(procedure\|function\|package\)\>.*\<is\s*new\>'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
208 " Generic instantiation
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
209 let false_match = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 elseif line =~ ')\s*;\s*$' || line =~ '^\([^(]*([^)]*)\)*[^(]*;\s*$'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
211 " forward declaration
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
212 let false_match = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 " Move indent in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 if ! false_match
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
216 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 elseif line =~ '^\s*\(case\|exception\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 " Move indent in twice (next 'when' will move back)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
220 let ind = ind + 2 * shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 elseif line =~ '^\s*end\s*record\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 " Move indent back to tallying 'type' preceeding the 'record'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 " Allow indent to be equal to 'end record's.
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
224 let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 " Revert to indent of line that started this parenthesis pair
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 exe lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 exe 'normal! $F)%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 if getline('.') =~ '^\s*('
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1121
diff changeset
230 " Dire layout - use previous indent (could check for g:ada#Comment here)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
231 let ind = indent( prevnonblank( line('.')-1 ) )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 else
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
233 let ind = indent('.')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 exe v:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 elseif line =~ '[.=(]\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 " A statement continuation - move in one
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
238 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 elseif line =~ '^\s*new\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 " Multiple line generic instantiation ('package blah is\nnew thingy')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
241 let ind = s:StatementIndent( ind - shiftwidth(), lnum )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 elseif line =~ ';\s*$'
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
243 " Statement end (but not 'end' ) - try to find current statement-start indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 let ind = s:StatementIndent( ind, lnum )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 " Check for potential argument list on next line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 let continuation = (line =~ '[A-Za-z0-9_]\s*$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 " Check current line; search for simplistic matching start-of-block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 let line = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 if line =~ '^\s*#'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 " Start of line for ada-pp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 let ind = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 elseif continuation && line =~ '^\s*('
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
257 " Don't do this if we've already indented due to the previous line
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
258 if ind == initind
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
259 let ind = ind + shiftwidth()
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
260 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 elseif line =~ '^\s*\(begin\|is\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 let ind = s:MainBlockIndent( ind, lnum, '\(procedure\|function\|declare\|package\|task\)\>', 'begin\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 elseif line =~ '^\s*record\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
264 let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 elseif line =~ '^\s*\(else\|elsif\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 elseif line =~ '^\s*when\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 " Align 'when' one /in/ from matching block start
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 6238
diff changeset
269 let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 elseif line =~ '^\s*end\>\s*\<if\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 " End of if statements
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 let ind = s:EndBlockIndent( ind, lnum, 'if\>', 'end\>\s*\<if\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 elseif line =~ '^\s*end\>\s*\<loop\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 " End of loops
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 let ind = s:EndBlockIndent( ind, lnum, '\(\(while\|for\)\>.*\)\?\<loop\>', 'end\>\s*\<loop\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 elseif line =~ '^\s*end\>\s*\<record\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 " End of records
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 let ind = s:EndBlockIndent( ind, lnum, '\(type\>.*\)\=\<record\>', 'end\>\s*\<record\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 elseif line =~ '^\s*end\>\s*\<procedure\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 " End of procedures
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 let ind = s:EndBlockIndent( ind, lnum, 'procedure\>.*\<is\>', 'end\>\s*\<procedure\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 elseif line =~ '^\s*end\>\s*\<case\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 " End of case statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 let ind = s:EndBlockIndent( ind, lnum, 'case\>.*\<is\>', 'end\>\s*\<case\>' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 elseif line =~ '^\s*end\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 " General case for end
36
125e80798a85 updated for version 7.0021
vimboss
parents: 7
diff changeset
287 let ind = s:MainBlockIndent( ind, lnum, '\(if\|while\|for\|loop\|accept\|begin\|record\|case\|exception\|package\)\>', '' )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 elseif line =~ '^\s*exception\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 let ind = s:MainBlockIndent( ind, lnum, 'begin\>', '' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 elseif line =~ '^\s*then\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 return ind
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
295 endfunction GetAdaIndent
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
296
3496
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
297 let &cpo = s:keepcpo
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
298 unlet s:keepcpo
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
299
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
300 finish " 1}}}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
302 "------------------------------------------------------------------------------
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
303 " Copyright (C) 2006 Martin Krischik
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
304 "
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
305 " Vim is Charityware - see ":help license" or uganda.txt for licence details.
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
306 "------------------------------------------------------------------------------
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
307 " vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
308 " vim: foldmethod=marker