1 ;;; ada-mode.el --- An Emacs major-mode for editing Ada source.
3 ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
5 ;; Authors: Rolf Ebert <ebert@inf.enst.fr>
6 ;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
7 ;; Keywords: languages oop ada
8 ;; Rolf Ebert's version: 2.25
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; This mode is a complete rewrite of a major mode for editing Ada 83
28 ;;; and Ada 95 source code under Emacs-19. It contains completely new
29 ;;; indenting code and support for code browsing (see ada-xref).
34 ;;; Emacs should enter Ada mode when you load an Ada source (*.ad[abs]).
36 ;;; When you have entered ada-mode, you may get more info by pressing
37 ;;; C-h m. You may also get online help describing various functions by:
38 ;;; C-h d <Name of function you want described>
43 ;;; The first Ada mode for GNU Emacs was written by V. Broman in
44 ;;; 1985. He based his work on the already existing Modula-2 mode.
45 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29.
47 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of
48 ;;; several files with support for dired commands and other nice
49 ;;; things. It is currently available from the PAL
50 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z.
52 ;;; The probably very first Ada mode (called electric-ada.el) was
53 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
54 ;;; Gosling Emacs. L. Slater based his development on ada.el and
57 ;;; The current Ada mode is a complete rewrite by M. Heritsch and
58 ;;; R. Ebert. Some ideas from the Ada mode mailing list have been
59 ;;; added. Some of the functionality of L. Slater's mode has not
60 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
67 ;;; In the presence of comments and/or incorrect syntax
68 ;;; ada-format-paramlist produces weird results.
69 ;;; -------------------
70 ;;; Character constants with otherwise syntactic relevant characters
71 ;;; like `(' or `"' throw indentation off the track. Fontification
72 ;;; should work now in Emacs-19.35
73 ;;; C : constant Character := Character'('"');
74 ;;; -------------------
80 ;;; o bodify-single-subprogram
81 ;;; o make a function "separate" and put it in the corresponding file.
89 ;;; Philippe Waroquiers (PW) <philippe@cfmu.eurocontrol.be> in particular,
90 ;;; woodruff@stc.llnl.gov (John Woodruff)
91 ;;; jj@ddci.dk (Jesper Joergensen)
92 ;;; gse@ocsystems.com (Scott Evans)
93 ;;; comar@LANG8.CS.NYU.EDU (Cyrille Comar)
94 ;;; and others for their valuable hints.
96 ;;;--------------------
98 ;;;--------------------
100 ;; ---- configure indentation
103 "*Defines the size of Ada indentation.")
105 (defvar ada-broken-indent 2
106 "*# of columns to indent the continuation of a broken line.")
108 (defvar ada-label-indent -4
109 "*# of columns to indent a label.")
111 (defvar ada-stmt-end-indent 0
112 "*# of columns to indent a statement end keyword in a separate line.
113 Examples are 'is', 'loop', 'record', ...")
115 (defvar ada-when-indent 3
116 "*Defines the indentation for 'when' relative to 'exception' or 'case'.")
118 (defvar ada-indent-record-rel-type 3
119 "*Defines the indentation for 'record' relative to 'type' or 'use'.")
121 (defvar ada-indent-comment-as-code t
122 "*If non-nil, comment-lines get indented as Ada code.")
124 (defvar ada-indent-is-separate t
125 "*If non-nil, 'is separate' or 'is abstract' on a single line are indented.")
127 (defvar ada-indent-to-open-paren t
128 "*If non-nil, indent according to the innermost open parenthesis.")
130 (defvar ada-search-paren-char-count-limit 3000
131 "*Search that many characters for an open parenthesis.")
134 ;; ---- other user options
136 (defvar ada-tab-policy 'indent-auto
137 "*Control behaviour of the TAB key.
138 Must be one of `indent-rigidly', `indent-auto', `gei', `indent-af'
141 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line.
142 `indent-auto' : use indentation functions in this file.
143 `gei' : use David Kågedal's Generic Indentation Engine.
144 `indent-af' : use Gary E. Barnes' ada-format.el
145 `always-tab' : do indent-relative.")
147 (defvar ada-move-to-declaration nil
148 "*If non-nil, `ada-move-to-start' moves point to the subprog declaration,
151 (defvar ada-spec-suffix ".ads"
152 "*Suffix of Ada specification files.")
154 (defvar ada-body-suffix ".adb"
155 "*Suffix of Ada body files.")
157 (defvar ada-spec-suffix-as-regexp "\\.ads$"
158 "*Regexp to find Ada specification files.")
160 (defvar ada-body-suffix-as-regexp "\\.adb$"
161 "*Regexp to find Ada body files.")
163 (defvar ada-language-version 'ada95
164 "*Do we program in `ada83' or `ada95'?")
166 (defvar ada-case-keyword 'downcase-word
167 "*Function to call to adjust the case of Ada keywords.
168 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
171 (defvar ada-case-identifier 'ada-loose-case-word
172 "*Function to call to adjust the case of an Ada identifier.
173 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
176 (defvar ada-case-attribute 'capitalize-word
177 "*Function to call to adjust the case of Ada attributes.
178 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
181 (defvar ada-auto-case t
182 "*Non-nil automatically changes case of preceding word while typing.
183 Casing is done according to `ada-case-keyword', `ada-case-identifier'
184 and `ada-case-attribute'.")
186 (defvar ada-clean-buffer-before-saving t
187 "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.")
189 (defvar ada-mode-hook nil
190 "*List of functions to call when Ada mode is invoked.
191 This is a good place to add Ada environment specific bindings.")
193 (defvar ada-external-pretty-print-program "aimap"
194 "*External pretty printer to call from within Ada mode.")
196 (defvar ada-tmp-directory "/tmp/"
197 "*Directory to store the temporary file for the Ada pretty printer.")
199 (defvar ada-compile-options "-c"
200 "*Buffer local options passed to the Ada compiler.
201 These options are used when the compiler is invoked on the current buffer.")
202 (make-variable-buffer-local 'ada-compile-options)
204 (defvar ada-make-options "-c"
205 "*Buffer local options passed to `ada-compiler-make' (usually `gnatmake').
206 These options are used when `gnatmake' is invoked on the current buffer.")
207 (make-variable-buffer-local 'ada-make-options)
209 (defvar ada-compiler-syntax-check "gcc -c -gnats"
210 "*Compiler command with options for syntax checking.")
212 (defvar ada-compiler-make "gnatmake"
213 "*The `make' command for the given compiler.")
215 (defvar ada-fill-comment-prefix "-- "
216 "*This is inserted in the first columns when filling a comment paragraph.")
218 (defvar ada-fill-comment-postfix " --"
219 "*This is inserted at the end of each line when filling a comment paragraph.
220 with `ada-fill-comment-paragraph-postfix'.")
222 (defvar ada-krunch-args "0"
223 "*Argument of gnatkr, a string containing the max number of characters.
224 Set to 0, if you don't use crunched filenames.")
226 ;;; ---- end of user configurable variables
229 (defvar ada-mode-abbrev-table nil
230 "Abbrev table used in Ada mode.")
231 (define-abbrev-table 'ada-mode-abbrev-table ())
233 (defvar ada-mode-map ()
234 "Local keymap used for Ada mode.")
236 (defvar ada-mode-syntax-table nil
237 "Syntax table to be used for editing Ada source code.")
239 (defvar ada-mode-symbol-syntax-table nil
240 "Syntax table for Ada, where `_' is a word constituent.")
242 (defconst ada-83-keywords
243 "\\<\\(abort\\|abs\\|accept\\|access\\|all\\|and\\|array\\|\
244 at\\|begin\\|body\\|case\\|constant\\|declare\\|delay\\|delta\\|\
245 digits\\|do\\|else\\|elsif\\|end\\|entry\\|exception\\|exit\\|for\\|\
246 function\\|generic\\|goto\\|if\\|in\\|is\\|limited\\|loop\\|mod\\|\
247 new\\|not\\|null\\|of\\|or\\|others\\|out\\|package\\|pragma\\|\
248 private\\|procedure\\|raise\\|range\\|record\\|rem\\|renames\\|\
249 return\\|reverse\\|select\\|separate\\|subtype\\|task\\|terminate\\|\
250 then\\|type\\|use\\|when\\|while\\|with\\|xor\\)\\>"
251 ; "\\<\\(a\\(b\\(ort\\|s\\)\\|cce\\(pt\\|ss\\)\\|ll\\|nd\\|rray\\|t\\)\\|\
252 ;b\\(egin\\|ody\\)\\|c\\(ase\\|onstant\\)\\|\
253 ;d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|\
254 ;e\\(ls\\(e\\|if\\)\\|n\\(d\\|try\\)\\|x\\(ception\\|it\\)\\)\\|\
255 ;f\\(or\\|unction\\)\\|g\\(eneric\\|oto\\)\\|i[fns]\\|l\\(imited\\|oop\\)\\|\
256 ;mod\\|n\\(ew\\|ot\\|ull\\)\\|o\\([fr]\\|thers\\|ut\\)\\|\
257 ;p\\(ackage\\|r\\(agma\\|ivate\\|ocedure\\)\\)\\|\
258 ;r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|turn\\|verse\\)\\)\\|\
259 ;s\\(e\\(lect\\|parate\\)\\|ubtype\\)\\|use\\|
260 ;t\\(ask\\|erminate\\|hen\\|ype\\)\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\|xor\\)\\>"
261 "Regular expression for looking at Ada83 keywords.")
263 (defconst ada-95-keywords
264 "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\
265 all\\|and\\|array\\|at\\|begin\\|body\\|case\\|constant\\|declare\\|\
266 delay\\|delta\\|digits\\|do\\|else\\|elsif\\|end\\|entry\\|\
267 exception\\|exit\\|for\\|function\\|generic\\|goto\\|if\\|in\\|\
268 is\\|limited\\|loop\\|mod\\|new\\|not\\|null\\|of\\|or\\|others\\|\
269 out\\|package\\|pragma\\|private\\|procedure\\|protected\\|raise\\|\
270 range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\
271 select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\
272 type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>"
273 "Regular expression for looking at Ada95 keywords.")
275 (defvar ada-keywords ada-95-keywords
276 "Regular expression for looking at Ada keywords.")
278 (defvar ada-ret-binding nil
279 "Variable to save key binding of RET when casing is activated.")
281 (defvar ada-lfd-binding nil
282 "Variable to save key binding of LFD when casing is activated.")
284 ;;; ---- Regexps to find procedures/functions/packages
286 (defconst ada-ident-re
288 "Regexp matching Ada (qualified) identifiers.")
290 (defvar ada-procedure-start-regexp
291 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\([a-zA-Z0-9_\\.]+\\)"
292 "Regexp used to find Ada procedures/functions.")
294 (defvar ada-package-start-regexp
295 "^[ \t]*\\(package\\)"
296 "Regexp used to find Ada packages")
299 ;;; ---- regexps for indentation functions
301 (defvar ada-block-start-re
302 "\\<\\(begin\\|select\\|declare\\|private\\|or\\|generic\\|\
303 exception\\|loop\\|else\\|\
304 \\(\\(limited\\|abstract\\|tagged\\)[ \t]+\\)*record\\)\\>"
305 "Regexp for keywords starting Ada blocks.")
307 (defvar ada-end-stmt-re
308 "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\
309 \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|then\\|\
310 declare\\|generic\\|private\\)\\>\\|\
311 ^[ \t]*\\(package\\|procedure\\|function\\)\\>[ \ta-zA-Z0-9_\\.]+\\<is\\>\\|\
312 ^[ \t]*exception\\>\\)"
313 "Regexp of possible ends for a non-broken statement.
314 A new statement starts after these.")
316 (defvar ada-loop-start-re
317 "\\<\\(for\\|while\\|loop\\)\\>"
318 "Regexp for the start of a loop.")
320 (defvar ada-subprog-start-re
321 "\\<\\(procedure\\|protected\\|package\\|function\\|\
322 task\\|accept\\|entry\\)\\>"
323 "Regexp for the start of a subprogram.")
325 (defvar ada-named-block-re
326 "[ \t]*[a-zA-Z_0-9]+ *:[^=]"
327 "Regexp of the name of a block or loop.")
330 ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com>
332 (defvar ada-imenu-generic-expression
333 '((nil "^\\s-*\\(procedure\\|function\\)\\s-+\\([A-Za-z0-9_]+\\)" 2)
334 ("Type Defs" "^\\s-*\\(sub\\)?type\\s-+\\([A-Za-z0-9_]+\\)" 2))
336 "Imenu generic expression for Ada mode. See `imenu-generic-expression'.")
343 (or (string-match "Lucid" emacs-version)
344 (string-match "XEmacs" emacs-version)))
346 (defun ada-create-syntax-table ()
347 "Create the syntax table for Ada mode."
348 ;; There are two different syntax-tables. The standard one declares
349 ;; `_' as a symbol constituent, in the second one, it is a word
350 ;; constituent. For some search and replacing routines we
351 ;; temporarily switch between the two.
352 (setq ada-mode-syntax-table (make-syntax-table))
353 (set-syntax-table ada-mode-syntax-table)
355 ;; define string brackets (`%' is alternative string bracket, but
356 ;; almost never used as such and throws font-lock and indentation
358 (modify-syntax-entry ?% "$" ada-mode-syntax-table)
359 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
361 (modify-syntax-entry ?\# "$" ada-mode-syntax-table)
363 (modify-syntax-entry ?: "." ada-mode-syntax-table)
364 (modify-syntax-entry ?\; "." ada-mode-syntax-table)
365 (modify-syntax-entry ?& "." ada-mode-syntax-table)
366 (modify-syntax-entry ?\| "." ada-mode-syntax-table)
367 (modify-syntax-entry ?+ "." ada-mode-syntax-table)
368 (modify-syntax-entry ?* "." ada-mode-syntax-table)
369 (modify-syntax-entry ?/ "." ada-mode-syntax-table)
370 (modify-syntax-entry ?= "." ada-mode-syntax-table)
371 (modify-syntax-entry ?< "." ada-mode-syntax-table)
372 (modify-syntax-entry ?> "." ada-mode-syntax-table)
373 (modify-syntax-entry ?$ "." ada-mode-syntax-table)
374 (modify-syntax-entry ?\[ "." ada-mode-syntax-table)
375 (modify-syntax-entry ?\] "." ada-mode-syntax-table)
376 (modify-syntax-entry ?\{ "." ada-mode-syntax-table)
377 (modify-syntax-entry ?\} "." ada-mode-syntax-table)
378 (modify-syntax-entry ?. "." ada-mode-syntax-table)
379 (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
380 (modify-syntax-entry ?\' "." ada-mode-syntax-table)
382 ;; a single hyphen is punctuation, but a double hyphen starts a comment
383 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table)
385 ;; and \f and \n end a comment
386 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
387 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
389 ;; define what belongs in Ada symbols
390 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
392 ;; define parentheses to match
393 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
394 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
396 (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table))
397 (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table)
403 "Ada mode is the major mode for editing Ada code.
405 Bindings are as follows: (Note: 'LFD' is control-j.)
407 Indent line '\\[ada-tab]'
408 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
410 Re-format the parameter-list point is in '\\[ada-format-paramlist]'
411 Indent all lines in region '\\[ada-indent-region]'
412 Call external pretty printer program '\\[ada-call-pretty-printer]'
414 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]'
415 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]'
417 Call EXTERNAL pretty printer (if you have one) '\\[ada-call-pretty-printer]'
419 Fill comment paragraph '\\[ada-fill-comment-paragraph]'
420 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]'
421 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]'
423 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
424 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
426 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
427 Goto end of current block '\\[ada-move-to-end]'
429 Comments are handled using standard GNU Emacs conventions, including:
430 Start a comment '\\[indent-for-comment]'
431 Comment region '\\[comment-region]'
432 Uncomment region '\\[ada-uncomment-region]'
433 Continue comment on next line '\\[indent-new-comment-line]'
436 Display index-menu of functions & procedures '\\[imenu]'
438 If you use find-file.el:
439 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]'
440 or '\\[ff-mouse-find-other-file]
441 Switch to other file in other window '\\[ada-ff-other-window]'
442 or '\\[ff-mouse-find-other-file-other-window]
443 If you use this function in a spec and no body is available, it gets created
446 If you use ada-xref.el:
447 Goto declaration: '\\[ada-point-and-xref]' on the identifier
448 or '\\[ada-goto-declaration]' with point on the identifier
449 Complete identifier: '\\[ada-complete-identifier]'
450 Execute Gnatf: '\\[ada-gnatf-current]'"
453 (kill-all-local-variables)
455 (make-local-variable 'require-final-newline)
456 (setq require-final-newline t)
458 (make-local-variable 'comment-start)
459 (setq comment-start "-- ")
461 ;; comment end must be set because it may hold a wrong value if
462 ;; this buffer had been in another mode before. RE
463 (make-local-variable 'comment-end)
464 (setq comment-end "")
466 (make-local-variable 'comment-start-skip) ;; used by autofill
467 (setq comment-start-skip "--+[ \t]*")
469 (make-local-variable 'indent-line-function)
470 (setq indent-line-function 'ada-indent-current-function)
472 (make-local-variable 'fill-column)
473 (setq fill-column 75)
475 (make-local-variable 'comment-column)
476 (setq comment-column 40)
478 (make-local-variable 'parse-sexp-ignore-comments)
479 (setq parse-sexp-ignore-comments t)
481 (make-local-variable 'case-fold-search)
482 (setq case-fold-search t)
484 (make-local-variable 'outline-regexp)
485 (setq outline-regexp "[^\n\^M]")
486 (make-local-variable 'outline-level)
487 (setq outline-level 'ada-outline-level)
489 (make-local-variable 'fill-paragraph-function)
490 (setq fill-paragraph-function 'ada-fill-comment-paragraph)
491 ;;(make-local-variable 'adaptive-fill-regexp)
493 (make-local-variable 'imenu-generic-expression)
494 (setq imenu-generic-expression ada-imenu-generic-expression)
496 (if (ada-xemacs) nil ; XEmacs uses properties
497 (make-local-variable 'font-lock-defaults)
498 (setq font-lock-defaults
499 '((ada-font-lock-keywords
500 ada-font-lock-keywords-1 ada-font-lock-keywords-2)
502 ((?\_ . "w")(?\. . "w"))
504 (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords))))
506 (setq major-mode 'ada-mode)
507 (setq mode-name "Ada")
509 (use-local-map ada-mode-map)
511 (if ada-mode-syntax-table
512 (set-syntax-table ada-mode-syntax-table)
513 (ada-create-syntax-table))
515 (if ada-clean-buffer-before-saving
517 ;; remove all spaces at the end of lines in the whole buffer.
518 (add-hook 'local-write-file-hooks 'ada-remove-trailing-spaces)
519 ;; convert all tabs to the correct number of spaces.
520 (add-hook 'local-write-file-hooks 'ada-untabify-buffer)))
523 ;; add menu 'Ada' to the menu bar
526 (run-hooks 'ada-mode-hook)
528 ;; the following has to be done after running the ada-mode-hook
529 ;; because users might want to set the values of these variable
530 ;; inside the hook (MH)
532 (cond ((eq ada-language-version 'ada83)
533 (setq ada-keywords ada-83-keywords))
534 ((eq ada-language-version 'ada95)
535 (setq ada-keywords ada-95-keywords)))
538 (ada-activate-keys-for-case)))
541 ;;;--------------------------
543 ;;;--------------------------
545 (defun ada-check-syntax ()
546 "Check syntax of the current buffer.
547 Uses the function `compile' to execute `ada-compiler-syntax-check'."
549 (let ((old-compile-command compile-command))
550 (setq compile-command (concat ada-compiler-syntax-check
551 (if (eq ada-language-version 'ada83)
553 " " ada-compile-options " "
555 (setq compile-command (read-from-minibuffer
556 "enter command for syntax check: "
558 (compile compile-command)
559 ;; restore old compile-command
560 (setq compile-command old-compile-command)))
562 (defun ada-make-local ()
563 "Bring current Ada unit up-to-date.
564 Uses the function `compile' to execute `ada-compile-make'."
566 (let ((old-compile-command compile-command))
567 (setq compile-command (concat ada-compiler-make
568 " " ada-make-options " "
570 (setq compile-command (read-from-minibuffer
571 "enter command for local make: "
573 (compile compile-command)
574 ;; restore old compile-command
575 (setq compile-command old-compile-command)))
580 ;;;--------------------------
581 ;;; Fill Comment Paragraph
582 ;;;--------------------------
584 (defun ada-fill-comment-paragraph-justify ()
585 "Fills current comment paragraph and justifies each line as well."
587 (ada-fill-comment-paragraph t))
590 (defun ada-fill-comment-paragraph-postfix ()
591 "Fills current comment paragraph and justifies each line as well.
592 Prompts for a postfix to be appended to each line."
594 (ada-fill-comment-paragraph t t))
597 (defun ada-fill-comment-paragraph (&optional justify postfix)
598 "Fills the current comment paragraph.
599 If JUSTIFY is non-nil, each line is justified as well.
600 If POSTFIX and JUSTIFY are non-nil, `ada-fill-comment-postfix' is appended
601 to each filled and justified line.
602 If `ada-indent-comment-as-code' is non-nil, the paragraph is idented."
604 (let ((opos (point-marker))
609 (ada-fill-comment-old-postfix "")
612 ;; check if inside comment
613 (if (not (ada-in-comment-p))
614 (error "not inside comment"))
616 ;; prompt for postfix if wanted
619 (setq ada-fill-comment-postfix
620 (read-from-minibuffer "enter new postfix string: "
621 ada-fill-comment-postfix)))
623 ;; prompt for old postfix to remove if necessary
626 (setq ada-fill-comment-old-postfix
627 (read-from-minibuffer "enter already existing postfix string: "
628 ada-fill-comment-postfix)))
631 ;; find limits of paragraph
633 (message "filling comment paragraph ...")
635 (back-to-indentation)
636 ;; find end of paragraph
637 (while (and (looking-at "--.*$")
638 (not (looking-at "--[ \t]*$")))
640 (back-to-indentation))
642 (setq end (point-marker))
644 ;; find begin of paragraph
645 (back-to-indentation)
646 (while (and (looking-at "--.*$")
647 (not (looking-at "--[ \t]*$")))
649 (back-to-indentation))
651 ;; get indentation to calculate width for filling
653 (back-to-indentation)
654 (setq indent (current-column))
655 (setq begin (point-marker)))
657 ;; delete old postfix if necessary
662 (while (re-search-forward (concat ada-fill-comment-old-postfix
665 (replace-match "\n"))))
667 ;; delete leading whitespace and uncomment
671 (while (re-search-forward "^[ \t]*--[ \t]*" end t)
674 ;; calculate fill width
675 (setq fill-column (- fill-column indent
676 (length ada-fill-comment-prefix)
678 (length ada-fill-comment-postfix)
681 (fill-region begin (1- end) justify)
682 (setq fill-column (+ fill-column indent
683 (length ada-fill-comment-prefix)
685 (length ada-fill-comment-postfix)
687 ;; find end of second last line
692 (setq end-2 (point-marker)))
694 ;; re-comment and re-indent region
698 (insert ada-fill-comment-prefix)
699 (while (re-search-forward "\n" (1- end-2) t)
700 (replace-match (concat "\n" ada-fill-comment-prefix))
704 ;; append postfix if wanted
707 ada-fill-comment-postfix)
709 ;; append postfix up to there
712 (while (re-search-forward "\n" (1- end-2) t)
713 (replace-match (concat ada-fill-comment-postfix "\n")))
715 ;; fill last line and append postfix
720 (length ada-fill-comment-postfix)))
721 (insert ada-fill-comment-postfix))))
723 ;; delete the extra line that gets inserted somehow(??)
729 (message "filling comment paragraph ... done")
734 ;;;--------------------------------;;;
735 ;;; Call External Pretty Printer ;;;
736 ;;;--------------------------------;;;
738 (defun ada-call-pretty-printer ()
739 "Calls the external Pretty Printer.
740 The name is specified in `ada-external-pretty-print-program'. Saves the
741 current buffer in a directory specified by `ada-tmp-directory',
742 starts the pretty printer as external process on that file and then
743 reloads the beautified program in the buffer and cleans up
744 `ada-tmp-directory'."
746 (let ((filename-with-path buffer-file-name)
747 (curbuf (current-buffer))
749 (mesgbuf nil) ;; for byte-compiling
750 (file-path (file-name-directory buffer-file-name))
751 (filename-without-path (file-name-nondirectory buffer-file-name))
752 (tmp-file-with-directory
753 (concat ada-tmp-directory
754 (file-name-nondirectory buffer-file-name))))
756 ;; save buffer in temporary file
758 (message "saving current buffer to temporary file ...")
759 (write-file tmp-file-with-directory)
761 (message "saving current buffer to temporary file ... done")
763 ;; call external pretty printer program
766 (message "running external pretty printer ...")
767 ;; create a temporary buffer for messages of pretty printer
768 (setq mesgbuf (get-buffer-create "Pretty Printer Messages"))
769 ;; execute pretty printer on temporary file
770 (call-process ada-external-pretty-print-program
772 tmp-file-with-directory)
773 ;; display messages if there are some
774 (if (buffer-modified-p mesgbuf)
775 ;; show the message buffer
776 (display-buffer mesgbuf t)
777 ;; kill the message buffer
778 (kill-buffer mesgbuf))
779 (message "running external pretty printer ... done")
781 ;; kill current buffer and load pretty printer output
782 ;; or restore old buffer
785 "Really replace current buffer with pretty printer output ? ")
787 (set-buffer-modified-p nil)
789 (find-file tmp-file-with-directory))
790 (message "old buffer contents restored"))
792 ;; delete temporary file and restore information of current buffer
794 (delete-file tmp-file-with-directory)
795 (set-visited-file-name filename-with-path)
804 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be>
805 ;; modified by RE and MH
807 (defun ada-after-keyword-p ()
808 ;; returns t if cursor is after a keyword.
813 (= (point) (point-min))
815 (not (looking-at "_"))) ; (MH)
816 (looking-at (concat ada-keywords "[^_]")))))
818 (defun ada-in-char-const-p ()
819 ;; Returns t if point is inside a character constant.
820 ;; We assume to be in a constant if the previous and the next character
834 (defun ada-adjust-case (&optional force-identifier)
835 "Adjust the case of the word before the just typed character.
836 Respect options `ada-case-keyword', `ada-case-identifier', and
837 `ada-case-attribute'.
838 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH)
840 (if (and (> (point) 1) (not (or (ada-in-string-p)
842 (ada-in-char-const-p))))
843 (if (eq (char-syntax (char-after (1- (point)))) ?w)
846 (or (= (point) (point-min))
849 (funcall ada-case-attribute -1)
851 (not force-identifier) ; (MH)
852 (ada-after-keyword-p))
853 (funcall ada-case-keyword -1)
854 (funcall ada-case-identifier -1)))))
858 (defun ada-adjust-case-interactive (arg)
860 (let ((lastk last-command-char))
861 (cond ((or (eq lastk ?\n)
867 (delete-backward-char 1)
868 ;; some special keys and their bindings
871 (funcall ada-lfd-binding))
873 (funcall ada-ret-binding))))
874 ((eq lastk ?\C-i) (ada-tab))
875 ((self-insert-command (prefix-numeric-value arg))))
876 ;; if there is a keyword in front of the underscore
877 ;; then it should be part of an identifier (MH)
883 (defun ada-activate-keys-for-case ()
884 ;; save original keybindings to allow swapping ret/lfd
885 ;; when casing is activated
886 ;; the 'or ...' is there to be sure that the value will not
887 ;; be changed again when Ada mode is called more than once (MH)
889 (setq ada-ret-binding (key-binding "\C-M")))
891 (setq ada-lfd-binding (key-binding "\C-j")))
892 ;; call case modifying function after certain keys.
893 (mapcar (function (lambda(key) (define-key
896 'ada-adjust-case-interactive)))
897 '( ?` ?~ ?! ?@ ?# ?$ ?% ?^ ?& ?* ?( ?) ?- ?= ?+ ?[ ?{ ?] ?}
898 ?_ ?\\ ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?? ?/ ?\n 32 ?\r )))
899 ;; deleted ?\t from above list
904 (defun ada-loose-case-word (&optional arg)
905 "Capitalizes the first letter and the letters following `_'.
906 ARG is ignored, it's there to fit the standard casing functions' style."
909 (skip-chars-backward "a-zA-Z0-9_")
911 (search-forward "_" pos t))
914 (insert-char (upcase (following-char)) 1)
921 ;; modified by JSH to handle attributes
923 (defun ada-adjust-case-region (from to)
924 "Adjusts the case of all words in the region.
925 Attention: This function might take very long for big regions !"
933 (set-syntax-table ada-mode-symbol-syntax-table)
936 ;; loop: look for all identifiers, keywords, and attributes
938 (while (re-search-backward
939 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]"
943 ;; print status message
945 (message "adjusting case ... %5d characters left" (- (point) from))
946 (setq attribp (looking-at "'[a-zA-Z0-9_]+[^']"))
949 ;; do nothing if it is a string or comment
950 (ada-in-string-or-comment-p)
953 ;; get the identifier or keyword or attribute
956 (setq keywordp (looking-at (concat ada-keywords "[^_]")))
957 (skip-chars-forward "a-zA-Z0-9_")
959 ;; casing according to user-option
962 (funcall ada-case-keyword -1)
964 (funcall ada-case-attribute -1)
965 (funcall ada-case-identifier -1)))
967 (message "adjusting case ... done"))
968 (set-syntax-table ada-mode-syntax-table))))
974 (defun ada-adjust-case-buffer ()
975 "Adjusts the case of all words in the whole buffer.
976 ATTENTION: This function might take very long for big buffers !"
978 (ada-adjust-case-region (point-min) (point-max)))
981 ;;;------------------------;;;
982 ;;; Format Parameter Lists ;;;
983 ;;;------------------------;;;
985 (defun ada-format-paramlist ()
986 "Reformats a parameter list.
987 ATTENTION: 1) Comments inside the list are killed !
988 2) If the syntax is not correct (especially, if there are
989 semicolons missing), it can get totally confused !
990 In such a case, use `undo', correct the syntax and try again."
999 (set-syntax-table ada-mode-symbol-syntax-table)
1001 ;; check if really inside parameter list
1002 (or (ada-in-paramlist-p)
1003 (error "not in parameter list"))
1005 ;; find start of current parameter-list
1007 (ada-search-ignore-string-comment
1008 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil)
1009 (ada-search-ignore-string-comment "(" nil nil t)
1011 (setq begin (point))
1014 ;; find end of parameter-list
1017 (setq delend (point))
1021 ;; find end of last parameter-declaration
1023 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
1028 ;; build a list of all elements of the parameter-list
1030 (setq paramlist (ada-scan-paramlist (1+ begin) end))
1033 ;; delete the original parameter-list
1035 (delete-region begin (1- delend))
1038 ;; insert the new parameter-list
1041 (ada-insert-paramlist paramlist))
1044 ;; restore syntax-table
1046 (set-syntax-table ada-mode-syntax-table)
1050 (defun ada-scan-paramlist (begin end)
1051 ;; Scans a parameter-list between BEGIN and END and returns a list
1053 ;; The list has the following format:
1055 ;; Name of Param in? out? access? Name of Type Default-Exp or nil
1057 ;; ( ('Name_Param_1' t nil t Type_Param_1 ':= expression')
1058 ;; ('Name_Param_2' nil nil t Type_Param_2 nil) )
1060 (let ((paramlist (list))
1070 ;; loop until end of last parameter
1075 ;; find first character of parameter-declaration
1077 (ada-goto-next-non-ws)
1081 ;; find last character of parameter-declaration
1083 (if (setq match-cons
1084 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t))
1086 (setq epos (car match-cons))
1087 (setq semipos (cdr match-cons)))
1091 ;; read name(s) of parameter(s)
1094 (looking-at "\\([a-zA-Z0-9_, \t\n]*[a-zA-Z0-9_]\\)[ \t\n]*:[^=]")
1096 (setq param (list (buffer-substring (match-beginning 1)
1098 (ada-search-ignore-string-comment ":" nil epos t)
1108 (ada-search-ignore-string-comment "\\<in\\>"
1121 (ada-search-ignore-string-comment "\\<out\\>"
1127 ;; look for 'access'
1134 (ada-search-ignore-string-comment "\\<access\\>"
1140 ;; skip 'in'/'out'/'access'
1143 (ada-goto-next-non-ws)
1144 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>")
1146 (ada-goto-next-non-ws))
1149 ;; read type of parameter
1151 (looking-at "\\<[a-zA-Z0-9_\\.\\']+\\>")
1155 (buffer-substring (match-beginning 0)
1159 ;; read default-expression, if there is one
1161 (goto-char (setq apos (match-end 0)))
1165 (if (setq match-cons
1166 (ada-search-ignore-string-comment ":="
1170 (buffer-substring (car match-cons)
1174 ;; add this parameter-declaration to the list
1176 (setq paramlist (append paramlist (list param)))
1179 ;; check if it was the last parameter
1183 (goto-char semipos))
1187 (reverse paramlist)))
1190 (defun ada-insert-paramlist (paramlist)
1191 ;; Inserts a formatted PARAMLIST in the buffer.
1192 ;; See doc of `ada-scan-paramlist' for the format.
1193 (let ((i (length paramlist))
1205 ;; loop until last parameter
1207 (while (not (zerop i))
1211 ;; get max length of parameter-name
1214 (if (<= parlen (setq temp
1215 (length (nth 0 (nth i paramlist)))))
1220 ;; get max length of type-name
1223 (if (<= typlen (setq temp
1224 (length (nth 4 (nth i paramlist)))))
1229 ;; is there any 'in' ?
1233 (nth 1 (nth i paramlist))))
1236 ;; is there any 'out' ?
1240 (nth 2 (nth i paramlist))))
1243 ;; is there any 'access' ?
1247 (nth 3 (nth i paramlist))))) ; end of loop
1250 ;; does paramlist already start on a separate line ?
1253 (re-search-backward "^.\\|[^ \t]" nil t)
1255 ;; yes => re-indent it
1256 (ada-indent-current)
1258 ;; no => insert newline and indent it
1261 (ada-indent-current)
1263 (delete-horizontal-space)
1264 (setq orgpoint (point))
1265 (setq column (save-excursion
1266 (funcall (ada-indent-function) orgpoint)))
1272 (setq firstcol (current-column))
1273 (setq i (length paramlist))
1276 ;; loop until last parameter
1278 (while (not (zerop i))
1280 (setq column firstcol)
1283 ;; insert parameter-name, space and colon
1285 (insert (nth 0 (nth i paramlist)))
1286 (indent-to (+ column parlen 1))
1288 (setq column (current-column))
1291 ;; insert 'in' or space
1293 (if (nth 1 (nth i paramlist))
1298 (not (nth 3 (nth i paramlist))))
1302 ;; insert 'out' or space
1304 (if (nth 2 (nth i paramlist))
1309 (not (nth 3 (nth i paramlist))))
1315 (if (nth 3 (nth i paramlist))
1318 (setq column (current-column))
1321 ;; insert type-name and, if necessary, space and default-expression
1323 (insert (nth 4 (nth i paramlist)))
1324 (if (nth 5 (nth i paramlist))
1326 (indent-to (+ column typlen 1))
1327 (insert (nth 5 (nth i paramlist)))))
1330 ;; check if it was the last parameter
1333 ;; no => insert ';' and newline and indent
1337 (indent-to firstcol))
1344 ;; if anything follows, except semicolon:
1345 ;; put it in a new line and indent it
1347 (if (not (looking-at "[ \t]*[;\n]"))
1348 (ada-indent-newline-indent))
1353 ;;;----------------------------;;;
1354 ;;; Move To Matching Start/End ;;;
1355 ;;;----------------------------;;;
1357 (defun ada-move-to-start ()
1358 "Moves point to the matching start of the current Ada structure."
1360 (let ((pos (point)))
1363 (set-syntax-table ada-mode-symbol-syntax-table)
1365 (message "searching for block start ...")
1368 ;; do nothing if in string or comment or not on 'end ...;'
1369 ;; or if an error occurs during processing
1372 (ada-in-string-or-comment-p)
1374 (or (looking-at "[ \t]*\\<end\\>")
1376 (or (looking-at "[ \t]*\\<end\\>")
1378 (or (looking-at "[ \t]*\\<end\\>")
1379 (error "not on end ...;")))
1380 (ada-goto-matching-start 1)
1384 ;; on 'begin' => go on, according to user option
1386 ada-move-to-declaration
1387 (looking-at "\\<begin\\>")
1388 (ada-goto-matching-decl-start)
1389 (setq pos (point))))
1391 ) ; end of save-excursion
1393 ;; now really move to the found position
1395 (message "searching for block start ... done"))
1398 ;; restore syntax-table
1400 (set-syntax-table ada-mode-syntax-table))))
1403 (defun ada-move-to-end ()
1404 "Moves point to the matching end of the current block around point.
1405 Moves to 'begin' if in a declarative part."
1412 (set-syntax-table ada-mode-symbol-syntax-table)
1414 (message "searching for block end ...")
1419 ;; directly on 'begin'
1421 (ada-goto-previous-word)
1422 (looking-at "\\<begin\\>"))
1423 (ada-goto-matching-end 1))
1424 ;; on first line of defun declaration
1426 (and (ada-goto-stmt-start)
1427 (looking-at "\\<function\\>\\|\\<procedure\\>" )))
1428 (ada-search-ignore-string-comment "\\<begin\\>"))
1429 ;; on first line of task declaration
1431 (and (ada-goto-stmt-start)
1432 (looking-at "\\<task\\>" )
1434 (ada-search-ignore-string-comment "[^ \n\t]")
1435 (not (backward-char 1))
1436 (looking-at "\\<body\\>")))
1437 (ada-search-ignore-string-comment "\\<begin\\>"))
1438 ;; accept block start
1440 (and (ada-goto-stmt-start)
1441 (looking-at "\\<accept\\>" )))
1442 (ada-goto-matching-end 0))
1445 (and (ada-goto-matching-decl-start t)
1446 (looking-at "\\<package\\>")))
1447 (ada-goto-matching-end 1))
1448 ;; inside a 'begin' ... 'end' block
1450 (ada-goto-matching-decl-start t))
1451 (ada-search-ignore-string-comment "\\<begin\\>"))
1452 ;; (hopefully ;-) everything else
1454 (ada-goto-matching-end 1)))
1457 ) ; end of save-excursion
1459 ;; now really move to the found position
1461 (message "searching for block end ... done"))
1464 ;; restore syntax-table
1466 (set-syntax-table ada-mode-syntax-table))))
1469 ;;;-----------------------------;;;
1470 ;;; Functions For Indentation ;;;
1471 ;;;-----------------------------;;;
1473 ;; ---- main functions for indentation
1475 (defun ada-indent-region (beg end)
1476 "Indents the region using `ada-indent-current' on each line."
1479 (let ((block-done 0)
1480 (lines-remaining (count-lines beg end))
1481 (msg (format "indenting %4d lines %%4d lines remaining ..."
1482 (count-lines beg end)))
1483 (endmark (copy-marker end)))
1484 ;; catch errors while indenting
1486 (while (< (point) endmark)
1487 (if (> block-done 9)
1488 (progn (message msg lines-remaining)
1489 (setq block-done 0)))
1490 (if (looking-at "^$") nil
1491 (ada-indent-current))
1493 (setq block-done (1+ block-done))
1494 (setq lines-remaining (1- lines-remaining)))
1495 ;; show line number where the error occurred
1497 (error "line %d: %s" (1+ (count-lines (point-min) (point))) err) nil))
1498 (message "indenting ... done")))
1501 (defun ada-indent-newline-indent ()
1502 "Indents the current line, inserts a newline and then indents the new line."
1504 (ada-indent-current)
1506 (ada-indent-current))
1509 (defun ada-indent-current ()
1510 "Indents current line as Ada code.
1511 This works by two steps:
1512 1) It moves point to the end of the previous code line.
1513 Then it calls the function to calculate the indentation for the
1514 following line as if a newline would be inserted there.
1515 The calculated column # is saved and the old position of point
1517 2) Then another function is called to calculate the indentation for
1518 the current line, based on the previously calculated column #."
1524 (set-syntax-table ada-mode-symbol-syntax-table)
1527 (orgpoint (point-marker))
1536 (if (ada-goto-prev-nonblank-line t)
1538 ;; we are not in the first accessible line in the buffer
1543 ;; we are already at the BOL
1545 (setq line-end (point))
1548 (funcall (ada-indent-function) line-end))))
1549 (progn ; first line of buffer -> set indent
1550 (beginning-of-line) ; to 0
1551 (delete-horizontal-space)
1552 (setq prevline nil))))
1556 ;; we are not in the first accessible line in the buffer
1562 (back-to-indentation)
1563 (setq cur-indent (ada-get-current-indent prev-indent))
1564 ;; only reindent if indentation is different then the current
1565 (if (= (current-column) cur-indent)
1567 (delete-horizontal-space)
1568 (indent-to cur-indent))
1570 ;; restore position of point
1572 (goto-char orgpoint)
1573 (if (< (current-column) (current-indentation))
1574 (back-to-indentation))))))
1577 ;; restore syntax-table
1579 (set-syntax-table ada-mode-syntax-table)))
1582 (defun ada-get-current-indent (prev-indent)
1583 ;; Returns the column # to indent the current line to.
1584 ;; PREV-INDENT is the indentation resulting from the previous lines.
1591 ;; in open parenthesis, but not in parameter-list
1594 ada-indent-to-open-paren
1595 (not (ada-in-paramlist-p))
1596 (setq column (ada-in-open-paren-p)))
1597 ;; check if we have something like this (Table_Component_Type =>
1598 ;; Source_File_Record,)
1600 (if (and (ada-search-ignore-string-comment "[^ \t]" t nil)
1602 (ada-search-ignore-string-comment "[^ \t\n]" t nil)
1604 (setq column (+ ada-broken-indent column))))
1610 ((looking-at "\\<end\\>")
1613 (ada-goto-matching-start 1)
1616 ;; found 'loop' => skip back to 'while' or 'for'
1617 ;; if 'loop' is not on a separate line
1620 (looking-at "\\<loop\\>")
1622 (back-to-indentation)
1623 (not (looking-at "\\<loop\\>"))))
1627 (ada-search-ignore-string-comment
1628 ada-loop-start-re t nil))
1629 (not (looking-at "\\<loop\\>"))))
1631 (goto-char (car match-cons))
1634 (if (looking-at ada-named-block-re)
1635 (setq label (- ada-label-indent)))))))
1637 (+ (current-indentation) label))))
1641 ((looking-at "\\<exception\\>")
1643 (ada-goto-matching-start 1)
1644 (current-indentation)))
1648 ((looking-at "\\<when\\>")
1650 (ada-goto-matching-start 1)
1651 (+ (current-indentation) ada-when-indent)))
1655 ((looking-at "\\<else\\>")
1657 (ada-goto-previous-word)
1658 (looking-at "\\<or\\>"))
1661 (ada-goto-matching-start 1 nil t)
1662 (current-indentation))))
1666 ((looking-at "\\<elsif\\>")
1668 (ada-goto-matching-start 1 nil t)
1669 (current-indentation)))
1673 ((looking-at "\\<then\\>")
1675 (ada-goto-previous-word)
1676 (looking-at "\\<and\\>"))
1679 (ada-search-ignore-string-comment "\\<elsif\\>\\|\\<if\\>" t nil)
1680 (+ (current-indentation) ada-stmt-end-indent))))
1684 ((looking-at "\\<loop\\>")
1687 (goto-char (match-end 0))
1688 (ada-goto-stmt-start)
1689 (if (looking-at "\\<loop\\>\\|\\<if\\>")
1692 (if (not (looking-at ada-loop-start-re))
1693 (ada-search-ignore-string-comment ada-loop-start-re
1695 (if (looking-at "\\<loop\\>")
1697 (+ (current-indentation) ada-stmt-end-indent))))))
1701 ((looking-at "\\<begin\\>")
1703 (if (ada-goto-matching-decl-start t)
1704 (current-indentation)
1709 ((looking-at "\\<is\\>")
1711 ada-indent-is-separate
1713 (goto-char (match-end 0))
1714 (ada-goto-next-non-ws (save-excursion
1717 (looking-at "\\<abstract\\>\\|\\<separate\\>")))
1719 (ada-goto-stmt-start)
1720 (+ (current-indentation) ada-indent))
1722 (ada-goto-stmt-start)
1723 (+ (current-indentation) ada-stmt-end-indent))))
1727 ((looking-at "\\<record\\>")
1729 (ada-search-ignore-string-comment
1730 "\\<\\(type\\|use\\)\\>" t nil)
1731 (if (looking-at "\\<use\\>")
1732 (ada-search-ignore-string-comment "\\<for\\>" t nil))
1733 (+ (current-indentation) ada-indent-record-rel-type)))
1735 ;; or as statement-start
1737 ((ada-looking-at-semi-or)
1739 (ada-goto-matching-start 1)
1740 (current-indentation)))
1742 ;; private as statement-start
1744 ((ada-looking-at-semi-private)
1746 (ada-goto-matching-decl-start)
1747 (current-indentation)))
1749 ;; new/abstract/separate
1751 ((looking-at "\\<\\(new\\|abstract\\|separate\\)\\>")
1752 (- prev-indent ada-indent (- ada-broken-indent)))
1756 ((looking-at "\\<return\\>")
1759 (if (and (looking-at "(")
1762 (looking-at "\\<function\\>")))
1763 (1+ (current-column))
1768 ((looking-at "\\<do\\>")
1770 (ada-goto-stmt-start)
1771 (+ (current-indentation) ada-stmt-end-indent)))
1773 ;; package/function/procedure
1775 ((and (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")
1778 (ada-goto-stmt-start)
1779 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")))
1781 ;; look for 'generic'
1782 (if (and (ada-goto-matching-decl-start t)
1783 (looking-at "generic"))
1789 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*:[^=]")
1792 (+ prev-indent ada-label-indent)))
1794 ;; identifier and other noindent-statements
1796 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*")
1799 ;; beginning of a parameter list
1804 ;; end of a parameter list
1815 (if ada-indent-comment-as-code
1817 (current-indentation)))
1819 ;; unknown syntax - maybe this should signal an error ?
1825 (defun ada-indent-function (&optional nomove)
1826 ;; Returns the function to calculate the indentation for the current
1827 ;; line according to the previous statement, ignoring the contents
1828 ;; of the current line after point. Moves point to the beginning of
1829 ;; the current statement, if NOMOVE is nil.
1831 (let ((orgpoint (point))
1834 ;; inside a parameter-list
1836 (if (ada-in-paramlist-p)
1837 (setq func 'ada-get-indent-paramlist)
1840 ;; move to beginning of current statement
1843 (ada-goto-stmt-start))
1845 ;; no beginning found => don't change indentation
1848 (eq orgpoint (point))
1850 (setq func 'ada-get-indent-nochange)
1855 ada-indent-to-open-paren
1856 (ada-in-open-paren-p))
1857 (setq func 'ada-get-indent-open-paren))
1859 ((looking-at "\\<end\\>")
1860 (setq func 'ada-get-indent-end))
1862 ((looking-at ada-loop-start-re)
1863 (setq func 'ada-get-indent-loop))
1865 ((looking-at ada-subprog-start-re)
1866 (setq func 'ada-get-indent-subprog))
1868 ((looking-at ada-block-start-re)
1869 (setq func 'ada-get-indent-block-start))
1871 ((looking-at "\\<type\\>")
1872 (setq func 'ada-get-indent-type))
1874 ((looking-at "\\<\\(els\\)?if\\>")
1875 (setq func 'ada-get-indent-if))
1877 ((looking-at "\\<case\\>")
1878 (setq func 'ada-get-indent-case))
1880 ((looking-at "\\<when\\>")
1881 (setq func 'ada-get-indent-when))
1884 (setq func 'ada-get-indent-comment))
1886 ((looking-at "[a-zA-Z0-9_]+[ \t\n]*:[^=]")
1887 (setq func 'ada-get-indent-label))
1889 ((looking-at "\\<separate\\>")
1890 (setq func 'ada-get-indent-nochange))
1892 (setq func 'ada-get-indent-noindent))))))
1897 ;; ---- functions to return indentation for special cases
1899 (defun ada-get-indent-open-paren (orgpoint)
1900 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1901 ;; Assumes point to be behind an open parenthesis not yet closed.
1902 (ada-in-open-paren-p))
1905 (defun ada-get-indent-nochange (orgpoint)
1906 ;; Returns the indentation (column #) of the current line.
1909 (current-indentation)))
1912 (defun ada-get-indent-paramlist (orgpoint)
1913 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1914 ;; Assumes point to be inside a parameter-list.
1916 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
1919 ;; in front of the first parameter
1922 (goto-char (match-end 0))
1925 ;; in front of another parameter
1928 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
1929 (ada-goto-next-non-ws)
1932 ;; inside a parameter declaration
1935 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
1936 (ada-goto-next-non-ws)
1937 (+ (current-column) ada-broken-indent)))))
1940 (defun ada-get-indent-end (orgpoint)
1941 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1942 ;; Assumes point to be at the beginning of an end-statement.
1943 ;; Therefore it has to find the corresponding start. This can be a little
1944 ;; slow, if it has to search through big files with many nested blocks.
1945 ;; Signals an error if the corresponding block-start doesn't match.
1946 (let ((defun-name nil)
1950 ;; is the line already terminated by ';' ?
1953 (ada-search-ignore-string-comment ";" nil orgpoint))
1955 ;; yes, look what's following 'end'
1959 (ada-goto-next-non-ws)
1962 ;; loop/select/if/case/record/select
1964 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\|record\\)\\>")
1966 (ada-check-matching-start
1967 (buffer-substring (match-beginning 0)
1969 (if (looking-at "\\<\\(loop\\|record\\)\\>")
1972 (ada-goto-stmt-start)))
1973 ;; a label ? => skip it
1974 (if (looking-at ada-named-block-re)
1976 (setq label (- ada-label-indent))
1977 (goto-char (match-end 0))
1978 (ada-goto-next-non-ws)))
1979 ;; really looking-at the right thing ?
1980 (or (looking-at (concat "\\<\\("
1981 "loop\\|select\\|if\\|case\\|"
1982 "record\\|while\\|type\\)\\>"))
1984 (ada-search-ignore-string-comment
1986 "loop\\|select\\|if\\|case\\|"
1987 "record\\|while\\|type\\)\\>")))
1989 (+ (current-indentation) label)))
1991 ;; a named block end
1993 ((looking-at ada-ident-re)
1994 (setq defun-name (buffer-substring (match-beginning 0)
1997 (ada-goto-matching-start 0)
1998 (ada-check-defun-name defun-name)
1999 (current-indentation)))
2001 ;; a block-end without name
2005 (ada-goto-matching-start 0)
2006 (if (looking-at "\\<begin\\>")
2008 (setq indent (current-column))
2009 (if (ada-goto-matching-decl-start t)
2010 (current-indentation)
2013 ;; anything else - should maybe signal an error ?
2016 (+ (current-indentation) ada-broken-indent))))
2018 (+ (current-indentation) ada-broken-indent))))
2021 (defun ada-get-indent-case (orgpoint)
2022 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2023 ;; Assumes point to be at the beginning of a case-statement.
2024 (let ((cur-indent (current-indentation))
2029 ;; case..is..when..=>
2032 (setq match-cons (and
2033 ;; the `=>' must be after the keyword `is'.
2034 (ada-search-ignore-string-comment
2035 "\\<is\\>" nil orgpoint)
2036 (ada-search-ignore-string-comment
2037 "[ \t\n]+=>" nil orgpoint))))
2039 (goto-char (car match-cons))
2040 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos))
2041 (error "missing 'when' between 'case' and '=>'"))
2042 (+ (current-indentation) ada-indent)))
2047 (setq match-cons (ada-search-ignore-string-comment
2048 "\\<when\\>" nil orgpoint)))
2049 (goto-char (cdr match-cons))
2050 (+ (current-indentation) ada-broken-indent))
2055 (setq match-cons (ada-search-ignore-string-comment
2056 "\\<is\\>" nil orgpoint)))
2057 (+ (current-indentation) ada-when-indent))
2062 (+ (current-indentation) ada-broken-indent)))))
2065 (defun ada-get-indent-when (orgpoint)
2066 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2067 ;; Assumes point to be at the beginning of an when-statement.
2068 (let ((cur-indent (current-indentation)))
2069 (if (ada-search-ignore-string-comment
2070 "[ \t\n]+=>" nil orgpoint)
2071 (+ cur-indent ada-indent)
2072 (+ cur-indent ada-broken-indent))))
2075 (defun ada-get-indent-if (orgpoint)
2076 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2077 ;; Assumes point to be at the beginning of an if-statement.
2078 (let ((cur-indent (current-indentation))
2083 (if (ada-search-but-not
2084 "\\<then\\>" "\\<and\\>[ \t\n]+\\<then\\>" nil orgpoint)
2088 ;; 'then' first in separate line ?
2089 ;; => indent according to 'then'
2092 (back-to-indentation)
2093 (looking-at "\\<then\\>"))
2094 (setq cur-indent (current-indentation)))
2097 ;; something follows 'then' ?
2099 (if (setq match-cons
2100 (ada-search-ignore-string-comment
2101 "[^ \t\n]" nil orgpoint))
2103 (goto-char (car match-cons))
2105 (- cur-indent (current-indentation))
2106 (funcall (ada-indent-function t) orgpoint)))
2108 (+ cur-indent ada-indent)))
2110 (+ cur-indent ada-broken-indent))))
2113 (defun ada-get-indent-block-start (orgpoint)
2114 ;; Returns the indentation (column #) for the new line after
2115 ;; ORGPOINT. Assumes point to be at the beginning of a block start
2117 (let ((cur-indent (current-indentation))
2122 (setq pos (car (ada-search-ignore-string-comment
2123 "[^ \t\n]" nil orgpoint))))
2126 (funcall (ada-indent-function t) orgpoint)))
2128 ;; nothing follows the block-start
2131 (+ (current-indentation) ada-indent)))))
2134 (defun ada-get-indent-subprog (orgpoint)
2135 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2136 ;; Assumes point to be at the beginning of a subprog-/package-declaration.
2137 (let ((match-cons nil)
2138 (cur-indent (current-indentation))
2143 ;; is there an 'is' in front of point ?
2147 (ada-search-ignore-string-comment
2148 "\\<\\(is\\|do\\)\\>" nil orgpoint)))
2150 ;; yes, then skip to its end
2154 (goto-char (cdr match-cons)))
2156 ;; no, then goto next non-ws, if there is one in front of point
2159 (if (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)
2160 (ada-goto-next-non-ws)
2161 (goto-char orgpoint))))
2165 ;; nothing follows 'is'
2170 (not (ada-search-ignore-string-comment
2171 "[^ \t\n]" nil orgpoint t))))
2172 (+ cur-indent ada-indent))
2174 ;; is abstract/separate/new ...
2180 (ada-search-ignore-string-comment
2181 "\\<\\(separate\\|new\\|abstract\\)\\>"
2183 (goto-char (car match-cons))
2184 (ada-search-ignore-string-comment ada-subprog-start-re t)
2185 (ada-get-indent-noindent orgpoint))
2187 ;; something follows 'is'
2192 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
2193 (ada-goto-next-non-ws)
2194 (funcall (ada-indent-function t) orgpoint)))
2199 (ada-search-ignore-string-comment ";" nil orgpoint))
2205 (+ cur-indent ada-broken-indent)))))
2208 (defun ada-get-indent-noindent (orgpoint)
2209 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2210 ;; Assumes point to be at the beginning of a 'noindent statement'.
2214 (if (looking-at ada-named-block-re)
2215 (setq label (- ada-label-indent))))
2217 (ada-search-ignore-string-comment ";" nil orgpoint))
2218 (+ (current-indentation) label)
2219 (+ (current-indentation) ada-broken-indent label))))
2222 (defun ada-get-indent-label (orgpoint)
2223 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2224 ;; Assumes point to be at the beginning of a label or variable declaration.
2225 ;; Checks the context to decide if it's a label or a variable declaration.
2226 ;; This check might be a bit slow.
2227 (let ((match-cons nil)
2228 (cur-indent (current-indentation)))
2229 (goto-char (cdr (ada-search-ignore-string-comment ":")))
2235 (setq match-cons (ada-search-ignore-string-comment
2236 ada-loop-start-re nil orgpoint)))
2237 (goto-char (car match-cons))
2238 (ada-get-indent-loop orgpoint))
2243 (setq match-cons (ada-search-ignore-string-comment
2244 "\\<declare\\|begin\\>" nil orgpoint)))
2246 (goto-char (car match-cons))
2247 (+ (current-indentation) ada-indent)))
2249 ;; complete statement following colon
2252 (ada-search-ignore-string-comment ";" nil orgpoint))
2254 cur-indent ; variable-declaration
2255 (- cur-indent ada-label-indent))) ; label
2260 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
2262 (+ cur-indent ada-broken-indent)
2263 (+ cur-indent ada-broken-indent (- ada-label-indent))))
2265 ;; nothing follows colon
2269 (+ cur-indent ada-broken-indent) ; variable-declaration
2270 (- cur-indent ada-label-indent)))))) ; label
2273 (defun ada-get-indent-loop (orgpoint)
2274 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2275 ;; Assumes point to be at the beginning of a loop statement
2276 ;; or (unfortunately) also a for ... use statement.
2277 (let ((match-cons nil)
2279 (label (save-excursion
2281 (if (looking-at ada-named-block-re)
2282 (- ada-label-indent)
2288 ;; statement complete
2291 (ada-search-ignore-string-comment ";" nil orgpoint))
2292 (+ (current-indentation) label))
2296 ((looking-at "loop\\>")
2297 (+ (ada-get-indent-block-start orgpoint) label))
2300 ;; 'for'- loop (or also a for ... use statement)
2302 ((looking-at "for\\>")
2309 (goto-char (match-end 0))
2310 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
2311 (not (backward-char 1))
2312 (not (zerop (skip-chars-forward "_a-zA-Z0-9'")))
2313 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
2314 (not (backward-char 1))
2315 (looking-at "\\<use\\>")
2317 ;; check if there is a 'record' before point
2320 (setq match-cons (ada-search-ignore-string-comment
2321 "\\<record\\>" nil orgpoint))
2324 (goto-char (car match-cons)))
2325 (+ (current-indentation) ada-indent))
2330 (setq match-cons (ada-search-ignore-string-comment
2331 "\\<loop\\>" nil orgpoint)))
2332 (goto-char (car match-cons))
2334 ;; indent according to 'loop', if it's first in the line;
2335 ;; otherwise to 'for'
2337 (if (not (save-excursion
2338 (back-to-indentation)
2339 (looking-at "\\<loop\\>")))
2341 (+ (current-indentation) ada-indent label))
2343 ;; for-statement is broken
2346 (+ (current-indentation) ada-broken-indent label))))
2351 ((looking-at "while\\>")
2356 (setq match-cons (ada-search-ignore-string-comment
2357 "\\<loop\\>" nil orgpoint)))
2360 (goto-char (car match-cons))
2362 ;; indent according to 'loop', if it's first in the line;
2363 ;; otherwise to 'while'.
2365 (if (not (save-excursion
2366 (back-to-indentation)
2367 (looking-at "\\<loop\\>")))
2369 (+ (current-indentation) ada-indent label))
2371 (+ (current-indentation) ada-broken-indent label))))))
2374 (defun ada-get-indent-type (orgpoint)
2375 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2376 ;; Assumes point to be at the beginning of a type statement.
2377 (let ((match-dat nil))
2380 ;; complete record declaration
2384 (setq match-dat (ada-search-ignore-string-comment "\\<end\\>"
2387 (ada-goto-next-non-ws)
2388 (looking-at "\\<record\\>")
2390 (ada-goto-next-non-ws)
2392 (goto-char (car match-dat))
2393 (current-indentation))
2398 (setq match-dat (ada-search-ignore-string-comment "\\<record\\>"
2401 (goto-char (car match-dat))
2402 (+ (current-indentation) ada-indent))
2404 ;; complete type declaration
2407 (ada-search-ignore-string-comment ";" nil orgpoint))
2408 (current-indentation))
2410 ;; "type ... is", but not "type ... is ...", which is broken
2414 (ada-search-ignore-string-comment "\\<is\\>" nil orgpoint)
2415 (not (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))))
2416 (+ (current-indentation) ada-indent))
2421 (+ (current-indentation) ada-broken-indent)))))
2424 ;;; ---- support-functions for indentation
2426 ;;; ---- searching and matching
2428 (defun ada-goto-stmt-start (&optional limit)
2429 ;; Moves point to the beginning of the statement that point is in or
2430 ;; after. Returns the new position of point. Beginnings are found
2431 ;; by searching for 'ada-end-stmt-re' and then moving to the
2432 ;; following non-ws that is not a comment. LIMIT is actually not
2433 ;; used by the indentation functions.
2434 (let ((match-dat nil)
2437 (setq match-dat (ada-search-prev-end-stmt limit))
2440 ;; found a previous end-statement => check if anything follows
2445 (goto-char (cdr match-dat))
2446 (ada-search-ignore-string-comment
2447 "[^ \t\n]" nil orgpoint)))
2449 ;; nothing follows => it's the end-statement directly in
2450 ;; front of point => search again
2452 (setq match-dat (ada-search-prev-end-stmt limit)))
2454 ;; if found the correct end-statement => goto next non-ws
2457 (goto-char (cdr match-dat)))
2458 (ada-goto-next-non-ws))
2461 ;; no previous end-statement => we are at the beginning of the
2462 ;; accessible part of the buffer
2465 (goto-char (point-min))
2467 ;; skip to the very first statement, if there is one
2470 (ada-search-ignore-string-comment
2471 "[^ \t\n]" nil orgpoint))
2472 (goto-char (car match-dat))
2473 (goto-char orgpoint))))
2479 (defun ada-search-prev-end-stmt (&optional limit)
2480 ;; Moves point to previous end-statement. Returns a cons cell whose
2481 ;; car is the beginning and whose cdr the end of the match.
2482 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for
2483 ;; certain keywords if they follow 'end', which means they are no
2484 ;; end-statement there.
2485 (let ((match-dat nil)
2489 ;; search until found or beginning-of-buffer
2494 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re
2498 (goto-char (car match-dat))
2499 (if (not (ada-in-open-paren-p))
2501 ;; check if there is an 'end' in front of the match
2505 "\\<\\(record\\|loop\\|select\\|else\\|then\\)\\>")
2507 (ada-goto-previous-word)
2508 (looking-at "\\<\\(end\\|or\\|and\\)\\>"))))
2510 (goto-char (cdr match-dat))
2511 (ada-goto-next-word)
2512 (if (not (looking-at "\\<\\(separate\\|new\\)\\>"))
2515 (forward-word -1)))) ; end of loop
2522 (defun ada-goto-next-non-ws (&optional limit)
2523 ;; Skips whitespaces, newlines and comments to next non-ws
2524 ;; character. Signals an error if there is no more such character
2525 ;; and limit is nil.
2526 (let ((match-cons nil))
2527 (setq match-cons (ada-search-ignore-string-comment
2528 "[^ \t\n]" nil limit t))
2530 (goto-char (car match-cons))
2532 (error "no more non-ws")
2536 (defun ada-goto-stmt-end (&optional limit)
2537 ;; Moves point to the end of the statement that point is in or
2538 ;; before. Returns the new position of point or nil if not found.
2539 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
2544 (defun ada-goto-next-word (&optional backward)
2545 ;; Moves point to the beginning of the next word of Ada code.
2546 ;; If BACKWARD is non-nil, jump to the beginning of the previous word.
2547 ;; Returns the new position of point or nil if not found.
2548 (let ((match-cons nil)
2551 (skip-chars-forward "_a-zA-Z0-9\\."))
2552 (if (setq match-cons
2553 (ada-search-ignore-string-comment "\\w" backward nil t))
2555 ;; move to the beginning of the word found
2558 (goto-char (car match-cons))
2559 (skip-chars-backward "_a-zA-Z0-9")
2562 ;; if not found, restore old position of point
2565 (goto-char orgpoint)
2569 (defun ada-goto-previous-word ()
2570 ;; Moves point to the beginning of the previous word of Ada code.
2571 ;; Returns the new position of point or nil if not found.
2572 (ada-goto-next-word t))
2575 (defun ada-check-matching-start (keyword)
2576 ;; Signals an error if matching block start is not KEYWORD.
2577 ;; Moves point to the matching block start.
2578 (ada-goto-matching-start 0)
2579 (if (not (looking-at (concat "\\<" keyword "\\>")))
2580 (error "matching start is not '%s'" keyword)))
2583 (defun ada-check-defun-name (defun-name)
2584 ;; Checks if the name of the matching defun really is DEFUN-NAME.
2585 ;; Assumes point to be already positioned by 'ada-goto-matching-start'.
2586 ;; Moves point to the beginning of the declaration.
2589 ;; named block without a `declare'
2592 (ada-goto-previous-word)
2593 (looking-at (concat "\\<" defun-name "\\> *:")))
2596 ;; 'accept' or 'package' ?
2598 (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>"))
2599 (ada-goto-matching-decl-start))
2601 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
2605 ;; a named 'declare'-block ?
2607 (if (looking-at "\\<declare\\>")
2608 (ada-goto-stmt-start)
2610 ;; no, => 'procedure'/'function'/'task'/'protected'
2616 ;; skip 'body' 'type'
2618 (if (looking-at "\\<\\(body\\|type\\)\\>")
2623 ;; should be looking-at the correct name
2625 (if (not (looking-at (concat "\\<" defun-name "\\>")))
2626 (error "matching defun has different name: %s"
2627 (buffer-substring (point)
2628 (progn (forward-sexp 1) (point))))))))
2631 (defun ada-goto-matching-decl-start (&optional noerror nogeneric)
2632 ;; Moves point to the matching declaration start of the current 'begin'.
2633 ;; If NOERROR is non-nil, it only returns nil if no match was found.
2634 (let ((nest-count 1)
2639 ;; search backward for interesting keywords
2642 (not (zerop nest-count))
2643 (ada-search-ignore-string-comment
2645 "is\\|separate\\|end\\|declare\\|new\\|begin\\|generic"
2648 ;; calculate nest-depth
2653 (ada-goto-matching-start 1 noerror)
2654 (if (looking-at "begin")
2655 (setq nest-count (1+ nest-count))))
2657 ((looking-at "declare\\|generic")
2658 (setq nest-count (1- nest-count))
2662 ;; check if it is only a type definition, but not a protected
2663 ;; type definition, which should be handled like a procedure.
2664 (if (or (looking-at "is +<>")
2666 (ada-goto-previous-word)
2667 (skip-chars-backward "a-zA-Z0-9_.'")
2674 (skip-chars-backward "a-zA-Z0-9_.'")
2676 (ada-goto-previous-word)
2678 (looking-at "\\<type\\>")
2680 (ada-goto-previous-word)
2681 (not (looking-at "\\<protected\\>"))))
2683 (goto-char (match-beginning 0))
2685 (setq nest-count (1- nest-count))
2691 (ada-goto-previous-word)
2693 (goto-char (match-beginning 0))))
2696 (looking-at "begin"))
2701 (setq nest-count (1+ nest-count))
2706 ;; check if declaration-start is really found
2711 (if (looking-at "is")
2712 (ada-search-ignore-string-comment ada-subprog-start-re t)
2713 (looking-at "declare\\|generic"))))
2715 (error "no matching proc/func/task/declare/package/protected"))
2719 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
2720 ;; Moves point to the beginning of a block-start. Which block
2721 ;; depends on the value of NEST-LEVEL, which defaults to zero. If
2722 ;; NOERROR is non-nil, it only returns nil if no matching start was
2723 ;; found. If GOTOTHEN is non-nil, point moves to the 'then'
2725 (let ((nest-count (if nest-level nest-level 0))
2730 ;; search backward for interesting keywords
2734 (ada-search-ignore-string-comment
2736 "end\\|loop\\|select\\|begin\\|case\\|do\\|"
2737 "if\\|task\\|package\\|record\\|protected\\)\\>")
2741 ;; calculate nest-depth
2744 ;; found block end => increase nest depth
2746 (setq nest-count (1+ nest-count)))
2747 ;; found loop/select/record/case/if => check if it starts or
2749 ((looking-at "loop\\|select\\|record\\|case\\|if")
2753 ;; check if keyword follows 'end'
2755 (ada-goto-previous-word)
2756 (if (looking-at "\\<end\\> *[^;]")
2757 ;; it ends a block => increase nest depth
2759 (setq nest-count (1+ nest-count))
2761 ;; it starts a block => decrease nest depth
2762 (setq nest-count (1- nest-count))))
2764 ;; found package start => check if it really is a block
2765 ((looking-at "package")
2767 (ada-search-ignore-string-comment "\\<is\\>")
2768 (ada-goto-next-non-ws)
2769 ;; ignore it if it is only a declaration with 'new'
2770 (if (not (looking-at "\\<new\\>"))
2771 (setq nest-count (1- nest-count)))))
2772 ;; found task start => check if it has a body
2773 ((looking-at "task")
2776 (ada-goto-next-non-ws)
2777 ;; ignore it if it has no body
2778 (if (not (looking-at "\\<body\\>"))
2779 (setq nest-count (1- nest-count)))))
2780 ;; all the other block starts
2782 (setq nest-count (1- nest-count)))) ; end of 'cond'
2784 ;; match is found, if nest-depth is zero
2786 (setq found (zerop nest-count))) ; end of loop
2790 ;; match found => is there anything else to do ?
2795 ;; found 'if' => skip to 'then', if it's on a separate line
2796 ;; and GOTOTHEN is non-nil
2802 (ada-search-ignore-string-comment "\\<then\\>" nil nil)
2803 (back-to-indentation)
2804 (looking-at "\\<then\\>")))
2805 (goto-char (match-beginning 0)))
2807 ;; found 'do' => skip back to 'accept'
2810 (if (not (ada-search-ignore-string-comment "\\<accept\\>" t nil))
2811 (error "missing 'accept' in front of 'do'"))))
2816 (error "no matching start")))))
2819 (defun ada-goto-matching-end (&optional nest-level noerror)
2820 ;; Moves point to the end of a block. Which block depends on the
2821 ;; value of NEST-LEVEL, which defaults to zero. If NOERROR is
2822 ;; non-nil, it only returns nil if found no matching start.
2823 (let ((nest-count (if nest-level nest-level 0))
2827 ;; search forward for interesting keywords
2831 (ada-search-ignore-string-comment
2832 (concat "\\<\\(end\\|loop\\|select\\|begin\\|case\\|"
2833 "if\\|task\\|package\\|record\\|do\\)\\>")))
2836 ;; calculate nest-depth
2840 ;; found block end => decrease nest depth
2841 ((looking-at "\\<end\\>")
2842 (setq nest-count (1- nest-count))
2843 ;; skip the following keyword
2845 (skip-chars-forward "end")
2846 (ada-goto-next-non-ws)
2847 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>"))
2849 ;; found package start => check if it really starts a block
2850 ((looking-at "\\<package\\>")
2851 (ada-search-ignore-string-comment "\\<is\\>")
2852 (ada-goto-next-non-ws)
2853 ;; ignore and skip it if it is only a 'new' package
2854 (if (not (looking-at "\\<new\\>"))
2855 (setq nest-count (1+ nest-count))
2856 (skip-chars-forward "new")))
2857 ;; all the other block starts
2859 (setq nest-count (1+ nest-count))
2860 (forward-word 1))) ; end of 'cond'
2862 ;; match is found, if nest-depth is zero
2864 (setq found (zerop nest-count))) ; end of loop
2869 (error "no matching end"))
2873 (defun ada-forward-sexp-ignore-comment ()
2874 ;; Skips one sexp forward, ignoring comments.
2875 (while (looking-at "[ \t\n]*--")
2876 (skip-chars-forward "[ \t\n]")
2881 (defun ada-search-ignore-string-comment
2882 (search-re &optional backward limit paramlists)
2883 ;; Regexp-Search for SEARCH-RE, ignoring comments, strings and
2884 ;; parameter lists, if PARAMLISTS is nil. Returns a cons cell of
2885 ;; begin and end of match data or nil, if not found.
2891 (if backward 're-search-backward
2892 're-search-forward)))
2895 ;; search until found or end-of-buffer
2897 (while (and (not found)
2898 (funcall search-func search-re limit 1))
2899 (setq begin (match-beginning 0))
2900 (setq end (match-end 0))
2904 ;; found in comment => skip it
2909 (re-search-backward "--" nil 1)
2910 (goto-char (match-beginning 0)))
2913 (beginning-of-line))))
2915 ;; found in string => skip it
2920 (re-search-backward "\"" nil 1) ; "\"\\|#" don't treat #
2921 (goto-char (match-beginning 0))))
2922 (re-search-forward "\"" nil 1))
2924 ;; found character constant => ignore it
2927 (setq pos (- (point) (if backward 1 2)))
2928 (and (char-after pos)
2929 (= (char-after pos) ?')
2930 (= (char-after (+ pos 2)) ?')))
2933 ;; found a parameter-list but should ignore it => skip it
2935 ((and (not paramlists)
2936 (ada-in-paramlist-p))
2938 (ada-search-ignore-string-comment "(" t nil t)))
2940 ;; directly in front of a comment => skip it, if searching forward
2948 (beginning-of-line))))
2950 ;; found what we were looking for
2953 (setq found t)))) ; end of loop
2960 (defun ada-search-but-not (search-re not-search-re &optional backward limit)
2961 ;; Searches SEARCH-RE, ignoring parts of NOT-SEARCH-RE, strings,
2962 ;; comments and parameter-lists.
2972 ;; search until found or end-of-buffer
2978 (ada-search-ignore-string-comment search-re
2980 (if (consp ret-cons)
2982 (setq begin (car ret-cons))
2983 (setq end (cdr ret-cons))
2989 ;; if no NO-SEARCH-RE was found
2994 (ada-search-ignore-string-comment not-search-re
2996 (if (consp ret-cons)
2998 (setq begin-not (car ret-cons))
2999 (setq end-not (cdr ret-cons))
3003 ;; or this NO-SEARCH-RE is not a part of the SEARCH-RE
3008 (>= begin-not end)))
3013 ;; not found the correct match => skip this match
3015 (goto-char (if backward
3017 end)))) ; end of loop
3026 (defun ada-goto-prev-nonblank-line ( &optional ignore-comment)
3027 ;; Moves point to the beginning of previous non-blank line,
3028 ;; ignoring comments if IGNORE-COMMENT is non-nil.
3029 ;; It returns t if a matching line was found.
3035 ;; backward one line, if there is one
3037 (if (zerop (forward-line -1))
3039 ;; there is some kind of previous line
3043 (setq newpoint (point))
3046 ;; search until found or beginning-of-buffer
3048 (while (and (setq notfound
3049 (or (looking-at "[ \t]*$")
3050 (and (looking-at "[ \t]*--")
3052 (not (ada-in-limit-line-p)))
3054 ;;(beginning-of-line)
3055 (setq newpoint (point))) ; end of loop
3059 ) ; end of save-excursion
3063 (goto-char newpoint)
3067 (defun ada-goto-next-nonblank-line ( &optional ignore-comment)
3068 ;; Moves point to next non-blank line,
3069 ;; ignoring comments if IGNORE-COMMENT is non-nil.
3070 ;; It returns t if a matching line was found.
3078 (if (zerop (forward-line 1))
3080 ;; there is some kind of previous line
3084 (setq newpoint (point))
3087 ;; search until found or end-of-buffer
3089 (while (and (setq notfound
3090 (or (looking-at "[ \t]*$")
3091 (and (looking-at "[ \t]*--")
3093 (not (ada-in-limit-line-p)))
3096 (setq newpoint (point))) ; end of loop
3100 ) ; end of save-excursion
3104 (goto-char newpoint)
3108 ;; ---- boolean functions for indentation
3110 (defun ada-in-decl-p ()
3111 ;; Returns t if point is inside a declarative part.
3112 ;; Assumes point to be at the end of a statement.
3114 (ada-in-paramlist-p)
3116 (ada-goto-matching-decl-start t))))
3119 (defun ada-looking-at-semi-or ()
3120 ;; Returns t if looking-at an 'or' following a semicolon.
3122 (and (looking-at "\\<or\\>")
3125 (ada-goto-stmt-start)
3126 (looking-at "\\<or\\>")))))
3129 (defun ada-looking-at-semi-private ()
3130 ;; Returns t if looking-at an 'private' following a semicolon.
3132 (and (looking-at "\\<private\\>")
3135 (ada-goto-stmt-start)
3136 (looking-at "\\<private\\>")))))
3139 ;;; make a faster??? ada-in-limit-line-p not using count-lines
3140 (defun ada-in-limit-line-p ()
3141 ;; return t if point is in first or last accessible line.
3142 (or (save-excursion (beginning-of-line) (= (point-min) (point)))
3143 (save-excursion (end-of-line) (= (point-max) (point)))))
3146 (defun ada-in-comment-p ()
3147 ;; Returns t if inside a comment.
3148 (nth 4 (parse-partial-sexp
3149 (save-excursion (beginning-of-line) (point))
3153 (defun ada-in-string-p ()
3154 ;; Returns t if point is inside a string
3155 ;; (Taken from pascal-mode.el, modified by MH).
3158 (nth 3 (parse-partial-sexp
3162 ;; check if 'string quote' is only a character constant
3164 (re-search-backward "\"" nil t) ; `#' is not taken as a string delimiter
3165 (not (= (char-after (1- (point))) ?'))))))
3168 (defun ada-in-string-or-comment-p ()
3169 ;; Returns t if point is inside a string, a comment, or a character constant.
3170 (let ((parse-result (parse-partial-sexp
3171 (save-excursion (beginning-of-line) (point)) (point))))
3173 (nth 4 parse-result)
3176 (nth 3 parse-result)
3177 ;; check if 'string quote' is only a character constant
3179 (re-search-backward "\"" nil t) ; `#' not regarded a string delimiter
3180 (not (= (char-after (1- (point))) ?'))))
3182 (ada-in-char-const-p))))
3185 (defun ada-in-paramlist-p ()
3186 ;; Returns t if point is inside a parameter-list
3187 ;; following 'function'/'procedure'/'package'.
3190 (re-search-backward "(\\|)" nil t)
3191 ;; inside parentheses ?
3194 ;; right keyword before parenthesis ?
3195 (looking-at (concat "\\<\\("
3196 "procedure\\|function\\|body\\|package\\|"
3197 "task\\|entry\\|accept\\)\\>"))
3198 (re-search-forward ")\\|:" nil t)
3199 ;; at least one ':' inside the parentheses ?
3200 (not (backward-char 1))
3204 ;; not really a boolean function ...
3205 (defun ada-in-open-paren-p ()
3206 ;; If point is somewhere behind an open parenthesis not yet closed,
3207 ;; it returns the column # of the first non-ws behind this open
3208 ;; parenthesis, otherwise nil."
3209 (let ((start (if (<= (point) ada-search-paren-char-count-limit)
3212 (goto-char (- (point) ada-search-paren-char-count-limit))
3217 (setq parse-result (parse-partial-sexp start (point)))
3218 (if (nth 1 parse-result)
3220 (goto-char (1+ (nth 1 parse-result)))
3222 (re-search-forward "[^ \t]" nil 1)
3225 (not (looking-at "\n"))
3226 (setq col (current-column))))
3233 ;;;----------------------;;;
3234 ;;; Behaviour Of TAB Key ;;;
3235 ;;;----------------------;;;
3238 "Do indenting or tabbing according to `ada-tab-policy'."
3240 (cond ((eq ada-tab-policy 'indent-and-tab) (error "not implemented"))
3241 ;; ada-indent-and-tab
3242 ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard))
3243 ((eq ada-tab-policy 'indent-auto) (ada-indent-current))
3244 ((eq ada-tab-policy 'gei) (ada-tab-gei))
3245 ((eq ada-tab-policy 'indent-af) (af-indent-line)) ; GEB
3246 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3250 (defun ada-untab (arg)
3251 "Delete leading indenting according to `ada-tab-policy'."
3253 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard))
3254 ((eq ada-tab-policy 'indent-af) (backward-delete-char-untabify ; GEB
3255 (prefix-numeric-value arg) ; GEB
3257 ((eq ada-tab-policy 'indent-auto) (error "not implemented"))
3258 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3262 (defun ada-indent-current-function ()
3263 "Ada mode version of the indent-line-function."
3265 (let ((starting-point (point-marker)))
3266 (ada-beginning-of-line)
3268 (if (< (point) starting-point)
3269 (goto-char starting-point))
3270 (set-marker starting-point nil)
3274 (defun ada-tab-hard ()
3275 "Indent current line to next tab stop."
3279 (insert-char ? ada-indent))
3280 (if (save-excursion (= (point) (progn (beginning-of-line) (point))))
3281 (forward-char ada-indent)))
3284 (defun ada-untab-hard ()
3285 "indent current line to previous tab stop."
3287 (let ((bol (save-excursion (progn (beginning-of-line) (point))))
3288 (eol (save-excursion (progn (end-of-line) (point)))))
3289 (indent-rigidly bol eol (- 0 ada-indent))))
3293 ;;;---------------;;;
3294 ;;; Miscellaneous ;;;
3295 ;;;---------------;;;
3297 (defun ada-remove-trailing-spaces ()
3298 "remove trailing spaces in the whole buffer."
3304 (goto-char (point-min))
3305 (while (re-search-forward "[ \t]+$" (point-max) t)
3306 (replace-match "" nil nil))))))
3309 (defun ada-untabify-buffer ()
3310 ;; change all tabs to spaces
3312 (untabify (point-min) (point-max))
3316 (defun ada-uncomment-region (beg end)
3317 "delete `comment-start' at the beginning of a line in the region."
3319 (comment-region beg end -1))
3322 ;; define a function to support find-file.el if loaded
3323 (defun ada-ff-other-window ()
3324 "Find other file in other window using `ff-find-other-file'."
3326 (and (fboundp 'ff-find-other-file)
3327 (ff-find-other-file t)))
3329 ;; inspired by Laurent.GUERBY@enst-bretagne.fr
3330 (defun ada-gnat-style ()
3331 "Clean up comments, `(' and `,' for GNAT style checking switch."
3334 (goto-char (point-min))
3335 (while (re-search-forward "-- ?\\([^ -]\\)" nil t)
3336 (replace-match "-- \\1"))
3337 (goto-char (point-min))
3338 (while (re-search-forward "\\>(" nil t)
3339 (replace-match " ("))
3340 (goto-char (point-min))
3341 (while (re-search-forward ",\\<" nil t)
3342 (replace-match ", "))
3347 ;;;-------------------------------;;;
3348 ;;; Moving To Procedures/Packages ;;;
3349 ;;;-------------------------------;;;
3351 (defun ada-next-procedure ()
3352 "Moves point to next procedure."
3355 (if (re-search-forward ada-procedure-start-regexp nil t)
3356 (goto-char (match-beginning 1))
3357 (error "No more functions/procedures/tasks")))
3359 (defun ada-previous-procedure ()
3360 "Moves point to previous procedure."
3363 (if (re-search-backward ada-procedure-start-regexp nil t)
3364 (goto-char (match-beginning 1))
3365 (error "No more functions/procedures/tasks")))
3367 (defun ada-next-package ()
3368 "Moves point to next package."
3371 (if (re-search-forward ada-package-start-regexp nil t)
3372 (goto-char (match-beginning 1))
3373 (error "No more packages")))
3375 (defun ada-previous-package ()
3376 "Moves point to previous package."
3379 (if (re-search-backward ada-package-start-regexp nil t)
3380 (goto-char (match-beginning 1))
3381 (error "No more packages")))
3384 ;;;-----------------------
3385 ;;; define keymap for Ada
3386 ;;;-----------------------
3388 (if (not ada-mode-map)
3390 (setq ada-mode-map (make-sparse-keymap))
3392 ;; Indentation and Formatting
3393 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent)
3394 (define-key ada-mode-map "\t" 'ada-tab)
3395 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region)
3397 (define-key ada-mode-map '(shift tab) 'ada-untab)
3398 (define-key ada-mode-map [S-tab] 'ada-untab))
3399 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist)
3400 (define-key ada-mode-map "\C-c\C-p" 'ada-call-pretty-printer)
3401 ;;; We don't want to make meta-characters case-specific.
3402 ;;; (define-key ada-mode-map "\M-Q" 'ada-fill-comment-paragraph-justify)
3403 (define-key ada-mode-map "\M-\C-q" 'ada-fill-comment-paragraph-postfix)
3406 ;;; It isn't good to redefine these. What should be done instead? -- rms.
3407 ;;; (define-key ada-mode-map "\M-e" 'ada-next-package)
3408 ;;; (define-key ada-mode-map "\M-a" 'ada-previous-package)
3409 (define-key ada-mode-map "\M-\C-e" 'ada-next-procedure)
3410 (define-key ada-mode-map "\M-\C-a" 'ada-previous-procedure)
3411 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3412 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3415 (define-key ada-mode-map "\C-c\C-c" 'compile)
3416 (define-key ada-mode-map "\C-c\C-v" 'ada-check-syntax)
3417 (define-key ada-mode-map "\C-c\C-m" 'ada-make-local)
3420 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region)
3421 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3423 (define-key ada-mode-map "\177" 'backward-delete-char-untabify)
3425 ;; Use predefined function of emacs19 for comments (RE)
3426 (define-key ada-mode-map "\C-c;" 'comment-region)
3427 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
3429 ;; Change basic functionality
3431 ;; `substitute-key-definition' is not defined equally in Emacs
3432 ;; and XEmacs, you cannot put in an optional 4th parameter in
3433 ;; XEmacs. I don't think it's necessary, so I leave it out for
3434 ;; Emacs as well. If you encounter any problems with the
3435 ;; following three functions, please tell me. RE
3436 (mapcar (function (lambda (pair)
3437 (substitute-key-definition (car pair) (cdr pair)
3439 '((beginning-of-line . ada-beginning-of-line)
3440 (end-of-line . ada-end-of-line)
3441 (forward-to-indentation . ada-forward-to-indentation)
3444 ;;(mapcar (lambda (pair)
3445 ;; (substitute-key-definition (car pair) (cdr pair)
3446 ;; ada-mode-map global-map))
3451 ;;;-------------------
3452 ;;; define menu 'Ada'
3453 ;;;-------------------
3457 (defun ada-add-ada-menu ()
3458 "Adds the menu 'Ada' to the menu bar in Ada mode."
3459 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode."
3461 ["Next Package" ada-next-package t]
3462 ["Previous Package" ada-previous-package t]
3463 ["Next Procedure" ada-next-procedure t]
3464 ["Previous Procedure" ada-previous-procedure t]
3465 ["Goto Start" ada-move-to-start t]
3466 ["Goto End" ada-move-to-end t]
3467 ["------------------" nil nil]
3468 ["Indent Current Line (TAB)"
3469 ada-indent-current-function t]
3470 ["Indent Lines in Region" ada-indent-region t]
3471 ["Format Parameter List" ada-format-paramlist t]
3472 ["Pretty Print Buffer" ada-call-pretty-printer t]
3473 ["------------" nil nil]
3474 ["Fill Comment Paragraph"
3475 ada-fill-comment-paragraph t]
3476 ["Justify Comment Paragraph"
3477 ada-fill-comment-paragraph-justify t]
3478 ["Postfix Comment Paragraph"
3479 ada-fill-comment-paragraph-postfix t]
3480 ["------------" nil nil]
3481 ["Adjust Case Region" ada-adjust-case-region t]
3482 ["Adjust Case Buffer" ada-adjust-case-buffer t]
3483 ["----------" nil nil]
3484 ["Comment Region" comment-region t]
3485 ["Uncomment Region" ada-uncomment-region t]
3486 ["----------------" nil nil]
3487 ["Global Make" compile (fboundp 'compile)]
3488 ["Local Make" ada-make-local t]
3489 ["Check Syntax" ada-check-syntax t]
3490 ["Next Error" next-error (fboundp 'next-error)]
3491 ["---------------" nil nil]
3492 ["Index" imenu (fboundp 'imenu)]
3493 ["--------------" nil nil]
3494 ["Other File Other Window" ada-ff-other-window
3495 (fboundp 'ff-find-other-file)]
3496 ["Other File" ff-find-other-file
3497 (fboundp 'ff-find-other-file)]))
3498 (if (ada-xemacs) (progn
3499 (easy-menu-add ada-mode-menu)
3500 (setq mode-popup-menu (cons "Ada mode" ada-mode-menu)))))
3504 ;;;-------------------------------
3505 ;;; Define Some Support Functions
3506 ;;;-------------------------------
3508 (defun ada-beginning-of-line (&optional arg)
3511 ((eq ada-tab-policy 'indent-af) (af-beginning-of-line arg))
3512 (t (beginning-of-line arg))
3515 (defun ada-end-of-line (&optional arg)
3518 ((eq ada-tab-policy 'indent-af) (af-end-of-line arg))
3519 (t (end-of-line arg))
3522 (defun ada-current-column ()
3524 ((eq ada-tab-policy 'indent-af) (af-current-column))
3525 (t (current-column))
3528 (defun ada-forward-to-indentation (&optional arg)
3531 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg))
3532 (t (forward-to-indentation arg))
3535 ;;;---------------------------------------------------
3536 ;;; support for find-file.el
3537 ;;;---------------------------------------------------
3541 (defun ada-make-filename-from-adaname (adaname)
3542 "Determine the filename of a package/procedure from its own Ada name."
3543 ;; this is done simply by calling `gnatkr', when we work with GNAT. It
3544 ;; must be a more complex function in other compiler environments.
3547 (setq krunch-buf (generate-new-buffer "*gkrunch*"))
3549 (set-buffer krunch-buf)
3550 ;; send adaname to external process `gnatkr'.
3551 (call-process "gnatkr" nil krunch-buf nil
3552 adaname ada-krunch-args)
3553 ;; fetch output of that process
3554 (setq adaname (buffer-substring
3557 (goto-char (point-min))
3560 (kill-buffer krunch-buf)))
3561 (setq adaname adaname) ;; can I avoid this statement?
3565 ;;; functions for placing the cursor on the corresponding subprogram
3566 (defun ada-which-function-are-we-in ()
3567 "Determine whether we are on a function definition/declaration.
3568 If that is the case remember the name of that function."
3570 (setq ff-function-name nil)
3573 (if (re-search-backward ada-procedure-start-regexp nil t)
3574 (setq ff-function-name (buffer-substring (match-beginning 0)
3576 ; we didn't find a procedure start, perhaps there is a package
3577 (if (re-search-backward ada-package-start-regexp nil t)
3578 (setq ff-function-name (buffer-substring (match-beginning 0)
3583 ;;;---------------------------------------------------
3584 ;;; support for font-lock
3585 ;;;---------------------------------------------------
3587 ;; Strings are a real pain in Ada because a single quote character is
3588 ;; overloaded as a string quote and type/instance delimiter. By default, a
3589 ;; single quote is given punctuation syntax in `ada-mode-syntax-table'.
3590 ;; So, for Font Lock mode purposes, we mark single quotes as having string
3591 ;; syntax when the gods that created Ada determine them to be. sm.
3593 (defconst ada-font-lock-syntactic-keywords
3594 ;; Mark single quotes as having string quote syntax in 'c' instances.
3595 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\')))))
3597 (defconst ada-font-lock-keywords-1
3600 ;; handle "type T is access function return S;"
3602 (list "\\<\\(function[ \t]+return\\)\\>" '(1 font-lock-keyword-face) )
3604 ;; accept, entry, function, package (body), protected (body|type),
3605 ;; pragma, procedure, task (body) plus name.
3611 "package[ \t]+body\\|"
3615 "protected[ \t]+body\\|"
3616 "protected[ \t]+type\\|"
3618 ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\
3619 ;;\\|r\\(agma\\|ocedure\\)\\)\\|"
3623 ;; "task\\(\\|[ \t]+body\\)"
3625 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
3626 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t)))
3627 "Subdued level highlighting for Ada mode.")
3629 (defconst ada-font-lock-keywords-2
3630 (append ada-font-lock-keywords-1
3633 ;; Main keywords, except those treated specially below.
3635 ; ("abort" "abs" "abstract" "accept" "access" "aliased" "all"
3636 ; "and" "array" "at" "begin" "case" "declare" "delay" "delta"
3637 ; "digits" "do" "else" "elsif" "entry" "exception" "exit" "for"
3638 ; "generic" "if" "in" "is" "limited" "loop" "mod" "not"
3639 ; "null" "or" "others" "private" "protected"
3640 ; "range" "record" "rem" "renames" "requeue" "return" "reverse"
3641 ; "select" "separate" "tagged" "task" "terminate" "then" "until"
3643 "a\\(b\\(ort\\|s\\(\\|tract\\)\\)\\|cce\\(pt\\|ss\\)\\|"
3644 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|"
3645 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|"
3646 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|"
3647 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|"
3648 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|"
3649 "r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|"
3650 "se\\(lect\\|parate\\)\\|"
3651 "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed
3652 "wh\\(ile\\|en\\)\\|xor" ; "when" added
3655 ;; Anything following end and not already fontified is a body name.
3656 '("\\<\\(end\\)\\>\\([ \t]+\\)?\\([a-zA-Z0-9_\\.]+\\)?"
3657 (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
3659 ;; Variable name plus optional keywords followed by a type name. Slow.
3660 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*"
3661 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*"
3663 ; '(1 font-lock-variable-name-face)
3664 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t))
3666 ;; Optional keywords followed by a type name.
3667 (list (concat ; ":[ \t]*"
3668 "\\<\\(access\\|constant\\|in[ \t]+out\\|in\\|out\\)\\>"
3671 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
3673 ;; Keywords followed by a type or function name.
3674 (list (concat "\\<\\("
3675 "new\\|of\\|subtype\\|type"
3676 "\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*\\((\\)?")
3677 '(1 font-lock-keyword-face)
3678 '(2 (if (match-beginning 4)
3679 font-lock-function-name-face
3680 font-lock-type-face) nil t))
3682 ;; Keywords followed by a (comma separated list of) reference.
3683 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)\\>" ; "when" removed
3684 ; "[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?") ; RE
3685 "[ \t]*\\([a-zA-Z0-9_\\.\\|, ]+\\)\\W")
3686 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
3689 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
3691 "Gaudy level highlighting for Ada mode.")
3693 (defvar ada-font-lock-keywords ada-font-lock-keywords-1
3694 "Default expressions to highlight in Ada mode.")
3697 ;; set font-lock properties for XEmacs
3699 (put 'ada-mode 'font-lock-defaults
3700 '(ada-font-lock-keywords
3701 nil t ((?\_ . "w")(?\. . "w")) beginning-of-line)))
3704 ;;; support for outline
3707 ;; used by outline-minor-mode
3708 (defun ada-outline-level ()
3710 (skip-chars-forward "\t ")
3716 (defun ada-gen-comment-until-proc ()
3717 ;; comment until spec of a procedure or a function.
3719 (set-mark-command (point))
3720 (if (re-search-forward ada-procedure-start-regexp nil t)
3721 (progn (goto-char (match-beginning 1))
3722 (comment-region (mark) (point)))
3723 (error "No more functions/procedures")))
3726 (defun ada-gen-treat-proc (match)
3727 ;; make dummy body of a procedure/function specification.
3728 ;; MATCH is a cons cell containing the start and end location of the
3729 ;; last search for ada-procedure-start-regexp.
3730 (goto-char (car match))
3731 (let (proc-found func-found procname functype)
3733 ((or (setq proc-found (looking-at "^[ \t]*procedure"))
3734 (setq func-found (looking-at "^[ \t]*function")))
3735 ;; treat it as a proc/func
3738 (setq procname (buffer-substring (point) (cdr match))) ; store proc name
3740 ;; goto end of procname
3741 (goto-char (cdr match))
3743 ;; skip over parameterlist
3745 ;; if function, skip over 'return' and result type.
3749 (skip-chars-forward " \t\n")
3750 (setq functype (buffer-substring (point)
3755 ;; look for next non WS
3757 ((looking-at "[ \t]*;")
3758 (delete-region (match-beginning 0) (match-end 0)) ;; delete the ';'
3759 (ada-indent-newline-indent)
3761 (ada-indent-newline-indent)
3764 (insert "Result : ")
3767 (ada-indent-newline-indent)))
3768 (insert "begin -- ")
3770 (ada-indent-newline-indent)
3772 (ada-indent-newline-indent)
3775 (insert "return Result;")
3776 (ada-indent-newline-indent)))
3780 (ada-indent-newline-indent)
3783 ((looking-at "[ \t\n]*is")
3786 ((looking-at "[ \t\n]*rename")
3790 (message "unknown syntax")))
3794 (defun ada-make-body ()
3795 "Create an Ada package body in the current buffer.
3796 The potential old buffer contents is deleted first, then we copy the
3797 spec buffer in here and modify it to make it a body.
3799 This function typically is to be hooked into `ff-file-created-hooks'."
3801 (delete-region (point-min) (point-max))
3802 (insert-buffer (car (cdr (buffer-list))))
3807 (ada-search-ignore-string-comment ada-package-start-regexp))
3808 (progn (goto-char (cdr found))
3810 ;; (forward-line -1)
3811 ;;(comment-region (point-min) (point))
3813 (error "No package"))
3815 ;; (comment-until-proc)
3816 ;; does not work correctly
3817 ;; must be done by hand
3820 (ada-search-ignore-string-comment ada-procedure-start-regexp))
3821 (ada-gen-treat-proc found))))
3828 ;;; ada-mode.el ends here