1 ;; @(#) ada-mode.el --- major-mode for editing Ada source.
3 ;; Copyright (C) 1994, 95, 97, 98, 99, 2000 Free Software Foundation, Inc.
5 ;; Author: Rolf Ebert <ebert@inf.enst.fr>
6 ;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
7 ;; Emmanuel Briot <briot@gnat.com>
8 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
9 ;; Ada Core Technologies's version: $Revision: 1.38 $
10 ;; Keywords: languages ada
12 ;; This file is not part of GNU Emacs
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;; This mode is a major mode for editing Ada83 and Ada95 source code.
30 ;;; This is a major rewrite of the file packaged with Emacs-20. The
31 ;;; ada-mode is composed of four lisp file, ada-mode.el, ada-xref.el,
32 ;;; ada-prj.el and ada-stmt.el. Only this file (ada-mode.el) is
33 ;;; completely independent from the GNU Ada compiler Gnat, distributed
34 ;;; by Ada Core Technologies. All the other files rely heavily on
35 ;;; features provides only by Gnat.
37 ;;; Note: this mode will not work with Emacs 19. If you are on a VMS
38 ;;; system, where the latest version of Emacs is 19.28, you will need
39 ;;; another file, called ada-vms.el, that provides some required
43 ;;; Emacs should enter Ada mode automatically when you load an Ada file.
44 ;;; By default, the valid extensions for Ada files are .ads, .adb or .ada
45 ;;; If the ada-mode does not start automatically, then simply type the
46 ;;; following command :
49 ;;; By default, ada-mode is configured to take full advantage of the GNAT
50 ;;; compiler (the menus will include the cross-referencing features,...).
51 ;;; If you are using another compiler, you might want to set the following
52 ;;; variable in your .emacs (Note: do not set this in the ada-mode-hook, it
54 ;;; (setq ada-which-compiler 'generic)
56 ;;; This mode requires find-file.el to be present on your system.
59 ;;; The first Ada mode for GNU Emacs was written by V. Broman in
60 ;;; 1985. He based his work on the already existing Modula-2 mode.
61 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29.
63 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of
64 ;;; several files with support for dired commands and other nice
65 ;;; things. It is currently available from the PAL
66 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z.
68 ;;; The probably very first Ada mode (called electric-ada.el) was
69 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
70 ;;; Gosling Emacs. L. Slater based his development on ada.el and
73 ;;; A complete rewrite by M. Heritsch and R. Ebert has been done.
74 ;;; Some ideas from the Ada mode mailing list have been
75 ;;; added. Some of the functionality of L. Slater's mode has not
76 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
79 ;;; A complete rewrite for Emacs-20 / Gnat-3.11 has been done by Ada Core
80 ;;; Technologies. Please send bugs to briot@gnat.com
83 ;;; Many thanks to John McCabe <john@assen.demon.co.uk> for sending so
84 ;;; many patches included in this package.
85 ;;; Christian Egli <Christian.Egli@hcsd.hac.com>:
86 ;;; ada-imenu-generic-expression
87 ;;; Many thanks also to the following persons that have contributed one day
89 ;;; Philippe Waroquiers (PW) <philippe@cfmu.eurocontrol.be> in particular,
90 ;;; woodruff@stc.llnl.gov (John Woodruff)
91 ;;; jj@ddci.dk (Jesper Joergensen)
92 ;;; gse@ocsystems.com (Scott Evans)
93 ;;; comar@gnat.com (Cyrille Comar)
94 ;;; stephen.leake@gsfc.nasa.gov (Stephen Leake)
95 ;;; and others for their valuable hints.
98 ;;; Note: Every function in this package is compiler-independent.
99 ;;; The names start with ada-
100 ;;; The variables that the user can edit can all be modified through
101 ;;; the customize mode. They are sorted in alphabetical order in this
105 ;; this function is needed at compile time
107 (defun ada-check-emacs-version (major minor
&optional is-xemacs
)
108 "Returns t if Emacs's version is greater or equal to MAJOR.MINOR.
109 If IS-XEMACS is non-nil, check for XEmacs instead of Emacs."
110 (let ((xemacs-running (or (string-match "Lucid" emacs-version
)
111 (string-match "XEmacs" emacs-version
))))
112 (and (or (and is-xemacs xemacs-running
)
113 (not (or is-xemacs xemacs-running
)))
114 (or (> emacs-major-version major
)
115 (and (= emacs-major-version major
)
116 (>= emacs-minor-version minor
)))))))
119 ;; We create a constant for that, for efficiency only
120 ;; This should be evaluated both at compile time, only a runtime
122 (defconst ada-xemacs
(and (boundp 'running-xemacs
)
123 (symbol-value 'running-xemacs
))
124 "Return t if we are using XEmacs."))
130 (condition-case nil
(require 'find-file
) (error nil
)))
132 ;; This call should not be made in the release that is done for the
133 ;; official FSF Emacs, since it does nothing useful for the latest version
134 ;; (require 'ada-support)
136 (defvar ada-mode-hook nil
137 "*List of functions to call when Ada mode is invoked.
138 This hook is automatically executed after the ada-mode is
140 This is a good place to add Ada environment specific bindings.")
143 "Major mode for editing Ada source in Emacs."
146 (defcustom ada-auto-case t
147 "*Non-nil means automatically change case of preceding word while typing.
148 Casing is done according to `ada-case-keyword', `ada-case-identifier'
149 and `ada-case-attribute'."
150 :type
'boolean
:group
'ada
)
152 (defcustom ada-broken-decl-indent
0
153 "*Number of columns to indent a broken declaration.
158 >>>>>B : Integer; -- from ada-broken-decl-indent"
159 :type
'integer
:group
'ada
)
161 (defcustom ada-broken-indent
2
162 "*Number of columns to indent the continuation of a broken line.
165 My_Var : My_Type := (Field1 =>
166 >>>>>>>>>Value); -- from ada-broken-indent"
167 :type
'integer
:group
'ada
)
169 (defcustom ada-case-attribute
'ada-capitalize-word
170 "*Function to call to adjust the case of Ada attributes.
171 It may be `downcase-word', `upcase-word', `ada-loose-case-word',
172 `ada-capitalize-word' or `ada-no-auto-case'."
173 :type
'(choice (const downcase-word
)
175 (const ada-capitalize-word
)
176 (const ada-loose-case-word
)
177 (const ada-no-auto-case
))
180 (defcustom ada-case-exception-file
'("~/.emacs_case_exceptions")
181 "*List of special casing exceptions dictionaries for identifiers.
182 The first file is the one where new exceptions will be saved by Emacs
183 when you call `ada-create-case-exception'.
185 These files should contain one word per line, that gives the casing
186 to be used for that word in Ada files. Each line can be terminated by
188 :type
'(repeat (file))
191 (defcustom ada-case-keyword
'downcase-word
192 "*Function to call to adjust the case of an Ada keywords.
193 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
194 `ada-capitalize-word'."
195 :type
'(choice (const downcase-word
)
197 (const ada-capitalize-word
)
198 (const ada-loose-case-word
)
199 (const ada-no-auto-case
))
202 (defcustom ada-case-identifier
'ada-loose-case-word
203 "*Function to call to adjust the case of an Ada identifier.
204 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
205 `ada-capitalize-word'."
206 :type
'(choice (const downcase-word
)
208 (const ada-capitalize-word
)
209 (const ada-loose-case-word
)
210 (const ada-no-auto-case
))
213 (defcustom ada-clean-buffer-before-saving t
214 "*Non-nil means remove trailing spaces and untabify the buffer before saving."
215 :type
'boolean
:group
'ada
)
217 (defcustom ada-indent
3
218 "*Size of Ada indentation.
223 >>>>>>>>>>null; -- from ada-indent"
224 :type
'integer
:group
'ada
)
226 (defcustom ada-indent-after-return t
227 "*Non-nil means automatically indent after RET or LFD."
228 :type
'boolean
:group
'ada
)
230 (defcustom ada-indent-align-comments t
231 "*Non-nil means align comments on previous line comments, if any.
232 If nil, indentation is calculated as usual.
233 Note that indentation is calculated only if `ada-indent-comment-as-code' is t.
236 A := 1; -- A multi-line comment
237 -- aligned if ada-indent-align-comments is t"
238 :type
'boolean
:group
'ada
)
240 (defcustom ada-indent-comment-as-code t
241 "*Non-nil means indent comment lines as code.
242 Nil means do not auto-indent comments."
243 :type
'boolean
:group
'ada
)
245 (defcustom ada-indent-is-separate t
246 "*Non-nil means indent 'is separate' or 'is abstract' if on a single line."
247 :type
'boolean
:group
'ada
)
249 (defcustom ada-indent-record-rel-type
3
250 "*Indentation for 'record' relative to 'type' or 'use'.
254 >>>>>>>>>>>record -- from ada-indent-record-rel-type"
255 :type
'integer
:group
'ada
)
257 (defcustom ada-indent-renames ada-broken-indent
258 "*Indentation for renames relative to the matching function statement.
259 If ada-indent-return is null or negative, the indentation is done relative to
260 the open parenthesis (if there is no parenthesis, ada-broken-indent is used).
263 function A (B : Integer)
264 return C; -- from ada-indent-return
265 >>>renames Foo; -- from ada-indent-renames"
266 :type
'integer
:group
'ada
)
268 (defcustom ada-indent-return
0
269 "*Indentation for 'return' relative to the matching 'function' statement.
270 If ada-indent-return is null or negative, the indentation is done relative to
271 the open parenthesis (if there is no parenthesis, ada-broken-indent is used).
274 function A (B : Integer)
275 >>>>>return C; -- from ada-indent-return"
276 :type
'integer
:group
'ada
)
278 (defcustom ada-indent-to-open-paren t
279 "*Non-nil means indent according to the innermost open parenthesis."
280 :type
'boolean
:group
'ada
)
282 (defcustom ada-fill-comment-prefix
"-- "
283 "*Text inserted in the first columns when filling a comment paragraph.
284 Note: if you modify this variable, you will have to restart the ada-mode to
285 reread this variable."
286 :type
'string
:group
'ada
)
288 (defcustom ada-fill-comment-postfix
" --"
289 "*Text inserted at the end of each line when filling a comment paragraph.
290 with `ada-fill-comment-paragraph-postfix'."
291 :type
'string
:group
'ada
)
293 (defcustom ada-label-indent -
4
294 "*Number of columns to indent a label.
299 >>>>>>>>>>>>Label: -- from ada-label-indent"
300 :type
'integer
:group
'ada
)
302 (defcustom ada-language-version
'ada95
303 "*Do we program in `ada83' or `ada95'?"
304 :type
'(choice (const ada83
) (const ada95
)) :group
'ada
)
306 (defcustom ada-move-to-declaration nil
307 "*Non-nil means `ada-move-to-start' moves point to the subprogram declaration,
309 :type
'boolean
:group
'ada
)
311 (defcustom ada-popup-key
'[down-mouse-3
]
312 "*Key used for binding the contextual menu.
313 If nil, no contextual menu is available."
314 :type
'(restricted-sexp :match-alternatives
(stringp vectorp
))
317 (defcustom ada-search-directories
318 '("." "$ADA_INCLUDE_PATH" "/usr/adainclude" "/usr/local/adainclude"
319 "/opt/gnu/adainclude")
320 "*List of directories to search for Ada files.
321 See the description for the `ff-search-directories' variable.
322 Emacs will automatically add the paths defined in your project file, and if you
323 are using the GNAT compiler the output of the gnatls command to find where the
325 :type
'(repeat (choice :tag
"Directory"
326 (const :tag
"default" nil
)
327 (directory :format
"%v")))
330 (defcustom ada-stmt-end-indent
0
331 "*Number of columns to indent the end of a statement on a separate line.
335 >>>>>>>>>>>then -- from ada-stmt-end-indent"
336 :type
'integer
:group
'ada
)
338 (defcustom ada-tab-policy
'indent-auto
339 "*Control the behavior of the TAB key.
341 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line.
342 `indent-auto' : use indentation functions in this file.
343 `always-tab' : do indent-relative."
344 :type
'(choice (const indent-auto
)
345 (const indent-rigidly
)
349 (defcustom ada-use-indent ada-broken-indent
350 "*Indentation for the lines in a 'use' statement.
354 >>>>>Ada.Numerics; -- from ada-use-indent"
355 :type
'integer
:group
'ada
)
357 (defcustom ada-when-indent
3
358 "*Indentation for 'when' relative to 'exception' or 'case'.
362 >>>>>>>>when B => -- from ada-when-indent"
363 :type
'integer
:group
'ada
)
365 (defcustom ada-with-indent ada-broken-indent
366 "*Indentation for the lines in a 'with' statement.
370 >>>>>Ada.Numerics; -- from ada-with-indent"
371 :type
'integer
:group
'ada
)
373 (defcustom ada-which-compiler
'gnat
374 "*Name of the compiler to use.
375 This will determine what features are made available through the ada-mode.
376 The possible choices are :
377 `gnat': Use Ada Core Technologies' Gnat compiler. Add some cross-referencing
379 `generic': Use a generic compiler"
380 :type
'(choice (const gnat
)
385 ;;; ---- end of user configurable variables
388 (defvar ada-body-suffixes
'(".adb")
389 "List of possible suffixes for Ada body files.
390 The extensions should include a `.' if needed.")
392 (defvar ada-spec-suffixes
'(".ads")
393 "List of possible suffixes for Ada spec files.
394 The extensions should include a `.' if needed.")
396 (defvar ada-mode-menu
(make-sparse-keymap "Ada")
397 "Menu for ada-mode.")
399 (defvar ada-mode-map
(make-sparse-keymap)
400 "Local keymap used for Ada mode.")
402 (defvar ada-mode-abbrev-table nil
403 "Local abbrev table for Ada mode.")
405 (defvar ada-mode-syntax-table nil
406 "Syntax table to be used for editing Ada source code.")
408 (defvar ada-mode-symbol-syntax-table nil
409 "Syntax table for Ada, where `_' is a word constituent.")
412 (defconst ada-83-string-keywords
413 '("abort" "abs" "accept" "access" "all" "and" "array" "at" "begin"
414 "body" "case" "constant" "declare" "delay" "delta" "digits" "do"
415 "else" "elsif" "end" "entry" "exception" "exit" "for" "function"
416 "generic" "goto" "if" "in" "is" "limited" "loop" "mod" "new"
417 "not" "null" "of" "or" "others" "out" "package" "pragma" "private"
418 "procedure" "raise" "range" "record" "rem" "renames" "return"
419 "reverse" "select" "separate" "subtype" "task" "terminate" "then"
420 "type" "use" "when" "while" "with" "xor")
421 "List of Ada keywords.
422 This variable is used to define `ada-83-keywords' and `ada-95-keywords'"))
424 (defvar ada-ret-binding nil
425 "Variable to save key binding of RET when casing is activated.")
427 (defvar ada-case-exception
'()
428 "Alist of words (entities) that have special casing.")
430 (defvar ada-lfd-binding nil
431 "Variable to save key binding of LFD when casing is activated.")
433 (defvar ada-other-file-alist nil
434 "Variable used by find-file to find the name of the other package.
435 See `ff-other-file-alist'.")
437 ;;; ---- Below are the regexp used in this package for parsing
439 (defconst ada-83-keywords
441 (concat "\\<" (regexp-opt ada-83-string-keywords t
) "\\>"))
442 "Regular expression for looking at Ada83 keywords.")
444 (defconst ada-95-keywords
446 (concat "\\<" (regexp-opt
448 '("abstract" "aliased" "protected" "requeue"
450 ada-83-string-keywords
) t
) "\\>"))
451 "Regular expression for looking at Ada95 keywords.")
453 (defvar ada-keywords ada-95-keywords
454 "Regular expression for looking at Ada keywords.")
456 (defconst ada-ident-re
458 "Regexp matching Ada (qualified) identifiers.")
460 (defvar ada-procedure-start-regexp
461 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\(\\(\\sw\\|[_.]\\)+\\)"
462 "Regexp used to find Ada procedures/functions.")
464 (defvar ada-package-start-regexp
465 "^[ \t]*\\(package\\)"
466 "Regexp used to find Ada packages.")
469 ;;; ---- regexps for indentation functions
471 (defvar ada-block-start-re
473 (concat "\\<\\(" (regexp-opt '("begin" "declare" "else"
474 "exception" "generic" "loop" "or"
475 "private" "select" ))
476 "\\|\\(\\(limited\\|abstract\\|tagged\\)[ \t\n]+\\)*record\\)\\>"))
477 "Regexp for keywords starting Ada blocks.")
479 (defvar ada-end-stmt-re
484 "^[ \t]*separate[ \t]*(\\(\\sw\\|[_.]\\)+)" "\\|"
485 "\\<" (regexp-opt '("begin" "declare" "is" "do" "else" "generic"
486 "loop" "private" "record" "select"
487 "then abort" "then") t
) "\\>" "\\|"
488 "^[ \t]*" (regexp-opt '("function" "package" "procedure")
489 t
) "\\>\\(\\sw\\|[ \t_.]\\)+\\<is\\>" "\\|"
490 "^[ \t]*exception\\>"
492 "Regexp of possible ends for a non-broken statement.
493 A new statement starts after these.")
495 (defvar ada-matching-start-re
499 '("end" "loop" "select" "begin" "case" "do"
500 "if" "task" "package" "record" "protected") t
)
502 "Regexp used in ada-goto-matching-start.")
504 (defvar ada-matching-decl-start-re
508 '("is" "separate" "end" "declare" "if" "new" "begin" "generic" "when") t
)
510 "Regexp used in ada-goto-matching-decl-start.")
512 (defvar ada-loop-start-re
513 "\\<\\(for\\|while\\|loop\\)\\>"
514 "Regexp for the start of a loop.")
516 (defvar ada-subprog-start-re
518 (concat "\\<" (regexp-opt '("accept" "entry" "function" "package" "procedure"
519 "protected" "task") t
) "\\>"))
520 "Regexp for the start of a subprogram.")
522 (defvar ada-named-block-re
523 "[ \t]*\\(\\sw\\|_\\)+[ \t]*:[^=]"
524 "Regexp of the name of a block or loop.")
526 (defvar ada-contextual-menu-on-identifier nil
527 "Set to true when the right mouse button was clicked on an identifier.")
529 (defvar ada-contextual-menu-last-point nil
530 "Position of point just before displaying the menu.
531 This is a list (point buffer).
532 Since `ada-popup-menu' moves the point where the user clicked, the region
533 is modified. Therefore no command from the menu knows what the user selected
534 before displaying the contextual menu.
535 To get the original region, restore the point to this position before
536 calling `region-end' and `region-beginning'.
537 Modify this variable if you want to restore the point to another position.")
539 (defvar ada-contextual-menu
542 ["Goto Declaration/Body"
543 (ada-call-from-contextual-menu 'ada-point-and-xref
)
544 :included
(and (functionp 'ada-point-and-xref
)
545 ada-contextual-menu-on-identifier
)]
546 ["Goto Previous Reference"
547 (ada-call-from-contextual-menu 'ada-xref-goto-previous-reference
)
548 :included
(functionp 'ada-xref-goto-previous-reference
)]
549 ["List References" ada-find-references
550 :included ada-contextual-menu-on-identifier
]
552 ["Other File" ff-find-other-file
]
553 ["Goto Parent Unit" ada-goto-parent
]
556 (let ((map (make-sparse-keymap "Ada")))
557 ;; The identifier part
558 (if (equal ada-which-compiler
'gnat
)
560 (define-key-after map
[Ref]
561 '(menu-item "Goto Declaration/Body"
562 (lambda()(interactive)
563 (ada-call-from-contextual-menu
564 'ada-point-and-xref))
566 (and (functionp 'ada-point-and-xref)
567 ada-contextual-menu-on-identifier))
569 (define-key-after map [Prev]
570 '(menu-item "Goto Previous Reference"
571 (lambda()(interactive)
572 (ada-call-from-contextual-menu
573 'ada-xref-goto-previous-reference))
575 (functionp 'ada-xref-goto-previous-reference))
577 (define-key-after map [List]
578 '(menu-item "List References"
580 :visible ada-contextual-menu-on-identifier) t)
581 (define-key-after map [-] '("-" nil) t)
583 (define-key-after map [Other] '("Other file" . ff-find-other-file) t)
584 (define-key-after map [Parent] '("Goto Parent Unit" . ada-goto-parent)t)
586 "Defines the menu to use when the user presses the right mouse button.
587 The variable `ada-contextual-menu-on-identifier' will be set to t before
588 displaying the menu if point was on an identifier."
592 ;;------------------------------------------------------------------
593 ;; Support for imenu (see imenu.el)
594 ;;------------------------------------------------------------------
596 (defconst ada-imenu-subprogram-menu-re
597 "^[ \t]*\\(procedure\\|function\\)[ \t\n]+\\(\\(\\sw\\|_\\)+\\)[ \t\n]*\\([ \t\n]\\|([^)]+)\\)[ \t\n]*\\(return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?is[ \t\n]")
599 (defvar ada-imenu-generic-expression
601 (list nil ada-imenu-subprogram-menu-re 2)
604 "^[ \t]*\\(procedure\\|function\\)[ \t\n]+\\(\\(\\sw\\|_\\)+\\)"
606 "\\([ \t\n]+\\|[ \t\n]*([^)]+)\\)";; parameter list or simple space
607 "\\([ \t\n]*return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?"
609 '("*Tasks*" "^[ \t]*task[ \t]+\\(\\(body\\|type\\)[ \t]+\\)?\\(\\(\\sw\\|_\\)+\\)" 3)
610 '("*Type Defs*" "^[ \t]*\\(sub\\)?type[ \t]+\\(\\(\\sw\\|_\\)+\\)" 2)
611 '("*Packages*" "^[ \t]*package[ \t]+\\(\\(body[ \t]+\\)?\\(\\sw\\|[_.]\\)+\\)" 1))
612 "Imenu generic expression for Ada mode.
613 See `imenu-generic-expression'. This variable will create two submenus, one
614 for type and subtype definitions, the other for subprograms declarations.
615 The main menu will reference the bodies of the subprograms.")
619 ;;------------------------------------------------------------
620 ;; Support for compile.el
621 ;;------------------------------------------------------------
623 (defun ada-compile-mouse-goto-error ()
624 "Mouse interface for ada-compile-goto-error."
626 (mouse-set-point last-input-event)
627 (ada-compile-goto-error (point))
630 (defun ada-compile-goto-error (pos)
631 "Replaces `compile-goto-error' from compile.el.
632 If POS is on a file and line location, go to this position. It adds to
633 compile.el the capacity to go to a reference in an error message.
634 For instance, on this line:
635 foo.adb:61:11: [...] in call to size declared at foo.ads:11
636 both file locations can be clicked on and jumped to."
640 (skip-chars-backward "-a-zA-Z0-9_:./\\")
642 ;; special case: looking at a filename:line not at the beginning of a line
645 "\\([-_.a-zA-Z0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"))
646 (let ((line (match-string 2))
647 (error-pos (point-marker))
652 ;; Use funcall so as to prevent byte-compiler warnings
653 (set-buffer (funcall (symbol-function 'compilation-find-file)
654 (point-marker) (match-string 1)
657 (goto-line (string-to-number line)))
658 (setq source (point-marker))))
659 (funcall (symbol-function 'compilation-goto-locus)
660 (cons source error-pos))
663 ;; otherwise, default behavior
665 (funcall (symbol-function 'compile-goto-error)))
670 ;;-------------------------------------------------------------------------
671 ;; Grammar related function
672 ;; The functions below work with the syntax class of the characters in an Ada
673 ;; buffer. Two syntax tables are created, depending on whether we want '_'
674 ;; to be considered as part of a word or not.
675 ;; Some characters may have multiple meanings depending on the context:
676 ;; - ' is either the beginning of a constant character or an attribute
677 ;; - # is either part of a based litteral or a gnatprep statement.
678 ;; - " starts a string, but not if inside a constant character.
679 ;; - ( and ) should be ignored if inside a constant character.
680 ;; Thus their syntax property is changed automatically, and we can still use
681 ;; the standard Emacs functions for sexp (see `ada-in-string-p')
683 ;; On Emacs, this is done through the `syntax-table' text property. The
684 ;; modification is done automatically each time the user as typed a new
685 ;; character. This is already done in `font-lock-mode' (in
686 ;; `font-lock-syntactic-keywords', so we take advantage of the existing
687 ;; mechanism. If font-lock-mode is not activated, we do it by hand in
688 ;; `ada-after-change-function', thanks to `ada-deactivate-properties' and
689 ;; `ada-initialize-properties'.
691 ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
692 ;; slow advice to `parse-partial-sexp' to do the same thing.
693 ;; When executing parse-partial-sexp, we simply modify the strings before and
694 ;; after, so that the special constants '"', '(' and ')' do not interact
695 ;; with parse-partial-sexp.
696 ;; Note: this code is slow and needs to be rewritten as soon as something
697 ;; better is available on XEmacs.
698 ;;-------------------------------------------------------------------------
700 (defun ada-create-syntax-table ()
701 "Create the two syntax tables use in the Ada mode.
702 The standard table declares `_' as a symbol constituent, the second one
703 declares it as a word constituent."
705 (setq ada-mode-syntax-table (make-syntax-table))
706 (set-syntax-table ada-mode-syntax-table)
708 ;; define string brackets (`%' is alternative string bracket, but
709 ;; almost never used as such and throws font-lock and indentation
711 (modify-syntax-entry ?% "$" ada-mode-syntax-table)
712 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
714 (modify-syntax-entry ?: "." ada-mode-syntax-table)
715 (modify-syntax-entry ?\; "." ada-mode-syntax-table)
716 (modify-syntax-entry ?& "." ada-mode-syntax-table)
717 (modify-syntax-entry ?\| "." ada-mode-syntax-table)
718 (modify-syntax-entry ?+ "." ada-mode-syntax-table)
719 (modify-syntax-entry ?* "." ada-mode-syntax-table)
720 (modify-syntax-entry ?/ "." ada-mode-syntax-table)
721 (modify-syntax-entry ?= "." ada-mode-syntax-table)
722 (modify-syntax-entry ?< "." ada-mode-syntax-table)
723 (modify-syntax-entry ?> "." ada-mode-syntax-table)
724 (modify-syntax-entry ?$ "." ada-mode-syntax-table)
725 (modify-syntax-entry ?\[ "." ada-mode-syntax-table)
726 (modify-syntax-entry ?\] "." ada-mode-syntax-table)
727 (modify-syntax-entry ?\{ "." ada-mode-syntax-table)
728 (modify-syntax-entry ?\} "." ada-mode-syntax-table)
729 (modify-syntax-entry ?. "." ada-mode-syntax-table)
730 (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
731 (modify-syntax-entry ?\' "." ada-mode-syntax-table)
733 ;; a single hyphen is punctuation, but a double hyphen starts a comment
734 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table)
736 ;; See the comment above on grammar related function for the special
739 (modify-syntax-entry ?# "<" ada-mode-syntax-table)
740 (modify-syntax-entry ?# "$" ada-mode-syntax-table))
742 ;; and \f and \n end a comment
743 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
744 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
746 ;; define what belongs in Ada symbols
747 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
749 ;; define parentheses to match
750 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
751 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
753 (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table))
754 (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table)
757 ;; Support of special characters in XEmacs (see the comments at the beginning
758 ;; of the section on Grammar related functions).
761 (defadvice parse-partial-sexp (around parse-partial-sexp-protect-constants)
762 "Handles special character constants and gnatprep statements."
766 (setq from to to tmp)))
769 (while (re-search-forward "'\\([(\")#]\\)'" to t)
770 (setq change (cons (list (match-beginning 1)
774 (replace-match "'A'"))
776 (while (re-search-forward "\\(#[0-9a-fA-F]*#\\)" to t)
777 (setq change (cons (list (match-beginning 1)
778 (length (match-string 1))
781 (replace-match (make-string (length (match-string 1)) ?@))))
785 (goto-char (caar change))
786 (delete-char (cadar change))
787 (insert (caddar change))
788 (setq change (cdr change)))))))
790 (defun ada-deactivate-properties ()
791 "Deactivate ada-mode's properties handling.
792 This would be a duplicate of font-lock if both are used at the same time."
793 (remove-hook 'after-change-functions 'ada-after-change-function t))
795 (defun ada-initialize-properties ()
796 "Initialize some special text properties in the whole buffer.
797 In particular, character constants are said to be strings, #...# are treated
798 as numbers instead of gnatprep comments."
802 (goto-char (point-min))
803 (while (re-search-forward "'.'" nil t)
804 (add-text-properties (match-beginning 0) (match-end 0)
805 '(syntax-table ("'" . ?\"))))
806 (goto-char (point-min))
807 (while (re-search-forward "^[ \t]*#" nil t)
808 (add-text-properties (match-beginning 0) (match-end 0)
809 '(syntax-table (11 . 10))))
810 (set-buffer-modified-p nil)
812 ;; Setting this only if font-lock is not set won't work
813 ;; if the user activates or deactivates font-lock-mode,
814 ;; but will make things faster most of the time
815 (make-local-hook 'after-change-functions)
816 (add-hook 'after-change-functions 'ada-after-change-function nil t)
819 (defun ada-after-change-function (beg end old-len)
820 "Called when the region between BEG and END was changed in the buffer.
821 OLD-LEN indicates what the length of the replaced text was."
822 (let ((inhibit-point-motion-hooks t)
827 (remove-text-properties (point) eol '(syntax-table nil))
828 (while (re-search-forward "'.'" eol t)
829 (add-text-properties (match-beginning 0) (match-end 0)
830 '(syntax-table ("'" . ?\"))))
832 (if (looking-at "^[ \t]*#")
833 (add-text-properties (match-beginning 0) (match-end 0)
834 '(syntax-table (11 . 10))))
837 ;;------------------------------------------------------------------
838 ;; Testing the grammatical context
839 ;;------------------------------------------------------------------
841 (defsubst ada-in-comment-p (&optional parse-result)
842 "Returns t if inside a comment."
843 (nth 4 (or parse-result
845 (save-excursion (beginning-of-line) (point)) (point)))))
847 (defsubst ada-in-string-p (&optional parse-result)
848 "Returns t if point is inside a string.
849 If parse-result is non-nil, use is instead of calling parse-partial-sexp."
850 (nth 3 (or parse-result
852 (save-excursion (beginning-of-line) (point)) (point)))))
854 (defsubst ada-in-string-or-comment-p (&optional parse-result)
855 "Returns t if inside a comment or string."
856 (setq parse-result (or parse-result
858 (save-excursion (beginning-of-line) (point)) (point))))
859 (or (ada-in-string-p parse-result) (ada-in-comment-p parse-result)))
862 ;;------------------------------------------------------------------
864 ;; The Ada-mode comes with contextual menus, bound by default to the right
866 ;; Add items to this menu by modifying `ada-contextual-menu'. Note that the
867 ;; variable `ada-contextual-menu-on-identifier' is set automatically to t
868 ;; if the mouse button was pressed on an identifier.
869 ;;------------------------------------------------------------------
871 (defun ada-call-from-contextual-menu (function)
872 "Execute FUNCTION when called from the contextual menu.
873 It forces Emacs to change the cursor position."
876 (setq ada-contextual-menu-last-point
877 (list (point) (current-buffer))))
879 (defun ada-popup-menu (position)
880 "Pops up a contextual menu, depending on where the user clicked.
881 POSITION is the location the mouse was clicked on.
882 Sets `ada-contextual-menu-last-point' to the current position before
883 displaying the menu. When a function from the menu is called, the point is
884 where the mouse button was clicked."
887 ;; declare this as a local variable, so that the function called
888 ;; in the contextual menu does not hide the region in
889 ;; transient-mark-mode.
890 (let ((deactivate-mark nil))
891 (setq ada-contextual-menu-last-point
892 (list (point) (current-buffer)))
893 (mouse-set-point last-input-event)
895 (setq ada-contextual-menu-on-identifier
897 (or (= (char-syntax (char-after)) ?w)
899 (not (ada-in-string-or-comment-p))
900 (save-excursion (skip-syntax-forward "w")
901 (not (ada-after-keyword-p)))
905 (setq choice (funcall (symbol-function 'popup-menu)
906 ada-contextual-menu))
907 (setq choice (x-popup-menu position ada-contextual-menu)))
909 (funcall (lookup-key ada-contextual-menu (vector (car choice))))))
910 (set-buffer (cadr ada-contextual-menu-last-point))
911 (goto-char (car ada-contextual-menu-last-point))
915 ;;------------------------------------------------------------------
917 ;;------------------------------------------------------------------
920 (defun ada-add-extensions (spec body)
921 "Define SPEC and BODY as being valid extensions for Ada files.
922 Going from body to spec with `ff-find-other-file' used these
924 SPEC and BODY are two regular expressions that must match against the file
926 (let* ((reg (concat (regexp-quote body) "$"))
927 (tmp (assoc reg ada-other-file-alist)))
929 (setcdr tmp (list (cons spec (cadr tmp))))
930 (add-to-list 'ada-other-file-alist (list reg (list spec)))))
932 (let* ((reg (concat (regexp-quote spec) "$"))
933 (tmp (assoc reg ada-other-file-alist)))
935 (setcdr tmp (list (cons body (cadr tmp))))
936 (add-to-list 'ada-other-file-alist (list reg (list body)))))
938 (add-to-list 'auto-mode-alist (cons spec 'ada-mode))
939 (add-to-list 'auto-mode-alist (cons body 'ada-mode))
941 (add-to-list 'ada-spec-suffixes spec)
942 (add-to-list 'ada-body-suffixes body)
944 ;; Support for speedbar (Specifies that we want to see these files in
949 (funcall (symbol-function 'speedbar-add-supported-extension)
951 (funcall (symbol-function 'speedbar-add-supported-extension)
958 "Ada mode is the major mode for editing Ada code.
960 Bindings are as follows: (Note: 'LFD' is control-j.)
962 Indent line '\\[ada-tab]'
963 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
965 Re-format the parameter-list point is in '\\[ada-format-paramlist]'
966 Indent all lines in region '\\[ada-indent-region]'
968 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]'
969 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]'
971 Fill comment paragraph, justify and append postfix '\\[fill-paragraph]'
973 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
974 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
976 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
977 Goto end of current block '\\[ada-move-to-end]'
979 Comments are handled using standard GNU Emacs conventions, including:
980 Start a comment '\\[indent-for-comment]'
981 Comment region '\\[comment-region]'
982 Uncomment region '\\[ada-uncomment-region]'
983 Continue comment on next line '\\[indent-new-comment-line]'
986 Display index-menu of functions & procedures '\\[imenu]'
988 If you use find-file.el:
989 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]'
990 or '\\[ff-mouse-find-other-file]
991 Switch to other file in other window '\\[ada-ff-other-window]'
992 or '\\[ff-mouse-find-other-file-other-window]
993 If you use this function in a spec and no body is available, it gets created with body stubs.
995 If you use ada-xref.el:
996 Goto declaration: '\\[ada-point-and-xref]' on the identifier
997 or '\\[ada-goto-declaration]' with point on the identifier
998 Complete identifier: '\\[ada-complete-identifier]'."
1001 (kill-all-local-variables)
1003 (set (make-local-variable 'require-final-newline) t)
1005 (make-local-variable 'comment-start)
1006 (if ada-fill-comment-prefix
1007 (setq comment-start ada-fill-comment-prefix)
1008 (setq comment-start "-- "))
1010 ;; Set the paragraph delimiters so that one can select a whole block
1012 (set (make-local-variable 'paragraph-start) "[ \t\n\f]*$")
1013 (set (make-local-variable 'paragraph-separate) "[ \t\n\f]*$")
1015 ;; comment end must be set because it may hold a wrong value if
1016 ;; this buffer had been in another mode before. RE
1017 (set (make-local-variable 'comment-end) "")
1019 ;; used by autofill and indent-new-comment-line
1020 (set (make-local-variable 'comment-start-skip) "---*[ \t]*")
1022 ;; used by autofill to break a comment line and continue it on another line.
1023 ;; The reason we need this one is that the default behavior does not work
1024 ;; correctly with the definition of paragraph-start above when the comment
1025 ;; is right after a multi-line subprogram declaration (the comments are
1026 ;; aligned under the latest parameter, not under the declaration start).
1027 (set (make-local-variable 'comment-line-break-function)
1028 (lambda (&optional soft) (let ((fill-prefix nil))
1029 (indent-new-comment-line soft))))
1031 (set (make-local-variable 'indent-line-function)
1032 'ada-indent-current-function)
1034 (set (make-local-variable 'comment-column) 40)
1036 ;; Emacs 20.3 defines a comment-padding to insert spaces between
1037 ;; the comment and the text. We do not want any, this is already
1038 ;; included in comment-start
1041 (if (ada-check-emacs-version 20 3)
1043 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1044 (set (make-local-variable 'comment-padding) 0)))
1045 (set (make-local-variable 'parse-sexp-lookup-properties) t)
1048 (setq case-fold-search t)
1049 (if (boundp 'imenu-case-fold-search)
1050 (setq imenu-case-fold-search t))
1052 (set (make-local-variable 'fill-paragraph-function)
1053 'ada-fill-comment-paragraph)
1055 (set (make-local-variable 'imenu-generic-expression)
1056 ada-imenu-generic-expression)
1058 ;; Support for compile.el
1059 ;; We just substitute our own functions to go to the error.
1060 (add-hook 'compilation-mode-hook
1062 (setq compile-auto-highlight 40)
1063 (define-key compilation-minor-mode-map [mouse-2]
1064 'ada-compile-mouse-goto-error)
1065 (define-key compilation-minor-mode-map "\C-c\C-c"
1066 'ada-compile-goto-error)
1067 (define-key compilation-minor-mode-map "\C-m"
1068 'ada-compile-goto-error)
1071 ;; font-lock support :
1072 ;; We need to set some properties for XEmacs, and define some variables
1077 (put 'ada-mode 'font-lock-defaults
1078 '(ada-font-lock-keywords
1079 nil t ((?\_ . "w") (?# . ".")) beginning-of-line))
1081 (set (make-local-variable 'font-lock-defaults)
1082 '(ada-font-lock-keywords
1084 ((?\_ . "w") (?# . "."))
1086 (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords)))
1089 ;; Set up support for find-file.el.
1090 (set (make-variable-buffer-local 'ff-other-file-alist)
1091 'ada-other-file-alist)
1092 (set (make-variable-buffer-local 'ff-search-directories)
1093 'ada-search-directories)
1094 (setq ff-post-load-hooks 'ada-set-point-accordingly
1095 ff-file-created-hooks 'ada-make-body)
1096 (add-hook 'ff-pre-load-hooks 'ada-which-function-are-we-in)
1098 ;; Some special constructs for find-file.el
1099 ;; We do not need to add the construction for 'with', which is in the
1100 ;; standard find-file.el
1101 (make-local-variable 'ff-special-constructs)
1103 ;; Go to the parent package :
1104 (add-to-list 'ff-special-constructs
1105 (cons (eval-when-compile
1106 (concat "^\\(private[ \t]\\)?[ \t]*package[ \t]+"
1108 "\\(\\(\\sw\\|[_.]\\)+\\)\\.\\(\\sw\\|_\\)+[ \t\n]+is"))
1110 (setq fname (ff-get-file
1111 ada-search-directories
1112 (ada-make-filename-from-adaname
1114 ada-spec-suffixes)))))
1115 ;; Another special construct for find-file.el : when in a separate clause,
1116 ;; go to the correct package.
1117 (add-to-list 'ff-special-constructs
1118 (cons "^separate[ \t\n]*(\\(\\(\\sw\\|[_.]\\)+\\))"
1120 (setq fname (ff-get-file
1121 ada-search-directories
1122 (ada-make-filename-from-adaname
1124 ada-spec-suffixes)))))
1125 ;; Another special construct, that redefines the one in find-file.el. The
1126 ;; old one can handle only one possible type of extension for Ada files
1127 ;; remove from the list the standard "with..." that is put by find-file.el,
1128 ;; since it uses the old ada-spec-suffix variable
1129 ;; This one needs to replace the standard one defined in find-file.el (with
1130 ;; Emacs <= 20.4), since that one uses the old variable ada-spec-suffix
1131 (let ((old-construct
1132 (assoc "^with[ \t]+\\([a-zA-Z0-9_\\.]+\\)" ff-special-constructs))
1135 (setq fname (ff-get-file
1136 ada-search-directories
1137 (ada-make-filename-from-adaname
1139 ada-spec-suffixes)))))
1141 (setcdr old-construct new-cdr)
1142 (add-to-list 'ff-special-constructs
1143 (cons "^with[ \t]+\\([a-zA-Z0-9_\\.]+\\)"
1146 ;; Support for outline-minor-mode
1147 (set (make-local-variable 'outline-regexp)
1148 "\\([ \t]*\\(procedure\\|function\\|package\\|if\\|while\\|for\\|declare\\|case\\|end\\|begin\\|loop\\)\\|--\\)")
1149 (set (make-local-variable 'outline-level) 'ada-outline-level)
1151 ;; Support for imenu : We want a sorted index
1152 (setq imenu-sort-function 'imenu--sort-by-name)
1154 ;; Support for which-function-mode is provided in ada-support (support
1155 ;; for nested subprograms)
1157 ;; Set up the contextual menu
1159 (define-key ada-mode-map ada-popup-key 'ada-popup-menu))
1161 ;; Support for Abbreviations (the user still need to "M-x abbrev-mode"
1162 (define-abbrev-table 'ada-mode-abbrev-table ())
1163 (setq local-abbrev-table ada-mode-abbrev-table)
1165 ;; Support for indent-new-comment-line (Especially for XEmacs)
1166 (setq comment-multi-line nil)
1167 (defconst comment-indent-function (lambda () comment-column))
1169 (setq major-mode 'ada-mode)
1170 (setq mode-name "Ada")
1172 (use-local-map ada-mode-map)
1175 (funcall (symbol-function 'easy-menu-add)
1176 ada-mode-menu ada-mode-map))
1178 (set-syntax-table ada-mode-syntax-table)
1180 (if ada-clean-buffer-before-saving
1182 ;; remove all spaces at the end of lines in the whole buffer.
1183 (add-hook 'local-write-file-hooks 'delete-trailing-whitespace)
1184 ;; convert all tabs to the correct number of spaces.
1185 (add-hook 'local-write-file-hooks
1186 (lambda () (untabify (point-min) (point-max))))))
1188 (run-hooks 'ada-mode-hook)
1190 ;; Run this after the hook to give the users a chance to activate
1195 (ada-initialize-properties)
1196 (make-local-hook 'font-lock-mode-hook)
1197 (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t)))
1199 ;; the following has to be done after running the ada-mode-hook
1200 ;; because users might want to set the values of these variable
1201 ;; inside the hook (MH)
1203 (cond ((eq ada-language-version 'ada83)
1204 (setq ada-keywords ada-83-keywords))
1205 ((eq ada-language-version 'ada95)
1206 (setq ada-keywords ada-95-keywords)))
1209 (ada-activate-keys-for-case)))
1212 ;;-----------------------------------------------------------------
1214 ;; Since Ada is case-insensitive, the Ada-mode provides an extensive set of
1215 ;; functions to auto-case identifiers, keywords, ...
1216 ;; The basic rules for autocasing are defined through the variables
1217 ;; `ada-case-attribute', `ada-case-keyword' and `ada-case-identifier'. These
1218 ;; are references to the functions that will do the actual casing.
1220 ;; However, in most cases, the user will want to define some exceptions to
1221 ;; these casing rules. This is done through a list of files, that contain
1222 ;; one word per line. These files are stored in `ada-case-exception-file'.
1223 ;; For backward compatibility, this variable can also be a string.
1224 ;;-----------------------------------------------------------------
1226 (defun ada-create-case-exception (&optional word)
1227 "Defines WORD as an exception for the casing system.
1228 If WORD is not given, then the current word in the buffer is used instead.
1229 The new words is added to the first file in `ada-case-exception-file'.
1230 The standard casing rules will no longer apply to this word."
1232 (let ((previous-syntax-table (syntax-table))
1233 (exception-list '())
1237 (cond ((stringp ada-case-exception-file)
1238 (setq file-name ada-case-exception-file))
1239 ((listp ada-case-exception-file)
1240 (setq file-name (car ada-case-exception-file)))
1242 (error "No exception file specified")))
1244 (set-syntax-table ada-mode-symbol-syntax-table)
1247 (skip-syntax-backward "w")
1248 (setq word (buffer-substring-no-properties
1249 (point) (save-excursion (forward-word 1) (point))))))
1251 ;; Reread the exceptions file, in case it was modified by some other,
1252 ;; and to keep the end-of-line comments that may exist in it.
1253 (if (file-readable-p (expand-file-name file-name))
1254 (let ((buffer (current-buffer)))
1255 (find-file (expand-file-name file-name))
1256 (set-syntax-table ada-mode-symbol-syntax-table)
1258 (goto-char (point-min))
1260 (add-to-list 'exception-list
1262 (buffer-substring-no-properties
1263 (point) (save-excursion (forward-word 1) (point)))
1264 (buffer-substring-no-properties
1265 (save-excursion (forward-word 1) (point))
1266 (save-excursion (end-of-line) (point)))
1270 (set-buffer buffer)))
1272 ;; If the word is already in the list, even with a different casing
1273 ;; we simply want to replace it.
1274 (if (and (not (equal exception-list '()))
1275 (assoc-ignore-case word exception-list))
1276 (setcar (assoc-ignore-case word exception-list)
1278 (add-to-list 'exception-list (list word "" t))
1281 (if (and (not (equal ada-case-exception '()))
1282 (assoc-ignore-case word ada-case-exception))
1283 (setcar (assoc-ignore-case word ada-case-exception)
1285 (add-to-list 'ada-case-exception (cons word t))
1288 ;; Save the list in the file
1289 (find-file (expand-file-name file-name))
1291 (mapcar (lambda (x) (insert (car x) (nth 1 x) "\n"))
1292 (sort exception-list
1293 (lambda(a b) (string< (car a) (car b)))))
1296 (set-syntax-table previous-syntax-table)
1299 (defun ada-case-read-exceptions-from-file (file-name)
1300 "Read the content of the casing exception file FILE-NAME."
1301 (if (file-readable-p (expand-file-name file-name))
1302 (let ((buffer (current-buffer)))
1303 (find-file (expand-file-name file-name))
1304 (set-syntax-table ada-mode-symbol-syntax-table)
1306 (goto-char (point-min))
1309 ;; If the item is already in the list, even with an other casing,
1310 ;; do not add it again. This way, the user can easily decide which
1311 ;; priority should be applied to each casing exception
1312 (let ((word (buffer-substring-no-properties
1313 (point) (save-excursion (forward-word 1) (point)))))
1314 (unless (assoc-ignore-case word ada-case-exception)
1315 (add-to-list 'ada-case-exception (cons word t))))
1319 (set-buffer buffer)))
1322 (defun ada-case-read-exceptions ()
1323 "Read all the casing exception files from `ada-case-exception-file'."
1326 ;; Reinitialize the casing exception list
1327 (setq ada-case-exception '())
1329 (cond ((stringp ada-case-exception-file)
1330 (ada-case-read-exceptions-from-file ada-case-exception-file))
1332 ((listp ada-case-exception-file)
1333 (mapcar 'ada-case-read-exceptions-from-file
1334 ada-case-exception-file))))
1336 (defun ada-adjust-case-identifier ()
1337 "Adjust case of the previous identifier.
1338 The auto-casing is done according to the value of `ada-case-identifier' and
1339 the exceptions defined in `ada-case-exception-file'."
1341 (if (or (equal ada-case-exception '())
1342 (equal (char-after) ?_))
1343 (funcall ada-case-identifier -1)
1347 (start (save-excursion (skip-syntax-backward "w")
1350 ;; If we have an exception, replace the word by the correct casing
1351 (if (setq match (assoc-ignore-case (buffer-substring start end)
1352 ada-case-exception))
1355 (delete-region start end)
1356 (insert (car match)))
1358 ;; Else simply re-case the word
1359 (funcall ada-case-identifier -1))))))
1361 (defun ada-after-keyword-p ()
1362 "Returns t if cursor is after a keyword that is not an attribute."
1365 (and (not (and (char-before)
1366 (or (= (char-before) ?_)
1367 (= (char-before) ?'))));; unless we have a _ or '
1368 (looking-at (concat ada-keywords "[^_]")))))
1370 (defun ada-adjust-case (&optional force-identifier)
1371 "Adjust the case of the word before the just typed character.
1372 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier."
1374 (if (and (> (point) 1)
1375 ;; or if at the end of a character constant
1376 (not (and (eq (char-after) ?')
1377 (eq (char-before (1- (point))) ?')))
1378 ;; or if the previous character was not part of a word
1379 (eq (char-syntax (char-before)) ?w)
1380 ;; if in a string or a comment
1381 (not (ada-in-string-or-comment-p))
1385 (or (= (point) (point-min))
1387 (= (char-after) ?'))
1388 (funcall ada-case-attribute -1)
1390 (not force-identifier) ; (MH)
1391 (ada-after-keyword-p))
1392 (funcall ada-case-keyword -1)
1393 (ada-adjust-case-identifier))))
1397 (defun ada-adjust-case-interactive (arg)
1398 "Adjust the case of the previous word, and process the character just typed.
1399 ARG is the prefix the user entered with \C-u."
1403 (let ((lastk last-command-char)
1404 (previous-syntax-table (syntax-table)))
1408 (set-syntax-table ada-mode-symbol-syntax-table)
1409 (cond ((or (eq lastk ?\n)
1414 ;; horrible dekludge
1415 (delete-backward-char 1)
1416 ;; some special keys and their bindings
1419 (funcall ada-lfd-binding))
1421 (funcall ada-ret-binding))))
1422 ((eq lastk ?\C-i) (ada-tab))
1423 ;; Else just insert the character
1424 ((self-insert-command (prefix-numeric-value arg))))
1425 ;; if there is a keyword in front of the underscore
1426 ;; then it should be part of an identifier (MH)
1431 ;; Restore the syntax table
1432 (set-syntax-table previous-syntax-table))
1435 ;; Else, no auto-casing
1437 ((eq last-command-char ?\n)
1438 (funcall ada-lfd-binding))
1439 ((eq last-command-char ?\r)
1440 (funcall ada-ret-binding))
1442 (self-insert-command (prefix-numeric-value arg))))
1445 (defun ada-activate-keys-for-case ()
1446 "Modifies the key bindings for all the keys that should readjust the casing."
1448 ;; Save original key-bindings to allow swapping ret/lfd
1449 ;; when casing is activated.
1450 ;; The 'or ...' is there to be sure that the value will not
1451 ;; be changed again when Ada mode is called more than once
1452 (or ada-ret-binding (setq ada-ret-binding (key-binding "\C-M")))
1453 (or ada-lfd-binding (setq ada-lfd-binding (key-binding "\C-j")))
1455 ;; Call case modifying function after certain keys.
1456 (mapcar (function (lambda(key) (define-key
1458 (char-to-string key)
1459 'ada-adjust-case-interactive)))
1460 '( ?` ?_ ?# ?% ?& ?* ?( ?) ?- ?= ?+
1461 ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?/ ?\n 32 ?\r )))
1463 (defun ada-loose-case-word (&optional arg)
1464 "Upcase first letter and letters following `_' in the following word.
1465 No other letter is modified.
1466 ARG is ignored, and is there for compatibility with `capitalize-word' only."
1469 (let ((end (save-excursion (skip-syntax-forward "w") (point)))
1471 (skip-syntax-backward "w")
1472 (while (and (or first (search-forward "_" end t))
1476 (insert-char (upcase (following-char)) 1)
1479 (defun ada-no-auto-case (&optional arg)
1481 This function can be used for the auto-casing variables in the ada-mode, to
1482 adapt to unusal auto-casing schemes. Since it does nothing, you can for
1483 instance use it for `ada-case-identifier' if you don't want any special
1484 auto-casing for identifiers, whereas keywords have to be lower-cased.
1485 See also `ada-auto-case' to disable auto casing altogether."
1488 (defun ada-capitalize-word (&optional arg)
1489 "Upcase first letter and letters following '_', lower case other letters.
1490 ARG is ignored, and is there for compatibility with `capitalize-word' only."
1492 (let ((end (save-excursion (skip-syntax-forward "w") (point)))
1493 (begin (save-excursion (skip-syntax-backward "w") (point))))
1494 (modify-syntax-entry ?_ "_")
1495 (capitalize-region begin end)
1496 (modify-syntax-entry ?_ "w")))
1498 (defun ada-adjust-case-region (from to)
1499 "Adjusts the case of all words in the region between FROM and TO.
1500 Attention: This function might take very long for big regions !"
1506 (previous-syntax-table (syntax-table)))
1507 (message "Adjusting case ...")
1510 (set-syntax-table ada-mode-symbol-syntax-table)
1513 ;; loop: look for all identifiers, keywords, and attributes
1515 (while (re-search-backward "\\<\\(\\sw+\\)\\>" from t)
1516 (setq end (match-end 1))
1518 (and (> (point) from)
1521 (setq attribp (looking-at "'.[^']")))))
1523 ;; do nothing if it is a string or comment
1524 (ada-in-string-or-comment-p)
1527 ;; get the identifier or keyword or attribute
1529 (setq begin (point))
1530 (setq keywordp (looking-at ada-keywords))
1533 ;; casing according to user-option
1536 (funcall ada-case-attribute -1)
1538 (funcall ada-case-keyword -1)
1539 (ada-adjust-case-identifier)))
1540 (goto-char begin))))
1541 (message "Adjusting case ... Done"))
1542 (set-syntax-table previous-syntax-table))))
1544 (defun ada-adjust-case-buffer ()
1545 "Adjusts the case of all words in the whole buffer.
1546 ATTENTION: This function might take very long for big buffers !"
1548 (ada-adjust-case-region (point-min) (point-max)))
1551 ;;--------------------------------------------------------------
1552 ;; Format Parameter Lists
1553 ;; Some special algorithms are provided to indent the parameter lists in
1554 ;; subprogram declarations. This is done in two steps:
1555 ;; - First parses the parameter list. The returned list has the following
1557 ;; ( (<Param_Name> in? out? access? <Type_Name> <Default_Expression>)
1559 ;; This is done in `ada-scan-paramlist'.
1560 ;; - Delete and recreate the parameter list in function
1561 ;; `ada-insert-paramlist'.
1562 ;; Both steps are called from `ada-format-paramlist'.
1563 ;; Note: Comments inside the parameter list are lost.
1564 ;; The syntax has to be correct, or the reformating will fail.
1565 ;;--------------------------------------------------------------
1567 (defun ada-format-paramlist ()
1568 "Reformats the parameter list point is in."
1574 (previous-syntax-table (syntax-table)))
1577 (set-syntax-table ada-mode-symbol-syntax-table)
1579 ;; check if really inside parameter list
1580 (or (ada-in-paramlist-p)
1581 (error "not in parameter list"))
1583 ;; find start of current parameter-list
1584 (ada-search-ignore-string-comment
1585 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil)
1588 (setq begin (point))
1590 ;; find end of parameter-list
1592 (setq delend (point))
1596 ;; find end of last parameter-declaration
1597 (forward-comment -1000)
1600 ;; build a list of all elements of the parameter-list
1601 (setq paramlist (ada-scan-paramlist (1+ begin) end))
1603 ;; delete the original parameter-list
1604 (delete-region begin delend)
1606 ;; insert the new parameter-list
1608 (ada-insert-paramlist paramlist))
1610 ;; restore syntax-table
1611 (set-syntax-table previous-syntax-table)
1614 (defun ada-scan-paramlist (begin end)
1615 "Scan the parameter list found in between BEGIN and END.
1616 Returns the equivalent internal parameter list."
1617 (let ((paramlist (list))
1627 ;; loop until end of last parameter
1630 ;; find first character of parameter-declaration
1631 (ada-goto-next-non-ws)
1634 ;; find last character of parameter-declaration
1635 (if (setq match-cons
1636 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t))
1638 (setq epos (car match-cons))
1639 (setq semipos (cdr match-cons)))
1642 ;; read name(s) of parameter(s)
1644 (looking-at "\\(\\(\\sw\\|[_, \t\n]\\)*\\(\\sw\\|_\\)\\)[ \t\n]*:[^=]")
1646 (setq param (list (match-string 1)))
1647 (ada-search-ignore-string-comment ":" nil epos t 'search-forward)
1655 (ada-search-ignore-string-comment
1656 "in" nil epos t 'word-search-forward)))))
1664 (ada-search-ignore-string-comment
1665 "out" nil epos t 'word-search-forward)))))
1667 ;; look for 'access'
1673 (ada-search-ignore-string-comment
1674 "access" nil epos t 'word-search-forward)))))
1676 ;; skip 'in'/'out'/'access'
1678 (ada-goto-next-non-ws)
1679 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>")
1681 (ada-goto-next-non-ws))
1683 ;; read type of parameter
1684 ;; We accept spaces in the name, since some software like Rose
1685 ;; generates something like: "A : B 'Class"
1686 (looking-at "\\<\\(\\sw\\|[_.' \t]\\)+\\>")
1689 (list (match-string 0))))
1691 ;; read default-expression, if there is one
1692 (goto-char (setq apos (match-end 0)))
1696 (if (setq match-cons
1697 (ada-search-ignore-string-comment
1698 ":=" nil epos t 'search-forward))
1699 (buffer-substring (car match-cons) epos)
1702 ;; add this parameter-declaration to the list
1703 (setq paramlist (append paramlist (list param)))
1705 ;; check if it was the last parameter
1708 (goto-char semipos))
1710 (reverse paramlist)))
1712 (defun ada-insert-paramlist (paramlist)
1713 "Inserts a formatted PARAMLIST in the buffer."
1714 (let ((i (length paramlist))
1723 ;; loop until last parameter
1724 (while (not (zerop i))
1727 ;; get max length of parameter-name
1728 (setq parlen (max parlen (length (nth 0 (nth i paramlist)))))
1730 ;; get max length of type-name
1731 (setq typlen (max typlen (length (nth 4 (nth i paramlist)))))
1733 ;; is there any 'in' ?
1734 (setq inp (or inp (nth 1 (nth i paramlist))))
1736 ;; is there any 'out' ?
1737 (setq outp (or outp (nth 2 (nth i paramlist))))
1739 ;; is there any 'access' ?
1740 (setq accessp (or accessp (nth 3 (nth i paramlist))))
1743 ;; does paramlist already start on a separate line ?
1745 (re-search-backward "^.\\|[^ \t]" nil t)
1747 ;; yes => re-indent it
1749 (ada-indent-current)
1751 (if (looking-at "\\(is\\|return\\)")
1752 (replace-match " \\1"))))
1754 ;; no => insert it where we are after removing any whitespace
1758 ((looking-at "[ \t]*\\(\n\\|;\\)")
1759 (replace-match "\\1"))
1760 ((looking-at "[ \t]*\\(is\\|return\\)")
1761 (replace-match " \\1"))))
1765 (ada-indent-current)
1767 (setq firstcol (current-column))
1768 (setq i (length paramlist))
1770 ;; loop until last parameter
1771 (while (not (zerop i))
1773 (setq column firstcol)
1775 ;; insert parameter-name, space and colon
1776 (insert (nth 0 (nth i paramlist)))
1777 (indent-to (+ column parlen 1))
1779 (setq column (current-column))
1781 ;; insert 'in' or space
1782 (if (nth 1 (nth i paramlist))
1787 (not (nth 3 (nth i paramlist))))
1790 ;; insert 'out' or space
1791 (if (nth 2 (nth i paramlist))
1796 (not (nth 3 (nth i paramlist))))
1800 (if (nth 3 (nth i paramlist))
1803 (setq column (current-column))
1805 ;; insert type-name and, if necessary, space and default-expression
1806 (insert (nth 4 (nth i paramlist)))
1807 (if (nth 5 (nth i paramlist))
1809 (indent-to (+ column typlen 1))
1810 (insert (nth 5 (nth i paramlist)))))
1812 ;; check if it was the last parameter
1815 ;; no => insert ';' and newline and indent
1818 (indent-to firstcol))
1821 ;; if anything follows, except semicolon, newline, is or return
1822 ;; put it in a new line and indent it
1823 (unless (looking-at "[ \t]*\\(;\\|\n\\|is\\|return\\)")
1824 (ada-indent-newline-indent))
1829 ;;;----------------------------------------------------------------
1830 ;; Indentation Engine
1831 ;; All indentations are indicated as a two-element string:
1832 ;; - position of reference in the buffer
1833 ;; - offset to indent from this position (can also be a symbol or a list
1834 ;; that are evaluated)
1835 ;; Thus the total indentation for a line is the column number of the reference
1836 ;; position plus whatever value the evaluation of the second element provides.
1837 ;; This mechanism is used so that the ada-mode can "explain" how the
1838 ;; indentation was calculated, by showing which variables were used.
1840 ;; The indentation itself is done in only one pass: first we try to guess in
1841 ;; what context we are by looking at the following keyword or punctuation
1842 ;; sign. If nothing remarkable is found, just try to guess the indentation
1843 ;; based on previous lines.
1845 ;; The relevant functions for indentation are:
1846 ;; - `ada-indent-region': Re-indent a region of text
1847 ;; - `ada-justified-indent-current': Re-indent the current line and shows the
1848 ;; calculation that were done
1849 ;; - `ada-indent-current': Re-indent the current line
1850 ;; - `ada-get-current-indent': Calculate the indentation for the current line,
1851 ;; based on the context (see above).
1852 ;; - `ada-get-indent-*': Calculate the indentation in a specific context.
1853 ;; For efficiency, these functions do not check they are in the correct
1855 ;;;----------------------------------------------------------------
1857 (defun ada-indent-region (beg end)
1858 "Indent the region between BEG end END."
1861 (let ((block-done 0)
1862 (lines-remaining (count-lines beg end))
1863 (msg (format "%%4d out of %4d lines remaining ..."
1864 (count-lines beg end)))
1865 (endmark (copy-marker end)))
1866 ;; catch errors while indenting
1867 (while (< (point) endmark)
1868 (if (> block-done 39)
1870 (setq lines-remaining (- lines-remaining block-done)
1872 (message msg lines-remaining)))
1873 (if (= (char-after) ?\n) nil
1874 (ada-indent-current))
1876 (setq block-done (1+ block-done)))
1877 (message "indenting ... done")))
1879 (defun ada-indent-newline-indent ()
1880 "Indents the current line, inserts a newline and then indents the new line."
1882 (ada-indent-current)
1884 (ada-indent-current))
1886 (defun ada-indent-newline-indent-conditional ()
1887 "Insert a newline and indent it.
1888 The original line is indented first if `ada-indent-after-return' is non-nil.
1889 This function is intended to be bound to the \C-m and \C-j keys."
1891 (if ada-indent-after-return (ada-indent-current))
1893 (ada-indent-current))
1895 (defun ada-justified-indent-current ()
1896 "Indent the current line and explains how the calculation was done."
1899 (let ((cur-indent (ada-indent-current)))
1902 (if (equal (cdr cur-indent) '(0))
1903 (message "same indentation")
1904 (message (mapconcat (lambda(x)
1909 (number-to-string x))
1911 (concat "- " (symbol-name (cadr x))))
1916 (goto-char (car cur-indent))
1919 (defun ada-batch-reformat ()
1920 "Re-indent and re-case all the files found on the command line.
1921 This function should be used from the Unix/Windows command line, with a
1923 emacs -batch -l ada-mode -f ada-batch-reformat file1 file2 ..."
1925 (while command-line-args-left
1926 (let ((source (car command-line-args-left)))
1927 (message (concat "formating " source))
1929 (ada-indent-region (point-min) (point-max))
1930 (ada-adjust-case-buffer)
1931 (write-file source))
1932 (setq command-line-args-left (cdr command-line-args-left)))
1936 (defsubst ada-goto-previous-word ()
1937 "Moves point to the beginning of the previous word of Ada code.
1938 Returns the new position of point or nil if not found."
1939 (ada-goto-next-word t))
1941 (defun ada-indent-current ()
1942 "Indent current line as Ada code.
1943 Returns the calculation that was done, including the reference point and the
1946 (let ((previous-syntax-table (syntax-table))
1947 (orgpoint (point-marker))
1948 cur-indent tmp-indent
1953 (set-syntax-table ada-mode-symbol-syntax-table)
1955 ;; This need to be done here so that the advice is not always
1956 ;; activated (this might interact badly with other modes)
1958 (ad-activate 'parse-partial-sexp t))
1963 ;; Not First line in the buffer ?
1964 (if (save-excursion (zerop (forward-line -1)))
1966 (back-to-indentation)
1967 (ada-get-current-indent))
1969 ;; first line in the buffer
1970 (list (point-min) 0))))
1972 ;; Evaluate the list to get the column to indent to
1973 ;; prev-indent contains the column to indent to
1975 (setq prev-indent (save-excursion (goto-char (car cur-indent))
1977 tmp-indent (cdr cur-indent))
1978 (setq prev-indent 0 tmp-indent '()))
1980 (while (not (null tmp-indent))
1982 ((numberp (car tmp-indent))
1983 (setq prev-indent (+ prev-indent (car tmp-indent))))
1985 (setq prev-indent (+ prev-indent (eval (car tmp-indent)))))
1987 (setq tmp-indent (cdr tmp-indent)))
1989 ;; only re-indent if indentation is different then the current
1990 (if (= (save-excursion (back-to-indentation) (current-column)) prev-indent)
1993 (delete-horizontal-space)
1994 (indent-to prev-indent))
1996 ;; restore position of point
1998 (goto-char orgpoint)
1999 (if (< (current-column) (current-indentation))
2000 (back-to-indentation)))
2002 ;; restore syntax-table
2003 (set-syntax-table previous-syntax-table)
2005 (ad-deactivate 'parse-partial-sexp))
2011 (defun ada-get-current-indent ()
2012 "Return the indentation to use for the current line."
2017 (orgpoint (save-excursion
2019 (forward-comment -10000)
2026 ;;-----------------------------
2027 ;; in open parenthesis, but not in parameter-list
2028 ;;-----------------------------
2030 ((and ada-indent-to-open-paren
2031 (not (ada-in-paramlist-p))
2032 (setq column (ada-in-open-paren-p)))
2034 ;; check if we have something like this (Table_Component_Type =>
2035 ;; Source_File_Record)
2037 (if (and (skip-chars-backward " \t")
2038 (= (char-before) ?\n)
2039 (not (forward-comment -10000))
2040 (= (char-before) ?>))
2041 ;; ??? Could use a different variable
2042 (list column 'ada-broken-indent)
2045 ;;---------------------------
2047 ;;---------------------------
2050 (ada-indent-on-previous-lines nil orgpoint orgpoint))
2052 ;;---------------------------
2054 ;;---------------------------
2056 ((= (char-after) ?e)
2059 ;; ------- end ------
2061 ((looking-at "end\\>")
2065 (ada-goto-matching-start 1)
2068 ;; found 'loop' => skip back to 'while' or 'for'
2069 ;; if 'loop' is not on a separate line
2070 ;; Stop the search for 'while' and 'for' when a ';' is encountered.
2074 (looking-at ".+\\<loop\\>"))
2077 (setq limit (car (ada-search-ignore-string-comment ";" t))))
2081 (ada-search-ignore-string-comment ada-loop-start-re t limit))
2082 (not (looking-at "\\<loop\\>"))))
2084 (goto-char (car match-cons))
2087 (if (looking-at ada-named-block-re)
2088 (setq label (- ada-label-indent))))))))
2090 (list (+ (save-excursion (back-to-indentation) (point)) label) 0))))
2092 ;; ------ exception ----
2094 ((looking-at "exception\\>")
2096 (ada-goto-matching-start 1)
2097 (list (save-excursion (back-to-indentation) (point)) 0)))
2101 ((looking-at "else\\>")
2102 (if (save-excursion (ada-goto-previous-word)
2103 (looking-at "\\<or\\>"))
2104 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2106 (ada-goto-matching-start 1 nil t)
2107 (list (progn (back-to-indentation) (point)) 0))))
2111 ((looking-at "elsif\\>")
2113 (ada-goto-matching-start 1 nil t)
2114 (list (progn (back-to-indentation) (point)) 0)))
2118 ;;---------------------------
2119 ;; starting with w (when)
2120 ;;---------------------------
2122 ((and (= (char-after) ?w)
2123 (looking-at "when\\>"))
2125 (ada-goto-matching-start 1)
2126 (list (save-excursion (back-to-indentation) (point))
2129 ;;---------------------------
2130 ;; starting with t (then)
2131 ;;---------------------------
2133 ((and (= (char-after) ?t)
2134 (looking-at "then\\>"))
2135 (if (save-excursion (ada-goto-previous-word)
2136 (looking-at "and\\>"))
2137 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2139 ;; Select has been added for the statement: "select ... then abort"
2140 (ada-search-ignore-string-comment
2141 "\\<\\(elsif\\|if\\|select\\)\\>" t nil)
2142 (list (progn (back-to-indentation) (point))
2143 'ada-stmt-end-indent))))
2145 ;;---------------------------
2146 ;; starting with l (loop)
2147 ;;---------------------------
2149 ((and (= (char-after) ?l)
2150 (looking-at "loop\\>"))
2153 (goto-char (match-end 0))
2154 (ada-goto-stmt-start)
2155 (if (looking-at "\\<\\(loop\\|if\\)\\>")
2156 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2157 (unless (looking-at ada-loop-start-re)
2158 (ada-search-ignore-string-comment ada-loop-start-re
2160 (if (looking-at "\\<loop\\>")
2161 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2162 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent)))))
2164 ;;---------------------------
2165 ;; starting with b (begin)
2166 ;;---------------------------
2168 ((and (= (char-after) ?b)
2169 (looking-at "begin\\>"))
2171 (if (ada-goto-matching-decl-start t)
2172 (list (progn (back-to-indentation) (point)) 0)
2173 (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2175 ;;---------------------------
2176 ;; starting with i (is)
2177 ;;---------------------------
2179 ((and (= (char-after) ?i)
2180 (looking-at "is\\>"))
2182 (if (and ada-indent-is-separate
2184 (goto-char (match-end 0))
2185 (ada-goto-next-non-ws (save-excursion (end-of-line)
2187 (looking-at "\\<abstract\\>\\|\\<separate\\>")))
2189 (ada-goto-stmt-start)
2190 (list (progn (back-to-indentation) (point)) 'ada-indent))
2192 (ada-goto-stmt-start)
2193 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent))))
2195 ;;---------------------------
2196 ;; starting with r (record, return, renames)
2197 ;;---------------------------
2199 ((= (char-after) ?r)
2203 ;; ----- record ------
2205 ((looking-at "record\\>")
2207 (ada-search-ignore-string-comment
2208 "\\<\\(type\\|use\\)\\>" t nil)
2209 (if (looking-at "\\<use\\>")
2210 (ada-search-ignore-string-comment "for" t nil nil 'word-search-backward))
2211 (list (progn (back-to-indentation) (point)) 'ada-indent-record-rel-type)))
2213 ;; ----- return or renames ------
2215 ((looking-at "re\\(turn\\|names\\)\\>")
2217 (let ((var 'ada-indent-return))
2218 ;; If looking at a renames, skip the 'return' statement too
2219 (if (looking-at "renames")
2222 (setq pos (ada-search-ignore-string-comment ";\\|return\\>" t)))
2224 (= (char-after (car pos)) ?r))
2225 (goto-char (car pos)))
2226 (setq var 'ada-indent-renames)))
2228 (forward-comment -1000)
2229 (if (= (char-before) ?\))
2233 ;; If there is a parameter list, and we have a function declaration
2234 ;; or a access to subprogram declaration
2236 (if (and (= (char-after) ?\()
2240 (looking-at "function\\>"))
2244 (looking-at "function\\>")))))
2246 ;; The indentation depends of the value of ada-indent-return
2247 (if (<= (eval var) 0)
2248 (list (point) (list '- var))
2249 (list (progn (backward-word num-back) (point))
2252 ;; Else there is no parameter list, but we have a function
2253 ;; Only do something special if the user want to indent
2254 ;; relative to the "function" keyword
2255 (if (and (> (eval var) 0)
2256 (save-excursion (forward-word -1)
2257 (looking-at "function\\>")))
2258 (list (progn (forward-word -1) (point)) var)
2261 (ada-indent-on-previous-lines nil orgpoint orgpoint)))))))
2264 ;;--------------------------------
2265 ;; starting with 'o' or 'p'
2266 ;; 'or' as statement-start
2267 ;; 'private' as statement-start
2268 ;;--------------------------------
2270 ((and (or (= (char-after) ?o)
2271 (= (char-after) ?p))
2272 (or (ada-looking-at-semi-or)
2273 (ada-looking-at-semi-private)))
2275 (ada-goto-matching-start 1)
2276 (list (progn (back-to-indentation) (point)) 0)))
2278 ;;--------------------------------
2279 ;; starting with 'd' (do)
2280 ;;--------------------------------
2282 ((and (= (char-after) ?d)
2283 (looking-at "do\\>"))
2285 (ada-goto-stmt-start)
2286 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent)))
2288 ;;--------------------------------
2289 ;; starting with '-' (comment)
2290 ;;--------------------------------
2292 ((= (char-after) ?-)
2293 (if ada-indent-comment-as-code
2295 ;; Indent comments on previous line comments if required
2296 ;; We must use a search-forward (even if the code is more complex),
2297 ;; since we want to find the beginning of the comment.
2300 (if (and ada-indent-align-comments
2304 (while (and (not pos)
2305 (search-forward "--"
2307 (end-of-line) (point))
2309 (unless (ada-in-string-p)
2310 (setq pos (point))))
2314 ;; Else always on previous line
2315 (ada-indent-on-previous-lines nil orgpoint orgpoint)))
2317 ;; Else same indentation as the previous line
2318 (list (save-excursion (back-to-indentation) (point)) 0)))
2320 ;;--------------------------------
2321 ;; starting with '#' (preprocessor line)
2322 ;;--------------------------------
2324 ((and (= (char-after) ?#)
2325 (equal ada-which-compiler 'gnat)
2326 (looking-at "#[ \t]*\\(if\\|els\\(e\\|if\\)\\|end[ \t]*if\\)"))
2327 (list (save-excursion (beginning-of-line) (point)) 0))
2329 ;;--------------------------------
2330 ;; starting with ')' (end of a parameter list)
2331 ;;--------------------------------
2333 ((and (not (eobp)) (= (char-after) ?\)))
2339 ;;---------------------------------
2340 ;; new/abstract/separate
2341 ;;---------------------------------
2343 ((looking-at "\\(new\\|abstract\\|separate\\)\\>")
2344 (ada-indent-on-previous-lines nil orgpoint orgpoint))
2346 ;;---------------------------------
2347 ;; package/function/procedure
2348 ;;---------------------------------
2350 ((and (or (= (char-after) ?p) (= (char-after) ?f))
2351 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>"))
2353 ;; Go up until we find either a generic section, or the end of the
2354 ;; previous subprogram/package
2356 (while (and (not found)
2357 (ada-search-ignore-string-comment
2358 "\\<\\(generic\\|end\\|begin\\|package\\|procedure\\|function\\)\\>" t))
2360 ;; avoid "with procedure"... in generic parts
2363 (setq found (not (looking-at "with"))))))
2365 (if (looking-at "generic")
2366 (list (progn (back-to-indentation) (point)) 0)
2367 (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2369 ;;---------------------------------
2371 ;;---------------------------------
2373 ((looking-at "\\(\\sw\\|_\\)+[ \t\n]*:[^=]")
2375 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2376 (append (ada-indent-on-previous-lines nil orgpoint orgpoint)
2377 '(ada-label-indent))))
2381 ;;---------------------------------
2383 ;;---------------------------------
2384 (or result (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2386 (defun ada-indent-on-previous-lines (&optional nomove orgpoint initial-pos)
2387 "Calculate the indentation for the new line after ORGPOINT.
2388 The result list is based on the previous lines in the buffer.
2389 If NOMOVE is nil, moves point to the beginning of the current statement.
2390 if INITIAL-POS is non-nil, moves point to INITIAL-POS before calculation."
2392 (goto-char initial-pos))
2393 (let ((oldpoint (point)))
2395 ;; Is inside a parameter-list ?
2396 (if (ada-in-paramlist-p)
2397 (ada-get-indent-paramlist)
2399 ;; move to beginning of current statement
2401 (ada-goto-stmt-start))
2403 ;; no beginning found => don't change indentation
2404 (if (and (eq oldpoint (point))
2406 (ada-get-indent-nochange)
2411 ada-indent-to-open-paren
2412 (ada-in-open-paren-p))
2413 (ada-get-indent-open-paren))
2415 ((looking-at "end\\>")
2416 (ada-get-indent-end orgpoint))
2418 ((looking-at ada-loop-start-re)
2419 (ada-get-indent-loop orgpoint))
2421 ((looking-at ada-subprog-start-re)
2422 (ada-get-indent-subprog orgpoint))
2424 ((looking-at ada-block-start-re)
2425 (ada-get-indent-block-start orgpoint))
2427 ((looking-at "\\(sub\\)?type\\>")
2428 (ada-get-indent-type orgpoint))
2430 ;; "then" has to be included in the case of "select...then abort"
2431 ;; statements, since (goto-stmt-start) at the beginning of
2432 ;; the current function would leave the cursor on that position
2433 ((looking-at "\\(\\(els\\)?if\\>\\)\\|then abort\\\>")
2434 (ada-get-indent-if orgpoint))
2436 ((looking-at "case\\>")
2437 (ada-get-indent-case orgpoint))
2439 ((looking-at "when\\>")
2440 (ada-get-indent-when orgpoint))
2442 ((looking-at "\\(\\sw\\|_\\)+[ \t\n]*:[^=]")
2443 (ada-get-indent-label orgpoint))
2445 ((looking-at "separate\\>")
2446 (ada-get-indent-nochange))
2448 ((looking-at "with\\>\\|use\\>")
2449 ;; Are we still in that statement, or are we in fact looking at
2450 ;; the previous one ?
2451 (if (save-excursion (search-forward ";" oldpoint t))
2452 (list (progn (back-to-indentation) (point)) 0)
2453 (list (point) (if (looking-at "with")
2458 (ada-get-indent-noindent orgpoint)))))
2461 (defun ada-get-indent-open-paren ()
2462 "Calculates the indentation when point is behind an unclosed parenthesis."
2463 (list (ada-in-open-paren-p) 0))
2465 (defun ada-get-indent-nochange ()
2466 "Return the current indentation of the previous line."
2469 (back-to-indentation)
2472 (defun ada-get-indent-paramlist ()
2473 "Calculates the indentation when point is inside a parameter list."
2475 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
2477 ;; in front of the first parameter
2478 ((= (char-after) ?\()
2479 (goto-char (match-end 0))
2482 ;; in front of another parameter
2483 ((= (char-after) ?\;)
2484 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
2485 (ada-goto-next-non-ws)
2488 ;; inside a parameter declaration
2490 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
2491 (ada-goto-next-non-ws)
2492 (list (point) 'ada-broken-indent)))))
2494 (defun ada-get-indent-end (orgpoint)
2495 "Calculates the indentation when point is just before an end_statement.
2496 ORGPOINT is the limit position used in the calculation."
2497 (let ((defun-name nil)
2500 ;; is the line already terminated by ';' ?
2502 (ada-search-ignore-string-comment ";" nil orgpoint nil
2505 ;; yes, look what's following 'end'
2508 (ada-goto-next-non-ws)
2510 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\)\\>")
2511 (save-excursion (ada-check-matching-start (match-string 0)))
2512 (list (save-excursion (back-to-indentation) (point)) 0))
2515 ;; loop/select/if/case/record/select
2517 ((looking-at "\\<record\\>")
2519 (ada-check-matching-start (match-string 0))
2520 ;; we are now looking at the matching "record" statement
2522 (ada-goto-stmt-start)
2523 ;; now on the matching type declaration, or use clause
2524 (unless (looking-at "\\(for\\|type\\)\\>")
2525 (ada-search-ignore-string-comment "\\<type\\>" t))
2526 (list (progn (back-to-indentation) (point)) 0)))
2528 ;; a named block end
2530 ((looking-at ada-ident-re)
2531 (setq defun-name (match-string 0))
2533 (ada-goto-matching-start 0)
2534 (ada-check-defun-name defun-name))
2535 (list (progn (back-to-indentation) (point)) 0))
2537 ;; a block-end without name
2539 ((= (char-after) ?\;)
2541 (ada-goto-matching-start 0)
2542 (if (looking-at "\\<begin\\>")
2544 (setq indent (list (point) 0))
2545 (if (ada-goto-matching-decl-start t)
2546 (list (progn (back-to-indentation) (point)) 0)
2549 ;; anything else - should maybe signal an error ?
2552 (list (save-excursion (back-to-indentation) (point))
2553 'ada-broken-indent))))
2555 (list (save-excursion (back-to-indentation) (point))
2556 'ada-broken-indent))))
2558 (defun ada-get-indent-case (orgpoint)
2559 "Calculates the indentation when point is just before a case statement.
2560 ORGPOINT is the limit position used in the calculation."
2561 (let ((match-cons nil)
2565 ;; case..is..when..=>
2568 (setq match-cons (and
2569 ;; the `=>' must be after the keyword `is'.
2570 (ada-search-ignore-string-comment
2571 "is" nil orgpoint nil 'word-search-forward)
2572 (ada-search-ignore-string-comment
2573 "[ \t\n]+=>" nil orgpoint))))
2575 (goto-char (car match-cons))
2576 (unless (ada-search-ignore-string-comment "when" t opos)
2577 (error "missing 'when' between 'case' and '=>'"))
2578 (list (save-excursion (back-to-indentation) (point)) 'ada-indent)))
2583 (setq match-cons (ada-search-ignore-string-comment
2584 "when" nil orgpoint nil 'word-search-forward)))
2585 (goto-char (cdr match-cons))
2586 (list (save-excursion (back-to-indentation) (point)) 'ada-broken-indent))
2591 (setq match-cons (ada-search-ignore-string-comment
2592 "is" nil orgpoint nil 'word-search-forward)))
2593 (list (save-excursion (back-to-indentation) (point)) 'ada-when-indent))
2598 (list (save-excursion (back-to-indentation) (point))
2599 'ada-broken-indent)))))
2601 (defun ada-get-indent-when (orgpoint)
2602 "Calculates the indentation when point is just before a when statement.
2603 ORGPOINT is the limit position used in the calculation."
2604 (let ((cur-indent (save-excursion (back-to-indentation) (point))))
2605 (if (ada-search-ignore-string-comment "[ \t\n]*=>" nil orgpoint)
2606 (list cur-indent 'ada-indent)
2607 (list cur-indent 'ada-broken-indent))))
2609 (defun ada-get-indent-if (orgpoint)
2610 "Calculates the indentation when point is just before an if statement.
2611 ORGPOINT is the limit position used in the calculation."
2612 (let ((cur-indent (save-excursion (back-to-indentation) (point)))
2615 ;; Move to the correct then (ignore all "and then")
2617 (while (and (setq match-cons (ada-search-ignore-string-comment
2618 "\\<\\(then\\|and[ \t]*then\\)\\>"
2620 (= (char-after (car match-cons)) ?a)))
2621 ;; If "then" was found (we are looking at it)
2625 ;; 'then' first in separate line ?
2626 ;; => indent according to 'then',
2627 ;; => else indent according to 'if'
2630 (back-to-indentation)
2631 (looking-at "\\<then\\>"))
2632 (setq cur-indent (save-excursion (back-to-indentation) (point))))
2635 (list cur-indent 'ada-indent))
2637 (list cur-indent 'ada-broken-indent))))
2639 (defun ada-get-indent-block-start (orgpoint)
2640 "Calculates the indentation when point is at the start of a block.
2641 ORGPOINT is the limit position used in the calculation."
2646 (setq pos (ada-goto-next-non-ws orgpoint)))
2649 (ada-indent-on-previous-lines t orgpoint)))
2651 ;; nothing follows the block-start
2653 (list (save-excursion (back-to-indentation) (point)) 'ada-indent)))))
2655 (defun ada-get-indent-subprog (orgpoint)
2656 "Calculates the indentation when point is just before a subprogram.
2657 ORGPOINT is the limit position used in the calculation."
2658 (let ((match-cons nil)
2659 (cur-indent (save-excursion (back-to-indentation) (point)))
2662 ;; is there an 'is' in front of point ?
2666 (ada-search-ignore-string-comment
2667 "\\<\\(is\\|do\\)\\>" nil orgpoint)))
2669 ;; yes, then skip to its end
2673 (goto-char (cdr match-cons)))
2675 ;; no, then goto next non-ws, if there is one in front of point
2678 (unless (ada-goto-next-non-ws orgpoint)
2679 (goto-char orgpoint))))
2683 ;; nothing follows 'is'
2688 (not (ada-search-ignore-string-comment
2689 "[^ \t\n]" nil orgpoint t))))
2690 (list cur-indent 'ada-indent))
2692 ;; is abstract/separate/new ...
2698 (ada-search-ignore-string-comment
2699 "\\<\\(separate\\|new\\|abstract\\)\\>"
2701 (goto-char (car match-cons))
2702 (ada-search-ignore-string-comment ada-subprog-start-re t)
2703 (ada-get-indent-noindent orgpoint))
2705 ;; something follows 'is'
2709 (save-excursion (setq match-cons (ada-goto-next-non-ws orgpoint)))
2710 (goto-char match-cons)
2711 (ada-indent-on-previous-lines t orgpoint)))
2716 (ada-search-ignore-string-comment ";" nil orgpoint nil 'search-forward))
2717 (list cur-indent 0))
2722 (list cur-indent 'ada-broken-indent)))))
2724 (defun ada-get-indent-noindent (orgpoint)
2725 "Calculates the indentation when point is just before a 'noindent stmt'.
2726 ORGPOINT is the limit position used in the calculation."
2733 ;; This one is called when indenting a line preceded by a multi-line
2734 ;; subprogram declaration (in that case, we are at this point inside
2735 ;; the parameter declaration list)
2736 ((ada-in-paramlist-p)
2737 (ada-previous-procedure)
2738 (list (save-excursion (back-to-indentation) (point)) 0))
2740 ;; This one is called when indenting the second line of a multi-line
2741 ;; declaration section, in a declare block or a record declaration
2742 ((looking-at "[ \t]*\\(\\sw\\|_\\)*[ \t]*,[ \t]*$")
2743 (list (save-excursion (back-to-indentation) (point))
2744 'ada-broken-decl-indent))
2746 ;; This one is called in every over case when indenting a line at the
2749 (if (looking-at ada-named-block-re)
2750 (setq label (- ada-label-indent))
2754 ;; "with private" or "null record" cases
2755 (if (or (save-excursion
2756 (and (ada-search-ignore-string-comment "\\<private\\>" nil orgpoint)
2758 (save-excursion (forward-char -7);; skip back "private"
2759 (ada-goto-previous-word)
2760 (looking-at "with"))))
2762 (and (ada-search-ignore-string-comment "\\<record\\>" nil orgpoint)
2764 (save-excursion (forward-char -6);; skip back "record"
2765 (ada-goto-previous-word)
2766 (looking-at "null")))))
2769 (re-search-backward "\\<\\(type\\|subtype\\)\\>" nil t)
2770 (list (save-excursion (back-to-indentation) (point)) 0)))))
2772 (ada-search-ignore-string-comment ";" nil orgpoint nil
2774 (list (+ (save-excursion (back-to-indentation) (point)) label) 0)
2775 (list (+ (save-excursion (back-to-indentation) (point)) label)
2776 'ada-broken-indent)))))))
2778 (defun ada-get-indent-label (orgpoint)
2779 "Calculates the indentation when before a label or variable declaration.
2780 ORGPOINT is the limit position used in the calculation."
2781 (let ((match-cons nil)
2782 (cur-indent (save-excursion (back-to-indentation) (point))))
2783 (ada-search-ignore-string-comment ":" nil)
2787 (setq match-cons (ada-search-ignore-string-comment
2788 ada-loop-start-re nil orgpoint)))
2789 (goto-char (car match-cons))
2790 (ada-get-indent-loop orgpoint))
2794 (setq match-cons (ada-search-ignore-string-comment
2795 "\\<declare\\|begin\\>" nil orgpoint)))
2796 (goto-char (car match-cons))
2797 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2799 ;; variable declaration
2802 (ada-search-ignore-string-comment ";" nil orgpoint))
2804 (list cur-indent 'ada-broken-indent)))
2806 ;; nothing follows colon
2808 (list cur-indent '(- ada-label-indent))))))
2810 (defun ada-get-indent-loop (orgpoint)
2811 "Calculates the indentation when just before a loop or a for ... use.
2812 ORGPOINT is the limit position used in the calculation."
2813 (let ((match-cons nil)
2816 ;; If looking at a named block, skip the label
2817 (label (save-excursion
2819 (if (looking-at ada-named-block-re)
2820 (- ada-label-indent)
2826 ;; statement complete
2829 (ada-search-ignore-string-comment ";" nil orgpoint nil
2831 (list (+ (save-excursion (back-to-indentation) (point)) label) 0))
2835 ((looking-at "loop\\>")
2836 (setq pos (ada-get-indent-block-start orgpoint))
2839 (list (+ (car pos) label) (cdr pos))))
2842 ;; 'for'- loop (or also a for ... use statement)
2844 ((looking-at "for\\>")
2851 (goto-char (match-end 0))
2852 (ada-goto-next-non-ws orgpoint)
2854 (if (= (char-after) ?') (forward-word 1) t)
2855 (ada-goto-next-non-ws orgpoint)
2856 (looking-at "\\<use\\>")
2858 ;; check if there is a 'record' before point
2861 (setq match-cons (ada-search-ignore-string-comment
2862 "record" nil orgpoint nil 'word-search-forward))
2865 (goto-char (car match-cons)))
2866 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2871 (setq match-cons (ada-search-ignore-string-comment
2872 "loop" nil orgpoint nil 'word-search-forward)))
2873 (goto-char (car match-cons))
2875 ;; indent according to 'loop', if it's first in the line;
2876 ;; otherwise to 'for'
2878 (unless (save-excursion
2879 (back-to-indentation)
2880 (looking-at "\\<loop\\>"))
2882 (list (+ (save-excursion (back-to-indentation) (point)) label)
2885 ;; for-statement is broken
2888 (list (+ (save-excursion (back-to-indentation) (point)) label)
2889 'ada-broken-indent))))
2894 ((looking-at "while\\>")
2899 (setq match-cons (ada-search-ignore-string-comment
2900 "loop" nil orgpoint nil 'word-search-forward)))
2903 (goto-char (car match-cons))
2905 ;; indent according to 'loop', if it's first in the line;
2906 ;; otherwise to 'while'.
2908 (unless (save-excursion
2909 (back-to-indentation)
2910 (looking-at "\\<loop\\>"))
2912 (list (+ (save-excursion (back-to-indentation) (point)) label)
2915 (list (+ (save-excursion (back-to-indentation) (point)) label)
2916 'ada-broken-indent))))))
2918 (defun ada-get-indent-type (orgpoint)
2919 "Calculates the indentation when before a type statement.
2920 ORGPOINT is the limit position used in the calculation."
2921 (let ((match-dat nil))
2924 ;; complete record declaration
2928 (setq match-dat (ada-search-ignore-string-comment
2929 "end" nil orgpoint nil 'word-search-forward))
2930 (ada-goto-next-non-ws)
2931 (looking-at "\\<record\\>")
2933 (ada-goto-next-non-ws)
2934 (= (char-after) ?\;)))
2935 (goto-char (car match-dat))
2936 (list (save-excursion (back-to-indentation) (point)) 0))
2941 (setq match-dat (ada-search-ignore-string-comment
2942 "record" nil orgpoint nil 'word-search-forward)))
2943 (goto-char (car match-dat))
2944 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2946 ;; complete type declaration
2949 (ada-search-ignore-string-comment ";" nil orgpoint nil
2951 (list (save-excursion (back-to-indentation) (point)) 0))
2953 ;; "type ... is", but not "type ... is ...", which is broken
2957 (ada-search-ignore-string-comment "is" nil orgpoint nil
2958 'word-search-forward)
2959 (not (ada-goto-next-non-ws orgpoint))))
2960 (list (save-excursion (back-to-indentation) (point)) 'ada-broken-indent))
2965 (list (save-excursion (back-to-indentation) (point))
2966 'ada-broken-indent)))))
2969 ;; -----------------------------------------------------------
2970 ;; -- searching and matching
2971 ;; -----------------------------------------------------------
2973 (defun ada-goto-stmt-start ()
2974 "Moves point to the beginning of the statement that point is in or after.
2975 Returns the new position of point.
2976 As a special case, if we are looking at a closing parenthesis, skip to the
2978 (let ((match-dat nil)
2981 (setq match-dat (ada-search-prev-end-stmt))
2985 ;; found a previous end-statement => check if anything follows
2987 (unless (looking-at "declare")
2989 (unless (save-excursion
2990 (goto-char (cdr match-dat))
2991 (ada-goto-next-non-ws orgpoint))
2993 ;; nothing follows => it's the end-statement directly in
2994 ;; front of point => search again
2996 (setq match-dat (ada-search-prev-end-stmt)))
2998 ;; if found the correct end-statement => goto next non-ws
3001 (goto-char (cdr match-dat)))
3002 (ada-goto-next-non-ws)
3006 ;; no previous end-statement => we are at the beginning of the
3007 ;; accessible part of the buffer
3010 (goto-char (point-min))
3012 ;; skip to the very first statement, if there is one
3014 (unless (ada-goto-next-non-ws orgpoint)
3015 (goto-char orgpoint))))
3019 (defun ada-search-prev-end-stmt ()
3020 "Moves point to previous end-statement.
3021 Returns a cons cell whose car is the beginning and whose cdr the end of the
3023 (let ((match-dat nil)
3026 ;; search until found or beginning-of-buffer
3030 (setq match-dat (ada-search-ignore-string-comment
3031 ada-end-stmt-re t)))
3033 (goto-char (car match-dat))
3034 (unless (ada-in-open-paren-p)
3035 (if (and (looking-at
3036 "\\<\\(record\\|loop\\|select\\|else\\|then\\)\\>")
3038 (ada-goto-previous-word)
3039 (looking-at "\\<\\(end\\|or\\|and\\)\\>[ \t]*[^;]")))
3043 (goto-char (cdr match-dat))
3044 (ada-goto-next-non-ws)
3046 ;; words that can go after an 'is'
3050 (regexp-opt '("separate" "access" "array"
3051 "abstract" "new") t)
3061 (defun ada-goto-next-non-ws (&optional limit)
3062 "Skips white spaces, newlines and comments to next non-ws character.
3063 Stop the search at LIMIT.
3064 Do not call this function from within a string."
3066 (setq limit (point-max)))
3067 (while (and (<= (point) limit)
3068 (progn (forward-comment 10000)
3069 (if (and (not (eobp))
3070 (save-excursion (forward-char 1)
3072 (progn (forward-sexp 1) t)))))
3073 (if (< (point) limit)
3079 (defun ada-goto-stmt-end (&optional limit)
3080 "Moves point to the end of the statement that point is in or before.
3081 Returns the new position of point or nil if not found.
3082 Stop the search at LIMIT."
3083 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
3088 (defun ada-goto-next-word (&optional backward)
3089 "Moves point to the beginning of the next word of Ada code.
3090 If BACKWARD is non-nil, jump to the beginning of the previous word.
3091 Returns the new position of point or nil if not found."
3092 (let ((match-cons nil)
3094 (old-syntax (char-to-string (char-syntax ?_))))
3095 (modify-syntax-entry ?_ "w")
3097 (skip-syntax-forward "w"))
3098 (if (setq match-cons
3100 (ada-search-ignore-string-comment "\\w" t nil t)
3101 (ada-search-ignore-string-comment "\\w" nil nil t)))
3103 ;; move to the beginning of the word found
3106 (goto-char (car match-cons))
3107 (skip-syntax-backward "w")
3110 ;; if not found, restore old position of point
3112 (goto-char orgpoint)
3114 (modify-syntax-entry ?_ old-syntax))
3118 (defun ada-check-matching-start (keyword)
3119 "Signals an error if matching block start is not KEYWORD.
3120 Moves point to the matching block start."
3121 (ada-goto-matching-start 0)
3122 (unless (looking-at (concat "\\<" keyword "\\>"))
3123 (error "matching start is not '%s'" keyword)))
3126 (defun ada-check-defun-name (defun-name)
3127 "Checks if the name of the matching defun really is DEFUN-NAME.
3128 Assumes point to be already positioned by 'ada-goto-matching-start'.
3129 Moves point to the beginning of the declaration."
3131 ;; named block without a `declare'
3133 (ada-goto-previous-word)
3134 (looking-at (concat "\\<" defun-name "\\> *:")))
3137 ;; 'accept' or 'package' ?
3139 (unless (looking-at ada-subprog-start-re)
3140 (ada-goto-matching-decl-start))
3142 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
3146 ;; a named 'declare'-block ?
3148 (if (looking-at "\\<declare\\>")
3149 (ada-goto-stmt-start)
3151 ;; no, => 'procedure'/'function'/'task'/'protected'
3157 ;; skip 'body' 'type'
3159 (if (looking-at "\\<\\(body\\|type\\)\\>")
3164 ;; should be looking-at the correct name
3166 (unless (looking-at (concat "\\<" defun-name "\\>"))
3167 (error "matching defun has different name: %s"
3168 (buffer-substring (point)
3169 (progn (forward-sexp 1) (point))))))))
3171 (defun ada-goto-matching-decl-start (&optional noerror recursive)
3172 "Moves point to the matching declaration start of the current 'begin'.
3173 If NOERROR is non-nil, it only returns nil if no match was found."
3174 (let ((nest-count 1)
3175 (first (not recursive))
3180 ;; Ignore "when" most of the time, except if we are looking at the
3181 ;; beginning of a block (structure: case .. is
3185 (if (looking-at "begin")
3186 (setq stop-at-when t))
3189 (looking-at "\\<\\(package\\|procedure\\|function\\)\\>")
3191 (ada-search-ignore-string-comment
3192 "\\<\\(package\\|procedure\\|function\\|generic\\)\\>" t)
3193 (looking-at "generic")))
3194 (setq count-generic t))
3196 ;; search backward for interesting keywords
3198 (not (zerop nest-count))
3199 (ada-search-ignore-string-comment ada-matching-decl-start-re t))
3201 ;; calculate nest-depth
3206 (ada-goto-matching-start 1 noerror)
3208 ;; In some case, two begin..end block can follow each other closely,
3209 ;; which we have to detect, as in
3214 ;; begin -- here we should go to procedure, not begin
3217 (if (looking-at "begin")
3218 (let ((loop-again t))
3221 ;; If begin was just there as the beginning of a block
3222 ;; (with no declare) then do nothing, otherwise just
3223 ;; register that we have to find the statement that
3224 ;; required the begin
3226 (ada-search-ignore-string-comment
3227 "\\<\\(declare\\|begin\\|end\\|procedure\\|function\\|task\\|package\\)\\>"
3230 (if (looking-at "end")
3231 (ada-goto-matching-decl-start noerror t)
3233 (setq loop-again nil)
3234 (unless (looking-at "begin")
3235 (setq nest-count (1+ nest-count))))
3239 ((looking-at "generic")
3243 (setq nest-count (1- nest-count)))))
3248 (unless (looking-at "\\<end[ \t\n]*if\\>")
3250 (setq nest-count (1- nest-count))
3251 (setq first nil)))))
3254 ((looking-at "declare\\|generic")
3255 (setq nest-count (1- nest-count))
3259 ;; check if it is only a type definition, but not a protected
3260 ;; type definition, which should be handled like a procedure.
3261 (if (or (looking-at "is[ \t]+<>")
3263 (forward-comment -10000)
3266 ;; Detect if we have a closing parenthesis (Could be
3267 ;; either the end of subprogram parameters or (<>)
3268 ;; in a type definition
3269 (if (= (char-after) ?\))
3273 (forward-comment -10000)
3275 (skip-chars-backward "a-zA-Z0-9_.'")
3276 (ada-goto-previous-word)
3278 (looking-at "\\<\\(sub\\)?type\\>")
3280 (ada-goto-previous-word)
3281 (not (looking-at "\\<protected\\>"))))
3283 (goto-char (match-beginning 0))
3285 (setq nest-count (1- nest-count))
3291 (ada-goto-previous-word)
3293 (goto-char (match-beginning 0))))
3296 (looking-at "begin"))
3297 (setq nest-count 0))
3299 ((looking-at "when")
3301 (setq nest-count (1- nest-count)))
3305 (setq nest-count (1+ nest-count))
3310 ;; check if declaration-start is really found
3313 (if (looking-at "is")
3314 (ada-search-ignore-string-comment ada-subprog-start-re t)
3315 (looking-at "declare\\|generic")))
3318 (error "no matching proc/func/task/declare/package/protected")))
3321 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
3322 "Moves point to the beginning of a block-start.
3323 Which block depends on the value of NEST-LEVEL, which defaults to zero. If
3324 NOERROR is non-nil, it only returns nil if no matching start was found.
3325 If GOTOTHEN is non-nil, point moves to the 'then' following 'if'."
3326 (let ((nest-count (if nest-level nest-level 0))
3331 ;; search backward for interesting keywords
3335 (ada-search-ignore-string-comment ada-matching-start-re t))
3337 (unless (and (looking-at "\\<record\\>")
3340 (looking-at "\\<null\\>")))
3343 ;; calculate nest-depth
3346 ;; found block end => increase nest depth
3348 (setq nest-count (1+ nest-count)))
3350 ;; found loop/select/record/case/if => check if it starts or
3352 ((looking-at "loop\\|select\\|record\\|case\\|if")
3356 ;; check if keyword follows 'end'
3358 (ada-goto-previous-word)
3359 (if (looking-at "\\<end\\>[ \t]*[^;]")
3360 ;; it ends a block => increase nest depth
3362 (setq nest-count (1+ nest-count))
3364 ;; it starts a block => decrease nest depth
3365 (setq nest-count (1- nest-count))))
3368 ;; found package start => check if it really is a block
3369 ((looking-at "package")
3371 ;; ignore if this is just a renames statement
3372 (let ((current (point))
3373 (pos (ada-search-ignore-string-comment
3374 "\\<\\(is\\|renames\\|;\\)\\>" nil)))
3376 (goto-char (car pos))
3378 "No matching 'is' or 'renames' for 'package' at"
3380 (number-to-string (count-lines (point-min)
3382 (unless (looking-at "renames")
3385 (ada-goto-next-non-ws)
3386 ;; ignore it if it is only a declaration with 'new'
3387 (if (not (looking-at "\\<\\(new\\|separate\\)\\>"))
3388 (setq nest-count (1- nest-count)))))))
3389 ;; found task start => check if it has a body
3390 ((looking-at "task")
3393 (ada-goto-next-non-ws)
3395 ((looking-at "\\<body\\>"))
3396 ((looking-at "\\<type\\>")
3397 ;; In that case, do nothing if there is a "is"
3398 (forward-word 2);; skip "type"
3399 (ada-goto-next-non-ws);; skip type name
3401 ;; Do nothing if we are simply looking at a simple
3402 ;; "task type name;" statement with no block
3403 (unless (looking-at ";")
3405 ;; Skip the parameters
3406 (if (looking-at "(")
3407 (ada-search-ignore-string-comment ")" nil))
3408 (let ((tmp (ada-search-ignore-string-comment
3409 "\\<\\(is\\|;\\)\\>" nil)))
3412 (goto-char (car tmp))
3413 (if (looking-at "is")
3414 (setq nest-count (1- nest-count)))))))))
3416 ;; Check if that task declaration had a block attached to
3417 ;; it (i.e do nothing if we have just "task name;")
3418 (unless (progn (forward-word 1)
3419 (looking-at "[ \t]*;"))
3420 (setq nest-count (1- nest-count)))))))
3421 ;; all the other block starts
3423 (setq nest-count (1- nest-count)))) ; end of 'cond'
3425 ;; match is found, if nest-depth is zero
3427 (setq found (zerop nest-count))))) ; end of loop
3431 ;; match found => is there anything else to do ?
3436 ;; found 'if' => skip to 'then', if it's on a separate line
3437 ;; and GOTOTHEN is non-nil
3443 (ada-search-ignore-string-comment "then" nil nil nil
3444 'word-search-forward)
3445 (back-to-indentation)
3446 (looking-at "\\<then\\>")))
3447 (goto-char (match-beginning 0)))
3449 ;; found 'do' => skip back to 'accept'
3452 (unless (ada-search-ignore-string-comment "accept" t nil nil
3453 'word-search-backward)
3454 (error "missing 'accept' in front of 'do'"))))
3459 (error "no matching start")))))
3462 (defun ada-goto-matching-end (&optional nest-level noerror)
3463 "Moves point to the end of a block.
3464 Which block depends on the value of NEST-LEVEL, which defaults to zero.
3465 If NOERROR is non-nil, it only returns nil if found no matching start."
3466 (let ((nest-count (if nest-level nest-level 0))
3470 ;; search forward for interesting keywords
3474 (ada-search-ignore-string-comment
3477 (regexp-opt '("end" "loop" "select" "begin" "case"
3478 "if" "task" "package" "record" "do") t)
3482 ;; calculate nest-depth
3486 ;; found block end => decrease nest depth
3487 ((looking-at "\\<end\\>")
3488 (setq nest-count (1- nest-count))
3489 ;; skip the following keyword
3491 (skip-chars-forward "end")
3492 (ada-goto-next-non-ws)
3493 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>"))
3495 ;; found package start => check if it really starts a block
3496 ((looking-at "\\<package\\>")
3497 (ada-search-ignore-string-comment "is" nil nil nil
3498 'word-search-forward)
3499 (ada-goto-next-non-ws)
3500 ;; ignore and skip it if it is only a 'new' package
3501 (if (looking-at "\\<new\\>")
3502 (goto-char (match-end 0))
3503 (setq nest-count (1+ nest-count))))
3504 ;; all the other block starts
3506 (setq nest-count (1+ nest-count))
3507 (forward-word 1))) ; end of 'cond'
3509 ;; match is found, if nest-depth is zero
3511 (setq found (zerop nest-count))) ; end of loop
3517 (error "no matching end")))
3521 (defun ada-search-ignore-string-comment
3522 (search-re &optional backward limit paramlists search-func)
3523 "Regexp-search for SEARCH-RE, ignoring comments, strings.
3524 If PARAMLISTS is nil, ignore parameter lists. Returns a cons cell of
3525 begin and end of match data or nil, if not found.
3526 The search is done using SEARCH-FUNC, which should search backward if
3527 BACKWARD is non-nil, forward otherwise. SEARCH-FUNC can be optimized in case
3528 we are searching for a constant string.
3529 The search stops at pos LIMIT.
3530 Point is moved at the beginning of the search-re."
3535 (previous-syntax-table (syntax-table)))
3538 (setq search-func (if backward 're-search-backward 're-search-forward)))
3541 ;; search until found or end-of-buffer
3542 ;; We have to test that we do not look further than limit
3544 (set-syntax-table ada-mode-symbol-syntax-table)
3545 (while (and (not found)
3547 (or (and backward (<= limit (point)))
3548 (>= limit (point))))
3549 (funcall search-func search-re limit 1))
3550 (setq begin (match-beginning 0))
3551 (setq end (match-end 0))
3553 (setq parse-result (parse-partial-sexp
3554 (save-excursion (beginning-of-line) (point))
3559 ;; If inside a string, skip it (and the following comments)
3561 ((ada-in-string-p parse-result)
3563 (search-backward "\"" nil t)
3564 (goto-char (nth 8 parse-result)))
3565 (unless backward (forward-sexp 1)))
3567 ;; If inside a comment, skip it (and the following comments)
3568 ;; There is a special code for comments at the end of the file
3570 ((ada-in-comment-p parse-result)
3575 (forward-comment -1))
3576 (goto-char (nth 8 parse-result)))
3578 ;; at the end of the file, it is not possible to skip a comment
3579 ;; so we just go at the end of the line
3580 (if (forward-comment 1)
3582 (forward-comment 1000)
3583 (beginning-of-line))
3586 ;; directly in front of a comment => skip it, if searching forward
3588 ((and (= (char-after begin) ?-) (= (char-after (1+ begin)) ?-))
3589 (unless backward (progn (forward-char -1) (forward-comment 1000))))
3592 ;; found a parameter-list but should ignore it => skip it
3594 ((and (not paramlists) (ada-in-paramlist-p))
3596 (search-backward "(" nil t)
3597 (search-forward ")" nil t)))
3599 ;; found what we were looking for
3602 (setq found t)))) ; end of loop
3604 (set-syntax-table previous-syntax-table)
3610 ;; -------------------------------------------------------
3611 ;; -- Testing the position of the cursor
3612 ;; -------------------------------------------------------
3614 (defun ada-in-decl-p ()
3615 "Returns t if point is inside a declarative part.
3616 Assumes point to be at the end of a statement."
3617 (or (ada-in-paramlist-p)
3619 (ada-goto-matching-decl-start t))))
3622 (defun ada-looking-at-semi-or ()
3623 "Returns t if looking-at an 'or' following a semicolon."
3625 (and (looking-at "\\<or\\>")
3628 (ada-goto-stmt-start)
3629 (looking-at "\\<or\\>")))))
3632 (defun ada-looking-at-semi-private ()
3633 "Returns t if looking at the start of a private section in a package.
3634 Returns nil if the private is part of the package name, as in
3635 'private package A is...' (this can only happen at top level)."
3637 (and (looking-at "\\<private\\>")
3638 (not (looking-at "\\<private[ \t]*\\(package\\|generic\\)"))
3640 ;; Make sure this is the start of a private section (ie after
3641 ;; a semicolon or just after the package declaration, but not
3642 ;; after a 'type ... is private' or 'is new ... with private'
3643 (progn (forward-comment -1000)
3644 (or (= (char-before) ?\;)
3645 (and (forward-word -3)
3646 (looking-at "\\<package\\>")))))))
3649 (defun ada-in-paramlist-p ()
3650 "Returns t if point is inside a parameter-list."
3653 (ada-search-ignore-string-comment "(\\|)" t nil t)
3654 ;; inside parentheses ?
3655 (= (char-after) ?\()
3657 ;; We could be looking at two things here:
3658 ;; operator definition: function "." (
3659 ;; subprogram definition: procedure .... (
3660 ;; Let's skip back over the first one
3662 (skip-syntax-backward " ")
3663 (if (= (char-before) ?\")
3668 ;; and now over the second one
3671 ;; We should ignore the case when the reserved keyword is in a
3672 ;; comment (for instance, when we have:
3675 ;; we should return nil
3677 (not (ada-in-string-or-comment-p))
3679 ;; right keyword two words before parenthesis ?
3680 ;; Type is in this list because of discriminants
3681 (looking-at (eval-when-compile
3683 "procedure\\|function\\|body\\|"
3684 "task\\|entry\\|accept\\|"
3685 "access[ \t]+procedure\\|"
3686 "access[ \t]+function\\|"
3690 (defun ada-search-ignore-complex-boolean (regexp backwardp)
3691 "Like `ada-search-ignore-string-comment', except that it also ignores
3692 boolean expressions 'and then' and 'or else'."
3694 (while (and (setq result (ada-search-ignore-string-comment regexp backwardp))
3695 (save-excursion (forward-word -1)
3696 (looking-at "and then\\|or else"))))
3699 (defun ada-in-open-paren-p ()
3700 "Returns the position of the first non-ws behind the last unclosed
3701 parenthesis, or nil."
3703 (let ((parse (parse-partial-sexp
3705 (or (car (ada-search-ignore-complex-boolean
3706 "\\<\\(;\\|is\\|then\\|loop\\|begin\\|else\\)\\>"
3712 (goto-char (1+ (nth 1 parse)))
3713 (skip-chars-forward " \t")
3717 ;; -----------------------------------------------------------
3718 ;; -- Behavior Of TAB Key
3719 ;; -----------------------------------------------------------
3722 "Do indenting or tabbing according to `ada-tab-policy'.
3723 In Transient Mark mode, if the mark is active, operate on the contents
3724 of the region. Otherwise, operates only on the current line."
3726 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard))
3727 ((eq ada-tab-policy 'indent-auto)
3728 ;; transient-mark-mode and mark-active are not defined in XEmacs
3729 (if (or (and ada-xemacs (funcall (symbol-function 'region-active-p)))
3730 (and (not ada-xemacs)
3731 (symbol-value 'transient-mark-mode)
3732 (symbol-value 'mark-active)))
3733 (ada-indent-region (region-beginning) (region-end))
3734 (ada-indent-current)))
3735 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3738 (defun ada-untab (arg)
3739 "Delete leading indenting according to `ada-tab-policy'."
3741 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard))
3742 ((eq ada-tab-policy 'indent-auto) (error "not implemented"))
3743 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3746 (defun ada-indent-current-function ()
3747 "Ada mode version of the indent-line-function."
3749 (let ((starting-point (point-marker)))
3752 (if (< (point) starting-point)
3753 (goto-char starting-point))
3754 (set-marker starting-point nil)
3757 (defun ada-tab-hard ()
3758 "Indent current line to next tab stop."
3762 (insert-char ? ada-indent))
3763 (if (save-excursion (= (point) (progn (beginning-of-line) (point))))
3764 (forward-char ada-indent)))
3766 (defun ada-untab-hard ()
3767 "indent current line to previous tab stop."
3769 (let ((bol (save-excursion (progn (beginning-of-line) (point))))
3770 (eol (save-excursion (progn (end-of-line) (point)))))
3771 (indent-rigidly bol eol (- 0 ada-indent))))
3775 ;; ------------------------------------------------------------
3777 ;; ------------------------------------------------------------
3779 (defun ada-gnat-style ()
3780 "Clean up comments, `(' and `,' for GNAT style checking switch."
3783 (goto-char (point-min))
3784 (while (re-search-forward "--[ \t]*\\([^-]\\)" nil t)
3785 (replace-match "-- \\1"))
3786 (goto-char (point-min))
3787 (while (re-search-forward "\\>(" nil t)
3788 (replace-match " ("))
3789 (goto-char (point-min))
3790 (while (re-search-forward "([ \t]+" nil t)
3791 (replace-match "("))
3792 (goto-char (point-min))
3793 (while (re-search-forward ")[ \t]+)" nil t)
3794 (replace-match "))"))
3795 (goto-char (point-min))
3796 (while (re-search-forward "\\>:" nil t)
3797 (replace-match " :"))
3798 (goto-char (point-min))
3799 (while (re-search-forward ",\\<" nil t)
3800 (replace-match ", "))
3801 (goto-char (point-min))
3802 (while (re-search-forward "[ \t]*\\.\\.[ \t]*" nil t)
3803 (replace-match " .. "))
3804 (goto-char (point-min))
3805 (while (re-search-forward "[ \t]*\\([-:+*/]\\)[ \t]*" nil t)
3806 (if (not (ada-in-string-or-comment-p))
3811 (replace-match " /= "))
3813 (replace-match ":= "))
3814 ((not (looking-at "--"))
3815 (replace-match " \\1 ")))
3821 ;; -------------------------------------------------------------
3822 ;; -- Moving To Procedures/Packages/Statements
3823 ;; -------------------------------------------------------------
3825 (defun ada-move-to-start ()
3826 "Moves point to the matching start of the current Ada structure."
3829 (previous-syntax-table (syntax-table)))
3832 (set-syntax-table ada-mode-symbol-syntax-table)
3834 (message "searching for block start ...")
3837 ;; do nothing if in string or comment or not on 'end ...;'
3838 ;; or if an error occurs during processing
3841 (ada-in-string-or-comment-p)
3843 (or (looking-at "[ \t]*\\<end\\>")
3845 (or (looking-at "[ \t]*\\<end\\>")
3847 (or (looking-at "[ \t]*\\<end\\>")
3848 (error "not on end ...;")))
3849 (ada-goto-matching-start 1)
3853 ;; on 'begin' => go on, according to user option
3855 ada-move-to-declaration
3856 (looking-at "\\<begin\\>")
3857 (ada-goto-matching-decl-start)
3858 (setq pos (point))))
3860 ) ; end of save-excursion
3862 ;; now really move to the found position
3864 (message "searching for block start ... done"))
3866 ;; restore syntax-table
3867 (set-syntax-table previous-syntax-table))))
3869 (defun ada-move-to-end ()
3870 "Moves point to the matching end of the block around point.
3871 Moves to 'begin' if in a declarative part."
3874 (previous-syntax-table (syntax-table)))
3877 (set-syntax-table ada-mode-symbol-syntax-table)
3879 (message "searching for block end ...")
3884 ;; directly on 'begin'
3886 (ada-goto-previous-word)
3887 (looking-at "\\<begin\\>"))
3888 (ada-goto-matching-end 1))
3889 ;; on first line of defun declaration
3891 (and (ada-goto-stmt-start)
3892 (looking-at "\\<function\\>\\|\\<procedure\\>" )))
3893 (ada-search-ignore-string-comment "begin" nil nil nil
3894 'word-search-forward))
3895 ;; on first line of task declaration
3897 (and (ada-goto-stmt-start)
3898 (looking-at "\\<task\\>" )
3900 (ada-goto-next-non-ws)
3901 (looking-at "\\<body\\>")))
3902 (ada-search-ignore-string-comment "begin" nil nil nil
3903 'word-search-forward))
3904 ;; accept block start
3906 (and (ada-goto-stmt-start)
3907 (looking-at "\\<accept\\>" )))
3908 (ada-goto-matching-end 0))
3911 (and (ada-goto-matching-decl-start t)
3912 (looking-at "\\<package\\>")))
3913 (ada-goto-matching-end 1))
3914 ;; inside a 'begin' ... 'end' block
3916 (ada-goto-matching-decl-start t))
3917 (ada-search-ignore-string-comment "begin" nil nil nil
3918 'word-search-forward))
3919 ;; (hopefully ;-) everything else
3921 (ada-goto-matching-end 1)))
3925 ;; now really move to the position found
3927 (message "searching for block end ... done"))
3929 ;; restore syntax-table
3930 (set-syntax-table previous-syntax-table))))
3932 (defun ada-next-procedure ()
3933 "Moves point to next procedure."
3936 (if (re-search-forward ada-procedure-start-regexp nil t)
3937 (goto-char (match-beginning 1))
3938 (error "No more functions/procedures/tasks")))
3940 (defun ada-previous-procedure ()
3941 "Moves point to previous procedure."
3944 (if (re-search-backward ada-procedure-start-regexp nil t)
3945 (goto-char (match-beginning 1))
3946 (error "No more functions/procedures/tasks")))
3948 (defun ada-next-package ()
3949 "Moves point to next package."
3952 (if (re-search-forward ada-package-start-regexp nil t)
3953 (goto-char (match-beginning 1))
3954 (error "No more packages")))
3956 (defun ada-previous-package ()
3957 "Moves point to previous package."
3960 (if (re-search-backward ada-package-start-regexp nil t)
3961 (goto-char (match-beginning 1))
3962 (error "No more packages")))
3965 ;; ------------------------------------------------------------
3966 ;; -- Define keymap and menus for Ada
3967 ;; -------------------------------------------------------------
3969 (defun ada-create-keymap ()
3970 "Create the keymap associated with the Ada mode."
3972 ;; Indentation and Formatting
3973 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent-conditional)
3974 (define-key ada-mode-map "\C-m" 'ada-indent-newline-indent-conditional)
3975 (define-key ada-mode-map "\t" 'ada-tab)
3976 (define-key ada-mode-map "\C-c\t" 'ada-justified-indent-current)
3977 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region)
3979 (define-key ada-mode-map '(shift tab) 'ada-untab)
3980 (define-key ada-mode-map [S-tab] 'ada-untab))
3981 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist)
3982 ;; We don't want to make meta-characters case-specific.
3985 (define-key ada-mode-map "\M-\C-e" 'ada-next-procedure)
3986 (define-key ada-mode-map "\M-\C-a" 'ada-previous-procedure)
3987 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3988 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3991 (unless (lookup-key ada-mode-map "\C-c\C-c")
3992 (define-key ada-mode-map "\C-c\C-c" 'compile))
3995 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3996 (define-key ada-mode-map "\C-c\C-t" 'ada-case-read-exceptions)
3997 (define-key ada-mode-map "\C-c\C-y" 'ada-create-case-exception)
3999 ;; On XEmacs, you can easily specify whether DEL should deletes
4000 ;; one character forward or one character backward. Take this into
4002 (if (boundp 'delete-key-deletes-forward)
4003 (define-key ada-mode-map [backspace] 'backward-delete-char-untabify)
4004 (define-key ada-mode-map "\177" 'backward-delete-char-untabify))
4007 (define-key ada-mode-map "\C-c\C-n" 'ada-make-subprogram-body)
4009 ;; Use predefined function of Emacs19 for comments (RE)
4010 (define-key ada-mode-map "\C-c;" 'comment-region)
4011 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
4015 (defun ada-create-menu ()
4016 "Create the ada menu as shown in the menu bar.
4017 This function is designed to be extensible, so that each compiler-specific file
4018 can add its own items."
4019 ;; Note that the separators must have different length in the submenus
4020 (autoload 'easy-menu-define "easymenu")
4023 ("Help" ["Ada Mode" (info "ada-mode") t])))
4024 (option '(["Auto Casing" (setq ada-auto-case (not ada-auto-case))
4025 :style toggle :selected ada-auto-case]
4026 ["Auto Indent After Return"
4027 (setq ada-indent-after-return (not ada-indent-after-return))
4028 :style toggle :selected ada-indent-after-return]))
4029 (goto '(["Next compilation error" next-error t]
4030 ["Previous Package" ada-previous-package t]
4031 ["Next Package" ada-next-package t]
4032 ["Previous Procedure" ada-previous-procedure t]
4033 ["Next Procedure" ada-next-procedure t]
4034 ["Goto Start Of Statement" ada-move-to-start t]
4035 ["Goto End Of Statement" ada-move-to-end t]
4037 ["Other File" ff-find-other-file t]
4038 ["Other File Other Window" ada-ff-other-window t]))
4039 (edit '(["Indent Line" ada-indent-current-function t]
4040 ["Justify Current Indentation" ada-justified-indent-current t]
4041 ["Indent Lines in Selection" ada-indent-region t]
4042 ["Indent Lines in File" (ada-indent-region (point-min) (point-max)) t]
4043 ["Format Parameter List" ada-format-paramlist t]
4045 ["Comment Selection" comment-region t]
4046 ["Uncomment Selection" ada-uncomment-region t]
4048 ["Fill Comment Paragraph" fill-paragraph t]
4049 ["Fill Comment Paragraph Justify" ada-fill-comment-paragraph-justify t]
4050 ["Fill Comment Paragraph Postfix" ada-fill-comment-paragraph-postfix t]
4052 ["Adjust Case Selection" ada-adjust-case-region t]
4053 ["Adjust Case Buffer" ada-adjust-case-buffer t]
4054 ["Create Case Exception" ada-create-case-exception t]
4055 ["Reload Case Exceptions" ada-case-read-exceptions t]
4057 ["Make body for subprogram" ada-make-subprogram-body t]))
4061 ;; Option menu present only if in Ada mode
4062 (setq m (append m (list (append (list "Options"
4063 (if ada-xemacs :included :visible)
4064 '(string= mode-name "Ada"))
4067 ;; Customize menu always present
4068 (setq m (append m '(["Customize" (customize-group 'ada)
4069 (>= emacs-major-version 20)])))
4071 ;; Goto and Edit menus present only if in Ada mode
4072 (setq m (append m (list (append (list "Goto"
4073 (if ada-xemacs :included :visible)
4074 '(string= mode-name "Ada"))
4076 (append (list "Edit"
4077 (if ada-xemacs :included :visible)
4078 '(string= mode-name "Ada"))
4081 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode" m)
4084 (easy-menu-add ada-mode-menu ada-mode-map)
4085 (define-key ada-mode-map [menu-bar] ada-mode-menu)
4086 (setq mode-popup-menu (cons "Ada mode" ada-mode-menu)))
4091 ;; -------------------------------------------------------
4092 ;; Commenting/Uncommenting code
4093 ;; The following two calls are provided to enhance the standard
4094 ;; comment-region function, which only allows uncommenting if the
4095 ;; comment is at the beginning of a line. If the line have been re-indented,
4096 ;; we are unable to use comment-region, which makes no sense.
4098 ;; In addition, we provide an interface to the standard comment handling
4099 ;; function for justifying the comments.
4100 ;; -------------------------------------------------------
4102 (defadvice comment-region (before ada-uncomment-anywhere)
4105 (string= mode-name "Ada"))
4107 (let ((cs (concat "^[ \t]*" (regexp-quote comment-start))))
4109 (while (re-search-forward cs end t)
4110 (replace-match comment-start))
4113 (defun ada-uncomment-region (beg end &optional arg)
4114 "Delete `comment-start' at the beginning of a line in the region."
4115 (interactive "r\nP")
4117 ;; This advice is not needed anymore with Emacs21. However, for older
4118 ;; versions, as well as for XEmacs, we still need to enable it.
4119 (if (or (<= emacs-major-version 20) (boundp 'running-xemacs))
4121 (ad-activate 'comment-region)
4122 (comment-region beg end (- (or arg 1)))
4123 (ad-deactivate 'comment-region))
4124 (comment-region beg end (list (- (or arg 1))))))
4126 (defun ada-fill-comment-paragraph-justify ()
4127 "Fills current comment paragraph and justifies each line as well."
4129 (ada-fill-comment-paragraph 'full))
4131 (defun ada-fill-comment-paragraph-postfix ()
4132 "Fills current comment paragraph and justifies each line as well.
4133 Adds `ada-fill-comment-postfix' at the end of each line."
4135 (ada-fill-comment-paragraph 'full t))
4137 (defun ada-fill-comment-paragraph (&optional justify postfix)
4138 "Fills the current comment paragraph.
4139 If JUSTIFY is non-nil, each line is justified as well.
4140 If POSTFIX and JUSTIFY are non-nil, `ada-fill-comment-postfix' is appended
4141 to each filled and justified line.
4142 The paragraph is indented on the first line."
4145 ;; check if inside comment or just in front a comment
4146 (if (and (not (ada-in-comment-p))
4147 (not (looking-at "[ \t]*--")))
4148 (error "not inside comment"))
4153 (opos (point-marker))
4155 ;; Sets this variable to nil, otherwise it prevents
4156 ;; fill-region-as-paragraph to work on Emacs <= 20.2
4157 (parse-sexp-lookup-properties nil)
4160 (fill-column (current-fill-column)))
4162 ;; Find end of paragraph
4163 (back-to-indentation)
4164 (while (and (not (eobp)) (looking-at "--[ \t]*[^ \t\n]"))
4167 ;; If we were at the last line in the buffer, create a dummy empty
4168 ;; line at the end of the buffer.
4171 (back-to-indentation)))
4173 (setq to (point-marker))
4176 ;; Find beginning of paragraph
4177 (back-to-indentation)
4178 (while (and (not (bobp)) (looking-at "--[ \t]*[^ \t\n]"))
4180 (back-to-indentation))
4182 ;; We want one line to above the first one, unless we are at the beginning
4187 (setq from (point-marker))
4189 ;; Calculate the indentation we will need for the paragraph
4190 (back-to-indentation)
4191 (setq indent (current-column))
4192 ;; unindent the first line of the paragraph
4193 (delete-region from (point))
4195 ;; Remove the old postfixes
4197 (while (re-search-forward "--\n" to t)
4198 (replace-match "\n"))
4200 ;; Remove the old prefixes (so that the number of spaces after -- is not
4201 ;; relevant), except on the first one since `fill-region-as-paragraph'
4202 ;; would not put it back on the first line.
4203 (goto-char (+ from 2))
4204 (while (re-search-forward "^-- *" to t)
4205 (replace-match " "))
4208 (setq to (point-marker))
4210 ;; Indent and justify the paragraph
4211 (setq fill-prefix ada-fill-comment-prefix)
4212 (set-left-margin from to indent)
4214 (setq fill-column (- fill-column (length ada-fill-comment-postfix))))
4216 (fill-region-as-paragraph from to justify)
4218 ;; Add the postfixes if required
4222 (narrow-to-region from to)
4225 (insert-char ? (- fill-column (current-column)))
4226 (insert ada-fill-comment-postfix)
4230 ;; In Emacs <= 20.2 and XEmacs <=20.4, there is a bug, and a newline is
4231 ;; inserted at the end. Delete it
4233 (<= emacs-major-version 19)
4234 (and (= emacs-major-version 20)
4235 (<= emacs-minor-version 2)))
4244 ;; ---------------------------------------------------
4245 ;; support for find-file.el
4246 ;; These functions are used by find-file to guess the file names from
4247 ;; unit names, and to find the other file (spec or body) from the current
4248 ;; file (body or spec).
4249 ;; It is also used to find in which function we are, so as to put the
4250 ;; cursor at the correct position.
4251 ;; Standard Ada does not force any relation between unit names and file names,
4252 ;; so some of these functions can only be a good approximation. However, they
4253 ;; are also overriden in `ada-xref'.el when we know that the user is using
4255 ;; ---------------------------------------------------
4257 ;; Overriden when we work with GNAT, to use gnatkrunch
4258 (defun ada-make-filename-from-adaname (adaname)
4259 "Determine the filename in which ADANAME is found.
4260 This is a generic function, independent from any compiler."
4261 (while (string-match "\\." adaname)
4262 (setq adaname (replace-match "-" t t adaname)))
4266 (defun ada-other-file-name ()
4267 "Return the name of the other file.
4268 The name returned is the body if current-buffer is the spec, or the spec
4273 (suffixes ada-spec-suffixes)
4274 (name (buffer-file-name)))
4276 ;; Guess whether we have a spec or a body, and get the basename of the
4277 ;; file. Since the extension may not start with '.', we can not use
4278 ;; file-name-extension
4279 (while (and (not is-spec)
4281 (if (string-match (concat "\\(.*\\)" (car suffixes) "$") name)
4283 name (match-string 1 name)))
4284 (setq suffixes (cdr suffixes)))
4288 (setq suffixes ada-body-suffixes)
4289 (while (and (not is-body)
4291 (if (string-match (concat "\\(.*\\)" (car suffixes) "$") name)
4293 name (match-string 1 name)))
4294 (setq suffixes (cdr suffixes)))))
4296 ;; If this wasn't in either list, return name itself
4297 (if (not (or is-spec is-body))
4300 ;; Else find the other possible names
4302 (setq suffixes ada-body-suffixes)
4303 (setq suffixes ada-spec-suffixes))
4307 (if (file-exists-p (concat name (car suffixes)))
4308 (setq is-spec (concat name (car suffixes))))
4309 (setq suffixes (cdr suffixes)))
4313 (defun ada-which-function-are-we-in ()
4314 "Return the name of the function whose definition/declaration point is in.
4315 Redefines the function `ff-which-function-are-we-in'."
4316 (setq ff-function-name nil)
4318 (end-of-line);; make sure we get the complete name
4319 (if (or (re-search-backward ada-procedure-start-regexp nil t)
4320 (re-search-backward ada-package-start-regexp nil t))
4321 (setq ff-function-name (match-string 0)))
4325 (defvar ada-last-which-function-line -1
4326 "Last on which ada-which-function was called")
4327 (defvar ada-last-which-function-subprog 0
4328 "Last subprogram name returned by ada-which-function")
4329 (make-variable-buffer-local 'ada-last-which-function-subprog)
4330 (make-variable-buffer-local 'ada-last-which-function-line)
4333 (defun ada-which-function ()
4334 "Returns the name of the function whose body the point is in.
4335 This function works even in the case of nested subprograms, whereas the
4336 standard Emacs function which-function does not.
4337 Note that this function expects subprogram bodies to be terminated by
4338 'end <name>;', not 'end;'.
4339 Since the search can be long, the results are cached."
4341 (let ((line (count-lines (point-min) (point)))
4347 ;; If this is the same line as before, simply return the same result
4348 (if (= line ada-last-which-function-line)
4349 ada-last-which-function-subprog
4352 ;; In case the current line is also the beginning of the body
4354 (while (and (ada-in-paramlist-p)
4355 (= (forward-line 1) 0))
4358 ;; Can't simply do forward-word, in case the "is" is not on the
4359 ;; same line as the closing parenthesis
4360 (skip-chars-forward "is \t\n")
4362 ;; No look for the closest subprogram body that has not ended yet.
4363 ;; Not that we expect all the bodies to be finished by "end <name",
4366 (while (and (not found)
4367 (re-search-backward ada-imenu-subprogram-menu-re nil t))
4368 (setq func-name (match-string 2))
4369 (if (and (not (ada-in-comment-p))
4370 (not (save-excursion
4371 (goto-char (match-end 0))
4372 (looking-at "[ \t\n]*new"))))
4374 (if (ada-search-ignore-string-comment
4375 (concat "end[ \t]+" func-name "[ \t]*;"))
4376 (setq end-pos (point))
4377 (setq end-pos (point-max)))
4378 (if (>= end-pos pos)
4379 (setq found func-name))))
4381 (setq ada-last-which-function-line line
4382 ada-last-which-function-subprog found)
4385 (defun ada-ff-other-window ()
4386 "Find other file in other window using `ff-find-other-file'."
4388 (and (fboundp 'ff-find-other-file)
4389 (ff-find-other-file t)))
4391 (defun ada-set-point-accordingly ()
4392 "Move to the function declaration that was set by
4393 `ff-which-function-are-we-in'."
4394 (if ff-function-name
4396 (goto-char (point-min))
4397 (unless (ada-search-ignore-string-comment
4398 (concat ff-function-name "\\b") nil)
4399 (goto-char (point-min))))))
4401 (defun ada-get-body-name (&optional spec-name)
4402 "Returns the file name for the body of SPEC-NAME.
4403 If SPEC-NAME is nil, returns the body for the current package.
4404 Returns nil if no body was found."
4407 (unless spec-name (setq spec-name (buffer-file-name)))
4409 ;; If find-file.el was available, use its functions
4410 (if (functionp 'ff-get-file)
4411 (ff-get-file-name ada-search-directories
4412 (ada-make-filename-from-adaname
4413 (file-name-nondirectory
4414 (file-name-sans-extension spec-name)))
4416 ;; Else emulate it very simply
4417 (concat (ada-make-filename-from-adaname
4418 (file-name-nondirectory
4419 (file-name-sans-extension spec-name)))
4423 ;; ---------------------------------------------------
4424 ;; support for font-lock.el
4425 ;; Strings are a real pain in Ada because a single quote character is
4426 ;; overloaded as a string quote and type/instance delimiter. By default, a
4427 ;; single quote is given punctuation syntax in `ada-mode-syntax-table'.
4428 ;; So, for Font Lock mode purposes, we mark single quotes as having string
4429 ;; syntax when the gods that created Ada determine them to be.
4431 ;; This only works in Emacs. See the comments before the grammar functions
4432 ;; at the beginning of this file for how this is done with XEmacs.
4433 ;; ----------------------------------------------------
4435 (defconst ada-font-lock-syntactic-keywords
4436 ;; Mark single quotes as having string quote syntax in 'c' instances.
4437 ;; As a special case, ''' will not be highlighted, but if we do not
4438 ;; set this special case, then the rest of the buffer is highlighted as
4440 ;; This sets the properties of the characters, so that ada-in-string-p
4441 ;; correctly handles '"' too...
4442 '(("\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
4443 ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))
4446 (defvar ada-font-lock-keywords
4450 ;; handle "type T is access function return S;"
4451 (list "\\<\\(function[ \t]+return\\)\\>" '(1 font-lock-keyword-face) )
4453 ;; preprocessor line
4454 (list "^[ \t]*\\(#.*\n\\)" '(1 font-lock-type-face t))
4457 ;; accept, entry, function, package (body), protected (body|type),
4458 ;; pragma, procedure, task (body) plus name.
4464 "package[ \t]+body\\|"
4468 "protected[ \t]+body\\|"
4469 "protected[ \t]+type\\|"
4475 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
4476 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t))
4478 ;; Optional keywords followed by a type name.
4479 (list (concat ; ":[ \t]*"
4480 "\\<\\(access[ \t]+all\\|access\\|constant\\|in[ \t]+out\\|in\\|out\\)\\>"
4482 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
4483 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
4486 ;; Main keywords, except those treated specially below.
4489 '("abort" "abs" "abstract" "accept" "access" "aliased" "all"
4490 "and" "array" "at" "begin" "case" "declare" "delay" "delta"
4491 "digits" "do" "else" "elsif" "entry" "exception" "exit" "for"
4492 "generic" "if" "in" "is" "limited" "loop" "mod" "not"
4493 "null" "or" "others" "private" "protected" "raise"
4494 "range" "record" "rem" "renames" "requeue" "return" "reverse"
4495 "select" "separate" "tagged" "task" "terminate" "then" "until"
4496 "when" "while" "xor") t)
4499 ;; Anything following end and not already fontified is a body name.
4500 '("\\<\\(end\\)\\>\\([ \t]+\\)?\\(\\(\\sw\\|[_.]\\)+\\)?"
4501 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
4503 ;; Keywords followed by a type or function name.
4504 (list (concat "\\<\\("
4505 "new\\|of\\|subtype\\|type"
4506 "\\)\\>[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?[ \t]*\\((\\)?")
4507 '(1 font-lock-keyword-face)
4508 '(2 (if (match-beginning 4)
4509 font-lock-function-name-face
4510 font-lock-type-face) nil t))
4512 ;; Keywords followed by a (comma separated list of) reference.
4513 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)\\>" ; "when" removed
4514 "[ \t\n]*\\(\\(\\sw\\|[_.|, \t\n]\\)+\\)\\W")
4515 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
4518 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
4520 "Default expressions to highlight in Ada mode.")
4523 ;; ---------------------------------------------------------
4524 ;; Support for outline.el
4525 ;; ---------------------------------------------------------
4527 (defun ada-outline-level ()
4528 "This is so that `current-column` DTRT in otherwise-hidden text"
4529 ;; patch from Dave Love <fx@gnu.org>
4530 (let (buffer-invisibility-spec)
4532 (back-to-indentation)
4535 ;; ---------------------------------------------------------
4536 ;; Automatic generation of code
4537 ;; The Ada-mode has a set of function to automatically generate a subprogram
4538 ;; or package body from its spec.
4539 ;; These function only use a primary and basic algorithm, this could use a
4540 ;; lot of improvement.
4541 ;; When the user is using GNAT, we rather use gnatstub to generate an accurate
4543 ;; ----------------------------------------------------------
4545 (defun ada-gen-treat-proc (match)
4546 "Make dummy body of a procedure/function specification.
4547 MATCH is a cons cell containing the start and end location of the last search
4548 for ada-procedure-start-regexp."
4549 (goto-char (car match))
4550 (let (func-found procname functype)
4552 ((or (looking-at "^[ \t]*procedure")
4553 (setq func-found (looking-at "^[ \t]*function")))
4554 ;; treat it as a proc/func
4557 (setq procname (buffer-substring (point) (cdr match))) ; store proc name
4559 ;; goto end of procname
4560 (goto-char (cdr match))
4562 ;; skip over parameterlist
4563 (unless (looking-at "[ \t\n]*\\(;\\|return\\)")
4566 ;; if function, skip over 'return' and result type.
4570 (skip-chars-forward " \t\n")
4571 (setq functype (buffer-substring (point)
4576 ;; look for next non WS
4578 ((looking-at "[ \t]*;")
4579 (delete-region (match-beginning 0) (match-end 0));; delete the ';'
4580 (ada-indent-newline-indent)
4582 (ada-indent-newline-indent)
4585 (insert "Result : " functype ";")
4586 (ada-indent-newline-indent)))
4588 (ada-indent-newline-indent)
4590 (insert "return Result;")
4592 (ada-indent-newline-indent)
4593 (insert "end " procname ";")
4594 (ada-indent-newline-indent)
4597 ((looking-at "[ \t\n]*is")
4600 ((looking-at "[ \t\n]*rename")
4604 (message "unknown syntax"))))
4606 (if (looking-at "^[ \t]*task")
4608 (message "Task conversion is not yet implemented")
4610 (if (looking-at "[ \t]*;")
4615 (defun ada-make-body ()
4616 "Create an Ada package body in the current buffer.
4617 The potential old buffer contents is deleted first, then we copy the
4618 spec buffer in here and modify it to make it a body.
4619 This function typically is to be hooked into `ff-file-created-hooks'."
4621 (delete-region (point-min) (point-max))
4622 (insert-buffer (car (cdr (buffer-list))))
4625 (let (found ada-procedure-or-package-start-regexp)
4627 (ada-search-ignore-string-comment ada-package-start-regexp nil))
4628 (progn (goto-char (cdr found))
4631 (error "No package"))
4633 (setq ada-procedure-or-package-start-regexp
4634 (concat ada-procedure-start-regexp
4636 ada-package-start-regexp))
4639 (ada-search-ignore-string-comment
4640 ada-procedure-or-package-start-regexp nil))
4642 (goto-char (car found))
4643 (if (looking-at ada-package-start-regexp)
4644 (progn (goto-char (cdr found))
4646 (ada-gen-treat-proc found))))))
4649 (defun ada-make-subprogram-body ()
4650 "Make one dummy subprogram body from spec surrounding point."
4652 (let* ((found (re-search-backward ada-procedure-start-regexp nil t))
4653 (spec (match-beginning 0))
4658 (if (and (re-search-forward "(\\|;" nil t)
4659 (= (char-before) ?\())
4661 (ada-search-ignore-string-comment ")" nil)
4662 (ada-search-ignore-string-comment ";" nil)))
4663 (setq spec (buffer-substring spec (point)))
4665 ;; If find-file.el was available, use its functions
4666 (setq body-file (ada-get-body-name))
4668 (find-file body-file)
4669 (error "No body found for the package. Create it first."))
4673 (goto-char (point-max))
4674 (forward-comment -10000)
4675 (re-search-backward "\\<end\\>" nil t)
4676 ;; Move to the beginning of the elaboration part, if any
4677 (re-search-backward "^begin" nil t)
4681 (re-search-backward ada-procedure-start-regexp nil t)
4682 (ada-gen-treat-proc (cons (match-beginning 0) (match-end 0)))
4684 (error "Not in subprogram spec"))))
4686 ;; --------------------------------------------------------
4687 ;; Global initializations
4688 ;; --------------------------------------------------------
4690 ;; Create the keymap once and for all. If we do that in ada-mode,
4691 ;; the keys changed in the user's .emacs have to be modified
4696 ;; Create the syntax tables, but do not activate them
4697 (ada-create-syntax-table)
4699 ;; Add the default extensions (and set up speedbar)
4700 (ada-add-extensions ".ads" ".adb")
4701 ;; This two files are generated by GNAT when running with -gnatD
4702 (if (equal ada-which-compiler 'gnat)
4703 (ada-add-extensions ".ads.dg" ".adb.dg"))
4705 ;; Read the special cases for exceptions
4706 (ada-case-read-exceptions)
4708 ;; include the other ada-mode files
4709 (if (equal ada-which-compiler 'gnat)
4711 ;; The order here is important: ada-xref defines the Project
4712 ;; submenu, and ada-prj adds to it.
4714 (condition-case nil (require 'ada-prj) (error nil))
4716 (condition-case nil (require 'ada-stmt) (error nil))
4718 ;;; provide ourselves
4721 ;;; ada-mode.el ends here