comparison lisp/modes/ada-mode.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 28f395d8dc7a
children
comparison
equal deleted inserted replaced
188:e29a8e7498d9 189:489f57a838ef
1 ;;; ada-mode.el --- An Emacs major-mode for editing Ada source. 1 ;;; ada-mode.el --- An Emacs major-mode for editing Ada source.
2 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. 2
3 3 ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
4 ;;; Authors: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> 4
5 ;;; Rolf Ebert <ebert@inf.enst.fr> 5 ;; Authors: Rolf Ebert <ebert@inf.enst.fr>
6 6 ;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
7 ;;; This file is part of XEmacs. 7 ;; Keywords: languages oop ada
8 8 ;; Rolf Ebert's version: 2.27
9 ;; XEmacs is free software; you can redistribute it and/or modify it 9
10 ;; under the terms of the GNU General Public License as published by 10 ;; This file is part of XEmacs
11
12 ;; XEmacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option) 14 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version. 15 ;; any later version.
13 16
14 ;; XEmacs is distributed in the hope that it will be useful, but 17 ;; XEmacs is distributed in the hope that it will be useful,
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; General Public License for more details. 20 ;; GNU General Public License for more details.
18 21
19 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free 23 ;; along with XEmacs; see the file COPYING. If not, write to the
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
23 26
24 ;;; This mode is a complete rewrite of a major mode for editing Ada 83 27 ;;; This mode is a complete rewrite of a major mode for editing Ada 83
25 ;;; and Ada 95 source code under Emacs-19. It contains completely new 28 ;;; and Ada 95 source code under Emacs-19. It contains completely new
26 ;;; indenting code and support for code browsing (see ada-xref). 29 ;;; indenting code and support for code browsing (see ada-xref).
27 30
28 ;;; Synched up with: FSF 19.34. 31 ;;; Synched up with: FSF 20.1
29 32
30 ;;; USAGE 33 ;;; USAGE
31 ;;; ===== 34 ;;; =====
32 ;;; Emacs should enter ada-mode when you load an ada source (*.ad[abs]). 35 ;;; Emacs should enter Ada mode when you load an Ada source (*.ad[abs]).
33 ;;; 36 ;;;
34 ;;; When you have entered ada-mode, you may get more info by pressing 37 ;;; When you have entered ada-mode, you may get more info by pressing
35 ;;; C-h m. You may also get online help describing various functions by: 38 ;;; C-h m. You may also get online help describing various functions by:
36 ;;; C-h d <Name of function you want described> 39 ;;; C-h d <Name of function you want described>
37 40
51 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the 54 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
52 ;;; Gosling Emacs. L. Slater based his development on ada.el and 55 ;;; Gosling Emacs. L. Slater based his development on ada.el and
53 ;;; electric-ada.el. 56 ;;; electric-ada.el.
54 ;;; 57 ;;;
55 ;;; The current Ada mode is a complete rewrite by M. Heritsch and 58 ;;; The current Ada mode is a complete rewrite by M. Heritsch and
56 ;;; R. Ebert. Some ideas from the ada-mode mailing list have been 59 ;;; R. Ebert. Some ideas from the Ada mode mailing list have been
57 ;;; added. Some of the functionality of L. Slater's mode has not 60 ;;; added. Some of the functionality of L. Slater's mode has not
58 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking 61 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
59 ;;; to his version. 62 ;;; to his version.
60 63
61 64
63 ;;; ========== 66 ;;; ==========
64 ;;; 67 ;;;
65 ;;; In the presence of comments and/or incorrect syntax 68 ;;; In the presence of comments and/or incorrect syntax
66 ;;; ada-format-paramlist produces weird results. 69 ;;; ada-format-paramlist produces weird results.
67 ;;; ------------------- 70 ;;; -------------------
68 ;;; Indenting of some tasking constructs is still buggy. 71 ;;; Character constants with otherwise syntactic relevant characters
72 ;;; like `(' or `"' throw indentation off the track. Fontification
73 ;;; should work now in Emacs-19.35
74 ;;; C : constant Character := Character'('"');
69 ;;; ------------------- 75 ;;; -------------------
70 ;;; package Test is 76
71 ;;; -- If I hit return on the "type" line it will indent the next line 77
72 ;;; -- in another 3 space instead of heading out to the "(". If I hit 78 ;;; TODO
73 ;;; -- tab or return it reindents the line correctly but does not initially. 79 ;;; ====
74 ;;; type Wait_Return is (Read_Success, Read_Timeout, Wait_Timeout, 80 ;;;
75 ;;; Nothing_To_Wait_For_In_Wait_List); 81 ;;; o bodify-single-subprogram
76 ;;; ------------------- 82 ;;; o make a function "separate" and put it in the corresponding file.
77 83
78 84
79 85
80 ;;; CREDITS 86 ;;; CREDITS
81 ;;; ======= 87 ;;; =======
90 96
91 ;;;-------------------- 97 ;;;--------------------
92 ;;; USER OPTIONS 98 ;;; USER OPTIONS
93 ;;;-------------------- 99 ;;;--------------------
94 100
101
102 ;; ---- customize support
103
104 (defgroup ada nil
105 "Major mode for editing Ada source in Emacs"
106 :group 'languages)
107
95 ;; ---- configure indentation 108 ;; ---- configure indentation
96 109
97 (defvar ada-indent 3 110 (defcustom ada-indent 3
98 "*Defines the size of Ada indentation.") 111 "*Defines the size of Ada indentation."
99 112 :type 'integer
100 (defvar ada-broken-indent 2 113 :group 'ada)
101 "*# of columns to indent the continuation of a broken line.") 114
102 115 (defcustom ada-broken-indent 2
103 (defvar ada-label-indent -4 116 "*# of columns to indent the continuation of a broken line."
104 "*# of columns to indent a label.") 117 :type 'integer
105 118 :group 'ada)
106 (defvar ada-stmt-end-indent 0 119
120 (defcustom ada-label-indent -4
121 "*# of columns to indent a label."
122 :type 'integer
123 :group 'ada)
124
125 (defcustom ada-stmt-end-indent 0
107 "*# of columns to indent a statement end keyword in a separate line. 126 "*# of columns to indent a statement end keyword in a separate line.
108 Examples are 'is', 'loop', 'record', ...") 127 Examples are 'is', 'loop', 'record', ..."
109 128 :type 'integer
110 (defvar ada-when-indent 3 129 :group 'ada)
111 "*Defines the indentation for 'when' relative to 'exception' or 'case'.") 130
112 131 (defcustom ada-when-indent 3
113 (defvar ada-indent-record-rel-type 3 132 "*Defines the indentation for 'when' relative to 'exception' or 'case'."
114 "*Defines the indentation for 'record' relative to 'type' or 'use'.") 133 :type 'integer
115 134 :group 'ada)
116 (defvar ada-indent-comment-as-code t 135
117 "*If non-nil, comment-lines get indented as Ada code.") 136 (defcustom ada-indent-record-rel-type 3
118 137 "*Defines the indentation for 'record' relative to 'type' or 'use'."
119 (defvar ada-indent-is-separate t 138 :type 'integer
120 "*If non-nil, 'is separate' or 'is abstract' on a single line are indented.") 139 :group 'ada)
121 140
122 (defvar ada-indent-to-open-paren t 141 (defcustom ada-indent-comment-as-code t
123 "*If non-nil, indent according to the innermost open parenthesis.") 142 "*If non-nil, comment-lines get indented as Ada code."
124 143 :type 'boolean
125 (defvar ada-search-paren-char-count-limit 3000 144 :group 'ada)
126 "*Search that many characters for an open parenthesis.") 145
146 (defcustom ada-indent-is-separate t
147 "*If non-nil, 'is separate' or 'is abstract' on a single line are indented."
148 :type 'boolean
149 :group 'ada)
150
151 (defcustom ada-indent-to-open-paren t
152 "*If non-nil, indent according to the innermost open parenthesis."
153 :type 'boolean
154 :group 'ada)
155
156 (defcustom ada-search-paren-char-count-limit 3000
157 "*Search that many characters for an open parenthesis."
158 :type 'integer
159 :group 'ada)
127 160
128 161
129 ;; ---- other user options 162 ;; ---- other user options
130 163
131 (defvar ada-tab-policy 'indent-auto 164 (defcustom ada-tab-policy 'indent-auto
132 "*Control behaviour of the TAB key. 165 "*Control behaviour of the TAB key.
133 Must be one of `indent-rigidly', `indent-auto', `gei', `indent-af' 166 Must be one of `indent-rigidly', `indent-auto', `gei', `indent-af'
134 or `always-tab'. 167 or `always-tab'.
135 168
136 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line. 169 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line.
137 `indent-auto' : use indentation functions in this file. 170 `indent-auto' : use indentation functions in this file.
138 `gei' : use David Kågedal's Generic Indentation Engine. 171 `gei' : use David Kågedal's Generic Indentation Engine.
139 `indent-af' : use Gary E. Barnes' ada-format.el 172 `indent-af' : use Gary E. Barnes' ada-format.el
140 `always-tab' : do indent-relative.") 173 `always-tab' : do indent-relative."
141 174 :type '(choice (const indent-auto)
142 (defvar ada-move-to-declaration nil 175 (const indent-rigidly)
176 (const gei)
177 (const indent-af)
178 (const always-tab))
179 :group 'ada)
180
181 (defcustom ada-move-to-declaration nil
143 "*If non-nil, `ada-move-to-start' moves point to the subprog declaration, 182 "*If non-nil, `ada-move-to-start' moves point to the subprog declaration,
144 not to 'begin'.") 183 not to 'begin'."
145 184 :type 'boolean
146 (defvar ada-spec-suffix ".ads" 185 :group 'ada)
147 "*Suffix of Ada specification files.") 186
148 187 (defcustom ada-spec-suffix ".ads"
149 (defvar ada-body-suffix ".adb" 188 "*Suffix of Ada specification files."
150 "*Suffix of Ada body files.") 189 :type 'string
151 190 :group 'ada)
152 (defvar ada-language-version 'ada95 191
153 "*Do we program in `ada83' or `ada95'?") 192 (defcustom ada-body-suffix ".adb"
154 193 "*Suffix of Ada body files."
155 (defvar ada-case-keyword 'downcase-word 194 :type 'string
195 :group 'ada)
196
197 (defcustom ada-spec-suffix-as-regexp "\\.ads$"
198 "*Regexp to find Ada specification files."
199 :type 'string
200 :group 'ada)
201
202 (defcustom ada-body-suffix-as-regexp "\\.adb$"
203 "*Regexp to find Ada body files."
204 :type 'string
205 :group 'ada)
206
207 (defvar ada-other-file-alist
208 (list
209 (list ada-spec-suffix-as-regexp (list ada-body-suffix))
210 (list ada-body-suffix-as-regexp (list ada-spec-suffix))
211 )
212 "*Alist of extensions to find given the current file's extension.
213
214 This list should contain the most used extensions before the others,
215 since the search algorithm searches sequentially through each directory
216 specified in `ada-search-directories'. If a file is not found, a new one
217 is created with the first matching extension (`.adb' yields `.ads').")
218
219 (defcustom ada-search-directories
220 '("." "/usr/adainclude" "/usr/local/adainclude" "/opt/gnu/adainclude")
221 "*List of directories to search for Ada files.
222 See the description for the `ff-search-directories' variable."
223 :type '(repeat (choice :tag "Directory"
224 (const :tag "default" nil)
225 (directory :format "%v")))
226 :group 'ada)
227
228 (defcustom ada-language-version 'ada95
229 "*Do we program in `ada83' or `ada95'?"
230 :type '(choice (const ada83)
231 (const ada95))
232 :group 'ada)
233
234 (defcustom ada-case-keyword 'downcase-word
156 "*Function to call to adjust the case of Ada keywords. 235 "*Function to call to adjust the case of Ada keywords.
157 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or 236 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
158 `capitalize-word'.") 237 `capitalize-word'."
159 238 :type '(choice (const downcase-word)
160 (defvar ada-case-identifier 'ada-loose-case-word 239 (const upcase-word)
240 (const capitalize-word)
241 (const ada-loose-case-word))
242 :group 'ada)
243
244 (defcustom ada-case-identifier 'ada-loose-case-word
161 "*Function to call to adjust the case of an Ada identifier. 245 "*Function to call to adjust the case of an Ada identifier.
162 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or 246 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
163 `capitalize-word'.") 247 `capitalize-word'."
164 248 :type '(choice (const downcase-word)
165 (defvar ada-case-attribute 'capitalize-word 249 (const upcase-word)
250 (const capitalize-word)
251 (const ada-loose-case-word))
252 :group 'ada)
253
254 (defcustom ada-case-attribute 'capitalize-word
166 "*Function to call to adjust the case of Ada attributes. 255 "*Function to call to adjust the case of Ada attributes.
167 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or 256 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
168 `capitalize-word'.") 257 `capitalize-word'."
169 258 :type '(choice (const downcase-word)
170 (defvar ada-auto-case t 259 (const upcase-word)
260 (const capitalize-word)
261 (const ada-loose-case-word))
262 :group 'ada)
263
264 (defcustom ada-auto-case t
171 "*Non-nil automatically changes case of preceding word while typing. 265 "*Non-nil automatically changes case of preceding word while typing.
172 Casing is done according to `ada-case-keyword', `ada-case-identifier' 266 Casing is done according to `ada-case-keyword', `ada-case-identifier'
173 and `ada-cacse-attribute'.") 267 and `ada-case-attribute'."
174 268 :type 'boolean
175 (defvar ada-clean-buffer-before-saving nil 269 :group 'ada)
176 "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.") 270
271 (defcustom ada-clean-buffer-before-saving t
272 "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving."
273 :type 'boolean
274 :group 'ada)
177 275
178 (defvar ada-mode-hook nil 276 (defvar ada-mode-hook nil
179 "*List of functions to call when Ada Mode is invoked. 277 "*List of functions to call when Ada mode is invoked.
180 This is a good place to add Ada environment specific bindings.") 278 This is a good place to add Ada environment specific bindings.")
181 279
182 (defvar ada-external-pretty-print-program "aimap" 280 (defcustom ada-external-pretty-print-program "aimap"
183 "*External pretty printer to call from within Ada Mode.") 281 "*External pretty printer to call from within Ada mode."
184 282 :type 'string
185 (defvar ada-tmp-directory "/tmp/" 283 :group 'ada)
186 "*Directory to store the temporary file for the Ada pretty printer.") 284
187 285 (defcustom ada-tmp-directory "/tmp/"
188 (defvar ada-fill-comment-prefix "-- " 286 "*Directory to store the temporary file for the Ada pretty printer."
189 "*This is inserted in the first columns when filling a comment paragraph.") 287 :type 'string
190 288 :group 'ada)
191 (defvar ada-fill-comment-postfix " --" 289
192 "*This is inserted at the end of each line when filling a comment paragraph 290 (defcustom ada-compile-options "-c"
193 with `ada-fill-comment-paragraph-postfix'.") 291 "*Buffer local options passed to the Ada compiler.
194 292 These options are used when the compiler is invoked on the current buffer."
195 (defvar ada-krunch-args "0" 293 :type 'string
196 "*Argument of gnatk8, a string containing the max number of characters. 294 :group 'ada)
197 Set to 0, if you don't use crunched filenames.") 295 (make-variable-buffer-local 'ada-compile-options)
296
297 (defcustom ada-make-options "-c"
298 "*Buffer local options passed to `ada-compiler-make' (usually `gnatmake').
299 These options are used when `gnatmake' is invoked on the current buffer."
300 :type 'string
301 :group 'ada)
302 (make-variable-buffer-local 'ada-make-options)
303
304 (defcustom ada-compiler-syntax-check "gcc -c -gnats"
305 "*Compiler command with options for syntax checking."
306 :type 'string
307 :group 'ada)
308
309 (defcustom ada-compiler-make "gnatmake"
310 "*The `make' command for the given compiler."
311 :type 'string
312 :group 'ada)
313
314 (defcustom ada-fill-comment-prefix "-- "
315 "*This is inserted in the first columns when filling a comment paragraph."
316 :type 'string
317 :group 'ada)
318
319 (defcustom ada-fill-comment-postfix " --"
320 "*This is inserted at the end of each line when filling a comment paragraph.
321 with `ada-fill-comment-paragraph-postfix'."
322 :type 'string
323 :group 'ada)
324
325 (defcustom ada-krunch-args "0"
326 "*Argument of gnatkr, a string containing the max number of characters.
327 Set to 0, if you don't use crunched filenames."
328 :type 'string
329 :group 'ada)
198 330
199 ;;; ---- end of user configurable variables 331 ;;; ---- end of user configurable variables
200 332
201 333
202 (defvar ada-mode-abbrev-table nil 334 (defvar ada-mode-abbrev-table nil
203 "Abbrev table used in Ada Mode.") 335 "Abbrev table used in Ada mode.")
204 (define-abbrev-table 'ada-mode-abbrev-table ()) 336 (define-abbrev-table 'ada-mode-abbrev-table ())
205 337
206 (defvar ada-mode-map () 338 (defvar ada-mode-map ()
207 "Local keymap used for Ada Mode.") 339 "Local keymap used for Ada mode.")
208 340
209 (defvar ada-mode-syntax-table nil 341 (defvar ada-mode-syntax-table nil
210 "Syntax table to be used for editing Ada source code.") 342 "Syntax table to be used for editing Ada source code.")
211 343
212 (defvar ada-mode-symbol-syntax-table nil 344 (defvar ada-mode-symbol-syntax-table nil
277 \\(\\(limited\\|abstract\\|tagged\\)[ \t]+\\)*record\\)\\>" 409 \\(\\(limited\\|abstract\\|tagged\\)[ \t]+\\)*record\\)\\>"
278 "Regexp for keywords starting Ada blocks.") 410 "Regexp for keywords starting Ada blocks.")
279 411
280 (defvar ada-end-stmt-re 412 (defvar ada-end-stmt-re
281 "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\ 413 "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\
282 \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|\ 414 \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|then\\|\
283 declare\\|generic\\|private\\)\\>\\|\ 415 declare\\|generic\\|private\\)\\>\\|\
284 ^[ \t]*\\(package\\|procedure\\|function\\)[ \ta-zA-Z0-9_\\.]+is\\|\ 416 ^[ \t]*\\(package\\|procedure\\|function\\)\\>[ \ta-zA-Z0-9_\\.]+\\<is\\>\\|\
285 ^[ \t]*exception\\>\\)" 417 ^[ \t]*exception\\>\\)"
286 "Regexp of possible ends for a non-broken statement. 418 "Regexp of possible ends for a non-broken statement.
287 A new statement starts after these.") 419 A new statement starts after these.")
288 420
289 (defvar ada-loop-start-re 421 (defvar ada-loop-start-re
293 (defvar ada-subprog-start-re 425 (defvar ada-subprog-start-re
294 "\\<\\(procedure\\|protected\\|package\\|function\\|\ 426 "\\<\\(procedure\\|protected\\|package\\|function\\|\
295 task\\|accept\\|entry\\)\\>" 427 task\\|accept\\|entry\\)\\>"
296 "Regexp for the start of a subprogram.") 428 "Regexp for the start of a subprogram.")
297 429
430 (defvar ada-named-block-re
431 "[ \t]*[a-zA-Z_0-9]+ *:[^=]"
432 "Regexp of the name of a block or loop.")
433
298 434
299 ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com> 435 ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com>
300 ;; 436 ;;
301 (defvar ada-imenu-generic-expression 437 (defvar ada-imenu-generic-expression
302 '((nil "^\\s-*\\(procedure\\|function\\)\\s-+\\([A-Za-z0-9_]+\\)" 2) 438 '((nil "^\\s-*\\(procedure\\|function\\)\\s-+\\([A-Za-z0-9_]+\\)" 2)
303 ("Type Defs" "^\\s-*\\(sub\\)?type\\s-+\\([A-Za-z0-9_]+\\)" 2)) 439 ("Type Defs" "^\\s-*\\(sub\\)?type\\s-+\\([A-Za-z0-9_]+\\)" 2))
304 440
305 "Imenu generic expression for Ada mode. See `imenu-generic-expression'.") 441 "Imenu generic expression for Ada mode. See `imenu-generic-expression'.")
306 442
307 ;;;------------- 443 ;;;-------------
308 ;;; functions 444 ;;; functions
311 (defun ada-xemacs () 447 (defun ada-xemacs ()
312 (or (string-match "Lucid" emacs-version) 448 (or (string-match "Lucid" emacs-version)
313 (string-match "XEmacs" emacs-version))) 449 (string-match "XEmacs" emacs-version)))
314 450
315 (defun ada-create-syntax-table () 451 (defun ada-create-syntax-table ()
316 "Create the syntax table for Ada Mode." 452 "Create the syntax table for Ada mode."
317 ;; There are two different syntax-tables. The standard one declares 453 ;; There are two different syntax-tables. The standard one declares
318 ;; `_' as a symbol constituent, in the second one, it is a word 454 ;; `_' as a symbol constituent, in the second one, it is a word
319 ;; constituent. For some search and replacing routines we 455 ;; constituent. For some search and replacing routines we
320 ;; temporarily switch between the two. 456 ;; temporarily switch between the two.
321 (setq ada-mode-syntax-table (make-syntax-table)) 457 (setq ada-mode-syntax-table (make-syntax-table))
322 (set-syntax-table ada-mode-syntax-table) 458 (set-syntax-table ada-mode-syntax-table)
323 459
324 ;; define string brackets (% is alternative string bracket) 460 ;; define string brackets (`%' is alternative string bracket, but
325 (modify-syntax-entry ?% "\"" ada-mode-syntax-table) 461 ;; almost never used as such and throws font-lock and indentation
462 ;; off the track.)
463 (modify-syntax-entry ?% "$" ada-mode-syntax-table)
326 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table) 464 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
327 465
328 (modify-syntax-entry ?\# "$" ada-mode-syntax-table) 466 (modify-syntax-entry ?\# "$" ada-mode-syntax-table)
329 467
330 (modify-syntax-entry ?: "." ada-mode-syntax-table) 468 (modify-syntax-entry ?: "." ada-mode-syntax-table)
351 489
352 ;; and \f and \n end a comment 490 ;; and \f and \n end a comment
353 (modify-syntax-entry ?\f "> " ada-mode-syntax-table) 491 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
354 (modify-syntax-entry ?\n "> " ada-mode-syntax-table) 492 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
355 493
356 ;; define what belongs in ada symbols 494 ;; define what belongs in Ada symbols
357 (modify-syntax-entry ?_ "_" ada-mode-syntax-table) 495 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
358 496
359 ;; define parentheses to match 497 ;; define parentheses to match
360 (modify-syntax-entry ?\( "()" ada-mode-syntax-table) 498 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
361 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table) 499 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
365 ) 503 )
366 504
367 505
368 ;;;###autoload 506 ;;;###autoload
369 (defun ada-mode () 507 (defun ada-mode ()
370 "Ada Mode is the major mode for editing Ada code. 508 "Ada mode is the major mode for editing Ada code.
371 509
372 Bindings are as follows: (Note: 'LFD' is control-j.) 510 Bindings are as follows: (Note: 'LFD' is control-j.)
373 511
374 Indent line '\\[ada-tab]' 512 Indent line '\\[ada-tab]'
375 Indent line, insert newline and indent the new line. '\\[newline-and-indent]' 513 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
385 523
386 Fill comment paragraph '\\[ada-fill-comment-paragraph]' 524 Fill comment paragraph '\\[ada-fill-comment-paragraph]'
387 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]' 525 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]'
388 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]' 526 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]'
389 527
390 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]' 528 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
391 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]' 529 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
392 530
393 Goto matching start of current 'end ...;' '\\[ada-move-to-start]' 531 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
394 Goto end of current block '\\[ada-move-to-end]' 532 Goto end of current block '\\[ada-move-to-end]'
395 533
446 (setq parse-sexp-ignore-comments t) 584 (setq parse-sexp-ignore-comments t)
447 585
448 (make-local-variable 'case-fold-search) 586 (make-local-variable 'case-fold-search)
449 (setq case-fold-search t) 587 (setq case-fold-search t)
450 588
589 (make-local-variable 'outline-regexp)
590 (setq outline-regexp "[^\n\^M]")
591 (make-local-variable 'outline-level)
592 (setq outline-level 'ada-outline-level)
593
451 (make-local-variable 'fill-paragraph-function) 594 (make-local-variable 'fill-paragraph-function)
452 (setq fill-paragraph-function 'ada-fill-comment-paragraph) 595 (setq fill-paragraph-function 'ada-fill-comment-paragraph)
596 ;;(make-local-variable 'adaptive-fill-regexp)
453 597
454 (make-local-variable 'imenu-generic-expression) 598 (make-local-variable 'imenu-generic-expression)
455 (setq imenu-generic-expression ada-imenu-generic-expression) 599 (setq imenu-generic-expression ada-imenu-generic-expression)
456 600
457 (make-local-variable 'font-lock-defaults) 601 (if (ada-xemacs) nil ; XEmacs uses properties
458 (setq font-lock-defaults '((ada-font-lock-keywords 602 (make-local-variable 'font-lock-defaults)
459 ada-font-lock-keywords-1 603 (setq font-lock-defaults
460 ada-font-lock-keywords-2) 604 '((ada-font-lock-keywords
461 nil t 605 ada-font-lock-keywords-1 ada-font-lock-keywords-2)
462 ((?\_ . "w")) 606 nil t
463 beginning-of-line)) 607 ((?\_ . "w")(?\. . "w"))
608 beginning-of-line
609 (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords)))
610
611 ;; Set up support for find-file.el.
612 (make-variable-buffer-local 'ff-other-file-alist)
613 (make-variable-buffer-local 'ff-search-directories)
614 (setq ff-other-file-alist 'ada-other-file-alist
615 ff-search-directories 'ada-search-directories
616 ff-pre-load-hooks 'ff-which-function-are-we-in
617 ff-post-load-hooks 'ff-set-point-accordingly
618 ff-file-created-hooks 'ada-make-body))
464 619
465 (setq major-mode 'ada-mode) 620 (setq major-mode 'ada-mode)
466 (setq mode-name "Ada") 621 (setq mode-name "Ada")
467
468 (setq blink-matching-paren t)
469 622
470 (use-local-map ada-mode-map) 623 (use-local-map ada-mode-map)
471 624
472 (if ada-mode-syntax-table 625 (if ada-mode-syntax-table
473 (set-syntax-table ada-mode-syntax-table) 626 (set-syntax-table ada-mode-syntax-table)
495 ((eq ada-language-version 'ada95) 648 ((eq ada-language-version 'ada95)
496 (setq ada-keywords ada-95-keywords))) 649 (setq ada-keywords ada-95-keywords)))
497 650
498 (if ada-auto-case 651 (if ada-auto-case
499 (ada-activate-keys-for-case))) 652 (ada-activate-keys-for-case)))
653
654
655 ;;;--------------------------
656 ;;; Compile support
657 ;;;--------------------------
658
659 (defun ada-check-syntax ()
660 "Check syntax of the current buffer.
661 Uses the function `compile' to execute `ada-compiler-syntax-check'."
662 (interactive)
663 (let ((old-compile-command compile-command))
664 (setq compile-command (concat ada-compiler-syntax-check
665 (if (eq ada-language-version 'ada83)
666 "-gnat83 ")
667 " " ada-compile-options " "
668 (buffer-name)))
669 (setq compile-command (read-from-minibuffer
670 "enter command for syntax check: "
671 compile-command))
672 (compile compile-command)
673 ;; restore old compile-command
674 (setq compile-command old-compile-command)))
675
676 (defun ada-make-local ()
677 "Bring current Ada unit up-to-date.
678 Uses the function `compile' to execute `ada-compile-make'."
679 (interactive)
680 (let ((old-compile-command compile-command))
681 (setq compile-command (concat ada-compiler-make
682 " " ada-make-options " "
683 (buffer-name)))
684 (setq compile-command (read-from-minibuffer
685 "enter command for local make: "
686 compile-command))
687 (compile compile-command)
688 ;; restore old compile-command
689 (setq compile-command old-compile-command)))
690
691
500 692
501 693
502 ;;;-------------------------- 694 ;;;--------------------------
503 ;;; Fill Comment Paragraph 695 ;;; Fill Comment Paragraph
504 ;;;-------------------------- 696 ;;;--------------------------
659 851
660 (defun ada-call-pretty-printer () 852 (defun ada-call-pretty-printer ()
661 "Calls the external Pretty Printer. 853 "Calls the external Pretty Printer.
662 The name is specified in `ada-external-pretty-print-program'. Saves the 854 The name is specified in `ada-external-pretty-print-program'. Saves the
663 current buffer in a directory specified by `ada-tmp-directory', 855 current buffer in a directory specified by `ada-tmp-directory',
664 starts the pretty printer as an external process on that file and then 856 starts the pretty printer as external process on that file and then
665 reloads the beautified program in the buffer and cleans up 857 reloads the beautified program in the buffer and cleans up
666 `ada-tmp-directory'." 858 `ada-tmp-directory'."
667 (interactive) 859 (interactive)
668 (let ((filename-with-path buffer-file-name) 860 (let ((filename-with-path buffer-file-name)
669 (curbuf (current-buffer)) 861 (curbuf (current-buffer))
722 ;;;--------------- 914 ;;;---------------
723 ;;; auto-casing 915 ;;; auto-casing
724 ;;;--------------- 916 ;;;---------------
725 917
726 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be> 918 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be>
727 ;; modifiedby RE and MH 919 ;; modified by RE and MH
728 920
729 (defun ada-after-keyword-p () 921 (defun ada-after-keyword-p ()
730 ;; returns t if cursor is after a keyword. 922 ;; returns t if cursor is after a keyword.
731 (save-excursion 923 (save-excursion
732 (forward-word -1) 924 (forward-word -1)
735 (= (point) (point-min)) 927 (= (point) (point-min))
736 (backward-char 1)) 928 (backward-char 1))
737 (not (looking-at "_"))) ; (MH) 929 (not (looking-at "_"))) ; (MH)
738 (looking-at (concat ada-keywords "[^_]"))))) 930 (looking-at (concat ada-keywords "[^_]")))))
739 931
740 (defun ada-after-char-p () 932 (defun ada-in-char-const-p ()
741 ;; returns t if after ada character "'". This is interpreted as being 933 ;; Returns t if point is inside a character constant.
742 ;; in a character constant. 934 ;; We assume to be in a constant if the previous and the next character
935 ;; are "'".
743 (save-excursion 936 (save-excursion
744 (if (> (point) 2) 937 (if (> (point) 1)
745 (progn 938 (and
746 (forward-char -2) 939 (progn
747 (looking-at "'")) 940 (forward-char 1)
941 (looking-at "'"))
942 (progn
943 (forward-char -2)
944 (looking-at "'")))
748 nil))) 945 nil)))
749 946
750 947
751 (defun ada-adjust-case (&optional force-identifier) 948 (defun ada-adjust-case (&optional force-identifier)
752 "Adjust the case of the word before the just typed character. 949 "Adjust the case of the word before the just typed character.
754 `ada-case-attribute'. 951 `ada-case-attribute'.
755 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH) 952 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH)
756 (forward-char -1) 953 (forward-char -1)
757 (if (and (> (point) 1) (not (or (ada-in-string-p) 954 (if (and (> (point) 1) (not (or (ada-in-string-p)
758 (ada-in-comment-p) 955 (ada-in-comment-p)
759 (ada-after-char-p)))) 956 (ada-in-char-const-p))))
760 (if (eq (char-syntax (char-after (1- (point)))) ?w) 957 (if (eq (char-syntax (char-after (1- (point)))) ?w)
761 (if (save-excursion 958 (if (save-excursion
762 (forward-word -1) 959 (forward-word -1)
763 (or (= (point) (point-min)) 960 (or (= (point) (point-min))
764 (backward-char 1)) 961 (backward-char 1))
799 996
800 (defun ada-activate-keys-for-case () 997 (defun ada-activate-keys-for-case ()
801 ;; save original keybindings to allow swapping ret/lfd 998 ;; save original keybindings to allow swapping ret/lfd
802 ;; when casing is activated 999 ;; when casing is activated
803 ;; the 'or ...' is there to be sure that the value will not 1000 ;; the 'or ...' is there to be sure that the value will not
804 ;; be changed again when Ada Mode is called more than once (MH) 1001 ;; be changed again when Ada mode is called more than once (MH)
805 (or ada-ret-binding 1002 (or ada-ret-binding
806 (setq ada-ret-binding (key-binding "\C-M"))) 1003 (setq ada-ret-binding (key-binding "\C-M")))
807 (or ada-lfd-binding 1004 (or ada-lfd-binding
808 (setq ada-lfd-binding (key-binding "\C-j"))) 1005 (setq ada-lfd-binding (key-binding "\C-j")))
809 ;; call case modifying function after certain keys. 1006 ;; call case modifying function after certain keys.
817 1014
818 ;; 1015 ;;
819 ;; added by MH 1016 ;; added by MH
820 ;; 1017 ;;
821 (defun ada-loose-case-word (&optional arg) 1018 (defun ada-loose-case-word (&optional arg)
822 "Capitalizes the first letter and the letters following `_'. 1019 "Capitalizes the first letter and the letters following `_'.
823 ARG is ignored, it's there to fit the standard casing functions' style." 1020 ARG is ignored, it's there to fit the standard casing functions' style."
824 (let ((pos (point)) 1021 (let ((pos (point))
825 (first t)) 1022 (first t))
826 (skip-chars-backward "a-zA-Z0-9_") 1023 (skip-chars-backward "a-zA-Z0-9_")
827 (while (or first 1024 (while (or first
833 (goto-char pos))) 1030 (goto-char pos)))
834 1031
835 1032
836 ;; 1033 ;;
837 ;; added by MH 1034 ;; added by MH
1035 ;; modified by JSH to handle attributes
838 ;; 1036 ;;
839 (defun ada-adjust-case-region (from to) 1037 (defun ada-adjust-case-region (from to)
840 "Adjusts the case of all words in the region. 1038 "Adjusts the case of all words in the region.
841 Attention: This function might take very long for big regions !" 1039 Attention: This function might take very long for big regions !"
842 (interactive "*r") 1040 (interactive "*r")
843 (let ((begin nil) 1041 (let ((begin nil)
844 (end nil) 1042 (end nil)
845 (keywordp nil) 1043 (keywordp nil)
846 (reldiff nil)) 1044 (attribp nil))
847 (unwind-protect 1045 (unwind-protect
848 (save-excursion 1046 (save-excursion
849 (set-syntax-table ada-mode-symbol-syntax-table) 1047 (set-syntax-table ada-mode-symbol-syntax-table)
850 (goto-char to) 1048 (goto-char to)
851 ;; 1049 ;;
852 ;; loop: look for all identifiers and keywords 1050 ;; loop: look for all identifiers, keywords, and attributes
853 ;; 1051 ;;
854 (while (re-search-backward 1052 (while (re-search-backward
855 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]" 1053 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]"
856 from 1054 from
857 t) 1055 t)
858 ;; 1056 ;;
859 ;; print status message 1057 ;; print status message
860 ;; 1058 ;;
861 (setq reldiff (- (point) from)) 1059 (message "adjusting case ... %5d characters left" (- (point) from))
862 (message "adjusting case ... %5d characters left" 1060 (setq attribp (looking-at "'[a-zA-Z0-9_]+[^']"))
863 (- (point) from))
864 (forward-char 1) 1061 (forward-char 1)
865 (or 1062 (or
866 ;; do nothing if it is a string or comment 1063 ;; do nothing if it is a string or comment
867 (ada-in-string-or-comment-p) 1064 (ada-in-string-or-comment-p)
868 (progn 1065 (progn
869 ;; 1066 ;;
870 ;; get the identifier or keyword 1067 ;; get the identifier or keyword or attribute
871 ;; 1068 ;;
872 (setq begin (point)) 1069 (setq begin (point))
873 (setq keywordp (looking-at (concat ada-keywords "[^_]"))) 1070 (setq keywordp (looking-at (concat ada-keywords "[^_]")))
874 (skip-chars-forward "a-zA-Z0-9_") 1071 (skip-chars-forward "a-zA-Z0-9_")
875 ;; 1072 ;;
876 ;; casing according to user-option 1073 ;; casing according to user-option
877 ;; 1074 ;;
878 (if keywordp 1075 (if keywordp
879 (funcall ada-case-keyword -1) 1076 (funcall ada-case-keyword -1)
880 (funcall ada-case-identifier -1)) 1077 (if attribp
1078 (funcall ada-case-attribute -1)
1079 (funcall ada-case-identifier -1)))
881 (goto-char begin)))) 1080 (goto-char begin))))
882 (message "adjusting case ... done")) 1081 (message "adjusting case ... done"))
883 (set-syntax-table ada-mode-syntax-table)))) 1082 (set-syntax-table ada-mode-syntax-table))))
884 1083
885 1084
886 ;; 1085 ;;
887 ;; added by MH 1086 ;; added by MH
888 ;; 1087 ;;
889 (defun ada-adjust-case-buffer () 1088 (defun ada-adjust-case-buffer ()
890 "Adjusts the case of all words in the whole buffer. 1089 "Adjusts the case of all words in the whole buffer.
891 Attention: This function might take very long for big buffers !" 1090 ATTENTION: This function might take very long for big buffers !"
892 (interactive "*") 1091 (interactive "*")
893 (ada-adjust-case-region (point-min) (point-max))) 1092 (ada-adjust-case-region (point-min) (point-max)))
894 1093
895 1094
896 ;;;------------------------;;; 1095 ;;;------------------------;;;
897 ;;; Format Parameter Lists ;;; 1096 ;;; Format Parameter Lists ;;;
898 ;;;------------------------;;; 1097 ;;;------------------------;;;
899 1098
900 (defun ada-format-paramlist () 1099 (defun ada-format-paramlist ()
901 "Reformats a parameter-list. 1100 "Reformats a parameter list.
902 Attention: 1) Comments inside the list are killed ! 1101 ATTENTION: 1) Comments inside the list are killed !
903 2) If the syntax is not correct (especially, if there are 1102 2) If the syntax is not correct (especially, if there are
904 semicolons missing), it can get totally confused ! 1103 semicolons missing), it can get totally confused !
905 In such a case, use `undo', correct the syntax and try again." 1104 In such a case, use `undo', correct the syntax and try again."
906 1105
907 (interactive) 1106 (interactive)
918 (error "not in parameter list")) 1117 (error "not in parameter list"))
919 ;; 1118 ;;
920 ;; find start of current parameter-list 1119 ;; find start of current parameter-list
921 ;; 1120 ;;
922 (ada-search-ignore-string-comment 1121 (ada-search-ignore-string-comment
923 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil) 1122 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil)
924 (ada-search-ignore-string-comment "(" nil nil t) 1123 (ada-search-ignore-string-comment "(" nil nil t)
925 (backward-char 1) 1124 (backward-char 1)
926 (setq begin (point)) 1125 (setq begin (point))
927 1126
928 ;; 1127 ;;
1059 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>") 1258 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>")
1060 (forward-word 1) 1259 (forward-word 1)
1061 (ada-goto-next-non-ws)) 1260 (ada-goto-next-non-ws))
1062 1261
1063 ;; 1262 ;;
1064 ;; read type of parameter 1263 ;; read type of parameter
1065 ;; 1264 ;;
1066 (looking-at "\\<[a-zA-Z0-9_\\.]+\\>") 1265 (looking-at "\\<[a-zA-Z0-9_\\.\\']+\\>")
1067 (setq param 1266 (setq param
1068 (append param 1267 (append param
1069 (list 1268 (list
1070 (buffer-substring (match-beginning 0) 1269 (buffer-substring (match-beginning 0)
1071 (match-end 0))))) 1270 (match-end 0)))))
1407 (forward-line 1) 1606 (forward-line 1)
1408 (setq block-done (1+ block-done)) 1607 (setq block-done (1+ block-done))
1409 (setq lines-remaining (1- lines-remaining))) 1608 (setq lines-remaining (1- lines-remaining)))
1410 ;; show line number where the error occurred 1609 ;; show line number where the error occurred
1411 (error 1610 (error
1412 (error "line %d: %s" (1+ (count-lines (point-min) (point))) err))) 1611 (error "line %d: %s" (1+ (count-lines (point-min) (point))) err) nil))
1413 (message "indenting ... done"))) 1612 (message "indenting ... done")))
1414 1613
1415 1614
1416 (defun ada-indent-newline-indent () 1615 (defun ada-indent-newline-indent ()
1417 "Indents the current line, inserts a newline and then indents the new line." 1616 "Indents the current line, inserts a newline and then indents the new line."
1418 (interactive "*") 1617 (interactive "*")
1419 (let ((column) 1618 (ada-indent-current)
1420 (orgpoint)) 1619 (newline)
1421 1620 (ada-indent-current))
1422 (ada-indent-current)
1423 (newline)
1424 (delete-horizontal-space)
1425 (setq orgpoint (point))
1426
1427 (unwind-protect
1428 (progn
1429 (set-syntax-table ada-mode-symbol-syntax-table)
1430
1431 (setq column (save-excursion
1432 (funcall (ada-indent-function) orgpoint))))
1433
1434 ;;
1435 ;; restore syntax-table
1436 ;;
1437 (set-syntax-table ada-mode-syntax-table))
1438
1439 (indent-to column)
1440
1441 ;; The following is needed to ensure that indentation will still be
1442 ;; correct if something follows behind point when typing LFD
1443 ;; For example: Imagine point to be there (*) when LFD is typed:
1444 ;; while cond loop
1445 ;; null; *end loop;
1446 ;; Result without the following statement would be:
1447 ;; while cond loop
1448 ;; null;
1449 ;; *end loop;
1450 ;; You would then have to type TAB to correct it.
1451 ;; If that doesn't bother you, you can comment out the following
1452 ;; statement to speed up indentation a LITTLE bit.
1453
1454 (if (not (looking-at "[ \t]*$"))
1455 (ada-indent-current))
1456 ))
1457 1621
1458 1622
1459 (defun ada-indent-current () 1623 (defun ada-indent-current ()
1460 "Indents current line as Ada code. 1624 "Indents current line as Ada code.
1461 This works by two steps: 1625 This works by two steps:
1494 (forward-line 1) 1658 (forward-line 1)
1495 (setq line-end (point)) 1659 (setq line-end (point))
1496 (setq prev-indent 1660 (setq prev-indent
1497 (save-excursion 1661 (save-excursion
1498 (funcall (ada-indent-function) line-end)))) 1662 (funcall (ada-indent-function) line-end))))
1499 (progn ; first line of buffer -> set indent 1663 (progn ; first line of buffer -> set indent
1500 (beginning-of-line) ; to 0 1664 (beginning-of-line) ; to 0
1501 (delete-horizontal-space) 1665 (delete-horizontal-space)
1502 (setq prevline nil)))) 1666 (setq prevline nil))))
1503 1667
1504 (if prevline 1668 (if prevline
1505 ;; 1669 ;;
1506 ;; we are not in the first accessible line in the buffer 1670 ;; we are not in the first accessible line in the buffer
1507 ;; 1671 ;;
1509 ;; 1673 ;;
1510 ;; second step 1674 ;; second step
1511 ;; 1675 ;;
1512 (back-to-indentation) 1676 (back-to-indentation)
1513 (setq cur-indent (ada-get-current-indent prev-indent)) 1677 (setq cur-indent (ada-get-current-indent prev-indent))
1514 ;; only reindent if indentation is different then the current 1678 ;; only reindent if indentation is different then the current
1515 (if (= (current-column) cur-indent) 1679 (if (= (current-column) cur-indent)
1516 nil 1680 nil
1517 (delete-horizontal-space) 1681 (delete-horizontal-space)
1518 (indent-to cur-indent)) 1682 (indent-to cur-indent))
1519
1520 ;; 1683 ;;
1521 ;; restore position of point 1684 ;; restore position of point
1522 ;; 1685 ;;
1523 (goto-char orgpoint) 1686 (goto-char orgpoint)
1524 (if (< (current-column) (current-indentation)) 1687 (if (< (current-column) (current-indentation))
1525 (back-to-indentation)))))) 1688 (back-to-indentation))))))
1526 1689
1527 ;; 1690 ;;
1528 ;; restore syntax-table 1691 ;; restore syntax-table
1529 ;; 1692 ;;
1530 (set-syntax-table ada-mode-syntax-table))) 1693 (set-syntax-table ada-mode-syntax-table)))
1557 1720
1558 ;; 1721 ;;
1559 ;; end 1722 ;; end
1560 ;; 1723 ;;
1561 ((looking-at "\\<end\\>") 1724 ((looking-at "\\<end\\>")
1562 (save-excursion 1725 (let ((label 0))
1563 (ada-goto-matching-start 1) 1726 (save-excursion
1564 1727 (ada-goto-matching-start 1)
1565 ;; 1728
1566 ;; found 'loop' => skip back to 'while' or 'for' 1729 ;;
1567 ;; if 'loop' is not on a separate line 1730 ;; found 'loop' => skip back to 'while' or 'for'
1568 ;; 1731 ;; if 'loop' is not on a separate line
1569 (if (and 1732 ;;
1570 (looking-at "\\<loop\\>") 1733 (if (and
1571 (save-excursion 1734 (looking-at "\\<loop\\>")
1572 (back-to-indentation) 1735 (save-excursion
1573 (not (looking-at "\\<loop\\>")))) 1736 (back-to-indentation)
1574 (if (save-excursion 1737 (not (looking-at "\\<loop\\>"))))
1575 (and 1738 (if (save-excursion
1576 (setq match-cons 1739 (and
1577 (ada-search-ignore-string-comment 1740 (setq match-cons
1578 ada-loop-start-re t nil)) 1741 (ada-search-ignore-string-comment
1579 (not (looking-at "\\<loop\\>")))) 1742 ada-loop-start-re t nil))
1580 (goto-char (car match-cons)))) 1743 (not (looking-at "\\<loop\\>"))))
1581 1744 (progn
1582 (current-indentation))) 1745 (goto-char (car match-cons))
1746 (save-excursion
1747 (beginning-of-line)
1748 (if (looking-at ada-named-block-re)
1749 (setq label (- ada-label-indent)))))))
1750
1751 (+ (current-indentation) label))))
1583 ;; 1752 ;;
1584 ;; exception 1753 ;; exception
1585 ;; 1754 ;;
1586 ((looking-at "\\<exception\\>") 1755 ((looking-at "\\<exception\\>")
1587 (save-excursion 1756 (save-excursion
1645 ;; 1814 ;;
1646 ((looking-at "\\<begin\\>") 1815 ((looking-at "\\<begin\\>")
1647 (save-excursion 1816 (save-excursion
1648 (if (ada-goto-matching-decl-start t) 1817 (if (ada-goto-matching-decl-start t)
1649 (current-indentation) 1818 (current-indentation)
1650 (progn 1819 prev-indent)))
1651 (message "no matching declaration start")
1652 prev-indent))))
1653 ;; 1820 ;;
1654 ;; is 1821 ;; is
1655 ;; 1822 ;;
1656 ((looking-at "\\<is\\>") 1823 ((looking-at "\\<is\\>")
1657 (if (and 1824 (if (and
1774 ;; line according to the previous statement, ignoring the contents 1941 ;; line according to the previous statement, ignoring the contents
1775 ;; of the current line after point. Moves point to the beginning of 1942 ;; of the current line after point. Moves point to the beginning of
1776 ;; the current statement, if NOMOVE is nil. 1943 ;; the current statement, if NOMOVE is nil.
1777 1944
1778 (let ((orgpoint (point)) 1945 (let ((orgpoint (point))
1779 (func nil) 1946 (func nil))
1780 (stmt-start nil))
1781 ;; 1947 ;;
1782 ;; inside a parameter-list 1948 ;; inside a parameter-list
1783 ;; 1949 ;;
1784 (if (ada-in-paramlist-p) 1950 (if (ada-in-paramlist-p)
1785 (setq func 'ada-get-indent-paramlist) 1951 (setq func 'ada-get-indent-paramlist)
1786 (progn 1952 (progn
1787 ;; 1953 ;;
1788 ;; move to beginning of current statement 1954 ;; move to beginning of current statement
1789 ;; 1955 ;;
1790 (if (not nomove) 1956 (if (not nomove)
1791 (setq stmt-start (ada-goto-stmt-start))) 1957 (ada-goto-stmt-start))
1792 ;; 1958 ;;
1793 ;; no beginning found => don't change indentation 1959 ;; no beginning found => don't change indentation
1794 ;; 1960 ;;
1795 (if (and 1961 (if (and
1796 (eq orgpoint (point)) 1962 (eq orgpoint (point))
1797 (not nomove)) 1963 (not nomove))
1798 (setq func 'ada-get-indent-nochange) 1964 (setq func 'ada-get-indent-nochange)
1799 1965
1800 (cond 1966 (cond
1801 ;; 1967 ;;
1802 ((and 1968 ((and
1803 ada-indent-to-open-paren 1969 ada-indent-to-open-paren
1810 ((looking-at ada-loop-start-re) 1976 ((looking-at ada-loop-start-re)
1811 (setq func 'ada-get-indent-loop)) 1977 (setq func 'ada-get-indent-loop))
1812 ;; 1978 ;;
1813 ((looking-at ada-subprog-start-re) 1979 ((looking-at ada-subprog-start-re)
1814 (setq func 'ada-get-indent-subprog)) 1980 (setq func 'ada-get-indent-subprog))
1815 ;;
1816 ((looking-at "\\<package\\>")
1817 (setq func 'ada-get-indent-subprog)) ; maybe it needs a
1818 ; special function
1819 ; sometimes ?
1820 ;; 1981 ;;
1821 ((looking-at ada-block-start-re) 1982 ((looking-at ada-block-start-re)
1822 (setq func 'ada-get-indent-block-start)) 1983 (setq func 'ada-get-indent-block-start))
1823 ;; 1984 ;;
1824 ((looking-at "\\<type\\>") 1985 ((looking-at "\\<type\\>")
1849 2010
1850 ;; ---- functions to return indentation for special cases 2011 ;; ---- functions to return indentation for special cases
1851 2012
1852 (defun ada-get-indent-open-paren (orgpoint) 2013 (defun ada-get-indent-open-paren (orgpoint)
1853 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2014 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1854 ;; Assumes point to be behind an open paranthesis not yet closed. 2015 ;; Assumes point to be behind an open parenthesis not yet closed.
1855 (ada-in-open-paren-p)) 2016 (ada-in-open-paren-p))
1856 2017
1857 2018
1858 (defun ada-get-indent-nochange (orgpoint) 2019 (defun ada-get-indent-nochange (orgpoint)
1859 ;; Returns the indentation (column #) of the current line. 2020 ;; Returns the indentation (column #) of the current line.
1895 ;; Assumes point to be at the beginning of an end-statement. 2056 ;; Assumes point to be at the beginning of an end-statement.
1896 ;; Therefore it has to find the corresponding start. This can be a little 2057 ;; Therefore it has to find the corresponding start. This can be a little
1897 ;; slow, if it has to search through big files with many nested blocks. 2058 ;; slow, if it has to search through big files with many nested blocks.
1898 ;; Signals an error if the corresponding block-start doesn't match. 2059 ;; Signals an error if the corresponding block-start doesn't match.
1899 (let ((defun-name nil) 2060 (let ((defun-name nil)
2061 (label 0)
1900 (indent nil)) 2062 (indent nil))
1901 ;; 2063 ;;
1902 ;; is the line already terminated by ';' ? 2064 ;; is the line already terminated by ';' ?
1903 ;; 2065 ;;
1904 (if (save-excursion 2066 (if (save-excursion
1921 (if (looking-at "\\<\\(loop\\|record\\)\\>") 2083 (if (looking-at "\\<\\(loop\\|record\\)\\>")
1922 (progn 2084 (progn
1923 (forward-word 1) 2085 (forward-word 1)
1924 (ada-goto-stmt-start))) 2086 (ada-goto-stmt-start)))
1925 ;; a label ? => skip it 2087 ;; a label ? => skip it
1926 (if (looking-at "[a-zA-Z0-9_]+[ \n\t]+:") 2088 (if (looking-at ada-named-block-re)
1927 (progn 2089 (progn
2090 (setq label (- ada-label-indent))
1928 (goto-char (match-end 0)) 2091 (goto-char (match-end 0))
1929 (ada-goto-next-non-ws))) 2092 (ada-goto-next-non-ws)))
1930 ;; really looking-at the right thing ? 2093 ;; really looking-at the right thing ?
1931 (or (looking-at (concat "\\<\\(" 2094 (or (looking-at (concat "\\<\\("
1932 "loop\\|select\\|if\\|case\\|" 2095 "loop\\|select\\|if\\|case\\|"
1935 (ada-search-ignore-string-comment 2098 (ada-search-ignore-string-comment
1936 (concat "\\<\\(" 2099 (concat "\\<\\("
1937 "loop\\|select\\|if\\|case\\|" 2100 "loop\\|select\\|if\\|case\\|"
1938 "record\\|while\\|type\\)\\>"))) 2101 "record\\|while\\|type\\)\\>")))
1939 (backward-word 1)) 2102 (backward-word 1))
1940 (current-indentation))) 2103 (+ (current-indentation) label)))
1941 ;; 2104 ;;
1942 ;; a named block end 2105 ;; a named block end
1943 ;; 2106 ;;
1944 ((looking-at ada-ident-re) 2107 ((looking-at ada-ident-re)
1945 (setq defun-name (buffer-substring (match-beginning 0) 2108 (setq defun-name (buffer-substring (match-beginning 0)
1969 (+ (current-indentation) ada-broken-indent)))) 2132 (+ (current-indentation) ada-broken-indent))))
1970 2133
1971 2134
1972 (defun ada-get-indent-case (orgpoint) 2135 (defun ada-get-indent-case (orgpoint)
1973 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2136 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1974 ;; Assumes point to be at the beginning of an case-statement. 2137 ;; Assumes point to be at the beginning of a case-statement.
1975 (let ((cur-indent (current-indentation)) 2138 (let ((cur-indent (current-indentation))
1976 (match-cons nil) 2139 (match-cons nil)
1977 (opos (point))) 2140 (opos (point)))
1978 (cond 2141 (cond
1979 ;; 2142 ;;
1980 ;; case..is..when..=> 2143 ;; case..is..when..=>
1981 ;; 2144 ;;
1982 ((save-excursion 2145 ((save-excursion
1983 (setq match-cons (ada-search-ignore-string-comment 2146 (setq match-cons (and
1984 "[ \t\n]+=>" nil orgpoint))) 2147 ;; the `=>' must be after the keyword `is'.
2148 (ada-search-ignore-string-comment
2149 "\\<is\\>" nil orgpoint)
2150 (ada-search-ignore-string-comment
2151 "[ \t\n]+=>" nil orgpoint))))
1985 (save-excursion 2152 (save-excursion
1986 (goto-char (car match-cons)) 2153 (goto-char (car match-cons))
1987 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos)) 2154 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos))
1988 (error "missing 'when' between 'case' and '=>'")) 2155 (error "missing 'when' between 'case' and '=>'"))
1989 (+ (current-indentation) ada-indent))) 2156 (+ (current-indentation) ada-indent)))
2090 ;; is there an 'is' in front of point ? 2257 ;; is there an 'is' in front of point ?
2091 ;; 2258 ;;
2092 (if (save-excursion 2259 (if (save-excursion
2093 (setq match-cons 2260 (setq match-cons
2094 (ada-search-ignore-string-comment 2261 (ada-search-ignore-string-comment
2095 "\\<is\\>\\|\\<do\\>" nil orgpoint))) 2262 "\\<\\(is\\|do\\)\\>" nil orgpoint)))
2096 ;; 2263 ;;
2097 ;; yes, then skip to its end 2264 ;; yes, then skip to its end
2098 ;; 2265 ;;
2099 (progn 2266 (progn
2100 (setq foundis t) 2267 (setq foundis t)
2153 2320
2154 2321
2155 (defun ada-get-indent-noindent (orgpoint) 2322 (defun ada-get-indent-noindent (orgpoint)
2156 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2323 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2157 ;; Assumes point to be at the beginning of a 'noindent statement'. 2324 ;; Assumes point to be at the beginning of a 'noindent statement'.
2158 (if (save-excursion 2325 (let ((label 0))
2159 (ada-search-ignore-string-comment ";" nil orgpoint)) 2326 (save-excursion
2160 (current-indentation) 2327 (beginning-of-line)
2161 (+ (current-indentation) ada-broken-indent))) 2328 (if (looking-at ada-named-block-re)
2329 (setq label (- ada-label-indent))))
2330 (if (save-excursion
2331 (ada-search-ignore-string-comment ";" nil orgpoint))
2332 (+ (current-indentation) label)
2333 (+ (current-indentation) ada-broken-indent label))))
2162 2334
2163 2335
2164 (defun ada-get-indent-label (orgpoint) 2336 (defun ada-get-indent-label (orgpoint)
2165 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2337 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2166 ;; Assumes point to be at the beginning of a label or variable declaration. 2338 ;; Assumes point to be at the beginning of a label or variable declaration.
2181 ;; 2353 ;;
2182 ;; declare label 2354 ;; declare label
2183 ;; 2355 ;;
2184 ((save-excursion 2356 ((save-excursion
2185 (setq match-cons (ada-search-ignore-string-comment 2357 (setq match-cons (ada-search-ignore-string-comment
2186 "\\<declare\\>" nil orgpoint))) 2358 "\\<declare\\|begin\\>" nil orgpoint)))
2187 (save-excursion 2359 (save-excursion
2188 (goto-char (car match-cons)) 2360 (goto-char (car match-cons))
2189 (+ (current-indentation) ada-indent))) 2361 (+ (current-indentation) ada-indent)))
2190 ;; 2362 ;;
2191 ;; complete statement following colon 2363 ;; complete statement following colon
2215 (defun ada-get-indent-loop (orgpoint) 2387 (defun ada-get-indent-loop (orgpoint)
2216 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2388 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2217 ;; Assumes point to be at the beginning of a loop statement 2389 ;; Assumes point to be at the beginning of a loop statement
2218 ;; or (unfortunately) also a for ... use statement. 2390 ;; or (unfortunately) also a for ... use statement.
2219 (let ((match-cons nil) 2391 (let ((match-cons nil)
2220 (pos (point))) 2392 (pos (point))
2393 (label (save-excursion
2394 (beginning-of-line)
2395 (if (looking-at ada-named-block-re)
2396 (- ada-label-indent)
2397 0))))
2398
2221 (cond 2399 (cond
2222 2400
2223 ;; 2401 ;;
2224 ;; statement complete 2402 ;; statement complete
2225 ;; 2403 ;;
2226 ((save-excursion 2404 ((save-excursion
2227 (ada-search-ignore-string-comment ";" nil orgpoint)) 2405 (ada-search-ignore-string-comment ";" nil orgpoint))
2228 (current-indentation)) 2406 (+ (current-indentation) label))
2229 ;; 2407 ;;
2230 ;; simple loop 2408 ;; simple loop
2231 ;; 2409 ;;
2232 ((looking-at "loop\\>") 2410 ((looking-at "loop\\>")
2233 (ada-get-indent-block-start orgpoint)) 2411 (+ (ada-get-indent-block-start orgpoint) label))
2234 2412
2235 ;; 2413 ;;
2236 ;; 'for'- loop (or also a for ... use statement) 2414 ;; 'for'- loop (or also a for ... use statement)
2237 ;; 2415 ;;
2238 ((looking-at "for\\>") 2416 ((looking-at "for\\>")
2272 ;; 2450 ;;
2273 (if (not (save-excursion 2451 (if (not (save-excursion
2274 (back-to-indentation) 2452 (back-to-indentation)
2275 (looking-at "\\<loop\\>"))) 2453 (looking-at "\\<loop\\>")))
2276 (goto-char pos)) 2454 (goto-char pos))
2277 (+ (current-indentation) ada-indent)) 2455 (+ (current-indentation) ada-indent label))
2278 ;; 2456 ;;
2279 ;; for-statement is broken 2457 ;; for-statement is broken
2280 ;; 2458 ;;
2281 (t 2459 (t
2282 (+ (current-indentation) ada-broken-indent)))) 2460 (+ (current-indentation) ada-broken-indent label))))
2283 2461
2284 ;; 2462 ;;
2285 ;; 'while'-loop 2463 ;; 'while'-loop
2286 ;; 2464 ;;
2287 ((looking-at "while\\>") 2465 ((looking-at "while\\>")
2300 ;; 2478 ;;
2301 (if (not (save-excursion 2479 (if (not (save-excursion
2302 (back-to-indentation) 2480 (back-to-indentation)
2303 (looking-at "\\<loop\\>"))) 2481 (looking-at "\\<loop\\>")))
2304 (goto-char pos)) 2482 (goto-char pos))
2305 (+ (current-indentation) ada-indent)) 2483 (+ (current-indentation) ada-indent label))
2306 2484
2307 (+ (current-indentation) ada-broken-indent)))))) 2485 (+ (current-indentation) ada-broken-indent label))))))
2308 2486
2309 2487
2310 (defun ada-get-indent-type (orgpoint) 2488 (defun ada-get-indent-type (orgpoint)
2311 ;; Returns the indentation (column #) for the new line after ORGPOINT. 2489 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2312 ;; Assumes point to be at the beginning of a type statement. 2490 ;; Assumes point to be at the beginning of a type statement.
2385 ;; nothing follows => it's the end-statement directly in 2563 ;; nothing follows => it's the end-statement directly in
2386 ;; front of point => search again 2564 ;; front of point => search again
2387 ;; 2565 ;;
2388 (setq match-dat (ada-search-prev-end-stmt limit))) 2566 (setq match-dat (ada-search-prev-end-stmt limit)))
2389 ;; 2567 ;;
2390 ;; if found the correct end-stetement => goto next non-ws 2568 ;; if found the correct end-statement => goto next non-ws
2391 ;; 2569 ;;
2392 (if match-dat 2570 (if match-dat
2393 (goto-char (cdr match-dat))) 2571 (goto-char (cdr match-dat)))
2394 (ada-goto-next-non-ws)) 2572 (ada-goto-next-non-ws))
2395 2573
2416 ;; Moves point to previous end-statement. Returns a cons cell whose 2594 ;; Moves point to previous end-statement. Returns a cons cell whose
2417 ;; car is the beginning and whose cdr the end of the match. 2595 ;; car is the beginning and whose cdr the end of the match.
2418 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for 2596 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for
2419 ;; certain keywords if they follow 'end', which means they are no 2597 ;; certain keywords if they follow 'end', which means they are no
2420 ;; end-statement there. 2598 ;; end-statement there.
2421 (interactive) ;; DEBUG
2422 (let ((match-dat nil) 2599 (let ((match-dat nil)
2423 (pos nil) 2600 (pos nil)
2424 (found nil)) 2601 (found nil))
2425 ;; 2602 ;;
2426 ;; search until found or beginning-of-buffer 2603 ;; search until found or beginning-of-buffer
2431 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re 2608 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re
2432 t 2609 t
2433 limit))) 2610 limit)))
2434 2611
2435 (goto-char (car match-dat)) 2612 (goto-char (car match-dat))
2436
2437 (if (not (ada-in-open-paren-p)) 2613 (if (not (ada-in-open-paren-p))
2438 ;; 2614 ;;
2439 ;; check if there is an 'end' in front of the match 2615 ;; check if there is an 'end' in front of the match
2440 ;; 2616 ;;
2441 (if (not (and 2617 (if (not (and
2442 (looking-at "\\<\\(record\\|loop\\|select\\)\\>") 2618 (looking-at
2619 "\\<\\(record\\|loop\\|select\\|else\\|then\\)\\>")
2443 (save-excursion 2620 (save-excursion
2444 (ada-goto-previous-word) 2621 (ada-goto-previous-word)
2445 (looking-at "\\<end\\>")))) 2622 (looking-at "\\<\\(end\\|or\\|and\\)\\>"))))
2446 (setq found t) 2623 (save-excursion
2447 2624 (goto-char (cdr match-dat))
2625 (ada-goto-next-word)
2626 (if (not (looking-at "\\<\\(separate\\|new\\)\\>"))
2627 (setq found t)))
2628
2448 (forward-word -1)))) ; end of loop 2629 (forward-word -1)))) ; end of loop
2449 2630
2450 (if found 2631 (if found
2451 match-dat 2632 match-dat
2452 nil))) 2633 nil)))
2472 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit) 2653 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
2473 (point) 2654 (point)
2474 nil)) 2655 nil))
2475 2656
2476 2657
2477 (defun ada-goto-previous-word () 2658 (defun ada-goto-next-word (&optional backward)
2478 ;; Moves point to the beginning of the previous word of Ada code. 2659 ;; Moves point to the beginning of the next word of Ada code.
2660 ;; If BACKWARD is non-nil, jump to the beginning of the previous word.
2479 ;; Returns the new position of point or nil if not found. 2661 ;; Returns the new position of point or nil if not found.
2480 (let ((match-cons nil) 2662 (let ((match-cons nil)
2481 (orgpoint (point))) 2663 (orgpoint (point)))
2664 (if (not backward)
2665 (skip-chars-forward "_a-zA-Z0-9\\."))
2482 (if (setq match-cons 2666 (if (setq match-cons
2483 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)) 2667 (ada-search-ignore-string-comment "\\w" backward nil t))
2484 ;; 2668 ;;
2485 ;; move to the beginning of the word found 2669 ;; move to the beginning of the word found
2486 ;; 2670 ;;
2487 (progn 2671 (progn
2488 (goto-char (cdr match-cons)) 2672 (goto-char (car match-cons))
2489 (skip-chars-backward "_a-zA-Z0-9") 2673 (skip-chars-backward "_a-zA-Z0-9")
2490 (point)) 2674 (point))
2491 ;; 2675 ;;
2492 ;; if not found, restore old position of point 2676 ;; if not found, restore old position of point
2493 ;; 2677 ;;
2494 (progn 2678 (progn
2495 (goto-char orgpoint) 2679 (goto-char orgpoint)
2496 'nil)))) 2680 'nil))))
2681
2682
2683 (defun ada-goto-previous-word ()
2684 ;; Moves point to the beginning of the previous word of Ada code.
2685 ;; Returns the new position of point or nil if not found.
2686 (ada-goto-next-word t))
2497 2687
2498 2688
2499 (defun ada-check-matching-start (keyword) 2689 (defun ada-check-matching-start (keyword)
2500 ;; Signals an error if matching block start is not KEYWORD. 2690 ;; Signals an error if matching block start is not KEYWORD.
2501 ;; Moves point to the matching block start. 2691 ;; Moves point to the matching block start.
2508 ;; Checks if the name of the matching defun really is DEFUN-NAME. 2698 ;; Checks if the name of the matching defun really is DEFUN-NAME.
2509 ;; Assumes point to be already positioned by 'ada-goto-matching-start'. 2699 ;; Assumes point to be already positioned by 'ada-goto-matching-start'.
2510 ;; Moves point to the beginning of the declaration. 2700 ;; Moves point to the beginning of the declaration.
2511 2701
2512 ;; 2702 ;;
2513 ;; 'accept' or 'package' ? 2703 ;; named block without a `declare'
2514 ;; 2704 ;;
2515 (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>")) 2705 (if (save-excursion
2516 (ada-goto-matching-decl-start)) 2706 (ada-goto-previous-word)
2517 ;; 2707 (looking-at (concat "\\<" defun-name "\\> *:")))
2518 ;; 'begin' of 'procedure'/'function'/'task' or 'declare' 2708 t ; do nothing
2519 ;; 2709 ;;
2520 (save-excursion 2710 ;; 'accept' or 'package' ?
2521 ;; 2711 ;;
2522 ;; a named 'declare'-block ? 2712 (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>"))
2523 ;; 2713 (ada-goto-matching-decl-start))
2524 (if (looking-at "\\<declare\\>") 2714 ;;
2525 (ada-goto-stmt-start) 2715 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
2526 ;; 2716 ;;
2527 ;; no, => 'procedure'/'function'/'task'/'protected' 2717 (save-excursion
2528 ;; 2718 ;;
2529 (progn 2719 ;; a named 'declare'-block ?
2530 (forward-word 2) 2720 ;;
2531 (backward-word 1) 2721 (if (looking-at "\\<declare\\>")
2722 (ada-goto-stmt-start)
2532 ;; 2723 ;;
2533 ;; skip 'body' 'protected' 'type' 2724 ;; no, => 'procedure'/'function'/'task'/'protected'
2534 ;; 2725 ;;
2535 (if (looking-at "\\<\\(body\\|type\\)\\>") 2726 (progn
2536 (forward-word 1)) 2727 (forward-word 2)
2537 (forward-sexp 1) 2728 (backward-word 1)
2538 (backward-sexp 1))) 2729 ;;
2539 ;; 2730 ;; skip 'body' 'type'
2540 ;; should be looking-at the correct name 2731 ;;
2541 ;; 2732 (if (looking-at "\\<\\(body\\|type\\)\\>")
2542 (if (not (looking-at (concat "\\<" defun-name "\\>"))) 2733 (forward-word 1))
2543 (error "matching defun has different name: %s" 2734 (forward-sexp 1)
2544 (buffer-substring (point) 2735 (backward-sexp 1)))
2545 (progn (forward-sexp 1) (point))))))) 2736 ;;
2737 ;; should be looking-at the correct name
2738 ;;
2739 (if (not (looking-at (concat "\\<" defun-name "\\>")))
2740 (error "matching defun has different name: %s"
2741 (buffer-substring (point)
2742 (progn (forward-sexp 1) (point))))))))
2546 2743
2547 2744
2548 (defun ada-goto-matching-decl-start (&optional noerror nogeneric) 2745 (defun ada-goto-matching-decl-start (&optional noerror nogeneric)
2549 ;; Moves point to the matching declaration start of the current 'begin'. 2746 ;; Moves point to the matching declaration start of the current 'begin'.
2550 ;; If NOERROR is non-nil, it only returns nil if no match was found. 2747 ;; If NOERROR is non-nil, it only returns nil if no match was found.
2551 (interactive) ;; DEBUG
2552 (let ((nest-count 1) 2748 (let ((nest-count 1)
2553 (pos nil) 2749 (pos nil)
2554 (first t) 2750 (first t)
2555 (flag nil)) 2751 (flag nil))
2556 ;; 2752 ;;
2576 (setq nest-count (1- nest-count)) 2772 (setq nest-count (1- nest-count))
2577 (setq first nil)) 2773 (setq first nil))
2578 ;; 2774 ;;
2579 ((looking-at "is") 2775 ((looking-at "is")
2580 ;; check if it is only a type definition, but not a protected 2776 ;; check if it is only a type definition, but not a protected
2581 ;; type definition, which should be handled like a procedure. 2777 ;; type definition, which should be handled like a procedure.
2582 (if (save-excursion 2778 (if (or (looking-at "is +<>")
2583 (ada-goto-previous-word) 2779 (save-excursion
2584 (skip-chars-backward "a-zA-Z0-9_.'") 2780 (ada-goto-previous-word)
2585 (if (save-excursion 2781 (skip-chars-backward "a-zA-Z0-9_.'")
2586 (backward-char 1) 2782 (if (save-excursion
2587 (looking-at ")")) 2783 (backward-char 1)
2588 (progn 2784 (looking-at ")"))
2589 (forward-char 1) 2785 (progn
2590 (backward-sexp 1) 2786 (forward-char 1)
2591 (skip-chars-backward "a-zA-Z0-9_.'") 2787 (backward-sexp 1)
2592 )) 2788 (skip-chars-backward "a-zA-Z0-9_.'")
2593 (ada-goto-previous-word) 2789 ))
2594 (and 2790 (ada-goto-previous-word)
2595 (looking-at "\\<type\\>") 2791 (and
2596 (save-match-data 2792 (looking-at "\\<type\\>")
2597 (ada-goto-previous-word) 2793 (save-match-data
2598 (not (looking-at "\\<protected\\>")))) 2794 (ada-goto-previous-word)
2599 ); end of save-excursion 2795 (not (looking-at "\\<protected\\>"))))
2796 )); end of `or'
2600 (goto-char (match-beginning 0)) 2797 (goto-char (match-beginning 0))
2601 (progn 2798 (progn
2602 (setq nest-count (1- nest-count)) 2799 (setq nest-count (1- nest-count))
2603 (setq first nil)))) 2800 (setq first nil))))
2604 2801
2623 ;; check if declaration-start is really found 2820 ;; check if declaration-start is really found
2624 (if (not 2821 (if (not
2625 (and 2822 (and
2626 (zerop nest-count) 2823 (zerop nest-count)
2627 (not flag) 2824 (not flag)
2628 (progn 2825 (if (looking-at "is")
2629 (if (looking-at "is") 2826 (ada-search-ignore-string-comment ada-subprog-start-re t)
2630 (ada-search-ignore-string-comment 2827 (looking-at "declare\\|generic"))))
2631 ada-subprog-start-re t)
2632 (looking-at "declare\\|generic")))))
2633 (if noerror nil 2828 (if noerror nil
2634 (error "no matching proc/func/task/declare/package/protected")) 2829 (error "no matching proc/func/task/declare/package/protected"))
2635 t))) 2830 t)))
2636 2831
2637 2832
2638 (defun ada-goto-matching-start (&optional nest-level noerror gotothen) 2833 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
2639 ;; Moves point to the beginning of a block-start. Which block 2834 ;; Moves point to the beginning of a block-start. Which block
2670 (save-excursion 2865 (save-excursion
2671 ;; 2866 ;;
2672 ;; check if keyword follows 'end' 2867 ;; check if keyword follows 'end'
2673 ;; 2868 ;;
2674 (ada-goto-previous-word) 2869 (ada-goto-previous-word)
2675 (if (looking-at "\\<end\\>") 2870 (if (looking-at "\\<end\\> *[^;]")
2676 ;; it ends a block => increase nest depth 2871 ;; it ends a block => increase nest depth
2677 (progn 2872 (progn
2678 (setq nest-count (1+ nest-count)) 2873 (setq nest-count (1+ nest-count))
2679 (setq pos (point))) 2874 (setq pos (point)))
2680 ;; it starts a block => decrease nest depth 2875 ;; it starts a block => decrease nest depth
3062 (save-excursion (end-of-line) (= (point-max) (point))))) 3257 (save-excursion (end-of-line) (= (point-max) (point)))))
3063 3258
3064 3259
3065 (defun ada-in-comment-p () 3260 (defun ada-in-comment-p ()
3066 ;; Returns t if inside a comment. 3261 ;; Returns t if inside a comment.
3067 ;; (save-excursion (and (re-search-backward "\\(--\\|\n\\)" nil 1)
3068 ;; (looking-at "-"))))
3069 (nth 4 (parse-partial-sexp 3262 (nth 4 (parse-partial-sexp
3070 (save-excursion (beginning-of-line) (point)) 3263 (save-excursion (beginning-of-line) (point))
3071 (point)))) 3264 (point))))
3072
3073 3265
3074 3266
3075 (defun ada-in-string-p () 3267 (defun ada-in-string-p ()
3076 ;; Returns t if point is inside a string 3268 ;; Returns t if point is inside a string
3077 ;; (Taken from pascal-mode.el, modified by MH). 3269 ;; (Taken from pascal-mode.el, modified by MH).
3081 (save-excursion 3273 (save-excursion
3082 (beginning-of-line) 3274 (beginning-of-line)
3083 (point)) (point))) 3275 (point)) (point)))
3084 ;; check if 'string quote' is only a character constant 3276 ;; check if 'string quote' is only a character constant
3085 (progn 3277 (progn
3086 (re-search-backward "\"" nil t) ; # not a string delimiter anymore 3278 (re-search-backward "\"" nil t) ; `#' is not taken as a string delimiter
3087 (not (= (char-after (1- (point))) ?')))))) 3279 (not (= (char-after (1- (point))) ?'))))))
3088 3280
3089 3281
3090 (defun ada-in-string-or-comment-p () 3282 (defun ada-in-string-or-comment-p ()
3091 ;; Returns t if point is inside a string or a comment. 3283 ;; Returns t if point is inside a string, a comment, or a character constant.
3092 (or (ada-in-comment-p) 3284 (let ((parse-result (parse-partial-sexp
3093 (ada-in-string-p))) 3285 (save-excursion (beginning-of-line) (point)) (point))))
3286 (or ;; in-comment-p
3287 (nth 4 parse-result)
3288 ;; in-string-p
3289 (and
3290 (nth 3 parse-result)
3291 ;; check if 'string quote' is only a character constant
3292 (progn
3293 (re-search-backward "\"" nil t) ; `#' not regarded a string delimiter
3294 (not (= (char-after (1- (point))) ?'))))
3295 ;; in-char-const-p
3296 (ada-in-char-const-p))))
3094 3297
3095 3298
3096 (defun ada-in-paramlist-p () 3299 (defun ada-in-paramlist-p ()
3097 ;; Returns t if point is inside a parameter-list 3300 ;; Returns t if point is inside a parameter-list
3098 ;; following 'function'/'procedure'/'package'. 3301 ;; following 'function'/'procedure'/'package'.
3115 ;; not really a boolean function ... 3318 ;; not really a boolean function ...
3116 (defun ada-in-open-paren-p () 3319 (defun ada-in-open-paren-p ()
3117 ;; If point is somewhere behind an open parenthesis not yet closed, 3320 ;; If point is somewhere behind an open parenthesis not yet closed,
3118 ;; it returns the column # of the first non-ws behind this open 3321 ;; it returns the column # of the first non-ws behind this open
3119 ;; parenthesis, otherwise nil." 3322 ;; parenthesis, otherwise nil."
3120 3323 (let ((start (if (<= (point) ada-search-paren-char-count-limit)
3121 (let ((start (if (< (point) ada-search-paren-char-count-limit) 3324 (point-min)
3122 1 3325 (save-excursion
3123 (- (point) ada-search-paren-char-count-limit))) 3326 (goto-char (- (point) ada-search-paren-char-count-limit))
3327 (beginning-of-line)
3328 (point))))
3124 parse-result 3329 parse-result
3125 (col nil)) 3330 (col nil))
3126 (setq parse-result (parse-partial-sexp start (point))) 3331 (setq parse-result (parse-partial-sexp start (point)))
3127 (if (nth 1 parse-result) 3332 (if (nth 1 parse-result)
3128 (save-excursion 3333 (save-excursion
3167 ((eq ada-tab-policy 'always-tab) (error "not implemented")) 3372 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3168 )) 3373 ))
3169 3374
3170 3375
3171 (defun ada-indent-current-function () 3376 (defun ada-indent-current-function ()
3172 "Ada Mode version of the indent-line-function." 3377 "Ada mode version of the indent-line-function."
3173 (interactive "*") 3378 (interactive "*")
3174 (let ((starting-point (point-marker))) 3379 (let ((starting-point (point-marker)))
3175 (ada-beginning-of-line) 3380 (ada-beginning-of-line)
3176 (ada-tab) 3381 (ada-tab)
3177 (if (< (point) starting-point) 3382 (if (< (point) starting-point)
3207 "remove trailing spaces in the whole buffer." 3412 "remove trailing spaces in the whole buffer."
3208 (interactive) 3413 (interactive)
3209 (save-match-data 3414 (save-match-data
3210 (save-excursion 3415 (save-excursion
3211 (save-restriction 3416 (save-restriction
3212 (widen) 3417 (widen)
3213 (goto-char (point-min)) 3418 (goto-char (point-min))
3214 (while (re-search-forward "[ \t]+$" (point-max) t) 3419 (while (re-search-forward "[ \t]+$" (point-max) t)
3215 (replace-match "" nil nil)))))) 3420 (replace-match "" nil nil))))))
3216 3421
3217 3422
3218 (defun ada-untabify-buffer () 3423 (defun ada-untabify-buffer ()
3219 ;; change all tabs to spaces 3424 ;; change all tabs to spaces
3220 (save-excursion 3425 (save-excursion
3221 (untabify (point-min) (point-max)))) 3426 (untabify (point-min) (point-max))
3427 nil))
3222 3428
3223 3429
3224 (defun ada-uncomment-region (beg end) 3430 (defun ada-uncomment-region (beg end)
3225 "delete `comment-start' at the beginning of a line in the region." 3431 "delete `comment-start' at the beginning of a line in the region."
3226 (interactive "r") 3432 (interactive "r")
3231 (defun ada-ff-other-window () 3437 (defun ada-ff-other-window ()
3232 "Find other file in other window using `ff-find-other-file'." 3438 "Find other file in other window using `ff-find-other-file'."
3233 (interactive) 3439 (interactive)
3234 (and (fboundp 'ff-find-other-file) 3440 (and (fboundp 'ff-find-other-file)
3235 (ff-find-other-file t))) 3441 (ff-find-other-file t)))
3442
3443 ;; inspired by Laurent.GUERBY@enst-bretagne.fr
3444 (defun ada-gnat-style ()
3445 "Clean up comments, `(' and `,' for GNAT style checking switch."
3446 (interactive)
3447 (save-excursion
3448 (goto-char (point-min))
3449 (while (re-search-forward "-- ?\\([^ -]\\)" nil t)
3450 (replace-match "-- \\1"))
3451 (goto-char (point-min))
3452 (while (re-search-forward "\\>(" nil t)
3453 (replace-match " ("))
3454 (goto-char (point-min))
3455 (while (re-search-forward ",\\<" nil t)
3456 (replace-match ", "))
3457 ))
3458
3236 3459
3237 3460
3238 ;;;-------------------------------;;; 3461 ;;;-------------------------------;;;
3239 ;;; Moving To Procedures/Packages ;;; 3462 ;;; Moving To Procedures/Packages ;;;
3240 ;;;-------------------------------;;; 3463 ;;;-------------------------------;;;
3302 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start) 3525 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3303 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end) 3526 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3304 3527
3305 ;; Compilation 3528 ;; Compilation
3306 (define-key ada-mode-map "\C-c\C-c" 'compile) 3529 (define-key ada-mode-map "\C-c\C-c" 'compile)
3530 (define-key ada-mode-map "\C-c\C-v" 'ada-check-syntax)
3531 (define-key ada-mode-map "\C-c\C-m" 'ada-make-local)
3307 3532
3308 ;; Casing 3533 ;; Casing
3309 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region) 3534 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region)
3310 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer) 3535 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3311 3536
3537 (define-key ada-mode-map "\177" 'backward-delete-char-untabify)
3538
3312 ;; Use predefined function of emacs19 for comments (RE) 3539 ;; Use predefined function of emacs19 for comments (RE)
3313 (define-key ada-mode-map "\C-c;" 'comment-region) 3540 (define-key ada-mode-map "\C-c;" 'comment-region)
3314 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region) 3541 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
3315 3542
3316 ;; Change basic functionality 3543 ;; Change basic functionality
3317 3544
3318 ;; `substitute-key-definition' is not defined equally in GNU Emacs 3545 ;; `substitute-key-definition' is not defined equally in Emacs
3319 ;; and XEmacs, you cannot put in an optional 4th parameter in 3546 ;; and XEmacs, you cannot put in an optional 4th parameter in
3320 ;; XEmacs. I don't think it's necessary, so I leave it out for 3547 ;; XEmacs. I don't think it's necessary, so I leave it out for
3321 ;; GNU Emacs as well. If you encounter any problems with the 3548 ;; Emacs as well. If you encounter any problems with the
3322 ;; following three functions, please tell me. RE 3549 ;; following three functions, please tell me. RE
3323 (mapcar (function (lambda (pair) 3550 (mapcar (function (lambda (pair)
3324 (substitute-key-definition (car pair) (cdr pair) 3551 (substitute-key-definition (car pair) (cdr pair)
3325 ada-mode-map))) 3552 ada-mode-map)))
3326 '((beginning-of-line . ada-beginning-of-line) 3553 '((beginning-of-line . ada-beginning-of-line)
3327 (end-of-line . ada-end-of-line) 3554 (end-of-line . ada-end-of-line)
3328 (forward-to-indentation . ada-forward-to-indentation) 3555 (forward-to-indentation . ada-forward-to-indentation)
3329 )) 3556 ))
3330 ;; else GNU Emacs 3557 ;; else Emacs
3331 ;;(mapcar (lambda (pair) 3558 ;;(mapcar (lambda (pair)
3332 ;; (substitute-key-definition (car pair) (cdr pair) 3559 ;; (substitute-key-definition (car pair) (cdr pair)
3333 ;; ada-mode-map global-map)) 3560 ;; ada-mode-map global-map))
3334 3561
3335 )) 3562 ))
3340 ;;;------------------- 3567 ;;;-------------------
3341 3568
3342 (require 'easymenu) 3569 (require 'easymenu)
3343 3570
3344 (defun ada-add-ada-menu () 3571 (defun ada-add-ada-menu ()
3345 "Adds the menu 'Ada' to the menu bar in Ada Mode." 3572 "Adds the menu 'Ada' to the menu bar in Ada mode."
3346 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode." 3573 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode."
3347 '("Ada" 3574 '("Ada"
3348 ["Next Package" ada-next-package t] 3575 ["Next Package" ada-next-package t]
3349 ["Previous Package" ada-previous-package t] 3576 ["Previous Package" ada-previous-package t]
3350 ["Next Procedure" ada-next-procedure t] 3577 ["Next Procedure" ada-next-procedure t]
3369 ["Adjust Case Buffer" ada-adjust-case-buffer t] 3596 ["Adjust Case Buffer" ada-adjust-case-buffer t]
3370 ["----------" nil nil] 3597 ["----------" nil nil]
3371 ["Comment Region" comment-region t] 3598 ["Comment Region" comment-region t]
3372 ["Uncomment Region" ada-uncomment-region t] 3599 ["Uncomment Region" ada-uncomment-region t]
3373 ["----------------" nil nil] 3600 ["----------------" nil nil]
3374 ["Compile" compile (fboundp 'compile)] 3601 ["Global Make" compile (fboundp 'compile)]
3602 ["Local Make" ada-make-local t]
3603 ["Check Syntax" ada-check-syntax t]
3375 ["Next Error" next-error (fboundp 'next-error)] 3604 ["Next Error" next-error (fboundp 'next-error)]
3376 ["---------------" nil nil] 3605 ["---------------" nil nil]
3377 ["Index" imenu (fboundp 'imenu)] 3606 ["Index" imenu (fboundp 'imenu)]
3378 ["--------------" nil nil] 3607 ["--------------" nil nil]
3379 ["Other File Other Window" ada-ff-other-window 3608 ["Other File Other Window" ada-ff-other-window
3380 (fboundp 'ff-find-other-file)] 3609 (fboundp 'ff-find-other-file)]
3381 ["Other File" ff-find-other-file 3610 ["Other File" ff-find-other-file
3382 (fboundp 'ff-find-other-file)])) 3611 (fboundp 'ff-find-other-file)]))
3383 (if (ada-xemacs) (progn 3612 (if (ada-xemacs) (progn
3384 (easy-menu-add ada-mode-menu) 3613 (easy-menu-add ada-mode-menu)
3385 (setq mode-popup-menu (cons "Ada Mode" ada-mode-menu))))) 3614 (setq mode-popup-menu (cons "Ada mode" ada-mode-menu)))))
3386 3615
3387 3616
3388 3617
3389 ;;;------------------------------- 3618 ;;;-------------------------------
3390 ;;; Define Some Support Functions 3619 ;;; Define Some Support Functions
3416 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg)) 3645 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg))
3417 (t (forward-to-indentation arg)) 3646 (t (forward-to-indentation arg))
3418 )) 3647 ))
3419 3648
3420 ;;;--------------------------------------------------- 3649 ;;;---------------------------------------------------
3421 ;;; support for find-file 3650 ;;; support for find-file.el
3422 ;;;--------------------------------------------------- 3651 ;;;---------------------------------------------------
3423 3652
3424 3653
3425 ;;;###autoload 3654 ;;;###autoload
3426 (defun ada-make-filename-from-adaname (adaname) 3655 (defun ada-make-filename-from-adaname (adaname)
3427 "Determine the filename of a package/procedure from its own Ada name." 3656 "Determine the filename of a package/procedure from its own Ada name."
3428 ;; this is done simply by calling gkrunch, when we work with GNAT. It 3657 ;; this is done simply by calling `gnatkr', when we work with GNAT. It
3429 ;; must be a more complex function in other compiler environments. 3658 ;; must be a more complex function in other compiler environments.
3430 (interactive "s") 3659 (interactive "s")
3431
3432 ;; things that should really be done by the external process
3433 ;; since gnat-2.0, gnatk8 can do these things. If you still use a
3434 ;; previous version, just uncomment the following lines.
3435 (let (krunch-buf) 3660 (let (krunch-buf)
3436 (setq krunch-buf (generate-new-buffer "*gkrunch*")) 3661 (setq krunch-buf (generate-new-buffer "*gkrunch*"))
3437 (save-excursion 3662 (save-excursion
3438 (set-buffer krunch-buf) 3663 (set-buffer krunch-buf)
3439 ; (insert (downcase adaname)) 3664 ;; send adaname to external process `gnatkr'.
3440 ; (goto-char (point-min)) 3665 (call-process "gnatkr" nil krunch-buf nil
3441 ; (while (search-forward "." nil t)
3442 ; (replace-match "-" nil t))
3443 ; (setq adaname (buffer-substring (point-min)
3444 ; (progn
3445 ; (goto-char (point-min))
3446 ; (end-of-line)
3447 ; (point))))
3448 ; ;; clean the buffer
3449 ; (delete-region (point-min) (point-max))
3450 ;; send adaname to external process "gnatk8"
3451 (call-process "gnatk8" nil krunch-buf nil
3452 adaname ada-krunch-args) 3666 adaname ada-krunch-args)
3453 ;; fetch output of that process 3667 ;; fetch output of that process
3454 (setq adaname (buffer-substring 3668 (setq adaname (buffer-substring
3455 (point-min) 3669 (point-min)
3456 (progn 3670 (progn
3479 (match-end 0))) 3693 (match-end 0)))
3480 )))) 3694 ))))
3481 3695
3482 3696
3483 ;;;--------------------------------------------------- 3697 ;;;---------------------------------------------------
3484 ;;; support for imenu
3485 ;;;---------------------------------------------------
3486
3487 (defun imenu-create-ada-index (&optional regexp)
3488 "Create index alist for Ada files."
3489 (let ((index-alist '())
3490 prev-pos char)
3491 (goto-char (point-min))
3492 ;(imenu-progress-message prev-pos 0)
3493 ;; Search for functions/procedures
3494 (save-match-data
3495 (while (re-search-forward
3496 (or regexp ada-procedure-start-regexp)
3497 nil t)
3498 ;(imenu-progress-message prev-pos)
3499 ;; do not store forward definitions
3500 ;; right now we store them. We want to avoid them only in
3501 ;; package bodies, not in the specs!! ???RE???
3502 (save-match-data
3503 ; (if (not (looking-at (concat
3504 ; "[ \t\n]*" ; WS
3505 ; "\([^)]+\)" ; parameterlist
3506 ; "\\([ \n\t]+return[ \n\t]+"; potential return
3507 ; "[a-zA-Z0-9_\\.]+\\)?"
3508 ; "[ \t]*" ; WS
3509 ; ";" ;; THIS is what we really look for
3510 ; )))
3511 ; ; (push (imenu-example--name-and-position) index-alist)
3512 (setq index-alist (cons (imenu-example--name-and-position)
3513 index-alist))
3514 ; )
3515 )
3516 ;(imenu-progress-message 100)
3517 ))
3518 (nreverse index-alist)))
3519
3520 ;;;---------------------------------------------------
3521 ;;; support for font-lock 3698 ;;; support for font-lock
3522 ;;;--------------------------------------------------- 3699 ;;;---------------------------------------------------
3523 3700
3524 ;; Strings are a real pain in Ada because both ' and " can appear in a 3701 ;; Strings are a real pain in Ada because a single quote character is
3525 ;; non-string quote context (the former as an operator, the latter as 3702 ;; overloaded as a string quote and type/instance delimiter. By default, a
3526 ;; a character string). We follow the least losing solution, in which 3703 ;; single quote is given punctuation syntax in `ada-mode-syntax-table'.
3527 ;; only " is a string quote. Therefore a character string of the form 3704 ;; So, for Font Lock mode purposes, we mark single quotes as having string
3528 ;; '"' will throw fontification off on the wrong track. 3705 ;; syntax when the gods that created Ada determine them to be. sm.
3706
3707 (defconst ada-font-lock-syntactic-keywords
3708 ;; Mark single quotes as having string quote syntax in 'c' instances.
3709 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\')))))
3529 3710
3530 (defconst ada-font-lock-keywords-1 3711 (defconst ada-font-lock-keywords-1
3531 (list 3712 (list
3713 ;;
3714 ;; handle "type T is access function return S;"
3715 ;;
3716 (list "\\<\\(function[ \t]+return\\)\\>" '(1 font-lock-keyword-face) )
3532 ;; 3717 ;;
3533 ;; accept, entry, function, package (body), protected (body|type), 3718 ;; accept, entry, function, package (body), protected (body|type),
3534 ;; pragma, procedure, task (body) plus name. 3719 ;; pragma, procedure, task (body) plus name.
3535 (list (concat 3720 (list (concat
3536 "\\<\\(" 3721 "\\<\\("
3537 "accept\\|" 3722 "accept\\|"
3538 "entry\\|" 3723 "entry\\|"
3539 "function\\|" 3724 "function\\|"
3540 "package[ \t]+body\\|" 3725 "package[ \t]+body\\|"
3541 "package\\|" 3726 "package\\|"
3542 "pragma\\|" 3727 "pragma\\|"
3543 "procedure\\|" 3728 "procedure\\|"
3544 "protected[ \t]+body\\|" 3729 "protected[ \t]+body\\|"
3545 "protected[ \t]+type\\|" 3730 "protected[ \t]+type\\|"
3546 "protected\\|" 3731 "protected\\|"
3547 ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\ 3732 ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\
3548 ;;\\|r\\(agma\\|ocedure\\)\\)\\|" 3733 ;;\\|r\\(agma\\|ocedure\\)\\)\\|"
3549 "task\\|"
3550 "task[ \t]+body\\|" 3734 "task[ \t]+body\\|"
3551 "task[ \t]+type" 3735 "task[ \t]+type\\|"
3736 "task"
3552 ;; "task\\(\\|[ \t]+body\\)" 3737 ;; "task\\(\\|[ \t]+body\\)"
3553 "\\)\\>[ \t]*" 3738 "\\)\\>[ \t]*"
3554 "\\(\\sw+\\(\\.\\sw*\\)*\\)?") 3739 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
3555 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t))) 3740 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t)))
3556 "Subdued level highlighting for Ada mode.") 3741 "Subdued level highlighting for Ada mode.")
3573 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|" 3758 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|"
3574 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|" 3759 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|"
3575 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|" 3760 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|"
3576 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|" 3761 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|"
3577 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|" 3762 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|"
3578 "r\\(ange\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|" 3763 "r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|"
3579 "se\\(lect\\|parate\\)\\|" 3764 "se\\(lect\\|parate\\)\\|"
3580 "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed 3765 "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed
3581 "wh\\(ile\\|en\\)\\|xor" ; "when" added 3766 "wh\\(ile\\|en\\)\\|xor" ; "when" added
3582 "\\)\\>") 3767 "\\)\\>")
3583 ;; 3768 ;;
3584 ;; Anything following end and not already fontified is a body name. 3769 ;; Anything following end and not already fontified is a body name.
3585 '("\\<\\(end\\)\\>[ \t]+\\([a-zA-Z0-9_\\.]+\\)?" 3770 '("\\<\\(end\\)\\>\\([ \t]+\\)?\\([a-zA-Z0-9_\\.]+\\)?"
3586 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) 3771 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
3587 ;; 3772 ;;
3588 ;; Variable name plus optional keywords followed by a type name. Slow. 3773 ;; Variable name plus optional keywords followed by a type name. Slow.
3589 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*" 3774 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*"
3590 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*" 3775 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*"
3591 ; "\\(\\sw+\\)?") 3776 ; "\\(\\sw+\\)?")
3592 ; '(1 font-lock-variable-name-face) 3777 ; '(1 font-lock-variable-name-face)
3593 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t)) 3778 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t))
3594 ;; 3779 ;;
3595 ;; Optional keywords followed by a type name. 3780 ;; Optional keywords followed by a type name.
3596 (list (concat ; ":[ \t]*" 3781 (list (concat ; ":[ \t]*"
3597 "\\<\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)\\>" 3782 "\\<\\(access\\|constant\\|in[ \t]+out\\|in\\|out\\)\\>"
3598 "[ \t]*" 3783 "[ \t]*"
3599 "\\(\\sw+\\)?") 3784 "\\(\\sw+\\)?")
3600 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t)) 3785 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
3601 ;; 3786 ;;
3602 ;; Keywords followed by a type or function name. 3787 ;; Keywords followed by a type or function name.
3617 ;; Goto tags. 3802 ;; Goto tags.
3618 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face) 3803 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
3619 )) 3804 ))
3620 "Gaudy level highlighting for Ada mode.") 3805 "Gaudy level highlighting for Ada mode.")
3621 3806
3622 ;; XEmacs change 3807 (defvar ada-font-lock-keywords ada-font-lock-keywords-1
3623 (defvar ada-font-lock-keywords (if font-lock-maximum-decoration 3808 "Default expressions to highlight in Ada mode.")
3624 ada-font-lock-keywords-2 3809
3625 ada-font-lock-keywords-1) 3810
3626 "Default Expressions to highlight in Ada mode. 3811 ;; set font-lock properties for XEmacs
3627 See the doc to `font-lock-maximum-decoration' for user configuration.") 3812 (if (ada-xemacs)
3628 3813 (put 'ada-mode 'font-lock-defaults
3629 ;; XEmacs change 3814 '(ada-font-lock-keywords
3630 (put 'ada-mode 'font-lock-defaults 3815 nil t ((?\_ . "w")(?\. . "w")) beginning-of-line)))
3631 '(ada-font-lock-keywords nil t ((?\_ . "w"))))
3632 3816
3633 ;;; 3817 ;;;
3634 ;;; ???? 3818 ;;; support for outline
3819 ;;;
3820
3821 ;; used by outline-minor-mode
3822 (defun ada-outline-level ()
3823 (save-excursion
3824 (skip-chars-forward "\t ")
3825 (current-column)))
3826
3827 ;;;
3828 ;;; generate body
3635 ;;; 3829 ;;;
3636 (defun ada-gen-comment-until-proc () 3830 (defun ada-gen-comment-until-proc ()
3637 ;; comment until spec of a procedure or a function. 3831 ;; comment until spec of a procedure or a function.
3638 (forward-line 1) 3832 (forward-line 1)
3639 (set-mark-command (point)) 3833 (set-mark-command (point))