1 ;;; ada-mode.el --- major-mode for editing Ada sources
3 ;; Copyright (C) 1994, 95, 97, 98, 99, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Author: Rolf Ebert <ebert@inf.enst.fr>
7 ;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
8 ;; Emmanuel Briot <briot@gnat.com>
9 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
10 ;; Ada Core Technologies's version: $Revision: 1.46 $
11 ;; Keywords: languages ada
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
31 ;;; This mode is a major mode for editing Ada83 and Ada95 source code.
32 ;;; This is a major rewrite of the file packaged with Emacs-20. The
33 ;;; ada-mode is composed of four lisp file, ada-mode.el, ada-xref.el,
34 ;;; ada-prj.el and ada-stmt.el. Only this file (ada-mode.el) is
35 ;;; completely independent from the GNU Ada compiler Gnat, distributed
36 ;;; by Ada Core Technologies. All the other files rely heavily on
37 ;;; features provided only by Gnat.
39 ;;; Note: this mode will not work with Emacs 19. If you are on a VMS
40 ;;; system, where the latest version of Emacs is 19.28, you will need
41 ;;; another file, called ada-vms.el, that provides some required
45 ;;; Emacs should enter Ada mode automatically when you load an Ada file.
46 ;;; By default, the valid extensions for Ada files are .ads, .adb or .ada
47 ;;; If the ada-mode does not start automatically, then simply type the
48 ;;; following command :
51 ;;; By default, ada-mode is configured to take full advantage of the GNAT
52 ;;; compiler (the menus will include the cross-referencing features,...).
53 ;;; If you are using another compiler, you might want to set the following
54 ;;; variable in your .emacs (Note: do not set this in the ada-mode-hook, it
56 ;;; (setq ada-which-compiler 'generic)
58 ;;; This mode requires find-file.el to be present on your system.
61 ;;; The first Ada mode for GNU Emacs was written by V. Broman in
62 ;;; 1985. He based his work on the already existing Modula-2 mode.
63 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29.
65 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of
66 ;;; several files with support for dired commands and other nice
67 ;;; things. It is currently available from the PAL
68 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z.
70 ;;; The probably very first Ada mode (called electric-ada.el) was
71 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
72 ;;; Gosling Emacs. L. Slater based his development on ada.el and
75 ;;; A complete rewrite by M. Heritsch and R. Ebert has been done.
76 ;;; Some ideas from the Ada mode mailing list have been
77 ;;; added. Some of the functionality of L. Slater's mode has not
78 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
81 ;;; A complete rewrite for Emacs-20 / Gnat-3.11 has been done by Ada Core
82 ;;; Technologies. Please send bugs to briot@gnat.com
85 ;;; Many thanks to John McCabe <john@assen.demon.co.uk> for sending so
86 ;;; many patches included in this package.
87 ;;; Christian Egli <Christian.Egli@hcsd.hac.com>:
88 ;;; ada-imenu-generic-expression
89 ;;; Many thanks also to the following persons that have contributed one day
91 ;;; Philippe Waroquiers (PW) <philippe@cfmu.eurocontrol.be> in particular,
92 ;;; woodruff@stc.llnl.gov (John Woodruff)
93 ;;; jj@ddci.dk (Jesper Joergensen)
94 ;;; gse@ocsystems.com (Scott Evans)
95 ;;; comar@gnat.com (Cyrille Comar)
96 ;;; stephen.leake@gsfc.nasa.gov (Stephen Leake)
97 ;;; and others for their valuable hints.
100 ;;; Note: Every function in this package is compiler-independent.
101 ;;; The names start with ada-
102 ;;; The variables that the user can edit can all be modified through
103 ;;; the customize mode. They are sorted in alphabetical order in this
107 ;; this function is needed at compile time
109 (defun ada-check-emacs-version (major minor &optional is-xemacs)
110 "Returns t if Emacs's version is greater or equal to MAJOR.MINOR.
111 If IS-XEMACS is non-nil, check for XEmacs instead of Emacs."
112 (let ((xemacs-running (or (string-match "Lucid" emacs-version)
113 (string-match "XEmacs" emacs-version))))
114 (and (or (and is-xemacs xemacs-running)
115 (not (or is-xemacs xemacs-running)))
116 (or (> emacs-major-version major)
117 (and (= emacs-major-version major)
118 (>= emacs-minor-version minor)))))))
121 ;; We create a constant for that, for efficiency only
122 ;; This should be evaluated both at compile time, only a runtime
124 (defconst ada-xemacs (and (boundp 'running-xemacs)
125 (symbol-value 'running-xemacs))
126 "Return t if we are using XEmacs."))
132 (condition-case nil (require 'find-file) (error nil)))
134 ;; This call should not be made in the release that is done for the
135 ;; official FSF Emacs, since it does nothing useful for the latest version
136 ;; (require 'ada-support)
138 (defvar ada-mode-hook nil
139 "*List of functions to call when Ada mode is invoked.
140 This hook is automatically executed after the ada-mode is
142 This is a good place to add Ada environment specific bindings.")
145 "Major mode for editing Ada source in Emacs."
148 (defcustom ada-auto-case t
149 "*Non-nil means automatically change case of preceding word while typing.
150 Casing is done according to `ada-case-keyword', `ada-case-identifier'
151 and `ada-case-attribute'."
152 :type 'boolean :group 'ada)
154 (defcustom ada-broken-decl-indent 0
155 "*Number of columns to indent a broken declaration.
160 >>>>>B : Integer; -- from ada-broken-decl-indent"
161 :type 'integer :group 'ada)
163 (defcustom ada-broken-indent 2
164 "*Number of columns to indent the continuation of a broken line.
167 My_Var : My_Type := (Field1 =>
168 >>>>>>>>>Value); -- from ada-broken-indent"
169 :type 'integer :group 'ada)
171 (defcustom ada-case-attribute 'ada-capitalize-word
172 "*Function to call to adjust the case of Ada attributes.
173 It may be `downcase-word', `upcase-word', `ada-loose-case-word',
174 `ada-capitalize-word' or `ada-no-auto-case'."
175 :type '(choice (const downcase-word)
177 (const ada-capitalize-word)
178 (const ada-loose-case-word)
179 (const ada-no-auto-case))
182 (defcustom ada-case-exception-file '("~/.emacs_case_exceptions")
183 "*List of special casing exceptions dictionaries for identifiers.
184 The first file is the one where new exceptions will be saved by Emacs
185 when you call `ada-create-case-exception'.
187 These files should contain one word per line, that gives the casing
188 to be used for that word in Ada files. Each line can be terminated by
190 :type '(repeat (file))
193 (defcustom ada-case-keyword 'downcase-word
194 "*Function to call to adjust the case of an Ada keywords.
195 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
196 `ada-capitalize-word'."
197 :type '(choice (const downcase-word)
199 (const ada-capitalize-word)
200 (const ada-loose-case-word)
201 (const ada-no-auto-case))
204 (defcustom ada-case-identifier 'ada-loose-case-word
205 "*Function to call to adjust the case of an Ada identifier.
206 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
207 `ada-capitalize-word'."
208 :type '(choice (const downcase-word)
210 (const ada-capitalize-word)
211 (const ada-loose-case-word)
212 (const ada-no-auto-case))
215 (defcustom ada-clean-buffer-before-saving t
216 "*Non-nil means remove trailing spaces and untabify the buffer before saving."
217 :type 'boolean :group 'ada)
219 (defcustom ada-indent 3
220 "*Size of Ada indentation.
225 >>>>>>>>>>null; -- from ada-indent"
226 :type 'integer :group 'ada)
228 (defcustom ada-indent-after-return t
229 "*Non-nil means automatically indent after RET or LFD."
230 :type 'boolean :group 'ada)
232 (defcustom ada-indent-align-comments t
233 "*Non-nil means align comments on previous line comments, if any.
234 If nil, indentation is calculated as usual.
235 Note that indentation is calculated only if `ada-indent-comment-as-code' is t.
238 A := 1; -- A multi-line comment
239 -- aligned if ada-indent-align-comments is t"
240 :type 'boolean :group 'ada)
242 (defcustom ada-indent-comment-as-code t
243 "*Non-nil means indent comment lines as code.
244 nil means do not auto-indent comments."
245 :type 'boolean :group 'ada)
247 (defcustom ada-indent-is-separate t
248 "*Non-nil means indent 'is separate' or 'is abstract' if on a single line."
249 :type 'boolean :group 'ada)
251 (defcustom ada-indent-record-rel-type 3
252 "*Indentation for 'record' relative to 'type' or 'use'.
256 >>>>>>>>>>>record -- from ada-indent-record-rel-type"
257 :type 'integer :group 'ada)
259 (defcustom ada-indent-renames ada-broken-indent
260 "*Indentation for renames relative to the matching function statement.
261 If ada-indent-return is null or negative, the indentation is done relative to
262 the open parenthesis (if there is no parenthesis, ada-broken-indent is used).
265 function A (B : Integer)
266 return C; -- from ada-indent-return
267 >>>renames Foo; -- from ada-indent-renames"
268 :type 'integer :group 'ada)
270 (defcustom ada-indent-return 0
271 "*Indentation for 'return' relative to the matching 'function' statement.
272 If ada-indent-return is null or negative, the indentation is done relative to
273 the open parenthesis (if there is no parenthesis, ada-broken-indent is used).
276 function A (B : Integer)
277 >>>>>return C; -- from ada-indent-return"
278 :type 'integer :group 'ada)
280 (defcustom ada-indent-to-open-paren t
281 "*Non-nil means indent according to the innermost open parenthesis."
282 :type 'boolean :group 'ada)
284 (defcustom ada-fill-comment-prefix "-- "
285 "*Text inserted in the first columns when filling a comment paragraph.
286 Note: if you modify this variable, you will have to invoke `ada-mode'
287 again to take account of the new value."
288 :type 'string :group 'ada)
290 (defcustom ada-fill-comment-postfix " --"
291 "*Text inserted at the end of each line when filling a comment paragraph.
292 with `ada-fill-comment-paragraph-postfix'."
293 :type 'string :group 'ada)
295 (defcustom ada-label-indent -4
296 "*Number of columns to indent a label.
301 >>>>>>>>>>>>Label: -- from ada-label-indent"
302 :type 'integer :group 'ada)
304 (defcustom ada-language-version 'ada95
305 "*Do we program in `ada83' or `ada95'?"
306 :type '(choice (const ada83) (const ada95)) :group 'ada)
308 (defcustom ada-move-to-declaration nil
309 "*Non-nil means `ada-move-to-start' moves point to the subprogram declaration,
311 :type 'boolean :group 'ada)
313 (defcustom ada-popup-key '[down-mouse-3]
314 "*Key used for binding the contextual menu.
315 If nil, no contextual menu is available."
316 :type '(restricted-sexp :match-alternatives (stringp vectorp))
319 (defcustom ada-search-directories
320 '("." "$ADA_INCLUDE_PATH" "/usr/adainclude" "/usr/local/adainclude"
321 "/opt/gnu/adainclude")
322 "*List of directories to search for Ada files.
323 See the description for the `ff-search-directories' variable.
324 Emacs will automatically add the paths defined in your project file, and if you
325 are using the GNAT compiler the output of the gnatls command to find where the
327 :type '(repeat (choice :tag "Directory"
328 (const :tag "default" nil)
329 (directory :format "%v")))
332 (defcustom ada-stmt-end-indent 0
333 "*Number of columns to indent the end of a statement on a separate line.
337 >>>>>>>>>>>then -- from ada-stmt-end-indent"
338 :type 'integer :group 'ada)
340 (defcustom ada-tab-policy 'indent-auto
341 "*Control the behavior of the TAB key.
343 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line.
344 `indent-auto' : use indentation functions in this file.
345 `always-tab' : do indent-relative."
346 :type '(choice (const indent-auto)
347 (const indent-rigidly)
351 (defcustom ada-use-indent ada-broken-indent
352 "*Indentation for the lines in a 'use' statement.
356 >>>>>Ada.Numerics; -- from ada-use-indent"
357 :type 'integer :group 'ada)
359 (defcustom ada-when-indent 3
360 "*Indentation for 'when' relative to 'exception' or 'case'.
364 >>>>>>>>when B => -- from ada-when-indent"
365 :type 'integer :group 'ada)
367 (defcustom ada-with-indent ada-broken-indent
368 "*Indentation for the lines in a 'with' statement.
372 >>>>>Ada.Numerics; -- from ada-with-indent"
373 :type 'integer :group 'ada)
375 (defcustom ada-which-compiler 'gnat
376 "*Name of the compiler to use.
377 This will determine what features are made available through the ada-mode.
378 The possible choices are :
379 `gnat': Use Ada Core Technologies' Gnat compiler. Add some cross-referencing
381 `generic': Use a generic compiler"
382 :type '(choice (const gnat)
387 ;;; ---- end of user configurable variables
390 (defvar ada-body-suffixes '(".adb")
391 "List of possible suffixes for Ada body files.
392 The extensions should include a `.' if needed.")
394 (defvar ada-spec-suffixes '(".ads")
395 "List of possible suffixes for Ada spec files.
396 The extensions should include a `.' if needed.")
398 (defvar ada-mode-menu (make-sparse-keymap "Ada")
399 "Menu for ada-mode.")
401 (defvar ada-mode-map (make-sparse-keymap)
402 "Local keymap used for Ada mode.")
404 (defvar ada-mode-abbrev-table nil
405 "Local abbrev table for Ada mode.")
407 (defvar ada-mode-syntax-table nil
408 "Syntax table to be used for editing Ada source code.")
410 (defvar ada-mode-symbol-syntax-table nil
411 "Syntax table for Ada, where `_' is a word constituent.")
414 (defconst ada-83-string-keywords
415 '("abort" "abs" "accept" "access" "all" "and" "array" "at" "begin"
416 "body" "case" "constant" "declare" "delay" "delta" "digits" "do"
417 "else" "elsif" "end" "entry" "exception" "exit" "for" "function"
418 "generic" "goto" "if" "in" "is" "limited" "loop" "mod" "new"
419 "not" "null" "of" "or" "others" "out" "package" "pragma" "private"
420 "procedure" "raise" "range" "record" "rem" "renames" "return"
421 "reverse" "select" "separate" "subtype" "task" "terminate" "then"
422 "type" "use" "when" "while" "with" "xor")
423 "List of Ada keywords.
424 This variable is used to define `ada-83-keywords' and `ada-95-keywords'"))
426 (defvar ada-ret-binding nil
427 "Variable to save key binding of RET when casing is activated.")
429 (defvar ada-case-exception '()
430 "Alist of words (entities) that have special casing.")
432 (defvar ada-lfd-binding nil
433 "Variable to save key binding of LFD when casing is activated.")
435 (defvar ada-other-file-alist nil
436 "Variable used by find-file to find the name of the other package.
437 See `ff-other-file-alist'.")
439 ;;; ---- Below are the regexp used in this package for parsing
441 (defconst ada-83-keywords
443 (concat "\\<" (regexp-opt ada-83-string-keywords t) "\\>"))
444 "Regular expression for looking at Ada83 keywords.")
446 (defconst ada-95-keywords
448 (concat "\\<" (regexp-opt
450 '("abstract" "aliased" "protected" "requeue"
452 ada-83-string-keywords) t) "\\>"))
453 "Regular expression for looking at Ada95 keywords.")
455 (defvar ada-keywords ada-95-keywords
456 "Regular expression for looking at Ada keywords.")
458 (defconst ada-ident-re
460 "Regexp matching Ada (qualified) identifiers.")
462 (defvar ada-procedure-start-regexp
463 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\(\\(\\sw\\|[_.]\\)+\\)"
464 "Regexp used to find Ada procedures/functions.")
466 (defvar ada-package-start-regexp
467 "^[ \t]*\\(package\\)"
468 "Regexp used to find Ada packages.")
471 ;;; ---- regexps for indentation functions
473 (defvar ada-block-start-re
475 (concat "\\<\\(" (regexp-opt '("begin" "declare" "else"
476 "exception" "generic" "loop" "or"
477 "private" "select" ))
478 "\\|\\(\\(limited\\|abstract\\|tagged\\)[ \t\n]+\\)*record\\)\\>"))
479 "Regexp for keywords starting Ada blocks.")
481 (defvar ada-end-stmt-re
486 "^[ \t]*separate[ \t]*(\\(\\sw\\|[_.]\\)+)" "\\|"
487 "\\<" (regexp-opt '("begin" "declare" "is" "do" "else" "generic"
488 "loop" "private" "record" "select"
489 "then abort" "then") t) "\\>" "\\|"
490 "^[ \t]*" (regexp-opt '("function" "package" "procedure")
491 t) "\\>\\(\\sw\\|[ \t_.]\\)+\\<is\\>" "\\|"
492 "^[ \t]*exception\\>"
494 "Regexp of possible ends for a non-broken statement.
495 A new statement starts after these.")
497 (defvar ada-matching-start-re
501 '("end" "loop" "select" "begin" "case" "do"
502 "if" "task" "package" "record" "protected") t)
504 "Regexp used in ada-goto-matching-start.")
506 (defvar ada-matching-decl-start-re
510 '("is" "separate" "end" "declare" "if" "new" "begin" "generic" "when") t)
512 "Regexp used in ada-goto-matching-decl-start.")
514 (defvar ada-loop-start-re
515 "\\<\\(for\\|while\\|loop\\)\\>"
516 "Regexp for the start of a loop.")
518 (defvar ada-subprog-start-re
520 (concat "\\<" (regexp-opt '("accept" "entry" "function" "package" "procedure"
521 "protected" "task") t) "\\>"))
522 "Regexp for the start of a subprogram.")
524 (defvar ada-named-block-re
525 "[ \t]*\\(\\sw\\|_\\)+[ \t]*:[^=]"
526 "Regexp of the name of a block or loop.")
528 (defvar ada-contextual-menu-on-identifier nil
529 "Set to true when the right mouse button was clicked on an identifier.")
531 (defvar ada-contextual-menu-last-point nil
532 "Position of point just before displaying the menu.
533 This is a list (point buffer).
534 Since `ada-popup-menu' moves the point where the user clicked, the region
535 is modified. Therefore no command from the menu knows what the user selected
536 before displaying the contextual menu.
537 To get the original region, restore the point to this position before
538 calling `region-end' and `region-beginning'.
539 Modify this variable if you want to restore the point to another position.")
541 (defvar ada-contextual-menu
544 ["Goto Declaration/Body"
545 (ada-call-from-contextual-menu 'ada-point-and-xref)
546 :included (and (functionp 'ada-point-and-xref)
547 ada-contextual-menu-on-identifier)]
548 ["Goto Previous Reference"
549 (ada-call-from-contextual-menu 'ada-xref-goto-previous-reference)
550 :included (functionp 'ada-xref-goto-previous-reference)]
551 ["List References" ada-find-references
552 :included ada-contextual-menu-on-identifier]
554 ["Other File" ff-find-other-file]
555 ["Goto Parent Unit" ada-goto-parent]
558 (let ((map (make-sparse-keymap "Ada")))
559 ;; The identifier part
560 (if (equal ada-which-compiler 'gnat)
562 (define-key-after map [Ref]
563 '(menu-item "Goto Declaration/Body"
564 (lambda()(interactive)
565 (ada-call-from-contextual-menu
566 'ada-point-and-xref))
568 (and (functionp 'ada-point-and-xref)
569 ada-contextual-menu-on-identifier))
571 (define-key-after map [Prev]
572 '(menu-item "Goto Previous Reference"
573 (lambda()(interactive)
574 (ada-call-from-contextual-menu
575 'ada-xref-goto-previous-reference))
577 (functionp 'ada-xref-goto-previous-reference))
579 (define-key-after map [List]
580 '(menu-item "List References"
582 :visible ada-contextual-menu-on-identifier) t)
583 (define-key-after map [-] '("-" nil) t)
585 (define-key-after map [Other] '("Other file" . ff-find-other-file) t)
586 (define-key-after map [Parent] '("Goto Parent Unit" . ada-goto-parent)t)
588 "Defines the menu to use when the user presses the right mouse button.
589 The variable `ada-contextual-menu-on-identifier' will be set to t before
590 displaying the menu if point was on an identifier."
594 ;;------------------------------------------------------------------
595 ;; Support for imenu (see imenu.el)
596 ;;------------------------------------------------------------------
598 (defconst ada-imenu-subprogram-menu-re
599 "^[ \t]*\\(procedure\\|function\\)[ \t\n]+\\(\\(\\sw\\|_\\)+\\)[ \t\n]*\\([ \t\n]\\|([^)]+)\\)[ \t\n]*\\(return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?is[ \t\n]")
601 (defvar ada-imenu-generic-expression
603 (list nil ada-imenu-subprogram-menu-re 2)
606 "^[ \t]*\\(procedure\\|function\\)[ \t\n]+\\(\\(\\sw\\|_\\)+\\)"
608 "\\([ \t\n]+\\|[ \t\n]*([^)]+)\\)";; parameter list or simple space
609 "\\([ \t\n]*return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?"
611 '("*Tasks*" "^[ \t]*task[ \t]+\\(\\(body\\|type\\)[ \t]+\\)?\\(\\(\\sw\\|_\\)+\\)" 3)
612 '("*Type Defs*" "^[ \t]*\\(sub\\)?type[ \t]+\\(\\(\\sw\\|_\\)+\\)" 2)
613 '("*Packages*" "^[ \t]*package[ \t]+\\(\\(body[ \t]+\\)?\\(\\sw\\|[_.]\\)+\\)" 1))
614 "Imenu generic expression for Ada mode.
615 See `imenu-generic-expression'. This variable will create two submenus, one
616 for type and subtype definitions, the other for subprograms declarations.
617 The main menu will reference the bodies of the subprograms.")
621 ;;------------------------------------------------------------
622 ;; Support for compile.el
623 ;;------------------------------------------------------------
625 (defun ada-compile-mouse-goto-error ()
626 "Mouse interface for ada-compile-goto-error."
628 (mouse-set-point last-input-event)
629 (ada-compile-goto-error (point))
632 (defun ada-compile-goto-error (pos)
633 "Replaces `compile-goto-error' from compile.el.
634 If POS is on a file and line location, go to this position. It adds to
635 compile.el the capacity to go to a reference in an error message.
636 For instance, on this line:
637 foo.adb:61:11: [...] in call to size declared at foo.ads:11
638 both file locations can be clicked on and jumped to."
642 (skip-chars-backward "-a-zA-Z0-9_:./\\")
644 ;; special case: looking at a filename:line not at the beginning of a line
647 "\\([-_.a-zA-Z0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"))
648 (let ((line (match-string 2))
649 (error-pos (point-marker))
654 ;; Use funcall so as to prevent byte-compiler warnings
655 (set-buffer (funcall (symbol-function 'compilation-find-file)
656 (point-marker) (match-string 1)
659 (goto-line (string-to-number line)))
660 (setq source (point-marker))))
661 (funcall (symbol-function 'compilation-goto-locus)
662 (cons source error-pos))
665 ;; otherwise, default behavior
667 (funcall (symbol-function 'compile-goto-error)))
672 ;;-------------------------------------------------------------------------
673 ;; Grammar related function
674 ;; The functions below work with the syntax class of the characters in an Ada
675 ;; buffer. Two syntax tables are created, depending on whether we want '_'
676 ;; to be considered as part of a word or not.
677 ;; Some characters may have multiple meanings depending on the context:
678 ;; - ' is either the beginning of a constant character or an attribute
679 ;; - # is either part of a based litteral or a gnatprep statement.
680 ;; - " starts a string, but not if inside a constant character.
681 ;; - ( and ) should be ignored if inside a constant character.
682 ;; Thus their syntax property is changed automatically, and we can still use
683 ;; the standard Emacs functions for sexp (see `ada-in-string-p')
685 ;; On Emacs, this is done through the `syntax-table' text property. The
686 ;; modification is done automatically each time the user as typed a new
687 ;; character. This is already done in `font-lock-mode' (in
688 ;; `font-lock-syntactic-keywords', so we take advantage of the existing
689 ;; mechanism. If font-lock-mode is not activated, we do it by hand in
690 ;; `ada-after-change-function', thanks to `ada-deactivate-properties' and
691 ;; `ada-initialize-properties'.
693 ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
694 ;; slow advice to `parse-partial-sexp' to do the same thing.
695 ;; When executing parse-partial-sexp, we simply modify the strings before and
696 ;; after, so that the special constants '"', '(' and ')' do not interact
697 ;; with parse-partial-sexp.
698 ;; Note: this code is slow and needs to be rewritten as soon as something
699 ;; better is available on XEmacs.
700 ;;-------------------------------------------------------------------------
702 (defun ada-create-syntax-table ()
703 "Create the two syntax tables use in the Ada mode.
704 The standard table declares `_' as a symbol constituent, the second one
705 declares it as a word constituent."
707 (setq ada-mode-syntax-table (make-syntax-table))
708 (set-syntax-table ada-mode-syntax-table)
710 ;; define string brackets (`%' is alternative string bracket, but
711 ;; almost never used as such and throws font-lock and indentation
713 (modify-syntax-entry ?% "$" ada-mode-syntax-table)
714 (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)
732 (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
733 (modify-syntax-entry ?\' "." ada-mode-syntax-table)
735 ;; a single hyphen is punctuation, but a double hyphen starts a comment
736 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table)
738 ;; See the comment above on grammar related function for the special
741 (modify-syntax-entry ?# "<" ada-mode-syntax-table)
742 (modify-syntax-entry ?# "$" ada-mode-syntax-table))
744 ;; and \f and \n end a comment
745 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
746 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
748 ;; define what belongs in Ada symbols
749 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
751 ;; define parentheses to match
752 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
753 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
755 (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table))
756 (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table)
759 ;; Support of special characters in XEmacs (see the comments at the beginning
760 ;; of the section on Grammar related functions).
763 (defadvice parse-partial-sexp (around parse-partial-sexp-protect-constants)
764 "Handles special character constants and gnatprep statements."
768 (setq from to to tmp)))
771 (while (re-search-forward "'\\([(\")#]\\)'" to t)
772 (setq change (cons (list (match-beginning 1)
776 (replace-match "'A'"))
778 (while (re-search-forward "\\(#[0-9a-fA-F]*#\\)" to t)
779 (setq change (cons (list (match-beginning 1)
780 (length (match-string 1))
783 (replace-match (make-string (length (match-string 1)) ?@))))
787 (goto-char (caar change))
788 (delete-char (cadar change))
789 (insert (caddar change))
790 (setq change (cdr change)))))))
792 (defun ada-deactivate-properties ()
793 "Deactivate ada-mode's properties handling.
794 This would be a duplicate of font-lock if both are used at the same time."
795 (remove-hook 'after-change-functions 'ada-after-change-function t))
797 (defun ada-initialize-properties ()
798 "Initialize some special text properties in the whole buffer.
799 In particular, character constants are said to be strings, #...# are treated
800 as numbers instead of gnatprep comments."
804 (goto-char (point-min))
805 (while (re-search-forward "'.'" nil t)
806 (add-text-properties (match-beginning 0) (match-end 0)
807 '(syntax-table ("'" . ?\"))))
808 (goto-char (point-min))
809 (while (re-search-forward "^[ \t]*#" nil t)
810 (add-text-properties (match-beginning 0) (match-end 0)
811 '(syntax-table (11 . 10))))
812 (set-buffer-modified-p nil)
814 ;; Setting this only if font-lock is not set won't work
815 ;; if the user activates or deactivates font-lock-mode,
816 ;; but will make things faster most of the time
817 (make-local-hook 'after-change-functions)
818 (add-hook 'after-change-functions 'ada-after-change-function nil t)
821 (defun ada-after-change-function (beg end old-len)
822 "Called when the region between BEG and END was changed in the buffer.
823 OLD-LEN indicates what the length of the replaced text was."
824 (let ((inhibit-point-motion-hooks t)
829 (remove-text-properties (point) eol '(syntax-table nil))
830 (while (re-search-forward "'.'" eol t)
831 (add-text-properties (match-beginning 0) (match-end 0)
832 '(syntax-table ("'" . ?\"))))
834 (if (looking-at "^[ \t]*#")
835 (add-text-properties (match-beginning 0) (match-end 0)
836 '(syntax-table (11 . 10))))
839 ;;------------------------------------------------------------------
840 ;; Testing the grammatical context
841 ;;------------------------------------------------------------------
843 (defsubst ada-in-comment-p (&optional parse-result)
844 "Returns t if inside a comment."
845 (nth 4 (or parse-result
847 (save-excursion (beginning-of-line) (point)) (point)))))
849 (defsubst ada-in-string-p (&optional parse-result)
850 "Returns t if point is inside a string.
851 If parse-result is non-nil, use is instead of calling parse-partial-sexp."
852 (nth 3 (or parse-result
854 (save-excursion (beginning-of-line) (point)) (point)))))
856 (defsubst ada-in-string-or-comment-p (&optional parse-result)
857 "Returns t if inside a comment or string."
858 (setq parse-result (or parse-result
860 (save-excursion (beginning-of-line) (point)) (point))))
861 (or (ada-in-string-p parse-result) (ada-in-comment-p parse-result)))
864 ;;------------------------------------------------------------------
866 ;; The Ada-mode comes with contextual menus, bound by default to the right
868 ;; Add items to this menu by modifying `ada-contextual-menu'. Note that the
869 ;; variable `ada-contextual-menu-on-identifier' is set automatically to t
870 ;; if the mouse button was pressed on an identifier.
871 ;;------------------------------------------------------------------
873 (defun ada-call-from-contextual-menu (function)
874 "Execute FUNCTION when called from the contextual menu.
875 It forces Emacs to change the cursor position."
878 (setq ada-contextual-menu-last-point
879 (list (point) (current-buffer))))
881 (defun ada-popup-menu (position)
882 "Pops up a contextual menu, depending on where the user clicked.
883 POSITION is the location the mouse was clicked on.
884 Sets `ada-contextual-menu-last-point' to the current position before
885 displaying the menu. When a function from the menu is called, the point is
886 where the mouse button was clicked."
889 ;; declare this as a local variable, so that the function called
890 ;; in the contextual menu does not hide the region in
891 ;; transient-mark-mode.
892 (let ((deactivate-mark nil))
893 (setq ada-contextual-menu-last-point
894 (list (point) (current-buffer)))
895 (mouse-set-point last-input-event)
897 (setq ada-contextual-menu-on-identifier
899 (or (= (char-syntax (char-after)) ?w)
901 (not (ada-in-string-or-comment-p))
902 (save-excursion (skip-syntax-forward "w")
903 (not (ada-after-keyword-p)))
907 (setq choice (funcall (symbol-function 'popup-menu)
908 ada-contextual-menu))
909 (setq choice (x-popup-menu position ada-contextual-menu)))
911 (funcall (lookup-key ada-contextual-menu (vector (car choice))))))
912 (set-buffer (cadr ada-contextual-menu-last-point))
913 (goto-char (car ada-contextual-menu-last-point))
917 ;;------------------------------------------------------------------
919 ;;------------------------------------------------------------------
922 (defun ada-add-extensions (spec body)
923 "Define SPEC and BODY as being valid extensions for Ada files.
924 Going from body to spec with `ff-find-other-file' used these
926 SPEC and BODY are two regular expressions that must match against the file
928 (let* ((reg (concat (regexp-quote body) "$"))
929 (tmp (assoc reg ada-other-file-alist)))
931 (setcdr tmp (list (cons spec (cadr tmp))))
932 (add-to-list 'ada-other-file-alist (list reg (list spec)))))
934 (let* ((reg (concat (regexp-quote spec) "$"))
935 (tmp (assoc reg ada-other-file-alist)))
937 (setcdr tmp (list (cons body (cadr tmp))))
938 (add-to-list 'ada-other-file-alist (list reg (list body)))))
940 (add-to-list 'auto-mode-alist
941 (cons (concat (regexp-quote spec) "\\'") 'ada-mode))
942 (add-to-list 'auto-mode-alist
943 (cons (concat (regexp-quote body) "\\'") 'ada-mode))
945 (add-to-list 'ada-spec-suffixes spec)
946 (add-to-list 'ada-body-suffixes body)
948 ;; Support for speedbar (Specifies that we want to see these files in
953 (funcall (symbol-function 'speedbar-add-supported-extension)
955 (funcall (symbol-function 'speedbar-add-supported-extension)
962 "Ada mode is the major mode for editing Ada code.
964 Bindings are as follows: (Note: 'LFD' is control-j.)
966 Indent line '\\[ada-tab]'
967 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
969 Re-format the parameter-list point is in '\\[ada-format-paramlist]'
970 Indent all lines in region '\\[ada-indent-region]'
972 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]'
973 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]'
975 Fill comment paragraph, justify and append postfix '\\[fill-paragraph]'
977 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
978 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
980 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
981 Goto end of current block '\\[ada-move-to-end]'
983 Comments are handled using standard GNU Emacs conventions, including:
984 Start a comment '\\[indent-for-comment]'
985 Comment region '\\[comment-region]'
986 Uncomment region '\\[ada-uncomment-region]'
987 Continue comment on next line '\\[indent-new-comment-line]'
990 Display index-menu of functions & procedures '\\[imenu]'
992 If you use find-file.el:
993 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]'
994 or '\\[ff-mouse-find-other-file]
995 Switch to other file in other window '\\[ada-ff-other-window]'
996 or '\\[ff-mouse-find-other-file-other-window]
997 If you use this function in a spec and no body is available, it gets created with body stubs.
999 If you use ada-xref.el:
1000 Goto declaration: '\\[ada-point-and-xref]' on the identifier
1001 or '\\[ada-goto-declaration]' with point on the identifier
1002 Complete identifier: '\\[ada-complete-identifier]'."
1005 (kill-all-local-variables)
1007 (set (make-local-variable 'require-final-newline) t)
1009 (make-local-variable 'comment-start)
1010 (if ada-fill-comment-prefix
1011 (setq comment-start ada-fill-comment-prefix)
1012 (setq comment-start "-- "))
1014 ;; Set the paragraph delimiters so that one can select a whole block
1016 (set (make-local-variable 'paragraph-start) "[ \t\n\f]*$")
1017 (set (make-local-variable 'paragraph-separate) "[ \t\n\f]*$")
1019 ;; comment end must be set because it may hold a wrong value if
1020 ;; this buffer had been in another mode before. RE
1021 (set (make-local-variable 'comment-end) "")
1023 ;; used by autofill and indent-new-comment-line
1024 (set (make-local-variable 'comment-start-skip) "---*[ \t]*")
1026 ;; used by autofill to break a comment line and continue it on another line.
1027 ;; The reason we need this one is that the default behavior does not work
1028 ;; correctly with the definition of paragraph-start above when the comment
1029 ;; is right after a multi-line subprogram declaration (the comments are
1030 ;; aligned under the latest parameter, not under the declaration start).
1031 (set (make-local-variable 'comment-line-break-function)
1032 (lambda (&optional soft) (let ((fill-prefix nil))
1033 (indent-new-comment-line soft))))
1035 (set (make-local-variable 'indent-line-function)
1036 'ada-indent-current-function)
1038 (set (make-local-variable 'comment-column) 40)
1040 ;; Emacs 20.3 defines a comment-padding to insert spaces between
1041 ;; the comment and the text. We do not want any, this is already
1042 ;; included in comment-start
1043 (set (make-local-variable 'comment-padding) 0)
1044 (set (make-local-variable 'parse-sexp-ignore-comments) t)
1045 (set (make-local-variable 'parse-sexp-lookup-properties) t)
1047 (setq case-fold-search t)
1048 (setq imenu-case-fold-search t)
1050 (set (make-local-variable 'fill-paragraph-function)
1051 'ada-fill-comment-paragraph)
1053 (set (make-local-variable 'imenu-generic-expression)
1054 ada-imenu-generic-expression)
1056 ;; Support for compile.el
1057 ;; We just substitute our own functions to go to the error.
1058 (add-hook 'compilation-mode-hook
1060 (set (make-local-variable 'compile-auto-highlight) 40)
1061 ;; FIXME: This has global impact! -stef
1062 (define-key compilation-minor-mode-map [mouse-2]
1063 'ada-compile-mouse-goto-error)
1064 (define-key compilation-minor-mode-map "\C-c\C-c"
1065 'ada-compile-goto-error)
1066 (define-key compilation-minor-mode-map "\C-m"
1067 'ada-compile-goto-error)))
1069 ;; font-lock support
1070 (set (make-local-variable 'font-lock-defaults)
1071 '(ada-font-lock-keywords
1073 ((?\_ . "w") (?# . "."))
1075 (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords)))
1077 ;; Set up support for find-file.el.
1078 (set (make-local-variable 'ff-other-file-alist)
1079 'ada-other-file-alist)
1080 (set (make-local-variable 'ff-search-directories)
1081 'ada-search-directories)
1082 (setq ff-post-load-hooks 'ada-set-point-accordingly
1083 ff-file-created-hooks 'ada-make-body)
1084 (add-hook 'ff-pre-load-hooks 'ada-which-function-are-we-in)
1086 ;; Some special constructs for find-file.el
1087 ;; We do not need to add the construction for 'with', which is in the
1088 ;; standard find-file.el
1089 (make-local-variable 'ff-special-constructs)
1091 ;; Go to the parent package :
1092 (add-to-list 'ff-special-constructs
1093 (cons (eval-when-compile
1094 (concat "^\\(private[ \t]\\)?[ \t]*package[ \t]+"
1096 "\\(\\(\\sw\\|[_.]\\)+\\)\\.\\(\\sw\\|_\\)+[ \t\n]+is"))
1098 (setq fname (ff-get-file
1099 ada-search-directories
1100 (ada-make-filename-from-adaname
1102 ada-spec-suffixes)))))
1103 ;; Another special construct for find-file.el : when in a separate clause,
1104 ;; go to the correct package.
1105 (add-to-list 'ff-special-constructs
1106 (cons "^separate[ \t\n]*(\\(\\(\\sw\\|[_.]\\)+\\))"
1108 (setq fname (ff-get-file
1109 ada-search-directories
1110 (ada-make-filename-from-adaname
1112 ada-spec-suffixes)))))
1113 ;; Another special construct, that redefines the one in find-file.el. The
1114 ;; old one can handle only one possible type of extension for Ada files
1115 ;; remove from the list the standard "with..." that is put by find-file.el,
1116 ;; since it uses the old ada-spec-suffix variable
1117 ;; This one needs to replace the standard one defined in find-file.el (with
1118 ;; Emacs <= 20.4), since that one uses the old variable ada-spec-suffix
1119 (let ((old-construct
1120 (assoc "^with[ \t]+\\([a-zA-Z0-9_\\.]+\\)" ff-special-constructs))
1123 (setq fname (ff-get-file
1124 ada-search-directories
1125 (ada-make-filename-from-adaname
1127 ada-spec-suffixes)))))
1129 (setcdr old-construct new-cdr)
1130 (add-to-list 'ff-special-constructs
1131 (cons "^with[ \t]+\\([a-zA-Z0-9_\\.]+\\)"
1134 ;; Support for outline-minor-mode
1135 (set (make-local-variable 'outline-regexp)
1136 "\\([ \t]*\\(procedure\\|function\\|package\\|if\\|while\\|for\\|declare\\|case\\|end\\|begin\\|loop\\)\\|--\\)")
1137 (set (make-local-variable 'outline-level) 'ada-outline-level)
1139 ;; Support for imenu : We want a sorted index
1140 (setq imenu-sort-function 'imenu--sort-by-name)
1142 ;; Support for which-function-mode is provided in ada-support (support
1143 ;; for nested subprograms)
1145 ;; Set up the contextual menu
1147 (define-key ada-mode-map ada-popup-key 'ada-popup-menu))
1149 ;; Support for Abbreviations (the user still need to "M-x abbrev-mode"
1150 (define-abbrev-table 'ada-mode-abbrev-table ())
1151 (setq local-abbrev-table ada-mode-abbrev-table)
1153 ;; Support for indent-new-comment-line (Especially for XEmacs)
1154 (setq comment-multi-line nil)
1156 (setq major-mode 'ada-mode)
1157 (setq mode-name "Ada")
1159 (use-local-map ada-mode-map)
1161 (easy-menu-add ada-mode-menu ada-mode-map)
1163 (set-syntax-table ada-mode-syntax-table)
1165 (if ada-clean-buffer-before-saving
1167 ;; remove all spaces at the end of lines in the whole buffer.
1168 (add-hook 'local-write-file-hooks 'delete-trailing-whitespace)
1169 ;; convert all tabs to the correct number of spaces.
1170 (add-hook 'local-write-file-hooks
1171 (lambda () (untabify (point-min) (point-max))))))
1173 (run-hooks 'ada-mode-hook)
1175 ;; Run this after the hook to give the users a chance to activate
1179 (ada-initialize-properties)
1180 (make-local-hook 'font-lock-mode-hook)
1181 (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t))
1183 ;; the following has to be done after running the ada-mode-hook
1184 ;; because users might want to set the values of these variable
1185 ;; inside the hook (MH)
1187 (cond ((eq ada-language-version 'ada83)
1188 (setq ada-keywords ada-83-keywords))
1189 ((eq ada-language-version 'ada95)
1190 (setq ada-keywords ada-95-keywords)))
1193 (ada-activate-keys-for-case)))
1196 ;;-----------------------------------------------------------------
1198 ;; Since Ada is case-insensitive, the Ada-mode provides an extensive set of
1199 ;; functions to auto-case identifiers, keywords, ...
1200 ;; The basic rules for autocasing are defined through the variables
1201 ;; `ada-case-attribute', `ada-case-keyword' and `ada-case-identifier'. These
1202 ;; are references to the functions that will do the actual casing.
1204 ;; However, in most cases, the user will want to define some exceptions to
1205 ;; these casing rules. This is done through a list of files, that contain
1206 ;; one word per line. These files are stored in `ada-case-exception-file'.
1207 ;; For backward compatibility, this variable can also be a string.
1208 ;;-----------------------------------------------------------------
1210 (defun ada-create-case-exception (&optional word)
1211 "Defines WORD as an exception for the casing system.
1212 If WORD is not given, then the current word in the buffer is used instead.
1213 The new words is added to the first file in `ada-case-exception-file'.
1214 The standard casing rules will no longer apply to this word."
1216 (let ((previous-syntax-table (syntax-table))
1217 (exception-list '())
1221 (cond ((stringp ada-case-exception-file)
1222 (setq file-name ada-case-exception-file))
1223 ((listp ada-case-exception-file)
1224 (setq file-name (car ada-case-exception-file)))
1226 (error "No exception file specified")))
1228 (set-syntax-table ada-mode-symbol-syntax-table)
1231 (skip-syntax-backward "w")
1232 (setq word (buffer-substring-no-properties
1233 (point) (save-excursion (forward-word 1) (point))))))
1235 ;; Reread the exceptions file, in case it was modified by some other,
1236 ;; and to keep the end-of-line comments that may exist in it.
1237 (if (file-readable-p (expand-file-name file-name))
1238 (let ((buffer (current-buffer)))
1239 (find-file (expand-file-name file-name))
1240 (set-syntax-table ada-mode-symbol-syntax-table)
1242 (goto-char (point-min))
1244 (add-to-list 'exception-list
1246 (buffer-substring-no-properties
1247 (point) (save-excursion (forward-word 1) (point)))
1248 (buffer-substring-no-properties
1249 (save-excursion (forward-word 1) (point))
1250 (save-excursion (end-of-line) (point)))
1254 (set-buffer buffer)))
1256 ;; If the word is already in the list, even with a different casing
1257 ;; we simply want to replace it.
1258 (if (and (not (equal exception-list '()))
1259 (assoc-ignore-case word exception-list))
1260 (setcar (assoc-ignore-case word exception-list)
1262 (add-to-list 'exception-list (list word "" t))
1265 (if (and (not (equal ada-case-exception '()))
1266 (assoc-ignore-case word ada-case-exception))
1267 (setcar (assoc-ignore-case word ada-case-exception)
1269 (add-to-list 'ada-case-exception (cons word t))
1272 ;; Save the list in the file
1273 (find-file (expand-file-name file-name))
1275 (mapcar (lambda (x) (insert (car x) (nth 1 x) "\n"))
1276 (sort exception-list
1277 (lambda(a b) (string< (car a) (car b)))))
1280 (set-syntax-table previous-syntax-table)
1283 (defun ada-case-read-exceptions-from-file (file-name)
1284 "Read the content of the casing exception file FILE-NAME."
1285 (if (file-readable-p (expand-file-name file-name))
1286 (let ((buffer (current-buffer)))
1287 (find-file (expand-file-name file-name))
1288 (set-syntax-table ada-mode-symbol-syntax-table)
1290 (goto-char (point-min))
1293 ;; If the item is already in the list, even with an other casing,
1294 ;; do not add it again. This way, the user can easily decide which
1295 ;; priority should be applied to each casing exception
1296 (let ((word (buffer-substring-no-properties
1297 (point) (save-excursion (forward-word 1) (point)))))
1298 (unless (assoc-ignore-case word ada-case-exception)
1299 (add-to-list 'ada-case-exception (cons word t))))
1303 (set-buffer buffer)))
1306 (defun ada-case-read-exceptions ()
1307 "Read all the casing exception files from `ada-case-exception-file'."
1310 ;; Reinitialize the casing exception list
1311 (setq ada-case-exception '())
1313 (cond ((stringp ada-case-exception-file)
1314 (ada-case-read-exceptions-from-file ada-case-exception-file))
1316 ((listp ada-case-exception-file)
1317 (mapcar 'ada-case-read-exceptions-from-file
1318 ada-case-exception-file))))
1320 (defun ada-adjust-case-identifier ()
1321 "Adjust case of the previous identifier.
1322 The auto-casing is done according to the value of `ada-case-identifier' and
1323 the exceptions defined in `ada-case-exception-file'."
1325 (if (or (equal ada-case-exception '())
1326 (equal (char-after) ?_))
1327 (funcall ada-case-identifier -1)
1331 (start (save-excursion (skip-syntax-backward "w")
1334 ;; If we have an exception, replace the word by the correct casing
1335 (if (setq match (assoc-ignore-case (buffer-substring start end)
1336 ada-case-exception))
1339 (delete-region start end)
1340 (insert (car match)))
1342 ;; Else simply re-case the word
1343 (funcall ada-case-identifier -1))))))
1345 (defun ada-after-keyword-p ()
1346 "Returns t if cursor is after a keyword that is not an attribute."
1349 (and (not (and (char-before)
1350 (or (= (char-before) ?_)
1351 (= (char-before) ?'))));; unless we have a _ or '
1352 (looking-at (concat ada-keywords "[^_]")))))
1354 (defun ada-adjust-case (&optional force-identifier)
1355 "Adjust the case of the word before the just typed character.
1356 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier."
1358 (if (and (> (point) 1)
1359 ;; or if at the end of a character constant
1360 (not (and (eq (char-after) ?')
1361 (eq (char-before (1- (point))) ?')))
1362 ;; or if the previous character was not part of a word
1363 (eq (char-syntax (char-before)) ?w)
1364 ;; if in a string or a comment
1365 (not (ada-in-string-or-comment-p))
1369 (or (= (point) (point-min))
1371 (= (char-after) ?'))
1372 (funcall ada-case-attribute -1)
1374 (not force-identifier) ; (MH)
1375 (ada-after-keyword-p))
1376 (funcall ada-case-keyword -1)
1377 (ada-adjust-case-identifier))))
1381 (defun ada-adjust-case-interactive (arg)
1382 "Adjust the case of the previous word, and process the character just typed.
1383 ARG is the prefix the user entered with \C-u."
1387 (let ((lastk last-command-char)
1388 (previous-syntax-table (syntax-table)))
1392 (set-syntax-table ada-mode-symbol-syntax-table)
1393 (cond ((or (eq lastk ?\n)
1398 ;; horrible dekludge
1399 (delete-backward-char 1)
1400 ;; some special keys and their bindings
1403 (funcall ada-lfd-binding))
1405 (funcall ada-ret-binding))))
1406 ((eq lastk ?\C-i) (ada-tab))
1407 ;; Else just insert the character
1408 ((self-insert-command (prefix-numeric-value arg))))
1409 ;; if there is a keyword in front of the underscore
1410 ;; then it should be part of an identifier (MH)
1415 ;; Restore the syntax table
1416 (set-syntax-table previous-syntax-table))
1419 ;; Else, no auto-casing
1421 ((eq last-command-char ?\n)
1422 (funcall ada-lfd-binding))
1423 ((eq last-command-char ?\r)
1424 (funcall ada-ret-binding))
1426 (self-insert-command (prefix-numeric-value arg))))
1429 (defun ada-activate-keys-for-case ()
1430 "Modifies the key bindings for all the keys that should readjust the casing."
1432 ;; Save original key-bindings to allow swapping ret/lfd
1433 ;; when casing is activated.
1434 ;; The 'or ...' is there to be sure that the value will not
1435 ;; be changed again when Ada mode is called more than once
1436 (or ada-ret-binding (setq ada-ret-binding (key-binding "\C-M")))
1437 (or ada-lfd-binding (setq ada-lfd-binding (key-binding "\C-j")))
1439 ;; Call case modifying function after certain keys.
1440 (mapcar (function (lambda(key) (define-key
1442 (char-to-string key)
1443 'ada-adjust-case-interactive)))
1444 '( ?` ?_ ?# ?% ?& ?* ?( ?) ?- ?= ?+
1445 ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?/ ?\n 32 ?\r )))
1447 (defun ada-loose-case-word (&optional arg)
1448 "Upcase first letter and letters following `_' in the following word.
1449 No other letter is modified.
1450 ARG is ignored, and is there for compatibility with `capitalize-word' only."
1453 (let ((end (save-excursion (skip-syntax-forward "w") (point)))
1455 (skip-syntax-backward "w")
1456 (while (and (or first (search-forward "_" end t))
1460 (insert-char (upcase (following-char)) 1)
1463 (defun ada-no-auto-case (&optional arg)
1465 This function can be used for the auto-casing variables in the ada-mode, to
1466 adapt to unusal auto-casing schemes. Since it does nothing, you can for
1467 instance use it for `ada-case-identifier' if you don't want any special
1468 auto-casing for identifiers, whereas keywords have to be lower-cased.
1469 See also `ada-auto-case' to disable auto casing altogether."
1472 (defun ada-capitalize-word (&optional arg)
1473 "Upcase first letter and letters following '_', lower case other letters.
1474 ARG is ignored, and is there for compatibility with `capitalize-word' only."
1476 (let ((end (save-excursion (skip-syntax-forward "w") (point)))
1477 (begin (save-excursion (skip-syntax-backward "w") (point))))
1478 (modify-syntax-entry ?_ "_")
1479 (capitalize-region begin end)
1480 (modify-syntax-entry ?_ "w")))
1482 (defun ada-adjust-case-region (from to)
1483 "Adjusts the case of all words in the region between FROM and TO.
1484 Attention: This function might take very long for big regions !"
1490 (previous-syntax-table (syntax-table)))
1491 (message "Adjusting case ...")
1494 (set-syntax-table ada-mode-symbol-syntax-table)
1497 ;; loop: look for all identifiers, keywords, and attributes
1499 (while (re-search-backward "\\<\\(\\sw+\\)\\>" from t)
1500 (setq end (match-end 1))
1502 (and (> (point) from)
1505 (setq attribp (looking-at "'.[^']")))))
1507 ;; do nothing if it is a string or comment
1508 (ada-in-string-or-comment-p)
1511 ;; get the identifier or keyword or attribute
1513 (setq begin (point))
1514 (setq keywordp (looking-at ada-keywords))
1517 ;; casing according to user-option
1520 (funcall ada-case-attribute -1)
1522 (funcall ada-case-keyword -1)
1523 (ada-adjust-case-identifier)))
1524 (goto-char begin))))
1525 (message "Adjusting case ... Done"))
1526 (set-syntax-table previous-syntax-table))))
1528 (defun ada-adjust-case-buffer ()
1529 "Adjusts the case of all words in the whole buffer.
1530 ATTENTION: This function might take very long for big buffers !"
1532 (ada-adjust-case-region (point-min) (point-max)))
1535 ;;--------------------------------------------------------------
1536 ;; Format Parameter Lists
1537 ;; Some special algorithms are provided to indent the parameter lists in
1538 ;; subprogram declarations. This is done in two steps:
1539 ;; - First parses the parameter list. The returned list has the following
1541 ;; ( (<Param_Name> in? out? access? <Type_Name> <Default_Expression>)
1543 ;; This is done in `ada-scan-paramlist'.
1544 ;; - Delete and recreate the parameter list in function
1545 ;; `ada-insert-paramlist'.
1546 ;; Both steps are called from `ada-format-paramlist'.
1547 ;; Note: Comments inside the parameter list are lost.
1548 ;; The syntax has to be correct, or the reformating will fail.
1549 ;;--------------------------------------------------------------
1551 (defun ada-format-paramlist ()
1552 "Reformats the parameter list point is in."
1558 (previous-syntax-table (syntax-table)))
1561 (set-syntax-table ada-mode-symbol-syntax-table)
1563 ;; check if really inside parameter list
1564 (or (ada-in-paramlist-p)
1565 (error "not in parameter list"))
1567 ;; find start of current parameter-list
1568 (ada-search-ignore-string-comment
1569 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil)
1572 (setq begin (point))
1574 ;; find end of parameter-list
1576 (setq delend (point))
1580 ;; find end of last parameter-declaration
1581 (forward-comment -1000)
1584 ;; build a list of all elements of the parameter-list
1585 (setq paramlist (ada-scan-paramlist (1+ begin) end))
1587 ;; delete the original parameter-list
1588 (delete-region begin delend)
1590 ;; insert the new parameter-list
1592 (ada-insert-paramlist paramlist))
1594 ;; restore syntax-table
1595 (set-syntax-table previous-syntax-table)
1598 (defun ada-scan-paramlist (begin end)
1599 "Scan the parameter list found in between BEGIN and END.
1600 Returns the equivalent internal parameter list."
1601 (let ((paramlist (list))
1611 ;; loop until end of last parameter
1614 ;; find first character of parameter-declaration
1615 (ada-goto-next-non-ws)
1618 ;; find last character of parameter-declaration
1619 (if (setq match-cons
1620 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t))
1622 (setq epos (car match-cons))
1623 (setq semipos (cdr match-cons)))
1626 ;; read name(s) of parameter(s)
1628 (looking-at "\\(\\(\\sw\\|[_, \t\n]\\)*\\(\\sw\\|_\\)\\)[ \t\n]*:[^=]")
1630 (setq param (list (match-string 1)))
1631 (ada-search-ignore-string-comment ":" nil epos t 'search-forward)
1639 (ada-search-ignore-string-comment
1640 "in" nil epos t 'word-search-forward)))))
1648 (ada-search-ignore-string-comment
1649 "out" nil epos t 'word-search-forward)))))
1651 ;; look for 'access'
1657 (ada-search-ignore-string-comment
1658 "access" nil epos t 'word-search-forward)))))
1660 ;; skip 'in'/'out'/'access'
1662 (ada-goto-next-non-ws)
1663 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>")
1665 (ada-goto-next-non-ws))
1667 ;; read type of parameter
1668 ;; We accept spaces in the name, since some software like Rose
1669 ;; generates something like: "A : B 'Class"
1670 (looking-at "\\<\\(\\sw\\|[_.' \t]\\)+\\>")
1673 (list (match-string 0))))
1675 ;; read default-expression, if there is one
1676 (goto-char (setq apos (match-end 0)))
1680 (if (setq match-cons
1681 (ada-search-ignore-string-comment
1682 ":=" nil epos t 'search-forward))
1683 (buffer-substring (car match-cons) epos)
1686 ;; add this parameter-declaration to the list
1687 (setq paramlist (append paramlist (list param)))
1689 ;; check if it was the last parameter
1692 (goto-char semipos))
1694 (reverse paramlist)))
1696 (defun ada-insert-paramlist (paramlist)
1697 "Inserts a formatted PARAMLIST in the buffer."
1698 (let ((i (length paramlist))
1707 ;; loop until last parameter
1708 (while (not (zerop i))
1711 ;; get max length of parameter-name
1712 (setq parlen (max parlen (length (nth 0 (nth i paramlist)))))
1714 ;; get max length of type-name
1715 (setq typlen (max typlen (length (nth 4 (nth i paramlist)))))
1717 ;; is there any 'in' ?
1718 (setq inp (or inp (nth 1 (nth i paramlist))))
1720 ;; is there any 'out' ?
1721 (setq outp (or outp (nth 2 (nth i paramlist))))
1723 ;; is there any 'access' ?
1724 (setq accessp (or accessp (nth 3 (nth i paramlist))))
1727 ;; does paramlist already start on a separate line ?
1729 (re-search-backward "^.\\|[^ \t]" nil t)
1731 ;; yes => re-indent it
1733 (ada-indent-current)
1735 (if (looking-at "\\(is\\|return\\)")
1736 (replace-match " \\1"))))
1738 ;; no => insert it where we are after removing any whitespace
1742 ((looking-at "[ \t]*\\(\n\\|;\\)")
1743 (replace-match "\\1"))
1744 ((looking-at "[ \t]*\\(is\\|return\\)")
1745 (replace-match " \\1"))))
1749 (ada-indent-current)
1751 (setq firstcol (current-column))
1752 (setq i (length paramlist))
1754 ;; loop until last parameter
1755 (while (not (zerop i))
1757 (setq column firstcol)
1759 ;; insert parameter-name, space and colon
1760 (insert (nth 0 (nth i paramlist)))
1761 (indent-to (+ column parlen 1))
1763 (setq column (current-column))
1765 ;; insert 'in' or space
1766 (if (nth 1 (nth i paramlist))
1771 (not (nth 3 (nth i paramlist))))
1774 ;; insert 'out' or space
1775 (if (nth 2 (nth i paramlist))
1780 (not (nth 3 (nth i paramlist))))
1784 (if (nth 3 (nth i paramlist))
1787 (setq column (current-column))
1789 ;; insert type-name and, if necessary, space and default-expression
1790 (insert (nth 4 (nth i paramlist)))
1791 (if (nth 5 (nth i paramlist))
1793 (indent-to (+ column typlen 1))
1794 (insert (nth 5 (nth i paramlist)))))
1796 ;; check if it was the last parameter
1799 ;; no => insert ';' and newline and indent
1802 (indent-to firstcol))
1805 ;; if anything follows, except semicolon, newline, is or return
1806 ;; put it in a new line and indent it
1807 (unless (looking-at "[ \t]*\\(;\\|\n\\|is\\|return\\)")
1808 (ada-indent-newline-indent))
1813 ;;;----------------------------------------------------------------
1814 ;; Indentation Engine
1815 ;; All indentations are indicated as a two-element string:
1816 ;; - position of reference in the buffer
1817 ;; - offset to indent from this position (can also be a symbol or a list
1818 ;; that are evaluated)
1819 ;; Thus the total indentation for a line is the column number of the reference
1820 ;; position plus whatever value the evaluation of the second element provides.
1821 ;; This mechanism is used so that the ada-mode can "explain" how the
1822 ;; indentation was calculated, by showing which variables were used.
1824 ;; The indentation itself is done in only one pass: first we try to guess in
1825 ;; what context we are by looking at the following keyword or punctuation
1826 ;; sign. If nothing remarkable is found, just try to guess the indentation
1827 ;; based on previous lines.
1829 ;; The relevant functions for indentation are:
1830 ;; - `ada-indent-region': Re-indent a region of text
1831 ;; - `ada-justified-indent-current': Re-indent the current line and shows the
1832 ;; calculation that were done
1833 ;; - `ada-indent-current': Re-indent the current line
1834 ;; - `ada-get-current-indent': Calculate the indentation for the current line,
1835 ;; based on the context (see above).
1836 ;; - `ada-get-indent-*': Calculate the indentation in a specific context.
1837 ;; For efficiency, these functions do not check they are in the correct
1839 ;;;----------------------------------------------------------------
1841 (defun ada-indent-region (beg end)
1842 "Indent the region between BEG end END."
1845 (let ((block-done 0)
1846 (lines-remaining (count-lines beg end))
1847 (msg (format "%%4d out of %4d lines remaining ..."
1848 (count-lines beg end)))
1849 (endmark (copy-marker end)))
1850 ;; catch errors while indenting
1851 (while (< (point) endmark)
1852 (if (> block-done 39)
1854 (setq lines-remaining (- lines-remaining block-done)
1856 (message msg lines-remaining)))
1857 (if (= (char-after) ?\n) nil
1858 (ada-indent-current))
1860 (setq block-done (1+ block-done)))
1861 (message "indenting ... done")))
1863 (defun ada-indent-newline-indent ()
1864 "Indents the current line, inserts a newline and then indents the new line."
1866 (ada-indent-current)
1868 (ada-indent-current))
1870 (defun ada-indent-newline-indent-conditional ()
1871 "Insert a newline and indent it.
1872 The original line is indented first if `ada-indent-after-return' is non-nil.
1873 This function is intended to be bound to the \C-m and \C-j keys."
1875 (if ada-indent-after-return (ada-indent-current))
1877 (ada-indent-current))
1879 (defun ada-justified-indent-current ()
1880 "Indent the current line and explains how the calculation was done."
1883 (let ((cur-indent (ada-indent-current)))
1886 (if (equal (cdr cur-indent) '(0))
1887 (message "same indentation")
1888 (message (mapconcat (lambda(x)
1893 (number-to-string x))
1895 (concat "- " (symbol-name (cadr x))))
1900 (goto-char (car cur-indent))
1903 (defun ada-batch-reformat ()
1904 "Re-indent and re-case all the files found on the command line.
1905 This function should be used from the Unix/Windows command line, with a
1907 emacs -batch -l ada-mode -f ada-batch-reformat file1 file2 ..."
1909 (while command-line-args-left
1910 (let ((source (car command-line-args-left)))
1911 (message (concat "formating " source))
1913 (ada-indent-region (point-min) (point-max))
1914 (ada-adjust-case-buffer)
1915 (write-file source))
1916 (setq command-line-args-left (cdr command-line-args-left)))
1920 (defsubst ada-goto-previous-word ()
1921 "Moves point to the beginning of the previous word of Ada code.
1922 Returns the new position of point or nil if not found."
1923 (ada-goto-next-word t))
1925 (defun ada-indent-current ()
1926 "Indent current line as Ada code.
1927 Returns the calculation that was done, including the reference point and the
1930 (let ((previous-syntax-table (syntax-table))
1931 (orgpoint (point-marker))
1932 cur-indent tmp-indent
1937 (set-syntax-table ada-mode-symbol-syntax-table)
1939 ;; This need to be done here so that the advice is not always
1940 ;; activated (this might interact badly with other modes)
1942 (ad-activate 'parse-partial-sexp t))
1947 ;; Not First line in the buffer ?
1948 (if (save-excursion (zerop (forward-line -1)))
1950 (back-to-indentation)
1951 (ada-get-current-indent))
1953 ;; first line in the buffer
1954 (list (point-min) 0))))
1956 ;; Evaluate the list to get the column to indent to
1957 ;; prev-indent contains the column to indent to
1959 (setq prev-indent (save-excursion (goto-char (car cur-indent))
1961 tmp-indent (cdr cur-indent))
1962 (setq prev-indent 0 tmp-indent '()))
1964 (while (not (null tmp-indent))
1966 ((numberp (car tmp-indent))
1967 (setq prev-indent (+ prev-indent (car tmp-indent))))
1969 (setq prev-indent (+ prev-indent (eval (car tmp-indent)))))
1971 (setq tmp-indent (cdr tmp-indent)))
1973 ;; only re-indent if indentation is different then the current
1974 (if (= (save-excursion (back-to-indentation) (current-column)) prev-indent)
1977 (delete-horizontal-space)
1978 (indent-to prev-indent))
1980 ;; restore position of point
1982 (goto-char orgpoint)
1983 (if (< (current-column) (current-indentation))
1984 (back-to-indentation)))
1986 ;; restore syntax-table
1987 (set-syntax-table previous-syntax-table)
1989 (ad-deactivate 'parse-partial-sexp))
1995 (defun ada-get-current-indent ()
1996 "Return the indentation to use for the current line."
2001 (orgpoint (save-excursion
2003 (forward-comment -10000)
2010 ;;-----------------------------
2011 ;; in open parenthesis, but not in parameter-list
2012 ;;-----------------------------
2014 ((and ada-indent-to-open-paren
2015 (not (ada-in-paramlist-p))
2016 (setq column (ada-in-open-paren-p)))
2018 ;; check if we have something like this (Table_Component_Type =>
2019 ;; Source_File_Record)
2021 (if (and (skip-chars-backward " \t")
2022 (= (char-before) ?\n)
2023 (not (forward-comment -10000))
2024 (= (char-before) ?>))
2025 ;; ??? Could use a different variable
2026 (list column 'ada-broken-indent)
2029 ;;---------------------------
2031 ;;---------------------------
2034 (ada-indent-on-previous-lines nil orgpoint orgpoint))
2036 ;;---------------------------
2038 ;;---------------------------
2040 ((= (char-after) ?e)
2043 ;; ------- end ------
2045 ((looking-at "end\\>")
2049 (ada-goto-matching-start 1)
2052 ;; found 'loop' => skip back to 'while' or 'for'
2053 ;; if 'loop' is not on a separate line
2054 ;; Stop the search for 'while' and 'for' when a ';' is encountered.
2058 (looking-at ".+\\<loop\\>"))
2061 (setq limit (car (ada-search-ignore-string-comment ";" t))))
2065 (ada-search-ignore-string-comment ada-loop-start-re t limit))
2066 (not (looking-at "\\<loop\\>"))))
2068 (goto-char (car match-cons))
2071 (if (looking-at ada-named-block-re)
2072 (setq label (- ada-label-indent))))))))
2074 (list (+ (save-excursion (back-to-indentation) (point)) label) 0))))
2076 ;; ------ exception ----
2078 ((looking-at "exception\\>")
2080 (ada-goto-matching-start 1)
2081 (list (save-excursion (back-to-indentation) (point)) 0)))
2085 ((looking-at "else\\>")
2086 (if (save-excursion (ada-goto-previous-word)
2087 (looking-at "\\<or\\>"))
2088 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2090 (ada-goto-matching-start 1 nil t)
2091 (list (progn (back-to-indentation) (point)) 0))))
2095 ((looking-at "elsif\\>")
2097 (ada-goto-matching-start 1 nil t)
2098 (list (progn (back-to-indentation) (point)) 0)))
2102 ;;---------------------------
2103 ;; starting with w (when)
2104 ;;---------------------------
2106 ((and (= (char-after) ?w)
2107 (looking-at "when\\>"))
2109 (ada-goto-matching-start 1)
2110 (list (save-excursion (back-to-indentation) (point))
2113 ;;---------------------------
2114 ;; starting with t (then)
2115 ;;---------------------------
2117 ((and (= (char-after) ?t)
2118 (looking-at "then\\>"))
2119 (if (save-excursion (ada-goto-previous-word)
2120 (looking-at "and\\>"))
2121 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2123 ;; Select has been added for the statement: "select ... then abort"
2124 (ada-search-ignore-string-comment
2125 "\\<\\(elsif\\|if\\|select\\)\\>" t nil)
2126 (list (progn (back-to-indentation) (point))
2127 'ada-stmt-end-indent))))
2129 ;;---------------------------
2130 ;; starting with l (loop)
2131 ;;---------------------------
2133 ((and (= (char-after) ?l)
2134 (looking-at "loop\\>"))
2137 (goto-char (match-end 0))
2138 (ada-goto-stmt-start)
2139 (if (looking-at "\\<\\(loop\\|if\\)\\>")
2140 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2141 (unless (looking-at ada-loop-start-re)
2142 (ada-search-ignore-string-comment ada-loop-start-re
2144 (if (looking-at "\\<loop\\>")
2145 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2146 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent)))))
2148 ;;---------------------------
2149 ;; starting with b (begin)
2150 ;;---------------------------
2152 ((and (= (char-after) ?b)
2153 (looking-at "begin\\>"))
2155 (if (ada-goto-matching-decl-start t)
2156 (list (progn (back-to-indentation) (point)) 0)
2157 (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2159 ;;---------------------------
2160 ;; starting with i (is)
2161 ;;---------------------------
2163 ((and (= (char-after) ?i)
2164 (looking-at "is\\>"))
2166 (if (and ada-indent-is-separate
2168 (goto-char (match-end 0))
2169 (ada-goto-next-non-ws (save-excursion (end-of-line)
2171 (looking-at "\\<abstract\\>\\|\\<separate\\>")))
2173 (ada-goto-stmt-start)
2174 (list (progn (back-to-indentation) (point)) 'ada-indent))
2176 (ada-goto-stmt-start)
2177 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent))))
2179 ;;---------------------------
2180 ;; starting with r (record, return, renames)
2181 ;;---------------------------
2183 ((= (char-after) ?r)
2187 ;; ----- record ------
2189 ((looking-at "record\\>")
2191 (ada-search-ignore-string-comment
2192 "\\<\\(type\\|use\\)\\>" t nil)
2193 (if (looking-at "\\<use\\>")
2194 (ada-search-ignore-string-comment "for" t nil nil 'word-search-backward))
2195 (list (progn (back-to-indentation) (point)) 'ada-indent-record-rel-type)))
2197 ;; ----- return or renames ------
2199 ((looking-at "re\\(turn\\|names\\)\\>")
2201 (let ((var 'ada-indent-return))
2202 ;; If looking at a renames, skip the 'return' statement too
2203 (if (looking-at "renames")
2206 (setq pos (ada-search-ignore-string-comment ";\\|return\\>" t)))
2208 (= (char-after (car pos)) ?r))
2209 (goto-char (car pos)))
2210 (setq var 'ada-indent-renames)))
2212 (forward-comment -1000)
2213 (if (= (char-before) ?\))
2217 ;; If there is a parameter list, and we have a function declaration
2218 ;; or a access to subprogram declaration
2220 (if (and (= (char-after) ?\()
2224 (looking-at "function\\>"))
2228 (looking-at "function\\>")))))
2230 ;; The indentation depends of the value of ada-indent-return
2231 (if (<= (eval var) 0)
2232 (list (point) (list '- var))
2233 (list (progn (backward-word num-back) (point))
2236 ;; Else there is no parameter list, but we have a function
2237 ;; Only do something special if the user want to indent
2238 ;; relative to the "function" keyword
2239 (if (and (> (eval var) 0)
2240 (save-excursion (forward-word -1)
2241 (looking-at "function\\>")))
2242 (list (progn (forward-word -1) (point)) var)
2245 (ada-indent-on-previous-lines nil orgpoint orgpoint)))))))
2248 ;;--------------------------------
2249 ;; starting with 'o' or 'p'
2250 ;; 'or' as statement-start
2251 ;; 'private' as statement-start
2252 ;;--------------------------------
2254 ((and (or (= (char-after) ?o)
2255 (= (char-after) ?p))
2256 (or (ada-looking-at-semi-or)
2257 (ada-looking-at-semi-private)))
2259 (ada-goto-matching-start 1)
2260 (list (progn (back-to-indentation) (point)) 0)))
2262 ;;--------------------------------
2263 ;; starting with 'd' (do)
2264 ;;--------------------------------
2266 ((and (= (char-after) ?d)
2267 (looking-at "do\\>"))
2269 (ada-goto-stmt-start)
2270 (list (progn (back-to-indentation) (point)) 'ada-stmt-end-indent)))
2272 ;;--------------------------------
2273 ;; starting with '-' (comment)
2274 ;;--------------------------------
2276 ((= (char-after) ?-)
2277 (if ada-indent-comment-as-code
2279 ;; Indent comments on previous line comments if required
2280 ;; We must use a search-forward (even if the code is more complex),
2281 ;; since we want to find the beginning of the comment.
2284 (if (and ada-indent-align-comments
2288 (while (and (not pos)
2289 (search-forward "--"
2291 (end-of-line) (point))
2293 (unless (ada-in-string-p)
2294 (setq pos (point))))
2298 ;; Else always on previous line
2299 (ada-indent-on-previous-lines nil orgpoint orgpoint)))
2301 ;; Else same indentation as the previous line
2302 (list (save-excursion (back-to-indentation) (point)) 0)))
2304 ;;--------------------------------
2305 ;; starting with '#' (preprocessor line)
2306 ;;--------------------------------
2308 ((and (= (char-after) ?#)
2309 (equal ada-which-compiler 'gnat)
2310 (looking-at "#[ \t]*\\(if\\|els\\(e\\|if\\)\\|end[ \t]*if\\)"))
2311 (list (save-excursion (beginning-of-line) (point)) 0))
2313 ;;--------------------------------
2314 ;; starting with ')' (end of a parameter list)
2315 ;;--------------------------------
2317 ((and (not (eobp)) (= (char-after) ?\)))
2323 ;;---------------------------------
2324 ;; new/abstract/separate
2325 ;;---------------------------------
2327 ((looking-at "\\(new\\|abstract\\|separate\\)\\>")
2328 (ada-indent-on-previous-lines nil orgpoint orgpoint))
2330 ;;---------------------------------
2331 ;; package/function/procedure
2332 ;;---------------------------------
2334 ((and (or (= (char-after) ?p) (= (char-after) ?f))
2335 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>"))
2337 ;; Go up until we find either a generic section, or the end of the
2338 ;; previous subprogram/package
2340 (while (and (not found)
2341 (ada-search-ignore-string-comment
2342 "\\<\\(generic\\|end\\|begin\\|package\\|procedure\\|function\\)\\>" t))
2344 ;; avoid "with procedure"... in generic parts
2347 (setq found (not (looking-at "with"))))))
2349 (if (looking-at "generic")
2350 (list (progn (back-to-indentation) (point)) 0)
2351 (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2353 ;;---------------------------------
2355 ;;---------------------------------
2357 ((looking-at "\\(\\sw\\|_\\)+[ \t\n]*:[^=]")
2359 (ada-indent-on-previous-lines nil orgpoint orgpoint)
2360 (append (ada-indent-on-previous-lines nil orgpoint orgpoint)
2361 '(ada-label-indent))))
2365 ;;---------------------------------
2367 ;;---------------------------------
2368 (or result (ada-indent-on-previous-lines nil orgpoint orgpoint))))
2370 (defun ada-indent-on-previous-lines (&optional nomove orgpoint initial-pos)
2371 "Calculate the indentation for the new line after ORGPOINT.
2372 The result list is based on the previous lines in the buffer.
2373 If NOMOVE is nil, moves point to the beginning of the current statement.
2374 if INITIAL-POS is non-nil, moves point to INITIAL-POS before calculation."
2376 (goto-char initial-pos))
2377 (let ((oldpoint (point)))
2379 ;; Is inside a parameter-list ?
2380 (if (ada-in-paramlist-p)
2381 (ada-get-indent-paramlist)
2383 ;; move to beginning of current statement
2385 (ada-goto-stmt-start))
2387 ;; no beginning found => don't change indentation
2388 (if (and (eq oldpoint (point))
2390 (ada-get-indent-nochange)
2395 ada-indent-to-open-paren
2396 (ada-in-open-paren-p))
2397 (ada-get-indent-open-paren))
2399 ((looking-at "end\\>")
2400 (ada-get-indent-end orgpoint))
2402 ((looking-at ada-loop-start-re)
2403 (ada-get-indent-loop orgpoint))
2405 ((looking-at ada-subprog-start-re)
2406 (ada-get-indent-subprog orgpoint))
2408 ((looking-at ada-block-start-re)
2409 (ada-get-indent-block-start orgpoint))
2411 ((looking-at "\\(sub\\)?type\\>")
2412 (ada-get-indent-type orgpoint))
2414 ;; "then" has to be included in the case of "select...then abort"
2415 ;; statements, since (goto-stmt-start) at the beginning of
2416 ;; the current function would leave the cursor on that position
2417 ((looking-at "\\(\\(els\\)?if\\>\\)\\|then abort\\\>")
2418 (ada-get-indent-if orgpoint))
2420 ((looking-at "case\\>")
2421 (ada-get-indent-case orgpoint))
2423 ((looking-at "when\\>")
2424 (ada-get-indent-when orgpoint))
2426 ((looking-at "\\(\\sw\\|_\\)+[ \t\n]*:[^=]")
2427 (ada-get-indent-label orgpoint))
2429 ((looking-at "separate\\>")
2430 (ada-get-indent-nochange))
2432 ((looking-at "with\\>\\|use\\>")
2433 ;; Are we still in that statement, or are we in fact looking at
2434 ;; the previous one ?
2435 (if (save-excursion (search-forward ";" oldpoint t))
2436 (list (progn (back-to-indentation) (point)) 0)
2437 (list (point) (if (looking-at "with")
2442 (ada-get-indent-noindent orgpoint)))))
2445 (defun ada-get-indent-open-paren ()
2446 "Calculates the indentation when point is behind an unclosed parenthesis."
2447 (list (ada-in-open-paren-p) 0))
2449 (defun ada-get-indent-nochange ()
2450 "Return the current indentation of the previous line."
2453 (back-to-indentation)
2456 (defun ada-get-indent-paramlist ()
2457 "Calculates the indentation when point is inside a parameter list."
2459 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
2461 ;; in front of the first parameter
2462 ((= (char-after) ?\()
2463 (goto-char (match-end 0))
2466 ;; in front of another parameter
2467 ((= (char-after) ?\;)
2468 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
2469 (ada-goto-next-non-ws)
2472 ;; inside a parameter declaration
2474 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
2475 (ada-goto-next-non-ws)
2476 (list (point) 'ada-broken-indent)))))
2478 (defun ada-get-indent-end (orgpoint)
2479 "Calculates the indentation when point is just before an end_statement.
2480 ORGPOINT is the limit position used in the calculation."
2481 (let ((defun-name nil)
2484 ;; is the line already terminated by ';' ?
2486 (ada-search-ignore-string-comment ";" nil orgpoint nil
2489 ;; yes, look what's following 'end'
2492 (ada-goto-next-non-ws)
2494 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\)\\>")
2495 (save-excursion (ada-check-matching-start (match-string 0)))
2496 (list (save-excursion (back-to-indentation) (point)) 0))
2499 ;; loop/select/if/case/record/select
2501 ((looking-at "\\<record\\>")
2503 (ada-check-matching-start (match-string 0))
2504 ;; we are now looking at the matching "record" statement
2506 (ada-goto-stmt-start)
2507 ;; now on the matching type declaration, or use clause
2508 (unless (looking-at "\\(for\\|type\\)\\>")
2509 (ada-search-ignore-string-comment "\\<type\\>" t))
2510 (list (progn (back-to-indentation) (point)) 0)))
2512 ;; a named block end
2514 ((looking-at ada-ident-re)
2515 (setq defun-name (match-string 0))
2517 (ada-goto-matching-start 0)
2518 (ada-check-defun-name defun-name))
2519 (list (progn (back-to-indentation) (point)) 0))
2521 ;; a block-end without name
2523 ((= (char-after) ?\;)
2525 (ada-goto-matching-start 0)
2526 (if (looking-at "\\<begin\\>")
2528 (setq indent (list (point) 0))
2529 (if (ada-goto-matching-decl-start t)
2530 (list (progn (back-to-indentation) (point)) 0)
2533 ;; anything else - should maybe signal an error ?
2536 (list (save-excursion (back-to-indentation) (point))
2537 'ada-broken-indent))))
2539 (list (save-excursion (back-to-indentation) (point))
2540 'ada-broken-indent))))
2542 (defun ada-get-indent-case (orgpoint)
2543 "Calculates the indentation when point is just before a case statement.
2544 ORGPOINT is the limit position used in the calculation."
2545 (let ((match-cons nil)
2549 ;; case..is..when..=>
2552 (setq match-cons (and
2553 ;; the `=>' must be after the keyword `is'.
2554 (ada-search-ignore-string-comment
2555 "is" nil orgpoint nil 'word-search-forward)
2556 (ada-search-ignore-string-comment
2557 "[ \t\n]+=>" nil orgpoint))))
2559 (goto-char (car match-cons))
2560 (unless (ada-search-ignore-string-comment "when" t opos)
2561 (error "missing 'when' between 'case' and '=>'"))
2562 (list (save-excursion (back-to-indentation) (point)) 'ada-indent)))
2567 (setq match-cons (ada-search-ignore-string-comment
2568 "when" nil orgpoint nil 'word-search-forward)))
2569 (goto-char (cdr match-cons))
2570 (list (save-excursion (back-to-indentation) (point)) 'ada-broken-indent))
2575 (setq match-cons (ada-search-ignore-string-comment
2576 "is" nil orgpoint nil 'word-search-forward)))
2577 (list (save-excursion (back-to-indentation) (point)) 'ada-when-indent))
2582 (list (save-excursion (back-to-indentation) (point))
2583 'ada-broken-indent)))))
2585 (defun ada-get-indent-when (orgpoint)
2586 "Calculates the indentation when point is just before a when statement.
2587 ORGPOINT is the limit position used in the calculation."
2588 (let ((cur-indent (save-excursion (back-to-indentation) (point))))
2589 (if (ada-search-ignore-string-comment "[ \t\n]*=>" nil orgpoint)
2590 (list cur-indent 'ada-indent)
2591 (list cur-indent 'ada-broken-indent))))
2593 (defun ada-get-indent-if (orgpoint)
2594 "Calculates the indentation when point is just before an if statement.
2595 ORGPOINT is the limit position used in the calculation."
2596 (let ((cur-indent (save-excursion (back-to-indentation) (point)))
2599 ;; Move to the correct then (ignore all "and then")
2601 (while (and (setq match-cons (ada-search-ignore-string-comment
2602 "\\<\\(then\\|and[ \t]*then\\)\\>"
2604 (= (char-after (car match-cons)) ?a)))
2605 ;; If "then" was found (we are looking at it)
2609 ;; 'then' first in separate line ?
2610 ;; => indent according to 'then',
2611 ;; => else indent according to 'if'
2614 (back-to-indentation)
2615 (looking-at "\\<then\\>"))
2616 (setq cur-indent (save-excursion (back-to-indentation) (point))))
2619 (list cur-indent 'ada-indent))
2621 (list cur-indent 'ada-broken-indent))))
2623 (defun ada-get-indent-block-start (orgpoint)
2624 "Calculates the indentation when point is at the start of a block.
2625 ORGPOINT is the limit position used in the calculation."
2630 (setq pos (ada-goto-next-non-ws orgpoint)))
2633 (ada-indent-on-previous-lines t orgpoint)))
2635 ;; nothing follows the block-start
2637 (list (save-excursion (back-to-indentation) (point)) 'ada-indent)))))
2639 (defun ada-get-indent-subprog (orgpoint)
2640 "Calculates the indentation when point is just before a subprogram.
2641 ORGPOINT is the limit position used in the calculation."
2642 (let ((match-cons nil)
2643 (cur-indent (save-excursion (back-to-indentation) (point)))
2646 ;; is there an 'is' in front of point ?
2650 (ada-search-ignore-string-comment
2651 "\\<\\(is\\|do\\)\\>" nil orgpoint)))
2653 ;; yes, then skip to its end
2657 (goto-char (cdr match-cons)))
2659 ;; no, then goto next non-ws, if there is one in front of point
2662 (unless (ada-goto-next-non-ws orgpoint)
2663 (goto-char orgpoint))))
2667 ;; nothing follows 'is'
2672 (not (ada-search-ignore-string-comment
2673 "[^ \t\n]" nil orgpoint t))))
2674 (list cur-indent 'ada-indent))
2676 ;; is abstract/separate/new ...
2682 (ada-search-ignore-string-comment
2683 "\\<\\(separate\\|new\\|abstract\\)\\>"
2685 (goto-char (car match-cons))
2686 (ada-search-ignore-string-comment ada-subprog-start-re t)
2687 (ada-get-indent-noindent orgpoint))
2689 ;; something follows 'is'
2693 (save-excursion (setq match-cons (ada-goto-next-non-ws orgpoint)))
2694 (goto-char match-cons)
2695 (ada-indent-on-previous-lines t orgpoint)))
2700 (ada-search-ignore-string-comment ";" nil orgpoint nil 'search-forward))
2701 (list cur-indent 0))
2706 (list cur-indent 'ada-broken-indent)))))
2708 (defun ada-get-indent-noindent (orgpoint)
2709 "Calculates the indentation when point is just before a 'noindent stmt'.
2710 ORGPOINT is the limit position used in the calculation."
2717 ;; This one is called when indenting a line preceded by a multi-line
2718 ;; subprogram declaration (in that case, we are at this point inside
2719 ;; the parameter declaration list)
2720 ((ada-in-paramlist-p)
2721 (ada-previous-procedure)
2722 (list (save-excursion (back-to-indentation) (point)) 0))
2724 ;; This one is called when indenting the second line of a multi-line
2725 ;; declaration section, in a declare block or a record declaration
2726 ((looking-at "[ \t]*\\(\\sw\\|_\\)*[ \t]*,[ \t]*$")
2727 (list (save-excursion (back-to-indentation) (point))
2728 'ada-broken-decl-indent))
2730 ;; This one is called in every over case when indenting a line at the
2733 (if (looking-at ada-named-block-re)
2734 (setq label (- ada-label-indent))
2738 ;; "with private" or "null record" cases
2739 (if (or (save-excursion
2740 (and (ada-search-ignore-string-comment "\\<private\\>" nil orgpoint)
2742 (save-excursion (forward-char -7);; skip back "private"
2743 (ada-goto-previous-word)
2744 (looking-at "with"))))
2746 (and (ada-search-ignore-string-comment "\\<record\\>" nil orgpoint)
2748 (save-excursion (forward-char -6);; skip back "record"
2749 (ada-goto-previous-word)
2750 (looking-at "null")))))
2753 (re-search-backward "\\<\\(type\\|subtype\\)\\>" nil t)
2754 (list (save-excursion (back-to-indentation) (point)) 0)))))
2756 (ada-search-ignore-string-comment ";" nil orgpoint nil
2758 (list (+ (save-excursion (back-to-indentation) (point)) label) 0)
2759 (list (+ (save-excursion (back-to-indentation) (point)) label)
2760 'ada-broken-indent)))))))
2762 (defun ada-get-indent-label (orgpoint)
2763 "Calculates the indentation when before a label or variable declaration.
2764 ORGPOINT is the limit position used in the calculation."
2765 (let ((match-cons nil)
2766 (cur-indent (save-excursion (back-to-indentation) (point))))
2767 (ada-search-ignore-string-comment ":" nil)
2771 (setq match-cons (ada-search-ignore-string-comment
2772 ada-loop-start-re nil orgpoint)))
2773 (goto-char (car match-cons))
2774 (ada-get-indent-loop orgpoint))
2778 (setq match-cons (ada-search-ignore-string-comment
2779 "\\<declare\\|begin\\>" nil orgpoint)))
2780 (goto-char (car match-cons))
2781 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2783 ;; variable declaration
2786 (ada-search-ignore-string-comment ";" nil orgpoint))
2788 (list cur-indent 'ada-broken-indent)))
2790 ;; nothing follows colon
2792 (list cur-indent '(- ada-label-indent))))))
2794 (defun ada-get-indent-loop (orgpoint)
2795 "Calculates the indentation when just before a loop or a for ... use.
2796 ORGPOINT is the limit position used in the calculation."
2797 (let ((match-cons nil)
2800 ;; If looking at a named block, skip the label
2801 (label (save-excursion
2803 (if (looking-at ada-named-block-re)
2804 (- ada-label-indent)
2810 ;; statement complete
2813 (ada-search-ignore-string-comment ";" nil orgpoint nil
2815 (list (+ (save-excursion (back-to-indentation) (point)) label) 0))
2819 ((looking-at "loop\\>")
2820 (setq pos (ada-get-indent-block-start orgpoint))
2823 (list (+ (car pos) label) (cdr pos))))
2826 ;; 'for'- loop (or also a for ... use statement)
2828 ((looking-at "for\\>")
2835 (goto-char (match-end 0))
2836 (ada-goto-next-non-ws orgpoint)
2838 (if (= (char-after) ?') (forward-word 1) t)
2839 (ada-goto-next-non-ws orgpoint)
2840 (looking-at "\\<use\\>")
2842 ;; check if there is a 'record' before point
2845 (setq match-cons (ada-search-ignore-string-comment
2846 "record" nil orgpoint nil 'word-search-forward))
2849 (goto-char (car match-cons)))
2850 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2855 (setq match-cons (ada-search-ignore-string-comment
2856 "loop" nil orgpoint nil 'word-search-forward)))
2857 (goto-char (car match-cons))
2859 ;; indent according to 'loop', if it's first in the line;
2860 ;; otherwise to 'for'
2862 (unless (save-excursion
2863 (back-to-indentation)
2864 (looking-at "\\<loop\\>"))
2866 (list (+ (save-excursion (back-to-indentation) (point)) label)
2869 ;; for-statement is broken
2872 (list (+ (save-excursion (back-to-indentation) (point)) label)
2873 'ada-broken-indent))))
2878 ((looking-at "while\\>")
2883 (setq match-cons (ada-search-ignore-string-comment
2884 "loop" nil orgpoint nil 'word-search-forward)))
2887 (goto-char (car match-cons))
2889 ;; indent according to 'loop', if it's first in the line;
2890 ;; otherwise to 'while'.
2892 (unless (save-excursion
2893 (back-to-indentation)
2894 (looking-at "\\<loop\\>"))
2896 (list (+ (save-excursion (back-to-indentation) (point)) label)
2899 (list (+ (save-excursion (back-to-indentation) (point)) label)
2900 'ada-broken-indent))))))
2902 (defun ada-get-indent-type (orgpoint)
2903 "Calculates the indentation when before a type statement.
2904 ORGPOINT is the limit position used in the calculation."
2905 (let ((match-dat nil))
2908 ;; complete record declaration
2912 (setq match-dat (ada-search-ignore-string-comment
2913 "end" nil orgpoint nil 'word-search-forward))
2914 (ada-goto-next-non-ws)
2915 (looking-at "\\<record\\>")
2917 (ada-goto-next-non-ws)
2918 (= (char-after) ?\;)))
2919 (goto-char (car match-dat))
2920 (list (save-excursion (back-to-indentation) (point)) 0))
2925 (setq match-dat (ada-search-ignore-string-comment
2926 "record" nil orgpoint nil 'word-search-forward)))
2927 (goto-char (car match-dat))
2928 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
2930 ;; complete type declaration
2933 (ada-search-ignore-string-comment ";" nil orgpoint nil
2935 (list (save-excursion (back-to-indentation) (point)) 0))
2937 ;; "type ... is", but not "type ... is ...", which is broken
2941 (ada-search-ignore-string-comment "is" nil orgpoint nil
2942 'word-search-forward)
2943 (not (ada-goto-next-non-ws orgpoint))))
2944 (list (save-excursion (back-to-indentation) (point)) 'ada-broken-indent))
2949 (list (save-excursion (back-to-indentation) (point))
2950 'ada-broken-indent)))))
2953 ;; -----------------------------------------------------------
2954 ;; -- searching and matching
2955 ;; -----------------------------------------------------------
2957 (defun ada-goto-stmt-start ()
2958 "Moves point to the beginning of the statement that point is in or after.
2959 Returns the new position of point.
2960 As a special case, if we are looking at a closing parenthesis, skip to the
2962 (let ((match-dat nil)
2965 (setq match-dat (ada-search-prev-end-stmt))
2969 ;; found a previous end-statement => check if anything follows
2971 (unless (looking-at "declare")
2973 (unless (save-excursion
2974 (goto-char (cdr match-dat))
2975 (ada-goto-next-non-ws orgpoint))
2977 ;; nothing follows => it's the end-statement directly in
2978 ;; front of point => search again
2980 (setq match-dat (ada-search-prev-end-stmt)))
2982 ;; if found the correct end-statement => goto next non-ws
2985 (goto-char (cdr match-dat)))
2986 (ada-goto-next-non-ws)
2990 ;; no previous end-statement => we are at the beginning of the
2991 ;; accessible part of the buffer
2994 (goto-char (point-min))
2996 ;; skip to the very first statement, if there is one
2998 (unless (ada-goto-next-non-ws orgpoint)
2999 (goto-char orgpoint))))
3003 (defun ada-search-prev-end-stmt ()
3004 "Moves point to previous end-statement.
3005 Returns a cons cell whose car is the beginning and whose cdr the end of the
3007 (let ((match-dat nil)
3010 ;; search until found or beginning-of-buffer
3014 (setq match-dat (ada-search-ignore-string-comment
3015 ada-end-stmt-re t)))
3017 (goto-char (car match-dat))
3018 (unless (ada-in-open-paren-p)
3019 (if (and (looking-at
3020 "\\<\\(record\\|loop\\|select\\|else\\|then\\)\\>")
3022 (ada-goto-previous-word)
3023 (looking-at "\\<\\(end\\|or\\|and\\)\\>[ \t]*[^;]")))
3027 (goto-char (cdr match-dat))
3028 (ada-goto-next-non-ws)
3030 ;; words that can go after an 'is'
3034 (regexp-opt '("separate" "access" "array"
3035 "abstract" "new") t)
3045 (defun ada-goto-next-non-ws (&optional limit)
3046 "Skips white spaces, newlines and comments to next non-ws character.
3047 Stop the search at LIMIT.
3048 Do not call this function from within a string."
3050 (setq limit (point-max)))
3051 (while (and (<= (point) limit)
3052 (progn (forward-comment 10000)
3053 (if (and (not (eobp))
3054 (save-excursion (forward-char 1)
3056 (progn (forward-sexp 1) t)))))
3057 (if (< (point) limit)
3063 (defun ada-goto-stmt-end (&optional limit)
3064 "Moves point to the end of the statement that point is in or before.
3065 Returns the new position of point or nil if not found.
3066 Stop the search at LIMIT."
3067 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
3072 (defun ada-goto-next-word (&optional backward)
3073 "Moves point to the beginning of the next word of Ada code.
3074 If BACKWARD is non-nil, jump to the beginning of the previous word.
3075 Returns the new position of point or nil if not found."
3076 (let ((match-cons nil)
3078 (old-syntax (char-to-string (char-syntax ?_))))
3079 (modify-syntax-entry ?_ "w")
3081 (skip-syntax-forward "w"))
3082 (if (setq match-cons
3084 (ada-search-ignore-string-comment "\\w" t nil t)
3085 (ada-search-ignore-string-comment "\\w" nil nil t)))
3087 ;; move to the beginning of the word found
3090 (goto-char (car match-cons))
3091 (skip-syntax-backward "w")
3094 ;; if not found, restore old position of point
3096 (goto-char orgpoint)
3098 (modify-syntax-entry ?_ old-syntax))
3102 (defun ada-check-matching-start (keyword)
3103 "Signals an error if matching block start is not KEYWORD.
3104 Moves point to the matching block start."
3105 (ada-goto-matching-start 0)
3106 (unless (looking-at (concat "\\<" keyword "\\>"))
3107 (error "matching start is not '%s'" keyword)))
3110 (defun ada-check-defun-name (defun-name)
3111 "Checks if the name of the matching defun really is DEFUN-NAME.
3112 Assumes point to be already positioned by 'ada-goto-matching-start'.
3113 Moves point to the beginning of the declaration."
3115 ;; named block without a `declare'
3117 (ada-goto-previous-word)
3118 (looking-at (concat "\\<" defun-name "\\> *:")))
3121 ;; 'accept' or 'package' ?
3123 (unless (looking-at ada-subprog-start-re)
3124 (ada-goto-matching-decl-start))
3126 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
3130 ;; a named 'declare'-block ?
3132 (if (looking-at "\\<declare\\>")
3133 (ada-goto-stmt-start)
3135 ;; no, => 'procedure'/'function'/'task'/'protected'
3141 ;; skip 'body' 'type'
3143 (if (looking-at "\\<\\(body\\|type\\)\\>")
3148 ;; should be looking-at the correct name
3150 (unless (looking-at (concat "\\<" defun-name "\\>"))
3151 (error "matching defun has different name: %s"
3152 (buffer-substring (point)
3153 (progn (forward-sexp 1) (point))))))))
3155 (defun ada-goto-matching-decl-start (&optional noerror recursive)
3156 "Moves point to the matching declaration start of the current 'begin'.
3157 If NOERROR is non-nil, it only returns nil if no match was found."
3158 (let ((nest-count 1)
3159 (first (not recursive))
3164 ;; Ignore "when" most of the time, except if we are looking at the
3165 ;; beginning of a block (structure: case .. is
3169 (if (looking-at "begin")
3170 (setq stop-at-when t))
3173 (looking-at "\\<\\(package\\|procedure\\|function\\)\\>")
3175 (ada-search-ignore-string-comment
3176 "\\<\\(package\\|procedure\\|function\\|generic\\)\\>" t)
3177 (looking-at "generic")))
3178 (setq count-generic t))
3180 ;; search backward for interesting keywords
3182 (not (zerop nest-count))
3183 (ada-search-ignore-string-comment ada-matching-decl-start-re t))
3185 ;; calculate nest-depth
3190 (ada-goto-matching-start 1 noerror)
3192 ;; In some case, two begin..end block can follow each other closely,
3193 ;; which we have to detect, as in
3198 ;; begin -- here we should go to procedure, not begin
3201 (if (looking-at "begin")
3202 (let ((loop-again t))
3205 ;; If begin was just there as the beginning of a block
3206 ;; (with no declare) then do nothing, otherwise just
3207 ;; register that we have to find the statement that
3208 ;; required the begin
3210 (ada-search-ignore-string-comment
3211 "\\<\\(declare\\|begin\\|end\\|procedure\\|function\\|task\\|package\\)\\>"
3214 (if (looking-at "end")
3215 (ada-goto-matching-decl-start noerror t)
3217 (setq loop-again nil)
3218 (unless (looking-at "begin")
3219 (setq nest-count (1+ nest-count))))
3223 ((looking-at "generic")
3227 (setq nest-count (1- nest-count)))))
3232 (unless (looking-at "\\<end[ \t\n]*if\\>")
3234 (setq nest-count (1- nest-count))
3235 (setq first nil)))))
3238 ((looking-at "declare\\|generic")
3239 (setq nest-count (1- nest-count))
3243 ;; check if it is only a type definition, but not a protected
3244 ;; type definition, which should be handled like a procedure.
3245 (if (or (looking-at "is[ \t]+<>")
3247 (forward-comment -10000)
3250 ;; Detect if we have a closing parenthesis (Could be
3251 ;; either the end of subprogram parameters or (<>)
3252 ;; in a type definition
3253 (if (= (char-after) ?\))
3257 (forward-comment -10000)
3259 (skip-chars-backward "a-zA-Z0-9_.'")
3260 (ada-goto-previous-word)
3262 (looking-at "\\<\\(sub\\)?type\\>")
3264 (ada-goto-previous-word)
3265 (not (looking-at "\\<protected\\>"))))
3267 (goto-char (match-beginning 0))
3269 (setq nest-count (1- nest-count))
3275 (ada-goto-previous-word)
3277 (goto-char (match-beginning 0))))
3280 (looking-at "begin"))
3281 (setq nest-count 0))
3283 ((looking-at "when")
3285 (setq nest-count (1- nest-count)))
3289 (setq nest-count (1+ nest-count))
3294 ;; check if declaration-start is really found
3297 (if (looking-at "is")
3298 (ada-search-ignore-string-comment ada-subprog-start-re t)
3299 (looking-at "declare\\|generic")))
3302 (error "no matching proc/func/task/declare/package/protected")))
3305 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
3306 "Moves point to the beginning of a block-start.
3307 Which block depends on the value of NEST-LEVEL, which defaults to zero. If
3308 NOERROR is non-nil, it only returns nil if no matching start was found.
3309 If GOTOTHEN is non-nil, point moves to the 'then' following 'if'."
3310 (let ((nest-count (if nest-level nest-level 0))
3315 ;; search backward for interesting keywords
3319 (ada-search-ignore-string-comment ada-matching-start-re t))
3321 (unless (and (looking-at "\\<record\\>")
3324 (looking-at "\\<null\\>")))
3327 ;; calculate nest-depth
3330 ;; found block end => increase nest depth
3332 (setq nest-count (1+ nest-count)))
3334 ;; found loop/select/record/case/if => check if it starts or
3336 ((looking-at "loop\\|select\\|record\\|case\\|if")
3340 ;; check if keyword follows 'end'
3342 (ada-goto-previous-word)
3343 (if (looking-at "\\<end\\>[ \t]*[^;]")
3344 ;; it ends a block => increase nest depth
3346 (setq nest-count (1+ nest-count))
3348 ;; it starts a block => decrease nest depth
3349 (setq nest-count (1- nest-count))))
3352 ;; found package start => check if it really is a block
3353 ((looking-at "package")
3355 ;; ignore if this is just a renames statement
3356 (let ((current (point))
3357 (pos (ada-search-ignore-string-comment
3358 "\\<\\(is\\|renames\\|;\\)\\>" nil)))
3360 (goto-char (car pos))
3362 "No matching 'is' or 'renames' for 'package' at"
3364 (number-to-string (count-lines (point-min)
3366 (unless (looking-at "renames")
3369 (ada-goto-next-non-ws)
3370 ;; ignore it if it is only a declaration with 'new'
3371 (if (not (looking-at "\\<\\(new\\|separate\\)\\>"))
3372 (setq nest-count (1- nest-count)))))))
3373 ;; found task start => check if it has a body
3374 ((looking-at "task")
3377 (ada-goto-next-non-ws)
3379 ((looking-at "\\<body\\>"))
3380 ((looking-at "\\<type\\>")
3381 ;; In that case, do nothing if there is a "is"
3382 (forward-word 2);; skip "type"
3383 (ada-goto-next-non-ws);; skip type name
3385 ;; Do nothing if we are simply looking at a simple
3386 ;; "task type name;" statement with no block
3387 (unless (looking-at ";")
3389 ;; Skip the parameters
3390 (if (looking-at "(")
3391 (ada-search-ignore-string-comment ")" nil))
3392 (let ((tmp (ada-search-ignore-string-comment
3393 "\\<\\(is\\|;\\)\\>" nil)))
3396 (goto-char (car tmp))
3397 (if (looking-at "is")
3398 (setq nest-count (1- nest-count)))))))))
3400 ;; Check if that task declaration had a block attached to
3401 ;; it (i.e do nothing if we have just "task name;")
3402 (unless (progn (forward-word 1)
3403 (looking-at "[ \t]*;"))
3404 (setq nest-count (1- nest-count)))))))
3405 ;; all the other block starts
3407 (setq nest-count (1- nest-count)))) ; end of 'cond'
3409 ;; match is found, if nest-depth is zero
3411 (setq found (zerop nest-count))))) ; end of loop
3415 ;; match found => is there anything else to do ?
3420 ;; found 'if' => skip to 'then', if it's on a separate line
3421 ;; and GOTOTHEN is non-nil
3427 (ada-search-ignore-string-comment "then" nil nil nil
3428 'word-search-forward)
3429 (back-to-indentation)
3430 (looking-at "\\<then\\>")))
3431 (goto-char (match-beginning 0)))
3433 ;; found 'do' => skip back to 'accept'
3436 (unless (ada-search-ignore-string-comment "accept" t nil nil
3437 'word-search-backward)
3438 (error "missing 'accept' in front of 'do'"))))
3443 (error "no matching start")))))
3446 (defun ada-goto-matching-end (&optional nest-level noerror)
3447 "Moves point to the end of a block.
3448 Which block depends on the value of NEST-LEVEL, which defaults to zero.
3449 If NOERROR is non-nil, it only returns nil if found no matching start."
3450 (let ((nest-count (if nest-level nest-level 0))
3454 ;; search forward for interesting keywords
3458 (ada-search-ignore-string-comment
3461 (regexp-opt '("end" "loop" "select" "begin" "case"
3462 "if" "task" "package" "record" "do") t)
3466 ;; calculate nest-depth
3470 ;; found block end => decrease nest depth
3471 ((looking-at "\\<end\\>")
3472 (setq nest-count (1- nest-count))
3473 ;; skip the following keyword
3475 (skip-chars-forward "end")
3476 (ada-goto-next-non-ws)
3477 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>"))
3479 ;; found package start => check if it really starts a block
3480 ((looking-at "\\<package\\>")
3481 (ada-search-ignore-string-comment "is" nil nil nil
3482 'word-search-forward)
3483 (ada-goto-next-non-ws)
3484 ;; ignore and skip it if it is only a 'new' package
3485 (if (looking-at "\\<new\\>")
3486 (goto-char (match-end 0))
3487 (setq nest-count (1+ nest-count))))
3488 ;; all the other block starts
3490 (setq nest-count (1+ nest-count))
3491 (forward-word 1))) ; end of 'cond'
3493 ;; match is found, if nest-depth is zero
3495 (setq found (zerop nest-count))) ; end of loop
3501 (error "no matching end")))
3505 (defun ada-search-ignore-string-comment
3506 (search-re &optional backward limit paramlists search-func)
3507 "Regexp-search for SEARCH-RE, ignoring comments, strings.
3508 If PARAMLISTS is nil, ignore parameter lists. Returns a cons cell of
3509 begin and end of match data or nil, if not found.
3510 The search is done using SEARCH-FUNC, which should search backward if
3511 BACKWARD is non-nil, forward otherwise. SEARCH-FUNC can be optimized in case
3512 we are searching for a constant string.
3513 The search stops at pos LIMIT.
3514 Point is moved at the beginning of the search-re."
3519 (previous-syntax-table (syntax-table)))
3522 (setq search-func (if backward 're-search-backward 're-search-forward)))
3525 ;; search until found or end-of-buffer
3526 ;; We have to test that we do not look further than limit
3528 (set-syntax-table ada-mode-symbol-syntax-table)
3529 (while (and (not found)
3531 (or (and backward (<= limit (point)))
3532 (>= limit (point))))
3533 (funcall search-func search-re limit 1))
3534 (setq begin (match-beginning 0))
3535 (setq end (match-end 0))
3537 (setq parse-result (parse-partial-sexp
3538 (save-excursion (beginning-of-line) (point))
3543 ;; If inside a string, skip it (and the following comments)
3545 ((ada-in-string-p parse-result)
3547 (search-backward "\"" nil t)
3548 (goto-char (nth 8 parse-result)))
3549 (unless backward (forward-sexp 1)))
3551 ;; If inside a comment, skip it (and the following comments)
3552 ;; There is a special code for comments at the end of the file
3554 ((ada-in-comment-p parse-result)
3559 (forward-comment -1))
3560 (goto-char (nth 8 parse-result)))
3562 ;; at the end of the file, it is not possible to skip a comment
3563 ;; so we just go at the end of the line
3564 (if (forward-comment 1)
3566 (forward-comment 1000)
3567 (beginning-of-line))
3570 ;; directly in front of a comment => skip it, if searching forward
3572 ((and (= (char-after begin) ?-) (= (char-after (1+ begin)) ?-))
3573 (unless backward (progn (forward-char -1) (forward-comment 1000))))
3576 ;; found a parameter-list but should ignore it => skip it
3578 ((and (not paramlists) (ada-in-paramlist-p))
3580 (search-backward "(" nil t)
3581 (search-forward ")" nil t)))
3583 ;; found what we were looking for
3586 (setq found t)))) ; end of loop
3588 (set-syntax-table previous-syntax-table)
3594 ;; -------------------------------------------------------
3595 ;; -- Testing the position of the cursor
3596 ;; -------------------------------------------------------
3598 (defun ada-in-decl-p ()
3599 "Returns t if point is inside a declarative part.
3600 Assumes point to be at the end of a statement."
3601 (or (ada-in-paramlist-p)
3603 (ada-goto-matching-decl-start t))))
3606 (defun ada-looking-at-semi-or ()
3607 "Returns t if looking-at an 'or' following a semicolon."
3609 (and (looking-at "\\<or\\>")
3612 (ada-goto-stmt-start)
3613 (looking-at "\\<or\\>")))))
3616 (defun ada-looking-at-semi-private ()
3617 "Returns t if looking at the start of a private section in a package.
3618 Returns nil if the private is part of the package name, as in
3619 'private package A is...' (this can only happen at top level)."
3621 (and (looking-at "\\<private\\>")
3622 (not (looking-at "\\<private[ \t]*\\(package\\|generic\\)"))
3624 ;; Make sure this is the start of a private section (ie after
3625 ;; a semicolon or just after the package declaration, but not
3626 ;; after a 'type ... is private' or 'is new ... with private'
3627 (progn (forward-comment -1000)
3628 (or (= (char-before) ?\;)
3629 (and (forward-word -3)
3630 (looking-at "\\<package\\>")))))))
3633 (defun ada-in-paramlist-p ()
3634 "Returns t if point is inside a parameter-list."
3637 (ada-search-ignore-string-comment "(\\|)" t nil t)
3638 ;; inside parentheses ?
3639 (= (char-after) ?\()
3641 ;; We could be looking at two things here:
3642 ;; operator definition: function "." (
3643 ;; subprogram definition: procedure .... (
3644 ;; Let's skip back over the first one
3646 (skip-syntax-backward " ")
3647 (if (= (char-before) ?\")
3652 ;; and now over the second one
3655 ;; We should ignore the case when the reserved keyword is in a
3656 ;; comment (for instance, when we have:
3659 ;; we should return nil
3661 (not (ada-in-string-or-comment-p))
3663 ;; right keyword two words before parenthesis ?
3664 ;; Type is in this list because of discriminants
3665 (looking-at (eval-when-compile
3667 "procedure\\|function\\|body\\|"
3668 "task\\|entry\\|accept\\|"
3669 "access[ \t]+procedure\\|"
3670 "access[ \t]+function\\|"
3674 (defun ada-search-ignore-complex-boolean (regexp backwardp)
3675 "Like `ada-search-ignore-string-comment', except that it also ignores
3676 boolean expressions 'and then' and 'or else'."
3678 (while (and (setq result (ada-search-ignore-string-comment regexp backwardp))
3679 (save-excursion (forward-word -1)
3680 (looking-at "and then\\|or else"))))
3683 (defun ada-in-open-paren-p ()
3684 "Returns the position of the first non-ws behind the last unclosed
3685 parenthesis, or nil."
3687 (let ((parse (parse-partial-sexp
3689 (or (car (ada-search-ignore-complex-boolean
3690 "\\<\\(;\\|is\\|then\\|loop\\|begin\\|else\\)\\>"
3696 (goto-char (1+ (nth 1 parse)))
3697 (skip-chars-forward " \t")
3701 ;; -----------------------------------------------------------
3702 ;; -- Behavior Of TAB Key
3703 ;; -----------------------------------------------------------
3706 "Do indenting or tabbing according to `ada-tab-policy'.
3707 In Transient Mark mode, if the mark is active, operate on the contents
3708 of the region. Otherwise, operates only on the current line."
3710 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard))
3711 ((eq ada-tab-policy 'indent-auto)
3712 ;; transient-mark-mode and mark-active are not defined in XEmacs
3713 (if (or (and ada-xemacs (funcall (symbol-function 'region-active-p)))
3714 (and (not ada-xemacs)
3715 (symbol-value 'transient-mark-mode)
3716 (symbol-value 'mark-active)))
3717 (ada-indent-region (region-beginning) (region-end))
3718 (ada-indent-current)))
3719 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3722 (defun ada-untab (arg)
3723 "Delete leading indenting according to `ada-tab-policy'."
3725 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard))
3726 ((eq ada-tab-policy 'indent-auto) (error "not implemented"))
3727 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3730 (defun ada-indent-current-function ()
3731 "Ada mode version of the indent-line-function."
3733 (let ((starting-point (point-marker)))
3736 (if (< (point) starting-point)
3737 (goto-char starting-point))
3738 (set-marker starting-point nil)
3741 (defun ada-tab-hard ()
3742 "Indent current line to next tab stop."
3746 (insert-char ? ada-indent))
3747 (if (save-excursion (= (point) (progn (beginning-of-line) (point))))
3748 (forward-char ada-indent)))
3750 (defun ada-untab-hard ()
3751 "indent current line to previous tab stop."
3753 (let ((bol (save-excursion (progn (beginning-of-line) (point))))
3754 (eol (save-excursion (progn (end-of-line) (point)))))
3755 (indent-rigidly bol eol (- 0 ada-indent))))
3759 ;; ------------------------------------------------------------
3761 ;; ------------------------------------------------------------
3763 (defun ada-gnat-style ()
3764 "Clean up comments, `(' and `,' for GNAT style checking switch."
3767 (goto-char (point-min))
3768 (while (re-search-forward "--[ \t]*\\([^-]\\)" nil t)
3769 (replace-match "-- \\1"))
3770 (goto-char (point-min))
3771 (while (re-search-forward "\\>(" nil t)
3772 (replace-match " ("))
3773 (goto-char (point-min))
3774 (while (re-search-forward "([ \t]+" nil t)
3775 (replace-match "("))
3776 (goto-char (point-min))
3777 (while (re-search-forward ")[ \t]+)" nil t)
3778 (replace-match "))"))
3779 (goto-char (point-min))
3780 (while (re-search-forward "\\>:" nil t)
3781 (replace-match " :"))
3782 (goto-char (point-min))
3783 (while (re-search-forward ",\\<" nil t)
3784 (replace-match ", "))
3785 (goto-char (point-min))
3786 (while (re-search-forward "[ \t]*\\.\\.[ \t]*" nil t)
3787 (replace-match " .. "))
3788 (goto-char (point-min))
3789 (while (re-search-forward "[ \t]*\\([-:+*/]\\)[ \t]*" nil t)
3790 (if (not (ada-in-string-or-comment-p))
3795 (replace-match " /= "))
3797 (replace-match ":= "))
3798 ((not (looking-at "--"))
3799 (replace-match " \\1 ")))
3805 ;; -------------------------------------------------------------
3806 ;; -- Moving To Procedures/Packages/Statements
3807 ;; -------------------------------------------------------------
3809 (defun ada-move-to-start ()
3810 "Moves point to the matching start of the current Ada structure."
3813 (previous-syntax-table (syntax-table)))
3816 (set-syntax-table ada-mode-symbol-syntax-table)
3818 (message "searching for block start ...")
3821 ;; do nothing if in string or comment or not on 'end ...;'
3822 ;; or if an error occurs during processing
3825 (ada-in-string-or-comment-p)
3827 (or (looking-at "[ \t]*\\<end\\>")
3829 (or (looking-at "[ \t]*\\<end\\>")
3831 (or (looking-at "[ \t]*\\<end\\>")
3832 (error "not on end ...;")))
3833 (ada-goto-matching-start 1)
3837 ;; on 'begin' => go on, according to user option
3839 ada-move-to-declaration
3840 (looking-at "\\<begin\\>")
3841 (ada-goto-matching-decl-start)
3842 (setq pos (point))))
3844 ) ; end of save-excursion
3846 ;; now really move to the found position
3848 (message "searching for block start ... done"))
3850 ;; restore syntax-table
3851 (set-syntax-table previous-syntax-table))))
3853 (defun ada-move-to-end ()
3854 "Moves point to the matching end of the block around point.
3855 Moves to 'begin' if in a declarative part."
3858 (previous-syntax-table (syntax-table)))
3861 (set-syntax-table ada-mode-symbol-syntax-table)
3863 (message "searching for block end ...")
3868 ;; directly on 'begin'
3870 (ada-goto-previous-word)
3871 (looking-at "\\<begin\\>"))
3872 (ada-goto-matching-end 1))
3873 ;; on first line of defun declaration
3875 (and (ada-goto-stmt-start)
3876 (looking-at "\\<function\\>\\|\\<procedure\\>" )))
3877 (ada-search-ignore-string-comment "begin" nil nil nil
3878 'word-search-forward))
3879 ;; on first line of task declaration
3881 (and (ada-goto-stmt-start)
3882 (looking-at "\\<task\\>" )
3884 (ada-goto-next-non-ws)
3885 (looking-at "\\<body\\>")))
3886 (ada-search-ignore-string-comment "begin" nil nil nil
3887 'word-search-forward))
3888 ;; accept block start
3890 (and (ada-goto-stmt-start)
3891 (looking-at "\\<accept\\>" )))
3892 (ada-goto-matching-end 0))
3895 (and (ada-goto-matching-decl-start t)
3896 (looking-at "\\<package\\>")))
3897 (ada-goto-matching-end 1))
3898 ;; inside a 'begin' ... 'end' block
3900 (ada-goto-matching-decl-start t))
3901 (ada-search-ignore-string-comment "begin" nil nil nil
3902 'word-search-forward))
3903 ;; (hopefully ;-) everything else
3905 (ada-goto-matching-end 1)))
3909 ;; now really move to the position found
3911 (message "searching for block end ... done"))
3913 ;; restore syntax-table
3914 (set-syntax-table previous-syntax-table))))
3916 (defun ada-next-procedure ()
3917 "Moves point to next procedure."
3920 (if (re-search-forward ada-procedure-start-regexp nil t)
3921 (goto-char (match-beginning 1))
3922 (error "No more functions/procedures/tasks")))
3924 (defun ada-previous-procedure ()
3925 "Moves point to previous procedure."
3928 (if (re-search-backward ada-procedure-start-regexp nil t)
3929 (goto-char (match-beginning 1))
3930 (error "No more functions/procedures/tasks")))
3932 (defun ada-next-package ()
3933 "Moves point to next package."
3936 (if (re-search-forward ada-package-start-regexp nil t)
3937 (goto-char (match-beginning 1))
3938 (error "No more packages")))
3940 (defun ada-previous-package ()
3941 "Moves point to previous package."
3944 (if (re-search-backward ada-package-start-regexp nil t)
3945 (goto-char (match-beginning 1))
3946 (error "No more packages")))
3949 ;; ------------------------------------------------------------
3950 ;; -- Define keymap and menus for Ada
3951 ;; -------------------------------------------------------------
3953 (defun ada-create-keymap ()
3954 "Create the keymap associated with the Ada mode."
3956 ;; Indentation and Formatting
3957 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent-conditional)
3958 (define-key ada-mode-map "\C-m" 'ada-indent-newline-indent-conditional)
3959 (define-key ada-mode-map "\t" 'ada-tab)
3960 (define-key ada-mode-map "\C-c\t" 'ada-justified-indent-current)
3961 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region)
3962 (define-key ada-mode-map [(shift tab)] 'ada-untab)
3963 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist)
3964 ;; We don't want to make meta-characters case-specific.
3967 (define-key ada-mode-map "\M-\C-e" 'ada-next-procedure)
3968 (define-key ada-mode-map "\M-\C-a" 'ada-previous-procedure)
3969 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3970 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3973 (unless (lookup-key ada-mode-map "\C-c\C-c")
3974 (define-key ada-mode-map "\C-c\C-c" 'compile))
3977 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3978 (define-key ada-mode-map "\C-c\C-t" 'ada-case-read-exceptions)
3979 (define-key ada-mode-map "\C-c\C-y" 'ada-create-case-exception)
3981 ;; On XEmacs, you can easily specify whether DEL should deletes
3982 ;; one character forward or one character backward. Take this into
3984 (if (boundp 'delete-key-deletes-forward)
3985 (define-key ada-mode-map [backspace] 'backward-delete-char-untabify)
3986 (define-key ada-mode-map "\177" 'backward-delete-char-untabify))
3989 (define-key ada-mode-map "\C-c\C-n" 'ada-make-subprogram-body)
3991 ;; Use predefined function of Emacs19 for comments (RE)
3992 (define-key ada-mode-map "\C-c;" 'comment-region)
3993 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
3997 (defun ada-create-menu ()
3998 "Create the ada menu as shown in the menu bar.
3999 This function is designed to be extensible, so that each compiler-specific file
4000 can add its own items."
4001 ;; Note that the separators must have different length in the submenus
4002 (autoload 'easy-menu-define "easymenu")
4005 ("Help" ["Ada Mode" (info "ada-mode") t])))
4006 (option '(["Auto Casing" (setq ada-auto-case (not ada-auto-case))
4007 :style toggle :selected ada-auto-case]
4008 ["Auto Indent After Return"
4009 (setq ada-indent-after-return (not ada-indent-after-return))
4010 :style toggle :selected ada-indent-after-return]))
4011 (goto '(["Next compilation error" next-error t]
4012 ["Previous Package" ada-previous-package t]
4013 ["Next Package" ada-next-package t]
4014 ["Previous Procedure" ada-previous-procedure t]
4015 ["Next Procedure" ada-next-procedure t]
4016 ["Goto Start Of Statement" ada-move-to-start t]
4017 ["Goto End Of Statement" ada-move-to-end t]
4019 ["Other File" ff-find-other-file t]
4020 ["Other File Other Window" ada-ff-other-window t]))
4021 (edit '(["Indent Line" ada-indent-current-function t]
4022 ["Justify Current Indentation" ada-justified-indent-current t]
4023 ["Indent Lines in Selection" ada-indent-region t]
4024 ["Indent Lines in File" (ada-indent-region (point-min) (point-max)) t]
4025 ["Format Parameter List" ada-format-paramlist t]
4027 ["Comment Selection" comment-region t]
4028 ["Uncomment Selection" ada-uncomment-region t]
4030 ["Fill Comment Paragraph" fill-paragraph t]
4031 ["Fill Comment Paragraph Justify" ada-fill-comment-paragraph-justify t]
4032 ["Fill Comment Paragraph Postfix" ada-fill-comment-paragraph-postfix t]
4034 ["Adjust Case Selection" ada-adjust-case-region t]
4035 ["Adjust Case Buffer" ada-adjust-case-buffer t]
4036 ["Create Case Exception" ada-create-case-exception t]
4037 ["Reload Case Exceptions" ada-case-read-exceptions t]
4039 ["Make body for subprogram" ada-make-subprogram-body t]))
4043 ;; Option menu present only if in Ada mode
4044 (setq m (append m (list (append '("Options"
4045 :included (eq major-mode 'ada-mode))
4048 ;; Customize menu always present
4049 (when (fboundp 'customize-group)
4050 (setq m (append m '(["Customize" (customize-group 'ada)]))))
4052 ;; Goto and Edit menus present only if in Ada mode
4053 (setq m (append m (list (append '("Goto"
4054 :included (eq major-mode 'ada-mode))
4057 :included (eq major-mode 'ada-mode))
4060 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode" m)
4061 (easy-menu-add ada-mode-menu ada-mode-map)
4063 ;; This looks bogus to me! -stef
4064 (define-key ada-mode-map [menu-bar] ada-mode-menu)
4065 (setq mode-popup-menu (cons "Ada mode" ada-mode-menu)))))
4068 ;; -------------------------------------------------------
4069 ;; Commenting/Uncommenting code
4070 ;; The following two calls are provided to enhance the standard
4071 ;; comment-region function, which only allows uncommenting if the
4072 ;; comment is at the beginning of a line. If the line have been re-indented,
4073 ;; we are unable to use comment-region, which makes no sense.
4075 ;; In addition, we provide an interface to the standard comment handling
4076 ;; function for justifying the comments.
4077 ;; -------------------------------------------------------
4079 (defadvice comment-region (before ada-uncomment-anywhere)
4082 (string= mode-name "Ada"))
4084 (let ((cs (concat "^[ \t]*" (regexp-quote comment-start))))
4086 (while (re-search-forward cs end t)
4087 (replace-match comment-start))
4090 (defun ada-uncomment-region (beg end &optional arg)
4091 "Delete `comment-start' at the beginning of a line in the region."
4092 (interactive "r\nP")
4094 ;; This advice is not needed anymore with Emacs21. However, for older
4095 ;; versions, as well as for XEmacs, we still need to enable it.
4096 (if (or (<= emacs-major-version 20) (boundp 'running-xemacs))
4098 (ad-activate 'comment-region)
4099 (comment-region beg end (- (or arg 1)))
4100 (ad-deactivate 'comment-region))
4101 (comment-region beg end (list (- (or arg 1))))))
4103 (defun ada-fill-comment-paragraph-justify ()
4104 "Fills current comment paragraph and justifies each line as well."
4106 (ada-fill-comment-paragraph 'full))
4108 (defun ada-fill-comment-paragraph-postfix ()
4109 "Fills current comment paragraph and justifies each line as well.
4110 Adds `ada-fill-comment-postfix' at the end of each line."
4112 (ada-fill-comment-paragraph 'full t))
4114 (defun ada-fill-comment-paragraph (&optional justify postfix)
4115 "Fills the current comment paragraph.
4116 If JUSTIFY is non-nil, each line is justified as well.
4117 If POSTFIX and JUSTIFY are non-nil, `ada-fill-comment-postfix' is appended
4118 to each filled and justified line.
4119 The paragraph is indented on the first line."
4122 ;; check if inside comment or just in front a comment
4123 (if (and (not (ada-in-comment-p))
4124 (not (looking-at "[ \t]*--")))
4125 (error "not inside comment"))
4130 (opos (point-marker))
4132 ;; Sets this variable to nil, otherwise it prevents
4133 ;; fill-region-as-paragraph to work on Emacs <= 20.2
4134 (parse-sexp-lookup-properties nil)
4137 (fill-column (current-fill-column)))
4139 ;; Find end of paragraph
4140 (back-to-indentation)
4141 (while (and (not (eobp)) (looking-at "--[ \t]*[^ \t\n]"))
4144 ;; If we were at the last line in the buffer, create a dummy empty
4145 ;; line at the end of the buffer.
4148 (back-to-indentation)))
4150 (setq to (point-marker))
4153 ;; Find beginning of paragraph
4155 (while (and (not (bobp)) (looking-at "[ \t]*--[ \t]*[^ \t\n]"))
4157 ;; If we found a paragraph-separating line,
4158 ;; don't actually include it in the paragraph.
4159 (unless (looking-at "[ \t]*--[ \t]*[^ \t\n]")
4161 (setq from (point-marker))
4163 ;; Calculate the indentation we will need for the paragraph
4164 (back-to-indentation)
4165 (setq indent (current-column))
4166 ;; unindent the first line of the paragraph
4167 (delete-region from (point))
4169 ;; Remove the old postfixes
4171 (while (re-search-forward "--\n" to t)
4172 (replace-match "\n"))
4174 ;; Remove the old prefixes (so that the number of spaces after -- is not
4175 ;; relevant), except on the first one since `fill-region-as-paragraph'
4176 ;; would not put it back on the first line.
4177 (goto-char (+ from 2))
4178 (while (re-search-forward "^-- *" to t)
4179 (replace-match " "))
4182 (setq to (point-marker))
4184 ;; Indent and justify the paragraph
4185 (setq fill-prefix ada-fill-comment-prefix)
4186 (set-left-margin from to indent)
4188 (setq fill-column (- fill-column (length ada-fill-comment-postfix))))
4190 (fill-region-as-paragraph from to justify)
4192 ;; Add the postfixes if required
4196 (narrow-to-region from to)
4199 (insert-char ? (- fill-column (current-column)))
4200 (insert ada-fill-comment-postfix)
4204 ;; In Emacs <= 20.2 and XEmacs <=20.4, there is a bug, and a newline is
4205 ;; inserted at the end. Delete it
4207 (<= emacs-major-version 19)
4208 (and (= emacs-major-version 20)
4209 (<= emacs-minor-version 2)))
4218 ;; ---------------------------------------------------
4219 ;; support for find-file.el
4220 ;; These functions are used by find-file to guess the file names from
4221 ;; unit names, and to find the other file (spec or body) from the current
4222 ;; file (body or spec).
4223 ;; It is also used to find in which function we are, so as to put the
4224 ;; cursor at the correct position.
4225 ;; Standard Ada does not force any relation between unit names and file names,
4226 ;; so some of these functions can only be a good approximation. However, they
4227 ;; are also overriden in `ada-xref'.el when we know that the user is using
4229 ;; ---------------------------------------------------
4231 ;; Overriden when we work with GNAT, to use gnatkrunch
4232 (defun ada-make-filename-from-adaname (adaname)
4233 "Determine the filename in which ADANAME is found.
4234 This is a generic function, independent from any compiler."
4235 (while (string-match "\\." adaname)
4236 (setq adaname (replace-match "-" t t adaname)))
4240 (defun ada-other-file-name ()
4241 "Return the name of the other file.
4242 The name returned is the body if current-buffer is the spec, or the spec
4247 (suffixes ada-spec-suffixes)
4248 (name (buffer-file-name)))
4250 ;; Guess whether we have a spec or a body, and get the basename of the
4251 ;; file. Since the extension may not start with '.', we can not use
4252 ;; file-name-extension
4253 (while (and (not is-spec)
4255 (if (string-match (concat "\\(.*\\)" (car suffixes) "$") name)
4257 name (match-string 1 name)))
4258 (setq suffixes (cdr suffixes)))
4262 (setq suffixes ada-body-suffixes)
4263 (while (and (not is-body)
4265 (if (string-match (concat "\\(.*\\)" (car suffixes) "$") name)
4267 name (match-string 1 name)))
4268 (setq suffixes (cdr suffixes)))))
4270 ;; If this wasn't in either list, return name itself
4271 (if (not (or is-spec is-body))
4274 ;; Else find the other possible names
4276 (setq suffixes ada-body-suffixes)
4277 (setq suffixes ada-spec-suffixes))
4281 (if (file-exists-p (concat name (car suffixes)))
4282 (setq is-spec (concat name (car suffixes))))
4283 (setq suffixes (cdr suffixes)))
4287 (defun ada-which-function-are-we-in ()
4288 "Return the name of the function whose definition/declaration point is in.
4289 Redefines the function `ff-which-function-are-we-in'."
4290 (setq ff-function-name nil)
4292 (end-of-line);; make sure we get the complete name
4293 (if (or (re-search-backward ada-procedure-start-regexp nil t)
4294 (re-search-backward ada-package-start-regexp nil t))
4295 (setq ff-function-name (match-string 0)))
4299 (defvar ada-last-which-function-line -1
4300 "Last on which ada-which-function was called")
4301 (defvar ada-last-which-function-subprog 0
4302 "Last subprogram name returned by ada-which-function")
4303 (make-variable-buffer-local 'ada-last-which-function-subprog)
4304 (make-variable-buffer-local 'ada-last-which-function-line)
4307 (defun ada-which-function ()
4308 "Returns the name of the function whose body the point is in.
4309 This function works even in the case of nested subprograms, whereas the
4310 standard Emacs function which-function does not.
4311 Note that this function expects subprogram bodies to be terminated by
4312 'end <name>;', not 'end;'.
4313 Since the search can be long, the results are cached."
4315 (let ((line (count-lines (point-min) (point)))
4321 ;; If this is the same line as before, simply return the same result
4322 (if (= line ada-last-which-function-line)
4323 ada-last-which-function-subprog
4326 ;; In case the current line is also the beginning of the body
4328 (while (and (ada-in-paramlist-p)
4329 (= (forward-line 1) 0))
4332 ;; Can't simply do forward-word, in case the "is" is not on the
4333 ;; same line as the closing parenthesis
4334 (skip-chars-forward "is \t\n")
4336 ;; No look for the closest subprogram body that has not ended yet.
4337 ;; Not that we expect all the bodies to be finished by "end <name",
4340 (while (and (not found)
4341 (re-search-backward ada-imenu-subprogram-menu-re nil t))
4342 (setq func-name (match-string 2))
4343 (if (and (not (ada-in-comment-p))
4344 (not (save-excursion
4345 (goto-char (match-end 0))
4346 (looking-at "[ \t\n]*new"))))
4348 (if (ada-search-ignore-string-comment
4349 (concat "end[ \t]+" func-name "[ \t]*;"))
4350 (setq end-pos (point))
4351 (setq end-pos (point-max)))
4352 (if (>= end-pos pos)
4353 (setq found func-name))))
4355 (setq ada-last-which-function-line line
4356 ada-last-which-function-subprog found)
4359 (defun ada-ff-other-window ()
4360 "Find other file in other window using `ff-find-other-file'."
4362 (and (fboundp 'ff-find-other-file)
4363 (ff-find-other-file t)))
4365 (defun ada-set-point-accordingly ()
4366 "Move to the function declaration that was set by
4367 `ff-which-function-are-we-in'."
4368 (if ff-function-name
4370 (goto-char (point-min))
4371 (unless (ada-search-ignore-string-comment
4372 (concat ff-function-name "\\b") nil)
4373 (goto-char (point-min))))))
4375 (defun ada-get-body-name (&optional spec-name)
4376 "Returns the file name for the body of SPEC-NAME.
4377 If SPEC-NAME is nil, returns the body for the current package.
4378 Returns nil if no body was found."
4381 (unless spec-name (setq spec-name (buffer-file-name)))
4383 ;; If find-file.el was available, use its functions
4384 (if (functionp 'ff-get-file)
4385 (ff-get-file-name ada-search-directories
4386 (ada-make-filename-from-adaname
4387 (file-name-nondirectory
4388 (file-name-sans-extension spec-name)))
4390 ;; Else emulate it very simply
4391 (concat (ada-make-filename-from-adaname
4392 (file-name-nondirectory
4393 (file-name-sans-extension spec-name)))
4397 ;; ---------------------------------------------------
4398 ;; support for font-lock.el
4399 ;; Strings are a real pain in Ada because a single quote character is
4400 ;; overloaded as a string quote and type/instance delimiter. By default, a
4401 ;; single quote is given punctuation syntax in `ada-mode-syntax-table'.
4402 ;; So, for Font Lock mode purposes, we mark single quotes as having string
4403 ;; syntax when the gods that created Ada determine them to be.
4405 ;; This only works in Emacs. See the comments before the grammar functions
4406 ;; at the beginning of this file for how this is done with XEmacs.
4407 ;; ----------------------------------------------------
4409 (defconst ada-font-lock-syntactic-keywords
4410 ;; Mark single quotes as having string quote syntax in 'c' instances.
4411 ;; As a special case, ''' will not be highlighted, but if we do not
4412 ;; set this special case, then the rest of the buffer is highlighted as
4414 ;; This sets the properties of the characters, so that ada-in-string-p
4415 ;; correctly handles '"' too...
4416 '(("\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
4417 ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))
4420 (defvar ada-font-lock-keywords
4424 ;; handle "type T is access function return S;"
4425 (list "\\<\\(function[ \t]+return\\)\\>" '(1 font-lock-keyword-face) )
4427 ;; preprocessor line
4428 (list "^[ \t]*\\(#.*\n\\)" '(1 font-lock-type-face t))
4431 ;; accept, entry, function, package (body), protected (body|type),
4432 ;; pragma, procedure, task (body) plus name.
4438 "package[ \t]+body\\|"
4442 "protected[ \t]+body\\|"
4443 "protected[ \t]+type\\|"
4449 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
4450 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t))
4452 ;; Optional keywords followed by a type name.
4453 (list (concat ; ":[ \t]*"
4454 "\\<\\(access[ \t]+all\\|access\\|constant\\|in[ \t]+out\\|in\\|out\\)\\>"
4456 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
4457 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
4460 ;; Main keywords, except those treated specially below.
4463 '("abort" "abs" "abstract" "accept" "access" "aliased" "all"
4464 "and" "array" "at" "begin" "case" "declare" "delay" "delta"
4465 "digits" "do" "else" "elsif" "entry" "exception" "exit" "for"
4466 "generic" "if" "in" "is" "limited" "loop" "mod" "not"
4467 "null" "or" "others" "private" "protected" "raise"
4468 "range" "record" "rem" "renames" "requeue" "return" "reverse"
4469 "select" "separate" "tagged" "task" "terminate" "then" "until"
4470 "when" "while" "xor") t)
4473 ;; Anything following end and not already fontified is a body name.
4474 '("\\<\\(end\\)\\>\\([ \t]+\\)?\\(\\(\\sw\\|[_.]\\)+\\)?"
4475 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
4477 ;; Keywords followed by a type or function name.
4478 (list (concat "\\<\\("
4479 "new\\|of\\|subtype\\|type"
4480 "\\)\\>[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?[ \t]*\\((\\)?")
4481 '(1 font-lock-keyword-face)
4482 '(2 (if (match-beginning 4)
4483 font-lock-function-name-face
4484 font-lock-type-face) nil t))
4486 ;; Keywords followed by a (comma separated list of) reference.
4487 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)\\>" ; "when" removed
4488 "[ \t\n]*\\(\\(\\sw\\|[_.|, \t\n]\\)+\\)\\W")
4489 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
4492 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
4494 "Default expressions to highlight in Ada mode.")
4497 ;; ---------------------------------------------------------
4498 ;; Support for outline.el
4499 ;; ---------------------------------------------------------
4501 (defun ada-outline-level ()
4502 "This is so that `current-column` DTRT in otherwise-hidden text"
4503 ;; patch from Dave Love <fx@gnu.org>
4504 (let (buffer-invisibility-spec)
4506 (back-to-indentation)
4509 ;; ---------------------------------------------------------
4510 ;; Automatic generation of code
4511 ;; The Ada-mode has a set of function to automatically generate a subprogram
4512 ;; or package body from its spec.
4513 ;; These function only use a primary and basic algorithm, this could use a
4514 ;; lot of improvement.
4515 ;; When the user is using GNAT, we rather use gnatstub to generate an accurate
4517 ;; ----------------------------------------------------------
4519 (defun ada-gen-treat-proc (match)
4520 "Make dummy body of a procedure/function specification.
4521 MATCH is a cons cell containing the start and end location of the last search
4522 for ada-procedure-start-regexp."
4523 (goto-char (car match))
4524 (let (func-found procname functype)
4526 ((or (looking-at "^[ \t]*procedure")
4527 (setq func-found (looking-at "^[ \t]*function")))
4528 ;; treat it as a proc/func
4531 (setq procname (buffer-substring (point) (cdr match))) ; store proc name
4533 ;; goto end of procname
4534 (goto-char (cdr match))
4536 ;; skip over parameterlist
4537 (unless (looking-at "[ \t\n]*\\(;\\|return\\)")
4540 ;; if function, skip over 'return' and result type.
4544 (skip-chars-forward " \t\n")
4545 (setq functype (buffer-substring (point)
4550 ;; look for next non WS
4552 ((looking-at "[ \t]*;")
4553 (delete-region (match-beginning 0) (match-end 0));; delete the ';'
4554 (ada-indent-newline-indent)
4556 (ada-indent-newline-indent)
4559 (insert "Result : " functype ";")
4560 (ada-indent-newline-indent)))
4562 (ada-indent-newline-indent)
4564 (insert "return Result;")
4566 (ada-indent-newline-indent)
4567 (insert "end " procname ";")
4568 (ada-indent-newline-indent)
4571 ((looking-at "[ \t\n]*is")
4574 ((looking-at "[ \t\n]*rename")
4578 (message "unknown syntax"))))
4580 (if (looking-at "^[ \t]*task")
4582 (message "Task conversion is not yet implemented")
4584 (if (looking-at "[ \t]*;")
4589 (defun ada-make-body ()
4590 "Create an Ada package body in the current buffer.
4591 The potential old buffer contents is deleted first, then we copy the
4592 spec buffer in here and modify it to make it a body.
4593 This function typically is to be hooked into `ff-file-created-hooks'."
4595 (delete-region (point-min) (point-max))
4596 (insert-buffer (car (cdr (buffer-list))))
4599 (let (found ada-procedure-or-package-start-regexp)
4601 (ada-search-ignore-string-comment ada-package-start-regexp nil))
4602 (progn (goto-char (cdr found))
4605 (error "No package"))
4607 (setq ada-procedure-or-package-start-regexp
4608 (concat ada-procedure-start-regexp
4610 ada-package-start-regexp))
4613 (ada-search-ignore-string-comment
4614 ada-procedure-or-package-start-regexp nil))
4616 (goto-char (car found))
4617 (if (looking-at ada-package-start-regexp)
4618 (progn (goto-char (cdr found))
4620 (ada-gen-treat-proc found))))))
4623 (defun ada-make-subprogram-body ()
4624 "Make one dummy subprogram body from spec surrounding point."
4626 (let* ((found (re-search-backward ada-procedure-start-regexp nil t))
4627 (spec (match-beginning 0))
4632 (if (and (re-search-forward "(\\|;" nil t)
4633 (= (char-before) ?\())
4635 (ada-search-ignore-string-comment ")" nil)
4636 (ada-search-ignore-string-comment ";" nil)))
4637 (setq spec (buffer-substring spec (point)))
4639 ;; If find-file.el was available, use its functions
4640 (setq body-file (ada-get-body-name))
4642 (find-file body-file)
4643 (error "No body found for the package. Create it first"))
4647 (goto-char (point-max))
4648 (forward-comment -10000)
4649 (re-search-backward "\\<end\\>" nil t)
4650 ;; Move to the beginning of the elaboration part, if any
4651 (re-search-backward "^begin" nil t)
4655 (re-search-backward ada-procedure-start-regexp nil t)
4656 (ada-gen-treat-proc (cons (match-beginning 0) (match-end 0)))
4658 (error "Not in subprogram spec"))))
4660 ;; --------------------------------------------------------
4661 ;; Global initializations
4662 ;; --------------------------------------------------------
4664 ;; Create the keymap once and for all. If we do that in ada-mode,
4665 ;; the keys changed in the user's .emacs have to be modified
4670 ;; Create the syntax tables, but do not activate them
4671 (ada-create-syntax-table)
4673 ;; Add the default extensions (and set up speedbar)
4674 (ada-add-extensions ".ads" ".adb")
4675 ;; This two files are generated by GNAT when running with -gnatD
4676 (if (equal ada-which-compiler 'gnat)
4677 (ada-add-extensions ".ads.dg" ".adb.dg"))
4679 ;; Read the special cases for exceptions
4680 (ada-case-read-exceptions)
4682 ;; include the other ada-mode files
4683 (if (equal ada-which-compiler 'gnat)
4685 ;; The order here is important: ada-xref defines the Project
4686 ;; submenu, and ada-prj adds to it.
4688 (condition-case nil (require 'ada-prj) (error nil))
4690 (condition-case nil (require 'ada-stmt) (error nil))
4692 ;;; provide ourselves
4695 ;;; ada-mode.el ends here