1 ;;; ada-mode.el - An Emacs major-mode for editing Ada source.
2 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 ;;; Authors: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
5 ;;; Rolf Ebert <ebert@inf.enst.fr>
7 ;;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 ;;; This mode is a complete rewrite of a major mode for editing Ada 83
24 ;;; and Ada 95 source code under Emacs-19. It contains completely new
25 ;;; indenting code and support for code browsing (see ada-xref).
30 ;;; Emacs should enter ada-mode when you load an ada source (*.ad[abs]).
32 ;;; When you have entered ada-mode, you may get more info by pressing
33 ;;; C-h m. You may also get online help describing various functions by:
34 ;;; C-h d <Name of function you want described>
39 ;;; The first Ada mode for GNU Emacs was written by V. Broman in
40 ;;; 1985. He based his work on the already existing Modula-2 mode.
41 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29.
43 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of
44 ;;; several files with support for dired commands and other nice
45 ;;; things. It is currently available from the PAL
46 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z.
48 ;;; The probably very first Ada mode (called electric-ada.el) was
49 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
50 ;;; Gosling Emacs. L. Slater based his development on ada.el and
53 ;;; The current Ada mode is a complete rewrite by M. Heritsch and
54 ;;; R. Ebert. Some ideas from the ada-mode mailing list have been
55 ;;; added. Some of the functionality of L. Slater's mode has not
56 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
63 ;;; In the presence of comments and/or incorrect syntax
64 ;;; ada-format-paramlist produces weird results.
65 ;;; -------------------
66 ;;; Indenting of some tasking constructs is still buggy.
67 ;;; -------------------
69 ;;; -- If I hit return on the "type" line it will indent the next line
70 ;;; -- in another 3 space instead of heading out to the "(". If I hit
71 ;;; -- tab or return it reindents the line correctly but does not initially.
72 ;;; type Wait_Return is (Read_Success, Read_Timeout, Wait_Timeout,
73 ;;; Nothing_To_Wait_For_In_Wait_List);
74 ;;; -------------------
82 ;;; Philippe Warroquiers (PW) <philippe@cfmu.eurocontrol.be> in particular,
83 ;;; woodruff@stc.llnl.gov (John Woodruff)
84 ;;; jj@ddci.dk (Jesper Joergensen)
85 ;;; gse@ocsystems.com (Scott Evans)
86 ;;; comar@LANG8.CS.NYU.EDU (Cyrille Comar)
87 ;;; and others for their valuable hints.
89 ;;;--------------------
91 ;;;--------------------
93 ;; ---- configure indentation
96 "*Defines the size of Ada indentation.")
98 (defvar ada-broken-indent 2
99 "*# of columns to indent the continuation of a broken line.")
101 (defvar ada-label-indent -4
102 "*# of columns to indent a label.")
104 (defvar ada-stmt-end-indent 0
105 "*# of columns to indent a statement end keyword in a separate line.
106 Examples are 'is', 'loop', 'record', ...")
108 (defvar ada-when-indent 3
109 "*Defines the indentation for 'when' relative to 'exception' or 'case'.")
111 (defvar ada-indent-record-rel-type 3
112 "*Defines the indentation for 'record' relative to 'type' or 'use'.")
114 (defvar ada-indent-comment-as-code t
115 "*If non-nil, comment-lines get indented as Ada code.")
117 (defvar ada-indent-is-separate t
118 "*If non-nil, 'is separate' or 'is abstract' on a single line are indented.")
120 (defvar ada-indent-to-open-paren t
121 "*If non-nil, indent according to the innermost open parenthesis.")
123 (defvar ada-search-paren-char-count-limit 3000
124 "*Search that many characters for an open parenthesis.")
127 ;; ---- other user options
129 (defvar ada-tab-policy 'indent-auto
130 "*Control behaviour of the TAB key.
131 Must be one of `indent-rigidly', `indent-auto', `gei', `indent-af'
134 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line.
135 `indent-auto' : use indentation functions in this file.
136 `gei' : use David Kågedal's Generic Indentation Engine.
137 `indent-af' : use Gary E. Barnes' ada-format.el
138 `always-tab' : do indent-relative.")
140 (defvar ada-move-to-declaration nil
141 "*If non-nil, `ada-move-to-start' moves point to the subprog declaration,
144 (defvar ada-spec-suffix ".ads"
145 "*Suffix of Ada specification files.")
147 (defvar ada-body-suffix ".adb"
148 "*Suffix of Ada body files.")
150 (defvar ada-language-version 'ada95
151 "*Do we program in `ada83' or `ada95'?")
153 (defvar ada-case-keyword 'downcase-word
154 "*Function to call to adjust the case of Ada keyworrds.
155 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
158 (defvar ada-case-identifier 'ada-loose-case-word
159 "*Function to call to adjust the case of an Ada identifier.
160 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
163 (defvar ada-case-attribute 'capitalize-word
164 "*Function to call to adjust the case of Ada attributes.
165 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
168 (defvar ada-auto-case t
169 "*Non-nil automatically changes casing of preceeding word while typing.
170 Casing is done according to `ada-case-keyword', `ada-case-identifier'
171 and `ada-cacse-attribute'.")
173 (defvar ada-clean-buffer-before-saving nil
174 "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.")
176 (defvar ada-mode-hook nil
177 "*List of functions to call when Ada Mode is invoked.
178 This is a good place to add Ada environment specific bindings.")
180 (defvar ada-external-pretty-print-program "aimap"
181 "*External pretty printer to call from within Ada Mode.")
183 (defvar ada-tmp-directory "/tmp/"
184 "*Directory to store the temporary file for the Ada pretty printer.")
186 (defvar ada-fill-comment-prefix "-- "
187 "*This is inserted in the first columns when filling a comment paragraph.")
189 (defvar ada-fill-comment-postfix " --"
190 "*This is inserted at the end of each line when filling a comment paragraph.
191 with `ada-fill-comment-paragraph-postfix'.")
193 (defvar ada-krunch-args "0"
194 "*Argument of gnatk8, a string containing the max number of characters.
195 Set to 0, if you dont use crunched filenames.")
197 ;;; ---- end of user configurable variables
200 (defvar ada-mode-abbrev-table nil
201 "Abbrev table used in Ada mode.")
202 (define-abbrev-table 'ada-mode-abbrev-table ())
204 (defvar ada-mode-map ()
205 "Local keymap used for Ada Mode.")
207 (defvar ada-mode-syntax-table nil
208 "Syntax table to be used for editing Ada source code.")
210 (defvar ada-mode-symbol-syntax-table nil
211 "Syntax table for Ada, where `_' is a word constituent.")
213 (defconst ada-83-keywords
214 "\\<\\(abort\\|abs\\|accept\\|access\\|all\\|and\\|array\\|\
215 at\\|begin\\|body\\|case\\|constant\\|declare\\|delay\\|delta\\|\
216 digits\\|do\\|else\\|elsif\\|end\\|entry\\|exception\\|exit\\|for\\|\
217 function\\|generic\\|goto\\|if\\|in\\|is\\|limited\\|loop\\|mod\\|\
218 new\\|not\\|null\\|of\\|or\\|others\\|out\\|package\\|pragma\\|\
219 private\\|procedure\\|raise\\|range\\|record\\|rem\\|renames\\|\
220 return\\|reverse\\|select\\|separate\\|subtype\\|task\\|terminate\\|\
221 then\\|type\\|use\\|when\\|while\\|with\\|xor\\)\\>"
222 ; "\\<\\(a\\(b\\(ort\\|s\\)\\|cce\\(pt\\|ss\\)\\|ll\\|nd\\|rray\\|t\\)\\|\
223 ;b\\(egin\\|ody\\)\\|c\\(ase\\|onstant\\)\\|\
224 ;d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|\
225 ;e\\(ls\\(e\\|if\\)\\|n\\(d\\|try\\)\\|x\\(ception\\|it\\)\\)\\|\
226 ;f\\(or\\|unction\\)\\|g\\(eneric\\|oto\\)\\|i[fns]\\|l\\(imited\\|oop\\)\\|\
227 ;mod\\|n\\(ew\\|ot\\|ull\\)\\|o\\([fr]\\|thers\\|ut\\)\\|\
228 ;p\\(ackage\\|r\\(agma\\|ivate\\|ocedure\\)\\)\\|\
229 ;r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|turn\\|verse\\)\\)\\|\
230 ;s\\(e\\(lect\\|parate\\)\\|ubtype\\)\\|use\\|
231 ;t\\(ask\\|erminate\\|hen\\|ype\\)\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\|xor\\)\\>"
232 "regular expression for looking at Ada83 keywords.")
234 (defconst ada-95-keywords
235 "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\
236 all\\|and\\|array\\|at\\|begin\\|body\\|case\\|constant\\|declare\\|\
237 delay\\|delta\\|digits\\|do\\|else\\|elsif\\|end\\|entry\\|\
238 exception\\|exit\\|for\\|function\\|generic\\|goto\\|if\\|in\\|\
239 is\\|limited\\|loop\\|mod\\|new\\|not\\|null\\|of\\|or\\|others\\|\
240 out\\|package\\|pragma\\|private\\|procedure\\|protected\\|raise\\|\
241 range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\
242 select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\
243 type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>"
244 "regular expression for looking at Ada95 keywords.")
246 (defvar ada-keywords ada-95-keywords
247 "Regular expression for looking at Ada keywords.")
249 (defvar ada-ret-binding nil
250 "Variable to save key binding of RET when casing is activated.")
252 (defvar ada-lfd-binding nil
253 "Variable to save key binding of LFD when casing is activated.")
255 ;;; ---- Regexps to find procedures/functions/packages
257 (defconst ada-ident-re
259 "Regexp matching Ada (qualified) identifiers.")
261 (defvar ada-procedure-start-regexp
262 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\([a-zA-Z0-9_\\.]+\\)"
263 "Regexp used to find Ada procedures/functions.")
265 (defvar ada-package-start-regexp
266 "^[ \t]*\\(package\\)"
267 "Regexp used to find Ada packages")
270 ;;; ---- regexps for indentation functions
272 (defvar ada-block-start-re
273 "\\<\\(begin\\|select\\|declare\\|private\\|or\\|generic\\|\
274 exception\\|loop\\|else\\|\
275 \\(\\(limited\\|abstract\\|tagged\\)[ \t]+\\)*record\\)\\>"
276 "Regexp for keywords starting Ada blocks.")
278 (defvar ada-end-stmt-re
279 "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\
280 \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|\
281 declare\\|generic\\|private\\)\\>\\|\
282 ^[ \t]*\\(package\\|procedure\\|function\\)[ \ta-zA-Z0-9_\\.]+is\\|\
283 ^[ \t]*exception\\>\\)"
284 "Regexp of possible ends for a non-broken statement.
285 A new statement starts after these.")
287 (defvar ada-loop-start-re
288 "\\<\\(for\\|while\\|loop\\)\\>"
289 "Regexp for the start of a loop.")
291 (defvar ada-subprog-start-re
292 "\\<\\(procedure\\|protected\\|package\\|function\\|\
293 task\\|accept\\|entry\\)\\>"
294 "Regexp for the start of a subprogram.")
297 ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com>
299 (defvar ada-imenu-generic-expression
300 '((nil "^\\s-*\\(procedure\\|function\\)\\s-+\\([A-Za-z0-9_]+\\)" 2)
301 ("Type Defs" "^\\s-*\\(sub\\)?type\\s-+\\([A-Za-z0-9_]+\\)" 2))
303 "Imenu generic expression for Ada mode. See `imenu-generic-expression'.")
310 (or (string-match "Lucid" emacs-version)
311 (string-match "XEmacs" emacs-version)))
313 (defun ada-create-syntax-table ()
314 "Create the syntax table for Ada Mode."
315 ;; There are two different syntax-tables. The standard one declares
316 ;; `_' as a symbol constituent, in the second one, it is a word
317 ;; constituent. For some search and replacing routines we
318 ;; temporarily switch between the two.
319 (setq ada-mode-syntax-table (make-syntax-table))
320 (set-syntax-table ada-mode-syntax-table)
322 ;; define string brackets (% is alternative string bracket)
323 (modify-syntax-entry ?% "\"" ada-mode-syntax-table)
324 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
326 (modify-syntax-entry ?\# "$" ada-mode-syntax-table)
328 (modify-syntax-entry ?: "." ada-mode-syntax-table)
329 (modify-syntax-entry ?\; "." ada-mode-syntax-table)
330 (modify-syntax-entry ?& "." ada-mode-syntax-table)
331 (modify-syntax-entry ?\| "." ada-mode-syntax-table)
332 (modify-syntax-entry ?+ "." ada-mode-syntax-table)
333 (modify-syntax-entry ?* "." ada-mode-syntax-table)
334 (modify-syntax-entry ?/ "." ada-mode-syntax-table)
335 (modify-syntax-entry ?= "." ada-mode-syntax-table)
336 (modify-syntax-entry ?< "." ada-mode-syntax-table)
337 (modify-syntax-entry ?> "." ada-mode-syntax-table)
338 (modify-syntax-entry ?$ "." ada-mode-syntax-table)
339 (modify-syntax-entry ?\[ "." ada-mode-syntax-table)
340 (modify-syntax-entry ?\] "." ada-mode-syntax-table)
341 (modify-syntax-entry ?\{ "." ada-mode-syntax-table)
342 (modify-syntax-entry ?\} "." ada-mode-syntax-table)
343 (modify-syntax-entry ?. "." ada-mode-syntax-table)
344 (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
345 (modify-syntax-entry ?\' "." ada-mode-syntax-table)
347 ;; a single hyphen is punctuation, but a double hyphen starts a comment
348 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table)
350 ;; and \f and \n end a comment
351 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
352 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
354 ;; define what belongs in ada symbols
355 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
357 ;; define parentheses to match
358 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
359 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
361 (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table))
362 (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table)
368 "Ada Mode is the major mode for editing Ada code.
370 Bindings are as follows: (Note: 'LFD' is control-j.)
372 Indent line '\\[ada-tab]'
373 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
375 Re-format the parameter-list point is in '\\[ada-format-paramlist]'
376 Indent all lines in region '\\[ada-indent-region]'
377 Call external pretty printer program '\\[ada-call-pretty-printer]'
379 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]'
380 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]'
382 Call EXTERNAL pretty printer (if you have one) '\\[ada-call-pretty-printer]'
384 Fill comment paragraph '\\[ada-fill-comment-paragraph]'
385 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]'
386 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]'
388 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
389 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
391 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
392 Goto end of current block '\\[ada-move-to-end]'
394 Comments are handled using standard GNU Emacs conventions, including:
395 Start a comment '\\[indent-for-comment]'
396 Comment region '\\[comment-region]'
397 Uncomment region '\\[ada-uncomment-region]'
398 Continue comment on next line '\\[indent-new-comment-line]'
401 Display index-menu of functions & procedures '\\[imenu]'
403 If you use find-file.el:
404 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]'
405 or '\\[ff-mouse-find-other-file]
406 Switch to other file in other window '\\[ada-ff-other-window]'
407 or '\\[ff-mouse-find-other-file-other-window]
408 If you use this function in a spec and no body is available, it gets created
411 If you use ada-xref.el:
412 Goto declaration: '\\[ada-point-and-xref]' on the identifier
413 or '\\[ada-goto-declaration]' with point on the identifier
414 Complete identifier: '\\[ada-complete-identifier]'
415 Execute Gnatf: '\\[ada-gnatf-current]'"
418 (kill-all-local-variables)
420 (make-local-variable 'require-final-newline)
421 (setq require-final-newline t)
423 (make-local-variable 'comment-start)
424 (setq comment-start "-- ")
426 ;; comment end must be set because it may hold a wrong value if
427 ;; this buffer had been in another mode before. RE
428 (make-local-variable 'comment-end)
429 (setq comment-end "")
431 (make-local-variable 'comment-start-skip) ;; used by autofill
432 (setq comment-start-skip "--+[ \t]*")
434 (make-local-variable 'indent-line-function)
435 (setq indent-line-function 'ada-indent-current-function)
437 (make-local-variable 'fill-column)
438 (setq fill-column 75)
440 (make-local-variable 'comment-column)
441 (setq comment-column 40)
443 (make-local-variable 'parse-sexp-ignore-comments)
444 (setq parse-sexp-ignore-comments t)
446 (make-local-variable 'case-fold-search)
447 (setq case-fold-search t)
449 (make-local-variable 'fill-paragraph-function)
450 (setq fill-paragraph-function 'ada-fill-comment-paragraph)
452 (make-local-variable 'imenu-generic-expression)
453 (setq imenu-generic-expression ada-imenu-generic-expression)
455 (make-local-variable 'font-lock-defaults)
456 (setq font-lock-defaults '((ada-font-lock-keywords
457 ada-font-lock-keywords-1
458 ada-font-lock-keywords-2)
463 (setq major-mode 'ada-mode)
464 (setq mode-name "Ada")
466 (setq blink-matching-paren t)
468 (use-local-map ada-mode-map)
470 (if ada-mode-syntax-table
471 (set-syntax-table ada-mode-syntax-table)
472 (ada-create-syntax-table))
474 (if ada-clean-buffer-before-saving
476 ;; remove all spaces at the end of lines in the whole buffer.
477 (add-hook 'local-write-file-hooks 'ada-remove-trailing-spaces)
478 ;; convert all tabs to the correct number of spaces.
479 (add-hook 'local-write-file-hooks 'ada-untabify-buffer)))
482 ;; add menu 'Ada' to the menu bar
485 (run-hooks 'ada-mode-hook)
487 ;; the following has to be done after running the ada-mode-hook
488 ;; because users might want to set the values of these variable
489 ;; inside the hook (MH)
491 (cond ((eq ada-language-version 'ada83)
492 (setq ada-keywords ada-83-keywords))
493 ((eq ada-language-version 'ada95)
494 (setq ada-keywords ada-95-keywords)))
497 (ada-activate-keys-for-case)))
500 ;;;--------------------------
501 ;;; Fill Comment Paragraph
502 ;;;--------------------------
504 (defun ada-fill-comment-paragraph-justify ()
505 "Fills current comment paragraph and justifies each line as well."
507 (ada-fill-comment-paragraph t))
510 (defun ada-fill-comment-paragraph-postfix ()
511 "Fills current comment paragraph and justifies each line as well.
512 Prompts for a postfix to be appended to each line."
514 (ada-fill-comment-paragraph t t))
517 (defun ada-fill-comment-paragraph (&optional justify postfix)
518 "Fills the current comment paragraph.
519 If JUSTIFY is non-nil, each line is justified as well.
520 If POSTFIX and JUSTIFY are non-nil, `ada-fill-comment-postfix' is appended
521 to each filled and justified line.
522 If `ada-indent-comment-as-code' is non-nil, the paragraph is idented."
524 (let ((opos (point-marker))
529 (ada-fill-comment-old-postfix "")
532 ;; check if inside comment
533 (if (not (ada-in-comment-p))
534 (error "not inside comment"))
536 ;; prompt for postfix if wanted
539 (setq ada-fill-comment-postfix
540 (read-from-minibuffer "enter new postfix string: "
541 ada-fill-comment-postfix)))
543 ;; prompt for old postfix to remove if necessary
546 (setq ada-fill-comment-old-postfix
547 (read-from-minibuffer "enter already existing postfix string: "
548 ada-fill-comment-postfix)))
551 ;; find limits of paragraph
553 (message "filling comment paragraph ...")
555 (back-to-indentation)
556 ;; find end of paragraph
557 (while (and (looking-at "--.*$")
558 (not (looking-at "--[ \t]*$")))
560 (back-to-indentation))
562 (setq end (point-marker))
564 ;; find begin of paragraph
565 (back-to-indentation)
566 (while (and (looking-at "--.*$")
567 (not (looking-at "--[ \t]*$")))
569 (back-to-indentation))
571 ;; get indentation to calculate width for filling
573 (back-to-indentation)
574 (setq indent (current-column))
575 (setq begin (point-marker)))
577 ;; delete old postfix if necessary
582 (while (re-search-forward (concat ada-fill-comment-old-postfix
585 (replace-match "\n"))))
587 ;; delete leading whitespace and uncomment
591 (while (re-search-forward "^[ \t]*--[ \t]*" end t)
594 ;; calculate fill width
595 (setq fill-column (- fill-column indent
596 (length ada-fill-comment-prefix)
598 (length ada-fill-comment-postfix)
601 (fill-region begin (1- end) justify)
602 (setq fill-column (+ fill-column indent
603 (length ada-fill-comment-prefix)
605 (length ada-fill-comment-postfix)
607 ;; find end of second last line
612 (setq end-2 (point-marker)))
614 ;; re-comment and re-indent region
618 (insert ada-fill-comment-prefix)
619 (while (re-search-forward "\n" (1- end-2) t)
620 (replace-match (concat "\n" ada-fill-comment-prefix))
624 ;; append postfix if wanted
627 ada-fill-comment-postfix)
629 ;; append postfix up to there
632 (while (re-search-forward "\n" (1- end-2) t)
633 (replace-match (concat ada-fill-comment-postfix "\n")))
635 ;; fill last line and append postfix
640 (length ada-fill-comment-postfix)))
641 (insert ada-fill-comment-postfix))))
643 ;; delete the extra line that gets inserted somehow(??)
649 (message "filling comment paragraph ... done")
654 ;;;--------------------------------;;;
655 ;;; Call External Pretty Printer ;;;
656 ;;;--------------------------------;;;
658 (defun ada-call-pretty-printer ()
659 "Calls the external Pretty Printer.
660 The name is specified in `ada-external-pretty-print-program'. Saves the
661 current buffer in a directory specified by `ada-tmp-directory',
662 starts the pretty printer as external process on that file and then
663 reloads the beautyfied program in the buffer and cleans up
664 `ada-tmp-directory'."
666 (let ((filename-with-path buffer-file-name)
667 (curbuf (current-buffer))
669 (mesgbuf nil) ;; for byte-compiling
670 (file-path (file-name-directory buffer-file-name))
671 (filename-without-path (file-name-nondirectory buffer-file-name))
672 (tmp-file-with-directory
673 (concat ada-tmp-directory
674 (file-name-nondirectory buffer-file-name))))
676 ;; save buffer in temporary file
678 (message "saving current buffer to temporary file ...")
679 (write-file tmp-file-with-directory)
681 (message "saving current buffer to temporary file ... done")
683 ;; call external pretty printer program
686 (message "running external pretty printer ...")
687 ;; create a temporary buffer for messages of pretty printer
688 (setq mesgbuf (get-buffer-create "Pretty Printer Messages"))
689 ;; execute pretty printer on temporary file
690 (call-process ada-external-pretty-print-program
692 tmp-file-with-directory)
693 ;; display messages if there are some
694 (if (buffer-modified-p mesgbuf)
695 ;; show the message buffer
696 (display-buffer mesgbuf t)
697 ;; kill the message buffer
698 (kill-buffer mesgbuf))
699 (message "running external pretty printer ... done")
701 ;; kill current buffer and load pretty printer output
702 ;; or restore old buffer
705 "Really replace current buffer with pretty printer output ? ")
707 (set-buffer-modified-p nil)
709 (find-file tmp-file-with-directory))
710 (message "old buffer contents restored"))
712 ;; delete temporary file and restore information of current buffer
714 (delete-file tmp-file-with-directory)
715 (set-visited-file-name filename-with-path)
724 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be>
725 ;; modifiedby RE and MH
727 (defun ada-after-keyword-p ()
728 ;; returns t if cursor is after a keyword.
733 (= (point) (point-min))
735 (not (looking-at "_"))) ; (MH)
736 (looking-at (concat ada-keywords "[^_]")))))
738 (defun ada-after-char-p ()
739 ;; returns t if after ada character "'". This is interpreted as being
740 ;; in a character constant.
749 (defun ada-adjust-case (&optional force-identifier)
750 "Adjust the case of the word before the just typed character.
751 Respect options `ada-case-keyword', `ada-case-identifier', and
752 `ada-case-attribute'.
753 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH)
755 (if (and (> (point) 1) (not (or (ada-in-string-p)
757 (ada-after-char-p))))
758 (if (eq (char-syntax (char-after (1- (point)))) ?w)
761 (or (= (point) (point-min))
764 (funcall ada-case-attribute -1)
766 (not force-identifier) ; (MH)
767 (ada-after-keyword-p))
768 (funcall ada-case-keyword -1)
769 (funcall ada-case-identifier -1)))))
773 (defun ada-adjust-case-interactive (arg)
775 (let ((lastk last-command-char))
776 (cond ((or (eq lastk ?\n)
782 (delete-backward-char 1)
783 ;; some special keys and their bindings
786 (funcall ada-lfd-binding))
788 (funcall ada-ret-binding))))
789 ((eq lastk ?\C-i) (ada-tab))
790 ((self-insert-command (prefix-numeric-value arg))))
791 ;; if there is a keyword in front of the underscore
792 ;; then it should be part of an identifier (MH)
798 (defun ada-activate-keys-for-case ()
799 ;; save original keybindings to allow swapping ret/lfd
800 ;; when casing is activated
801 ;; the 'or ...' is there to be sure that the value will not
802 ;; be changed again when Ada Mode is called more than once (MH)
804 (setq ada-ret-binding (key-binding "\C-M")))
806 (setq ada-lfd-binding (key-binding "\C-j")))
807 ;; call case modifying function after certain keys.
808 (mapcar (function (lambda(key) (define-key
811 'ada-adjust-case-interactive)))
812 '( ?` ?~ ?! ?@ ?# ?$ ?% ?^ ?& ?* ?( ?) ?- ?= ?+ ?[ ?{ ?] ?}
813 ?_ ?\\ ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?? ?/ ?\n 32 ?\r )))
814 ;; deleted ?\t from above list
819 (defun ada-loose-case-word (&optional arg)
820 "Capitalizes the first letter and the letters following `_'.
821 ARG is ignored, it's there to fit the standard casing functions' style."
824 (skip-chars-backward "a-zA-Z0-9_")
826 (search-forward "_" pos t))
829 (insert-char (upcase (following-char)) 1)
837 (defun ada-adjust-case-region (from to)
838 "Adjusts the case of all words in the region.
839 Attention: This function might take very long for big regions !"
847 (set-syntax-table ada-mode-symbol-syntax-table)
850 ;; loop: look for all identifiers and keywords
852 (while (re-search-backward
853 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]"
857 ;; print status message
859 (setq reldiff (- (point) from))
860 (message (format "adjusting case ... %5d characters left"
864 ;; do nothing if it is a string or comment
865 (ada-in-string-or-comment-p)
868 ;; get the identifier or keyword
871 (setq keywordp (looking-at (concat ada-keywords "[^_]")))
872 (skip-chars-forward "a-zA-Z0-9_")
874 ;; casing according to user-option
877 (funcall ada-case-keyword -1)
878 (funcall ada-case-identifier -1))
880 (message "adjusting case ... done"))
881 (set-syntax-table ada-mode-syntax-table))))
887 (defun ada-adjust-case-buffer ()
888 "Adjusts the case of all words in the whole buffer.
889 ATTENTION: This function might take very long for big buffers !"
891 (ada-adjust-case-region (point-min) (point-max)))
894 ;;;------------------------;;;
895 ;;; Format Parameter Lists ;;;
896 ;;;------------------------;;;
898 (defun ada-format-paramlist ()
899 "Reformats a parameter list.
900 ATTENTION: 1) Comments inside the list are killed !
901 2) If the syntax is not correct (especially, if there are
902 semicolons missing), it can get totally confused !
903 In such a case, use `undo', correct the syntax and try again."
912 (set-syntax-table ada-mode-symbol-syntax-table)
914 ;; check if really inside parameter list
915 (or (ada-in-paramlist-p)
916 (error "not in parameter list"))
918 ;; find start of current parameter-list
920 (ada-search-ignore-string-comment
921 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil)
922 (ada-search-ignore-string-comment "(" nil nil t)
927 ;; find end of parameter-list
930 (setq delend (point))
934 ;; find end of last parameter-declaration
936 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
941 ;; build a list of all elements of the parameter-list
943 (setq paramlist (ada-scan-paramlist (1+ begin) end))
946 ;; delete the original parameter-list
948 (delete-region begin (1- delend))
951 ;; insert the new parameter-list
954 (ada-insert-paramlist paramlist))
957 ;; restore syntax-table
959 (set-syntax-table ada-mode-syntax-table)
963 (defun ada-scan-paramlist (begin end)
964 ;; Scans a parameter-list between BEGIN and END and returns a list
966 ;; The list has the following format:
968 ;; Name of Param in? out? access? Name of Type Default-Exp or nil
970 ;; ( ('Name_Param_1' t nil t Type_Param_1 ':= expression')
971 ;; ('Name_Param_2' nil nil t Type_Param_2 nil) )
973 (let ((paramlist (list))
983 ;; loop until end of last parameter
988 ;; find first character of parameter-declaration
990 (ada-goto-next-non-ws)
994 ;; find last character of parameter-declaration
997 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t))
999 (setq epos (car match-cons))
1000 (setq semipos (cdr match-cons)))
1004 ;; read name(s) of parameter(s)
1007 (looking-at "\\([a-zA-Z0-9_, \t\n]*[a-zA-Z0-9_]\\)[ \t\n]*:[^=]")
1009 (setq param (list (buffer-substring (match-beginning 1)
1011 (ada-search-ignore-string-comment ":" nil epos t)
1021 (ada-search-ignore-string-comment "\\<in\\>"
1034 (ada-search-ignore-string-comment "\\<out\\>"
1040 ;; look for 'access'
1047 (ada-search-ignore-string-comment "\\<access\\>"
1053 ;; skip 'in'/'out'/'access'
1056 (ada-goto-next-non-ws)
1057 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>")
1059 (ada-goto-next-non-ws))
1062 ;; read type of parameter
1064 (looking-at "\\<[a-zA-Z0-9_\\.]+\\>")
1068 (buffer-substring (match-beginning 0)
1072 ;; read default-expression, if there is one
1074 (goto-char (setq apos (match-end 0)))
1078 (if (setq match-cons
1079 (ada-search-ignore-string-comment ":="
1083 (buffer-substring (car match-cons)
1087 ;; add this parameter-declaration to the list
1089 (setq paramlist (append paramlist (list param)))
1092 ;; check if it was the last parameter
1096 (goto-char semipos))
1100 (reverse paramlist)))
1103 (defun ada-insert-paramlist (paramlist)
1104 ;; Inserts a formatted PARAMLIST in the buffer.
1105 ;; See doc of `ada-scan-paramlist' for the format.
1106 (let ((i (length paramlist))
1118 ;; loop until last parameter
1120 (while (not (zerop i))
1124 ;; get max length of parameter-name
1127 (if (<= parlen (setq temp
1128 (length (nth 0 (nth i paramlist)))))
1133 ;; get max length of type-name
1136 (if (<= typlen (setq temp
1137 (length (nth 4 (nth i paramlist)))))
1142 ;; is there any 'in' ?
1146 (nth 1 (nth i paramlist))))
1149 ;; is there any 'out' ?
1153 (nth 2 (nth i paramlist))))
1156 ;; is there any 'access' ?
1160 (nth 3 (nth i paramlist))))) ; end of loop
1163 ;; does paramlist already start on a separate line ?
1166 (re-search-backward "^.\\|[^ \t]" nil t)
1168 ;; yes => re-indent it
1169 (ada-indent-current)
1171 ;; no => insert newline and indent it
1174 (ada-indent-current)
1176 (delete-horizontal-space)
1177 (setq orgpoint (point))
1178 (setq column (save-excursion
1179 (funcall (ada-indent-function) orgpoint)))
1185 (setq firstcol (current-column))
1186 (setq i (length paramlist))
1189 ;; loop until last parameter
1191 (while (not (zerop i))
1193 (setq column firstcol)
1196 ;; insert parameter-name, space and colon
1198 (insert (nth 0 (nth i paramlist)))
1199 (indent-to (+ column parlen 1))
1201 (setq column (current-column))
1204 ;; insert 'in' or space
1206 (if (nth 1 (nth i paramlist))
1211 (not (nth 3 (nth i paramlist))))
1215 ;; insert 'out' or space
1217 (if (nth 2 (nth i paramlist))
1222 (not (nth 3 (nth i paramlist))))
1228 (if (nth 3 (nth i paramlist))
1231 (setq column (current-column))
1234 ;; insert type-name and, if necessary, space and default-expression
1236 (insert (nth 4 (nth i paramlist)))
1237 (if (nth 5 (nth i paramlist))
1239 (indent-to (+ column typlen 1))
1240 (insert (nth 5 (nth i paramlist)))))
1243 ;; check if it was the last parameter
1246 ;; no => insert ';' and newline and indent
1250 (indent-to firstcol))
1257 ;; if anything follows, except semicolon:
1258 ;; put it in a new line and indent it
1260 (if (not (looking-at "[ \t]*[;\n]"))
1261 (ada-indent-newline-indent))
1266 ;;;----------------------------;;;
1267 ;;; Move To Matching Start/End ;;;
1268 ;;;----------------------------;;;
1270 (defun ada-move-to-start ()
1271 "Moves point to the matching start of the current Ada structure."
1273 (let ((pos (point)))
1276 (set-syntax-table ada-mode-symbol-syntax-table)
1278 (message "searching for block start ...")
1281 ;; do nothing if in string or comment or not on 'end ...;'
1282 ;; or if an error occurs during processing
1285 (ada-in-string-or-comment-p)
1287 (or (looking-at "[ \t]*\\<end\\>")
1289 (or (looking-at "[ \t]*\\<end\\>")
1291 (or (looking-at "[ \t]*\\<end\\>")
1292 (error "not on end ...;")))
1293 (ada-goto-matching-start 1)
1297 ;; on 'begin' => go on, according to user option
1299 ada-move-to-declaration
1300 (looking-at "\\<begin\\>")
1301 (ada-goto-matching-decl-start)
1302 (setq pos (point))))
1304 ) ; end of save-excursion
1306 ;; now really move to the found position
1308 (message "searching for block start ... done"))
1311 ;; restore syntax-table
1313 (set-syntax-table ada-mode-syntax-table))))
1316 (defun ada-move-to-end ()
1317 "Moves point to the matching end of the current block around point.
1318 Moves to 'begin' if in a declarative part."
1325 (set-syntax-table ada-mode-symbol-syntax-table)
1327 (message "searching for block end ...")
1332 ;; directly on 'begin'
1334 (ada-goto-previous-word)
1335 (looking-at "\\<begin\\>"))
1336 (ada-goto-matching-end 1))
1337 ;; on first line of defun declaration
1339 (and (ada-goto-stmt-start)
1340 (looking-at "\\<function\\>\\|\\<procedure\\>" )))
1341 (ada-search-ignore-string-comment "\\<begin\\>"))
1342 ;; on first line of task declaration
1344 (and (ada-goto-stmt-start)
1345 (looking-at "\\<task\\>" )
1347 (ada-search-ignore-string-comment "[^ \n\t]")
1348 (not (backward-char 1))
1349 (looking-at "\\<body\\>")))
1350 (ada-search-ignore-string-comment "\\<begin\\>"))
1351 ;; accept block start
1353 (and (ada-goto-stmt-start)
1354 (looking-at "\\<accept\\>" )))
1355 (ada-goto-matching-end 0))
1358 (and (ada-goto-matching-decl-start t)
1359 (looking-at "\\<package\\>")))
1360 (ada-goto-matching-end 1))
1361 ;; inside a 'begin' ... 'end' block
1363 (ada-goto-matching-decl-start t))
1364 (ada-search-ignore-string-comment "\\<begin\\>"))
1365 ;; (hopefully ;-) everything else
1367 (ada-goto-matching-end 1)))
1370 ) ; end of save-excursion
1372 ;; now really move to the found position
1374 (message "searching for block end ... done"))
1377 ;; restore syntax-table
1379 (set-syntax-table ada-mode-syntax-table))))
1382 ;;;-----------------------------;;;
1383 ;;; Functions For Indentation ;;;
1384 ;;;-----------------------------;;;
1386 ;; ---- main functions for indentation
1388 (defun ada-indent-region (beg end)
1389 "Indents the region using `ada-indent-current' on each line."
1392 (let ((block-done 0)
1393 (lines-remaining (count-lines beg end))
1394 (msg (format "indenting %4d lines %%4d lines remaining ..."
1395 (count-lines beg end)))
1396 (endmark (copy-marker end)))
1397 ;; catch errors while indenting
1399 (while (< (point) endmark)
1400 (if (> block-done 9)
1401 (progn (message (format msg lines-remaining))
1402 (setq block-done 0)))
1403 (if (looking-at "^$") nil
1404 (ada-indent-current))
1406 (setq block-done (1+ block-done))
1407 (setq lines-remaining (1- lines-remaining)))
1408 ;; show line number where the error occured
1410 (error (format "line %d: %s"
1411 (1+ (count-lines (point-min) (point)))
1413 (message "indenting ... done")))
1416 (defun ada-indent-newline-indent ()
1417 "Indents the current line, inserts a newline and then indents the new line."
1422 (ada-indent-current)
1424 (delete-horizontal-space)
1425 (setq orgpoint (point))
1429 (set-syntax-table ada-mode-symbol-syntax-table)
1431 (setq column (save-excursion
1432 (funcall (ada-indent-function) orgpoint))))
1435 ;; restore syntax-table
1437 (set-syntax-table ada-mode-syntax-table))
1441 ;; The following is needed to ensure that indentation will still be
1442 ;; correct if something follows behind point when typing LFD
1443 ;; For example: Imagine point to be there (*) when LFD is typed:
1446 ;; Result without the following statement would be:
1450 ;; You would then have to type TAB to correct it.
1451 ;; If that doesn't bother you, you can comment out the following
1452 ;; statement to speed up indentation a LITTLE bit.
1454 (if (not (looking-at "[ \t]*$"))
1455 (ada-indent-current))
1459 (defun ada-indent-current ()
1460 "Indents current line as Ada code.
1461 This works by two steps:
1462 1) It moves point to the end of the previous code line.
1463 Then it calls the function to calculate the indentation for the
1464 following line as if a newline would be inserted there.
1465 The calculated column # is saved and the old position of point
1467 2) Then another function is called to calculate the indentation for
1468 the current line, based on the previously calculated column #."
1474 (set-syntax-table ada-mode-symbol-syntax-table)
1477 (orgpoint (point-marker))
1486 (if (ada-goto-prev-nonblank-line t)
1488 ;; we are not in the first accessible line in the buffer
1493 ;; we are already at the BOL
1495 (setq line-end (point))
1498 (funcall (ada-indent-function) line-end))))
1499 (progn ; first line of buffer -> set indent
1500 (beginning-of-line) ; to 0
1501 (delete-horizontal-space)
1502 (setq prevline nil))))
1506 ;; we are not in the first accessible line in the buffer
1512 (back-to-indentation)
1513 (setq cur-indent (ada-get-current-indent prev-indent))
1514 ;; only reindent if indentation is different then the current
1515 (if (= (current-column) cur-indent)
1517 (delete-horizontal-space)
1518 (indent-to cur-indent))
1520 ;; restore position of point
1522 (goto-char orgpoint)
1523 (if (< (current-column) (current-indentation))
1524 (back-to-indentation))))))
1527 ;; restore syntax-table
1529 (set-syntax-table ada-mode-syntax-table)))
1532 (defun ada-get-current-indent (prev-indent)
1533 ;; Returns the column # to indent the current line to.
1534 ;; PREV-INDENT is the indentation resulting from the previous lines.
1541 ;; in open parenthesis, but not in parameter-list
1544 ada-indent-to-open-paren
1545 (not (ada-in-paramlist-p))
1546 (setq column (ada-in-open-paren-p)))
1547 ;; check if we have something like this (Table_Component_Type =>
1548 ;; Source_File_Record,)
1550 (if (and (ada-search-ignore-string-comment "[^ \t]" t nil)
1552 (ada-search-ignore-string-comment "[^ \t\n]" t nil)
1554 (setq column (+ ada-broken-indent column))))
1560 ((looking-at "\\<end\\>")
1562 (ada-goto-matching-start 1)
1565 ;; found 'loop' => skip back to 'while' or 'for'
1566 ;; if 'loop' is not on a separate line
1569 (looking-at "\\<loop\\>")
1571 (back-to-indentation)
1572 (not (looking-at "\\<loop\\>"))))
1576 (ada-search-ignore-string-comment
1577 ada-loop-start-re t nil))
1578 (not (looking-at "\\<loop\\>"))))
1579 (goto-char (car match-cons))))
1581 (current-indentation)))
1585 ((looking-at "\\<exception\\>")
1587 (ada-goto-matching-start 1)
1588 (current-indentation)))
1592 ((looking-at "\\<when\\>")
1594 (ada-goto-matching-start 1)
1595 (+ (current-indentation) ada-when-indent)))
1599 ((looking-at "\\<else\\>")
1601 (ada-goto-previous-word)
1602 (looking-at "\\<or\\>"))
1605 (ada-goto-matching-start 1 nil t)
1606 (current-indentation))))
1610 ((looking-at "\\<elsif\\>")
1612 (ada-goto-matching-start 1 nil t)
1613 (current-indentation)))
1617 ((looking-at "\\<then\\>")
1619 (ada-goto-previous-word)
1620 (looking-at "\\<and\\>"))
1623 (ada-search-ignore-string-comment "\\<elsif\\>\\|\\<if\\>" t nil)
1624 (+ (current-indentation) ada-stmt-end-indent))))
1628 ((looking-at "\\<loop\\>")
1631 (goto-char (match-end 0))
1632 (ada-goto-stmt-start)
1633 (if (looking-at "\\<loop\\>\\|\\<if\\>")
1636 (if (not (looking-at ada-loop-start-re))
1637 (ada-search-ignore-string-comment ada-loop-start-re
1639 (if (looking-at "\\<loop\\>")
1641 (+ (current-indentation) ada-stmt-end-indent))))))
1645 ((looking-at "\\<begin\\>")
1647 (if (ada-goto-matching-decl-start t)
1648 (current-indentation)
1650 (message "no matching declaration start")
1655 ((looking-at "\\<is\\>")
1657 ada-indent-is-separate
1659 (goto-char (match-end 0))
1660 (ada-goto-next-non-ws (save-excursion
1663 (looking-at "\\<abstract\\>\\|\\<separate\\>")))
1665 (ada-goto-stmt-start)
1666 (+ (current-indentation) ada-indent))
1668 (ada-goto-stmt-start)
1669 (+ (current-indentation) ada-stmt-end-indent))))
1673 ((looking-at "\\<record\\>")
1675 (ada-search-ignore-string-comment
1676 "\\<\\(type\\|use\\)\\>" t nil)
1677 (if (looking-at "\\<use\\>")
1678 (ada-search-ignore-string-comment "\\<for\\>" t nil))
1679 (+ (current-indentation) ada-indent-record-rel-type)))
1681 ;; or as statement-start
1683 ((ada-looking-at-semi-or)
1685 (ada-goto-matching-start 1)
1686 (current-indentation)))
1688 ;; private as statement-start
1690 ((ada-looking-at-semi-private)
1692 (ada-goto-matching-decl-start)
1693 (current-indentation)))
1695 ;; new/abstract/separate
1697 ((looking-at "\\<\\(new\\|abstract\\|separate\\)\\>")
1698 (- prev-indent ada-indent (- ada-broken-indent)))
1702 ((looking-at "\\<return\\>")
1705 (if (and (looking-at "(")
1708 (looking-at "\\<function\\>")))
1709 (1+ (current-column))
1714 ((looking-at "\\<do\\>")
1716 (ada-goto-stmt-start)
1717 (+ (current-indentation) ada-stmt-end-indent)))
1719 ;; package/function/procedure
1721 ((and (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")
1724 (ada-goto-stmt-start)
1725 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")))
1727 ;; look for 'generic'
1728 (if (and (ada-goto-matching-decl-start t)
1729 (looking-at "generic"))
1735 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*:[^=]")
1738 (+ prev-indent ada-label-indent)))
1740 ;; identifier and other noindent-statements
1742 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*")
1745 ;; beginning of a parameter list
1750 ;; end of a parameter list
1761 (if ada-indent-comment-as-code
1763 (current-indentation)))
1765 ;; unknown syntax - maybe this should signal an error ?
1771 (defun ada-indent-function (&optional nomove)
1772 ;; Returns the function to calculate the indentation for the current
1773 ;; line according to the previous statement, ignoring the contents
1774 ;; of the current line after point. Moves point to the beginning of
1775 ;; the current statement, if NOMOVE is nil.
1777 (let ((orgpoint (point))
1781 ;; inside a parameter-list
1783 (if (ada-in-paramlist-p)
1784 (setq func 'ada-get-indent-paramlist)
1787 ;; move to beginning of current statement
1790 (setq stmt-start (ada-goto-stmt-start)))
1792 ;; no beginning found => don't change indentation
1795 (eq orgpoint (point))
1797 (setq func 'ada-get-indent-nochange)
1802 ada-indent-to-open-paren
1803 (ada-in-open-paren-p))
1804 (setq func 'ada-get-indent-open-paren))
1806 ((looking-at "\\<end\\>")
1807 (setq func 'ada-get-indent-end))
1809 ((looking-at ada-loop-start-re)
1810 (setq func 'ada-get-indent-loop))
1812 ((looking-at ada-subprog-start-re)
1813 (setq func 'ada-get-indent-subprog))
1815 ((looking-at "\\<package\\>")
1816 (setq func 'ada-get-indent-subprog)) ; maybe it needs a
1820 ((looking-at ada-block-start-re)
1821 (setq func 'ada-get-indent-block-start))
1823 ((looking-at "\\<type\\>")
1824 (setq func 'ada-get-indent-type))
1826 ((looking-at "\\<\\(els\\)?if\\>")
1827 (setq func 'ada-get-indent-if))
1829 ((looking-at "\\<case\\>")
1830 (setq func 'ada-get-indent-case))
1832 ((looking-at "\\<when\\>")
1833 (setq func 'ada-get-indent-when))
1836 (setq func 'ada-get-indent-comment))
1838 ((looking-at "[a-zA-Z0-9_]+[ \t\n]*:[^=]")
1839 (setq func 'ada-get-indent-label))
1841 ((looking-at "\\<separate\\>")
1842 (setq func 'ada-get-indent-nochange))
1844 (setq func 'ada-get-indent-noindent))))))
1849 ;; ---- functions to return indentation for special cases
1851 (defun ada-get-indent-open-paren (orgpoint)
1852 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1853 ;; Assumes point to be behind an open paranthesis not yet closed.
1854 (ada-in-open-paren-p))
1857 (defun ada-get-indent-nochange (orgpoint)
1858 ;; Returns the indentation (column #) of the current line.
1861 (current-indentation)))
1864 (defun ada-get-indent-paramlist (orgpoint)
1865 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1866 ;; Assumes point to be inside a parameter-list.
1868 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
1871 ;; in front of the first parameter
1874 (goto-char (match-end 0))
1877 ;; in front of another parameter
1880 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
1881 (ada-goto-next-non-ws)
1884 ;; inside a parameter declaration
1887 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
1888 (ada-goto-next-non-ws)
1889 (+ (current-column) ada-broken-indent)))))
1892 (defun ada-get-indent-end (orgpoint)
1893 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1894 ;; Assumes point to be at the beginning of an end-statement.
1895 ;; Therefore it has to find the corresponding start. This can be a little
1896 ;; slow, if it has to search through big files with many nested blocks.
1897 ;; Signals an error if the corresponding block-start doesn't match.
1898 (let ((defun-name nil)
1901 ;; is the line already terminated by ';' ?
1904 (ada-search-ignore-string-comment ";" nil orgpoint))
1906 ;; yes, look what's following 'end'
1910 (ada-goto-next-non-ws)
1913 ;; loop/select/if/case/record/select
1915 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\|record\\)\\>")
1917 (ada-check-matching-start
1918 (buffer-substring (match-beginning 0)
1920 (if (looking-at "\\<\\(loop\\|record\\)\\>")
1923 (ada-goto-stmt-start)))
1924 ;; a label ? => skip it
1925 (if (looking-at "[a-zA-Z0-9_]+[ \n\t]+:")
1927 (goto-char (match-end 0))
1928 (ada-goto-next-non-ws)))
1929 ;; really looking-at the right thing ?
1930 (or (looking-at (concat "\\<\\("
1931 "loop\\|select\\|if\\|case\\|"
1932 "record\\|while\\|type\\)\\>"))
1934 (ada-search-ignore-string-comment
1936 "loop\\|select\\|if\\|case\\|"
1937 "record\\|while\\|type\\)\\>")))
1939 (current-indentation)))
1941 ;; a named block end
1943 ((looking-at ada-ident-re)
1944 (setq defun-name (buffer-substring (match-beginning 0)
1947 (ada-goto-matching-start 0)
1948 (ada-check-defun-name defun-name)
1949 (current-indentation)))
1951 ;; a block-end without name
1955 (ada-goto-matching-start 0)
1956 (if (looking-at "\\<begin\\>")
1958 (setq indent (current-column))
1959 (if (ada-goto-matching-decl-start t)
1960 (current-indentation)
1963 ;; anything else - should maybe signal an error ?
1966 (+ (current-indentation) ada-broken-indent))))
1968 (+ (current-indentation) ada-broken-indent))))
1971 (defun ada-get-indent-case (orgpoint)
1972 ;; Returns the indentation (column #) for the new line after ORGPOINT.
1973 ;; Assumes point to be at the beginning of an case-statement.
1974 (let ((cur-indent (current-indentation))
1979 ;; case..is..when..=>
1982 (setq match-cons (ada-search-ignore-string-comment
1983 "[ \t\n]+=>" nil orgpoint)))
1985 (goto-char (car match-cons))
1986 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos))
1987 (error "missing 'when' between 'case' and '=>'"))
1988 (+ (current-indentation) ada-indent)))
1993 (setq match-cons (ada-search-ignore-string-comment
1994 "\\<when\\>" nil orgpoint)))
1995 (goto-char (cdr match-cons))
1996 (+ (current-indentation) ada-broken-indent))
2001 (setq match-cons (ada-search-ignore-string-comment
2002 "\\<is\\>" nil orgpoint)))
2003 (+ (current-indentation) ada-when-indent))
2008 (+ (current-indentation) ada-broken-indent)))))
2011 (defun ada-get-indent-when (orgpoint)
2012 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2013 ;; Assumes point to be at the beginning of an when-statement.
2014 (let ((cur-indent (current-indentation)))
2015 (if (ada-search-ignore-string-comment
2016 "[ \t\n]+=>" nil orgpoint)
2017 (+ cur-indent ada-indent)
2018 (+ cur-indent ada-broken-indent))))
2021 (defun ada-get-indent-if (orgpoint)
2022 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2023 ;; Assumes point to be at the beginning of an if-statement.
2024 (let ((cur-indent (current-indentation))
2029 (if (ada-search-but-not
2030 "\\<then\\>" "\\<and\\>[ \t\n]+\\<then\\>" nil orgpoint)
2034 ;; 'then' first in separate line ?
2035 ;; => indent according to 'then'
2038 (back-to-indentation)
2039 (looking-at "\\<then\\>"))
2040 (setq cur-indent (current-indentation)))
2043 ;; something follows 'then' ?
2045 (if (setq match-cons
2046 (ada-search-ignore-string-comment
2047 "[^ \t\n]" nil orgpoint))
2049 (goto-char (car match-cons))
2051 (- cur-indent (current-indentation))
2052 (funcall (ada-indent-function t) orgpoint)))
2054 (+ cur-indent ada-indent)))
2056 (+ cur-indent ada-broken-indent))))
2059 (defun ada-get-indent-block-start (orgpoint)
2060 ;; Returns the indentation (column #) for the new line after
2061 ;; ORGPOINT. Assumes point to be at the beginning of a block start
2063 (let ((cur-indent (current-indentation))
2068 (setq pos (car (ada-search-ignore-string-comment
2069 "[^ \t\n]" nil orgpoint))))
2072 (funcall (ada-indent-function t) orgpoint)))
2074 ;; nothing follows the block-start
2077 (+ (current-indentation) ada-indent)))))
2080 (defun ada-get-indent-subprog (orgpoint)
2081 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2082 ;; Assumes point to be at the beginning of a subprog-/package-declaration.
2083 (let ((match-cons nil)
2084 (cur-indent (current-indentation))
2089 ;; is there an 'is' in front of point ?
2093 (ada-search-ignore-string-comment
2094 "\\<is\\>\\|\\<do\\>" nil orgpoint)))
2096 ;; yes, then skip to its end
2100 (goto-char (cdr match-cons)))
2102 ;; no, then goto next non-ws, if there is one in front of point
2105 (if (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)
2106 (ada-goto-next-non-ws)
2107 (goto-char orgpoint))))
2111 ;; nothing follows 'is'
2116 (not (ada-search-ignore-string-comment
2117 "[^ \t\n]" nil orgpoint t))))
2118 (+ cur-indent ada-indent))
2120 ;; is abstract/separate/new ...
2126 (ada-search-ignore-string-comment
2127 "\\<\\(separate\\|new\\|abstract\\)\\>"
2129 (goto-char (car match-cons))
2130 (ada-search-ignore-string-comment ada-subprog-start-re t)
2131 (ada-get-indent-noindent orgpoint))
2133 ;; something follows 'is'
2138 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
2139 (ada-goto-next-non-ws)
2140 (funcall (ada-indent-function t) orgpoint)))
2145 (ada-search-ignore-string-comment ";" nil orgpoint))
2151 (+ cur-indent ada-broken-indent)))))
2154 (defun ada-get-indent-noindent (orgpoint)
2155 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2156 ;; Assumes point to be at the beginning of a 'noindent statement'.
2158 (ada-search-ignore-string-comment ";" nil orgpoint))
2159 (current-indentation)
2160 (+ (current-indentation) ada-broken-indent)))
2163 (defun ada-get-indent-label (orgpoint)
2164 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2165 ;; Assumes point to be at the beginning of a label or variable declaration.
2166 ;; Checks the context to decide if it's a label or a variable declaration.
2167 ;; This check might be a bit slow.
2168 (let ((match-cons nil)
2169 (cur-indent (current-indentation)))
2170 (goto-char (cdr (ada-search-ignore-string-comment ":")))
2176 (setq match-cons (ada-search-ignore-string-comment
2177 ada-loop-start-re nil orgpoint)))
2178 (goto-char (car match-cons))
2179 (ada-get-indent-loop orgpoint))
2184 (setq match-cons (ada-search-ignore-string-comment
2185 "\\<declare\\>" nil orgpoint)))
2187 (goto-char (car match-cons))
2188 (+ (current-indentation) ada-indent)))
2190 ;; complete statement following colon
2193 (ada-search-ignore-string-comment ";" nil orgpoint))
2195 cur-indent ; variable-declaration
2196 (- cur-indent ada-label-indent))) ; label
2201 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
2203 (+ cur-indent ada-broken-indent)
2204 (+ cur-indent ada-broken-indent (- ada-label-indent))))
2206 ;; nothing follows colon
2210 (+ cur-indent ada-broken-indent) ; variable-declaration
2211 (- cur-indent ada-label-indent)))))) ; label
2214 (defun ada-get-indent-loop (orgpoint)
2215 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2216 ;; Assumes point to be at the beginning of a loop statement
2217 ;; or (unfortunately) also a for ... use statement.
2218 (let ((match-cons nil)
2223 ;; statement complete
2226 (ada-search-ignore-string-comment ";" nil orgpoint))
2227 (current-indentation))
2231 ((looking-at "loop\\>")
2232 (ada-get-indent-block-start orgpoint))
2235 ;; 'for'- loop (or also a for ... use statement)
2237 ((looking-at "for\\>")
2244 (goto-char (match-end 0))
2245 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
2246 (not (backward-char 1))
2247 (not (zerop (skip-chars-forward "_a-zA-Z0-9'")))
2248 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
2249 (not (backward-char 1))
2250 (looking-at "\\<use\\>")
2252 ;; check if there is a 'record' before point
2255 (setq match-cons (ada-search-ignore-string-comment
2256 "\\<record\\>" nil orgpoint))
2259 (goto-char (car match-cons)))
2260 (+ (current-indentation) ada-indent))
2265 (setq match-cons (ada-search-ignore-string-comment
2266 "\\<loop\\>" nil orgpoint)))
2267 (goto-char (car match-cons))
2269 ;; indent according to 'loop', if it's first in the line;
2270 ;; otherwise to 'for'
2272 (if (not (save-excursion
2273 (back-to-indentation)
2274 (looking-at "\\<loop\\>")))
2276 (+ (current-indentation) ada-indent))
2278 ;; for-statement is broken
2281 (+ (current-indentation) ada-broken-indent))))
2286 ((looking-at "while\\>")
2291 (setq match-cons (ada-search-ignore-string-comment
2292 "\\<loop\\>" nil orgpoint)))
2295 (goto-char (car match-cons))
2297 ;; indent according to 'loop', if it's first in the line;
2298 ;; otherwise to 'while'.
2300 (if (not (save-excursion
2301 (back-to-indentation)
2302 (looking-at "\\<loop\\>")))
2304 (+ (current-indentation) ada-indent))
2306 (+ (current-indentation) ada-broken-indent))))))
2309 (defun ada-get-indent-type (orgpoint)
2310 ;; Returns the indentation (column #) for the new line after ORGPOINT.
2311 ;; Assumes point to be at the beginning of a type statement.
2312 (let ((match-dat nil))
2315 ;; complete record declaration
2319 (setq match-dat (ada-search-ignore-string-comment "\\<end\\>"
2322 (ada-goto-next-non-ws)
2323 (looking-at "\\<record\\>")
2325 (ada-goto-next-non-ws)
2327 (goto-char (car match-dat))
2328 (current-indentation))
2333 (setq match-dat (ada-search-ignore-string-comment "\\<record\\>"
2336 (goto-char (car match-dat))
2337 (+ (current-indentation) ada-indent))
2339 ;; complete type declaration
2342 (ada-search-ignore-string-comment ";" nil orgpoint))
2343 (current-indentation))
2345 ;; "type ... is", but not "type ... is ...", which is broken
2349 (ada-search-ignore-string-comment "\\<is\\>" nil orgpoint)
2350 (not (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))))
2351 (+ (current-indentation) ada-indent))
2356 (+ (current-indentation) ada-broken-indent)))))
2359 ;;; ---- support-functions for indentation
2361 ;;; ---- searching and matching
2363 (defun ada-goto-stmt-start (&optional limit)
2364 ;; Moves point to the beginning of the statement that point is in or
2365 ;; after. Returns the new position of point. Beginnings are found
2366 ;; by searching for 'ada-end-stmt-re' and then moving to the
2367 ;; following non-ws that is not a comment. LIMIT is actually not
2368 ;; used by the indentation functions.
2369 (let ((match-dat nil)
2372 (setq match-dat (ada-search-prev-end-stmt limit))
2375 ;; found a previous end-statement => check if anything follows
2380 (goto-char (cdr match-dat))
2381 (ada-search-ignore-string-comment
2382 "[^ \t\n]" nil orgpoint)))
2384 ;; nothing follows => it's the end-statement directly in
2385 ;; front of point => search again
2387 (setq match-dat (ada-search-prev-end-stmt limit)))
2389 ;; if found the correct end-stetement => goto next non-ws
2392 (goto-char (cdr match-dat)))
2393 (ada-goto-next-non-ws))
2396 ;; no previous end-statement => we are at the beginning of the
2397 ;; accessible part of the buffer
2400 (goto-char (point-min))
2402 ;; skip to the very first statement, if there is one
2405 (ada-search-ignore-string-comment
2406 "[^ \t\n]" nil orgpoint))
2407 (goto-char (car match-dat))
2408 (goto-char orgpoint))))
2414 (defun ada-search-prev-end-stmt (&optional limit)
2415 ;; Moves point to previous end-statement. Returns a cons cell whose
2416 ;; car is the beginning and whose cdr the end of the match.
2417 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for
2418 ;; certain keywords if they follow 'end', which means they are no
2419 ;; end-statement there.
2420 (interactive) ;; DEBUG
2421 (let ((match-dat nil)
2425 ;; search until found or beginning-of-buffer
2430 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re
2434 (goto-char (car match-dat))
2436 (if (not (ada-in-open-paren-p))
2438 ;; check if there is an 'end' in front of the match
2441 (looking-at "\\<\\(record\\|loop\\|select\\)\\>")
2443 (ada-goto-previous-word)
2444 (looking-at "\\<end\\>"))))
2447 (forward-word -1)))) ; end of loop
2454 (defun ada-goto-next-non-ws (&optional limit)
2455 ;; Skips whitespaces, newlines and comments to next non-ws
2456 ;; character. Signals an error if there is no more such character
2457 ;; and limit is nil.
2458 (let ((match-cons nil))
2459 (setq match-cons (ada-search-ignore-string-comment
2460 "[^ \t\n]" nil limit t))
2462 (goto-char (car match-cons))
2464 (error "no more non-ws")
2468 (defun ada-goto-stmt-end (&optional limit)
2469 ;; Moves point to the end of the statement that point is in or
2470 ;; before. Returns the new position of point or nil if not found.
2471 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
2476 (defun ada-goto-previous-word ()
2477 ;; Moves point to the beginning of the previous word of Ada code.
2478 ;; Returns the new position of point or nil if not found.
2479 (let ((match-cons nil)
2481 (if (setq match-cons
2482 (ada-search-ignore-string-comment "[^ \t\n]" t nil t))
2484 ;; move to the beginning of the word found
2487 (goto-char (cdr match-cons))
2488 (skip-chars-backward "_a-zA-Z0-9")
2491 ;; if not found, restore old position of point
2494 (goto-char orgpoint)
2498 (defun ada-check-matching-start (keyword)
2499 ;; Signals an error if matching block start is not KEYWORD.
2500 ;; Moves point to the matching block start.
2501 (ada-goto-matching-start 0)
2502 (if (not (looking-at (concat "\\<" keyword "\\>")))
2504 "matching start is not '"
2508 (defun ada-check-defun-name (defun-name)
2509 ;; Checks if the name of the matching defun really is DEFUN-NAME.
2510 ;; Assumes point to be already positioned by 'ada-goto-matching-start'.
2511 ;; Moves point to the beginning of the declaration.
2514 ;; 'accept' or 'package' ?
2516 (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>"))
2517 (ada-goto-matching-decl-start))
2519 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
2523 ;; a named 'declare'-block ?
2525 (if (looking-at "\\<declare\\>")
2526 (ada-goto-stmt-start)
2528 ;; no, => 'procedure'/'function'/'task'/'protected'
2534 ;; skip 'body' 'protected' 'type'
2536 (if (looking-at "\\<\\(body\\|type\\)\\>")
2541 ;; should be looking-at the correct name
2543 (if (not (looking-at (concat "\\<" defun-name "\\>")))
2546 "matching defun has different name: "
2554 (defun ada-goto-matching-decl-start (&optional noerror nogeneric)
2555 ;; Moves point to the matching declaration start of the current 'begin'.
2556 ;; If NOERROR is non-nil, it only returns nil if no match was found.
2557 (interactive) ;; DEBUG
2558 (let ((nest-count 1)
2563 ;; search backward for interesting keywords
2566 (not (zerop nest-count))
2567 (ada-search-ignore-string-comment
2569 "is\\|separate\\|end\\|declare\\|new\\|begin\\|generic"
2572 ;; calculate nest-depth
2577 (ada-goto-matching-start 1 noerror)
2578 (if (looking-at "begin")
2579 (setq nest-count (1+ nest-count))))
2581 ((looking-at "declare\\|generic")
2582 (setq nest-count (1- nest-count))
2586 ;; check if it is only a type definition, but not a protected
2587 ;; type definition, which should be handled like a procedure.
2589 (ada-goto-previous-word)
2590 (skip-chars-backward "a-zA-Z0-9_.'")
2597 (skip-chars-backward "a-zA-Z0-9_.'")
2599 (ada-goto-previous-word)
2601 (looking-at "\\<type\\>")
2603 (ada-goto-previous-word)
2604 (not (looking-at "\\<protected\\>"))))
2605 ); end of save-excursion
2606 (goto-char (match-beginning 0))
2608 (setq nest-count (1- nest-count))
2614 (ada-goto-previous-word)
2616 (goto-char (match-beginning 0))))
2619 (looking-at "begin"))
2624 (setq nest-count (1+ nest-count))
2629 ;; check if declaration-start is really found
2635 (if (looking-at "is")
2636 (ada-search-ignore-string-comment
2637 ada-subprog-start-re t)
2638 (looking-at "declare\\|generic")))))
2640 (error "no matching proc/func/task/declare/package/protected"))
2644 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
2645 ;; Moves point to the beginning of a block-start. Which block
2646 ;; depends on the value of NEST-LEVEL, which defaults to zero. If
2647 ;; NOERROR is non-nil, it only returns nil if no matching start was
2648 ;; found. If GOTOTHEN is non-nil, point moves to the 'then'
2650 (let ((nest-count (if nest-level nest-level 0))
2655 ;; search backward for interesting keywords
2659 (ada-search-ignore-string-comment
2661 "end\\|loop\\|select\\|begin\\|case\\|do\\|"
2662 "if\\|task\\|package\\|record\\|protected\\)\\>")
2666 ;; calculate nest-depth
2669 ;; found block end => increase nest depth
2671 (setq nest-count (1+ nest-count)))
2672 ;; found loop/select/record/case/if => check if it starts or
2674 ((looking-at "loop\\|select\\|record\\|case\\|if")
2678 ;; check if keyword follows 'end'
2680 (ada-goto-previous-word)
2681 (if (looking-at "\\<end\\>")
2682 ;; it ends a block => increase nest depth
2684 (setq nest-count (1+ nest-count))
2686 ;; it starts a block => decrease nest depth
2687 (setq nest-count (1- nest-count))))
2689 ;; found package start => check if it really is a block
2690 ((looking-at "package")
2692 (ada-search-ignore-string-comment "\\<is\\>")
2693 (ada-goto-next-non-ws)
2694 ;; ignore it if it is only a declaration with 'new'
2695 (if (not (looking-at "\\<new\\>"))
2696 (setq nest-count (1- nest-count)))))
2697 ;; found task start => check if it has a body
2698 ((looking-at "task")
2701 (ada-goto-next-non-ws)
2702 ;; ignore it if it has no body
2703 (if (not (looking-at "\\<body\\>"))
2704 (setq nest-count (1- nest-count)))))
2705 ;; all the other block starts
2707 (setq nest-count (1- nest-count)))) ; end of 'cond'
2709 ;; match is found, if nest-depth is zero
2711 (setq found (zerop nest-count))) ; end of loop
2715 ;; match found => is there anything else to do ?
2720 ;; found 'if' => skip to 'then', if it's on a separate line
2721 ;; and GOTOTHEN is non-nil
2727 (ada-search-ignore-string-comment "\\<then\\>" nil nil)
2728 (back-to-indentation)
2729 (looking-at "\\<then\\>")))
2730 (goto-char (match-beginning 0)))
2732 ;; found 'do' => skip back to 'accept'
2735 (if (not (ada-search-ignore-string-comment "\\<accept\\>" t nil))
2736 (error "missing 'accept' in front of 'do'"))))
2741 (error "no matching start")))))
2744 (defun ada-goto-matching-end (&optional nest-level noerror)
2745 ;; Moves point to the end of a block. Which block depends on the
2746 ;; value of NEST-LEVEL, which defaults to zero. If NOERROR is
2747 ;; non-nil, it only returns nil if found no matching start.
2748 (let ((nest-count (if nest-level nest-level 0))
2752 ;; search forward for interesting keywords
2756 (ada-search-ignore-string-comment
2757 (concat "\\<\\(end\\|loop\\|select\\|begin\\|case\\|"
2758 "if\\|task\\|package\\|record\\|do\\)\\>")))
2761 ;; calculate nest-depth
2765 ;; found block end => decrease nest depth
2766 ((looking-at "\\<end\\>")
2767 (setq nest-count (1- nest-count))
2768 ;; skip the following keyword
2770 (skip-chars-forward "end")
2771 (ada-goto-next-non-ws)
2772 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>"))
2774 ;; found package start => check if it really starts a block
2775 ((looking-at "\\<package\\>")
2776 (ada-search-ignore-string-comment "\\<is\\>")
2777 (ada-goto-next-non-ws)
2778 ;; ignore and skip it if it is only a 'new' package
2779 (if (not (looking-at "\\<new\\>"))
2780 (setq nest-count (1+ nest-count))
2781 (skip-chars-forward "new")))
2782 ;; all the other block starts
2784 (setq nest-count (1+ nest-count))
2785 (forward-word 1))) ; end of 'cond'
2787 ;; match is found, if nest-depth is zero
2789 (setq found (zerop nest-count))) ; end of loop
2794 (error "no matching end"))
2798 (defun ada-forward-sexp-ignore-comment ()
2799 ;; Skips one sexp forward, ignoring comments.
2800 (while (looking-at "[ \t\n]*--")
2801 (skip-chars-forward "[ \t\n]")
2806 (defun ada-search-ignore-string-comment
2807 (search-re &optional backward limit paramlists)
2808 ;; Regexp-Search for SEARCH-RE, ignoring comments, strings and
2809 ;; parameter lists, if PARAMLISTS is nil. Returns a cons cell of
2810 ;; begin and end of match data or nil, if not found.
2816 (if backward 're-search-backward
2817 're-search-forward)))
2820 ;; search until found or end-of-buffer
2822 (while (and (not found)
2823 (funcall search-func search-re limit 1))
2824 (setq begin (match-beginning 0))
2825 (setq end (match-end 0))
2829 ;; found in comment => skip it
2834 (re-search-backward "--" nil 1)
2835 (goto-char (match-beginning 0)))
2838 (beginning-of-line))))
2840 ;; found in string => skip it
2845 (re-search-backward "\"" nil 1) ; "\"\\|#" don't treat #
2846 (goto-char (match-beginning 0))))
2847 (re-search-forward "\"" nil 1))
2849 ;; found character constant => ignore it
2852 (setq pos (- (point) (if backward 1 2)))
2853 (and (char-after pos)
2854 (= (char-after pos) ?')
2855 (= (char-after (+ pos 2)) ?')))
2858 ;; found a parameter-list but should ignore it => skip it
2860 ((and (not paramlists)
2861 (ada-in-paramlist-p))
2863 (ada-search-ignore-string-comment "(" t nil t)))
2865 ;; directly in front of a comment => skip it, if searching forward
2873 (beginning-of-line))))
2875 ;; found what we were looking for
2878 (setq found t)))) ; end of loop
2885 (defun ada-search-but-not (search-re not-search-re &optional backward limit)
2886 ;; Searches SEARCH-RE, ignoring parts of NOT-SEARCH-RE, strings,
2887 ;; comments and parameter-lists.
2897 ;; search until found or end-of-buffer
2903 (ada-search-ignore-string-comment search-re
2905 (if (consp ret-cons)
2907 (setq begin (car ret-cons))
2908 (setq end (cdr ret-cons))
2914 ;; if no NO-SEARCH-RE was found
2919 (ada-search-ignore-string-comment not-search-re
2921 (if (consp ret-cons)
2923 (setq begin-not (car ret-cons))
2924 (setq end-not (cdr ret-cons))
2928 ;; or this NO-SEARCH-RE is not a part of the SEARCH-RE
2933 (>= begin-not end)))
2938 ;; not found the correct match => skip this match
2940 (goto-char (if backward
2942 end)))) ; end of loop
2951 (defun ada-goto-prev-nonblank-line ( &optional ignore-comment)
2952 ;; Moves point to the beginning of previous non-blank line,
2953 ;; ignoring comments if IGNORE-COMMENT is non-nil.
2954 ;; It returns t if a matching line was found.
2960 ;; backward one line, if there is one
2962 (if (zerop (forward-line -1))
2964 ;; there is some kind of previous line
2968 (setq newpoint (point))
2971 ;; search until found or beginning-of-buffer
2973 (while (and (setq notfound
2974 (or (looking-at "[ \t]*$")
2975 (and (looking-at "[ \t]*--")
2977 (not (ada-in-limit-line-p)))
2979 ;;(beginning-of-line)
2980 (setq newpoint (point))) ; end of loop
2984 ) ; end of save-excursion
2988 (goto-char newpoint)
2992 (defun ada-goto-next-nonblank-line ( &optional ignore-comment)
2993 ;; Moves point to next non-blank line,
2994 ;; ignoring comments if IGNORE-COMMENT is non-nil.
2995 ;; It returns t if a matching line was found.
3003 (if (zerop (forward-line 1))
3005 ;; there is some kind of previous line
3009 (setq newpoint (point))
3012 ;; search until found or end-of-buffer
3014 (while (and (setq notfound
3015 (or (looking-at "[ \t]*$")
3016 (and (looking-at "[ \t]*--")
3018 (not (ada-in-limit-line-p)))
3021 (setq newpoint (point))) ; end of loop
3025 ) ; end of save-excursion
3029 (goto-char newpoint)
3033 ;; ---- boolean functions for indentation
3035 (defun ada-in-decl-p ()
3036 ;; Returns t if point is inside a declarative part.
3037 ;; Assumes point to be at the end of a statement.
3039 (ada-in-paramlist-p)
3041 (ada-goto-matching-decl-start t))))
3044 (defun ada-looking-at-semi-or ()
3045 ;; Returns t if looking-at an 'or' following a semicolon.
3047 (and (looking-at "\\<or\\>")
3050 (ada-goto-stmt-start)
3051 (looking-at "\\<or\\>")))))
3054 (defun ada-looking-at-semi-private ()
3055 ;; Returns t if looking-at an 'private' following a semicolon.
3057 (and (looking-at "\\<private\\>")
3060 (ada-goto-stmt-start)
3061 (looking-at "\\<private\\>")))))
3064 ;;; make a faster??? ada-in-limit-line-p not using count-lines
3065 (defun ada-in-limit-line-p ()
3066 ;; return t if point is in first or last accessible line.
3067 (or (save-excursion (beginning-of-line) (= (point-min) (point)))
3068 (save-excursion (end-of-line) (= (point-max) (point)))))
3071 (defun ada-in-comment-p ()
3072 ;; Returns t if inside a comment.
3073 ;; (save-excursion (and (re-search-backward "\\(--\\|\n\\)" nil 1)
3074 ;; (looking-at "-"))))
3075 (nth 4 (parse-partial-sexp
3076 (save-excursion (beginning-of-line) (point))
3081 (defun ada-in-string-p ()
3082 ;; Returns t if point is inside a string
3083 ;; (Taken from pascal-mode.el, modified by MH).
3086 (nth 3 (parse-partial-sexp
3090 ;; check if 'string quote' is only a character constant
3092 (re-search-backward "\"" nil t) ; # not a string delimiter anymore
3093 (not (= (char-after (1- (point))) ?'))))))
3096 (defun ada-in-string-or-comment-p ()
3097 ;; Returns t if point is inside a string or a comment.
3098 (or (ada-in-comment-p)
3102 (defun ada-in-paramlist-p ()
3103 ;; Returns t if point is inside a parameter-list
3104 ;; following 'function'/'procedure'/'package'.
3107 (re-search-backward "(\\|)" nil t)
3108 ;; inside parentheses ?
3111 ;; right keyword before paranthesis ?
3112 (looking-at (concat "\\<\\("
3113 "procedure\\|function\\|body\\|package\\|"
3114 "task\\|entry\\|accept\\)\\>"))
3115 (re-search-forward ")\\|:" nil t)
3116 ;; at least one ':' inside the parentheses ?
3117 (not (backward-char 1))
3121 ;; not really a boolean function ...
3122 (defun ada-in-open-paren-p ()
3123 ;; If point is somewhere behind an open parenthesis not yet closed,
3124 ;; it returns the column # of the first non-ws behind this open
3125 ;; parenthesis, otherwise nil."
3127 (let ((start (if (< (point) ada-search-paren-char-count-limit)
3129 (- (point) ada-search-paren-char-count-limit)))
3132 (setq parse-result (parse-partial-sexp start (point)))
3133 (if (nth 1 parse-result)
3135 (goto-char (1+ (nth 1 parse-result)))
3137 (re-search-forward "[^ \t]" nil 1)
3140 (not (looking-at "\n"))
3141 (setq col (current-column))))
3148 ;;;----------------------;;;
3149 ;;; Behaviour Of TAB Key ;;;
3150 ;;;----------------------;;;
3153 "Do indenting or tabbing according to `ada-tab-policy'."
3155 (cond ((eq ada-tab-policy 'indent-and-tab) (error "not implemented"))
3156 ;; ada-indent-and-tab
3157 ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard))
3158 ((eq ada-tab-policy 'indent-auto) (ada-indent-current))
3159 ((eq ada-tab-policy 'gei) (ada-tab-gei))
3160 ((eq ada-tab-policy 'indent-af) (af-indent-line)) ; GEB
3161 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3165 (defun ada-untab (arg)
3166 "Delete leading indenting according to `ada-tab-policy'."
3168 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard))
3169 ((eq ada-tab-policy 'indent-af) (backward-delete-char-untabify ; GEB
3170 (prefix-numeric-value arg) ; GEB
3172 ((eq ada-tab-policy 'indent-auto) (error "not implemented"))
3173 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3177 (defun ada-indent-current-function ()
3178 "Ada Mode version of the indent-line-function."
3180 (let ((starting-point (point-marker)))
3181 (ada-beginning-of-line)
3183 (if (< (point) starting-point)
3184 (goto-char starting-point))
3185 (set-marker starting-point nil)
3189 (defun ada-tab-hard ()
3190 "Indent current line to next tab stop."
3194 (insert-char ? ada-indent))
3195 (if (save-excursion (= (point) (progn (beginning-of-line) (point))))
3196 (forward-char ada-indent)))
3199 (defun ada-untab-hard ()
3200 "indent current line to previous tab stop."
3202 (let ((bol (save-excursion (progn (beginning-of-line) (point))))
3203 (eol (save-excursion (progn (end-of-line) (point)))))
3204 (indent-rigidly bol eol (- 0 ada-indent))))
3208 ;;;---------------;;;
3209 ;;; Miscellaneous ;;;
3210 ;;;---------------;;;
3212 (defun ada-remove-trailing-spaces ()
3213 "remove trailing spaces in the whole buffer."
3219 (goto-char (point-min))
3220 (while (re-search-forward "[ \t]+$" (point-max) t)
3221 (replace-match "" nil nil))))))
3224 (defun ada-untabify-buffer ()
3225 ;; change all tabs to spaces
3227 (untabify (point-min) (point-max))))
3230 (defun ada-uncomment-region (beg end)
3231 "delete `comment-start' at the beginning of a line in the region."
3233 (comment-region beg end -1))
3236 ;; define a function to support find-file.el if loaded
3237 (defun ada-ff-other-window ()
3238 "Find other file in other window using `ff-find-other-file'."
3240 (and (fboundp 'ff-find-other-file)
3241 (ff-find-other-file t)))
3244 ;;;-------------------------------;;;
3245 ;;; Moving To Procedures/Packages ;;;
3246 ;;;-------------------------------;;;
3248 (defun ada-next-procedure ()
3249 "Moves point to next procedure."
3252 (if (re-search-forward ada-procedure-start-regexp nil t)
3253 (goto-char (match-beginning 1))
3254 (error "No more functions/procedures/tasks")))
3256 (defun ada-previous-procedure ()
3257 "Moves point to previous procedure."
3260 (if (re-search-backward ada-procedure-start-regexp nil t)
3261 (goto-char (match-beginning 1))
3262 (error "No more functions/procedures/tasks")))
3264 (defun ada-next-package ()
3265 "Moves point to next package."
3268 (if (re-search-forward ada-package-start-regexp nil t)
3269 (goto-char (match-beginning 1))
3270 (error "No more packages")))
3272 (defun ada-previous-package ()
3273 "Moves point to previous package."
3276 (if (re-search-backward ada-package-start-regexp nil t)
3277 (goto-char (match-beginning 1))
3278 (error "No more packages")))
3281 ;;;-----------------------
3282 ;;; define keymap for Ada
3283 ;;;-----------------------
3285 (if (not ada-mode-map)
3287 (setq ada-mode-map (make-sparse-keymap))
3289 ;; Indentation and Formatting
3290 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent)
3291 (define-key ada-mode-map "\t" 'ada-tab)
3292 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region)
3294 (define-key ada-mode-map '(shift tab) 'ada-untab)
3295 (define-key ada-mode-map [S-tab] 'ada-untab))
3296 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist)
3297 (define-key ada-mode-map "\C-c\C-p" 'ada-call-pretty-printer)
3298 ;;; We don't want to make meta-characters case-specific.
3299 ;;; (define-key ada-mode-map "\M-Q" 'ada-fill-comment-paragraph-justify)
3300 (define-key ada-mode-map "\M-\C-q" 'ada-fill-comment-paragraph-postfix)
3303 ;;; It isn't good to redefine these. What should be done instead? -- rms.
3304 ;;; (define-key ada-mode-map "\M-e" 'ada-next-package)
3305 ;;; (define-key ada-mode-map "\M-a" 'ada-previous-package)
3306 (define-key ada-mode-map "\M-\C-e" 'ada-next-procedure)
3307 (define-key ada-mode-map "\M-\C-a" 'ada-previous-procedure)
3308 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3309 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3312 (define-key ada-mode-map "\C-c\C-c" 'compile)
3315 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region)
3316 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3318 (define-key ada-mode-map "\177" 'backward-delete-char-untabify)
3320 ;; Use predefined function of emacs19 for comments (RE)
3321 (define-key ada-mode-map "\C-c;" 'comment-region)
3322 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
3324 ;; Change basic functionality
3326 ;; `substitute-key-definition' is not defined equally in GNU Emacs
3327 ;; and XEmacs, you cannot put in an optional 4th parameter in
3328 ;; XEmacs. I don't think it's necessary, so I leave it out for
3329 ;; GNU Emacs as well. If you encounter any problems with the
3330 ;; following three functions, please tell me. RE
3331 (mapcar (function (lambda (pair)
3332 (substitute-key-definition (car pair) (cdr pair)
3334 '((beginning-of-line . ada-beginning-of-line)
3335 (end-of-line . ada-end-of-line)
3336 (forward-to-indentation . ada-forward-to-indentation)
3339 ;;(mapcar (lambda (pair)
3340 ;; (substitute-key-definition (car pair) (cdr pair)
3341 ;; ada-mode-map global-map))
3346 ;;;-------------------
3347 ;;; define menu 'Ada'
3348 ;;;-------------------
3352 (defun ada-add-ada-menu ()
3353 "Adds the menu 'Ada' to the menu bar in Ada Mode."
3354 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode."
3356 ["Next Package" ada-next-package t]
3357 ["Previous Package" ada-previous-package t]
3358 ["Next Procedure" ada-next-procedure t]
3359 ["Previous Procedure" ada-previous-procedure t]
3360 ["Goto Start" ada-move-to-start t]
3361 ["Goto End" ada-move-to-end t]
3362 ["------------------" nil nil]
3363 ["Indent Current Line (TAB)"
3364 ada-indent-current-function t]
3365 ["Indent Lines in Region" ada-indent-region t]
3366 ["Format Parameter List" ada-format-paramlist t]
3367 ["Pretty Print Buffer" ada-call-pretty-printer t]
3368 ["------------" nil nil]
3369 ["Fill Comment Paragraph"
3370 ada-fill-comment-paragraph t]
3371 ["Justify Comment Paragraph"
3372 ada-fill-comment-paragraph-justify t]
3373 ["Postfix Comment Paragraph"
3374 ada-fill-comment-paragraph-postfix t]
3375 ["------------" nil nil]
3376 ["Adjust Case Region" ada-adjust-case-region t]
3377 ["Adjust Case Buffer" ada-adjust-case-buffer t]
3378 ["----------" nil nil]
3379 ["Comment Region" comment-region t]
3380 ["Uncomment Region" ada-uncomment-region t]
3381 ["----------------" nil nil]
3382 ["Compile" compile (fboundp 'compile)]
3383 ["Next Error" next-error (fboundp 'next-error)]
3384 ["---------------" nil nil]
3385 ["Index" imenu (fboundp 'imenu)]
3386 ["--------------" nil nil]
3387 ["Other File Other Window" ada-ff-other-window
3388 (fboundp 'ff-find-other-file)]
3389 ["Other File" ff-find-other-file
3390 (fboundp 'ff-find-other-file)]))
3391 (if (ada-xemacs) (progn
3392 (easy-menu-add ada-mode-menu)
3393 (setq mode-popup-menu (cons "Ada Mode" ada-mode-menu)))))
3397 ;;;-------------------------------
3398 ;;; Define Some Support Functions
3399 ;;;-------------------------------
3401 (defun ada-beginning-of-line (&optional arg)
3404 ((eq ada-tab-policy 'indent-af) (af-beginning-of-line arg))
3405 (t (beginning-of-line arg))
3408 (defun ada-end-of-line (&optional arg)
3411 ((eq ada-tab-policy 'indent-af) (af-end-of-line arg))
3412 (t (end-of-line arg))
3415 (defun ada-current-column ()
3417 ((eq ada-tab-policy 'indent-af) (af-current-column))
3418 (t (current-column))
3421 (defun ada-forward-to-indentation (&optional arg)
3424 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg))
3425 (t (forward-to-indentation arg))
3428 ;;;---------------------------------------------------
3429 ;;; support for find-file
3430 ;;;---------------------------------------------------
3434 (defun ada-make-filename-from-adaname (adaname)
3435 "Determine the filename of a package/procedure from its own Ada name."
3436 ;; this is done simply by calling gkrunch, when we work with GNAT. It
3437 ;; must be a more complex function in other compiler environments.
3440 ;; things that should really be done by the external process
3441 ;; since gnat-2.0, gnatk8 can do these things. If you still use a
3442 ;; previous version, just uncomment the following lines.
3444 (setq krunch-buf (generate-new-buffer "*gkrunch*"))
3446 (set-buffer krunch-buf)
3447 ; (insert (downcase adaname))
3448 ; (goto-char (point-min))
3449 ; (while (search-forward "." nil t)
3450 ; (replace-match "-" nil t))
3451 ; (setq adaname (buffer-substring (point-min)
3453 ; (goto-char (point-min))
3456 ; ;; clean the buffer
3457 ; (delete-region (point-min) (point-max))
3458 ;; send adaname to external process "gnatk8"
3459 (call-process "gnatk8" nil krunch-buf nil
3460 adaname ada-krunch-args)
3461 ;; fetch output of that process
3462 (setq adaname (buffer-substring
3465 (goto-char (point-min))
3468 (kill-buffer krunch-buf)))
3469 (setq adaname adaname) ;; can I avoid this statement?
3473 ;;; functions for placing the cursor on the corresponding subprogram
3474 (defun ada-which-function-are-we-in ()
3475 "Determine whether we are on a function definition/declaration.
3476 If that is the case remember the name of that function."
3478 (setq ff-function-name nil)
3481 (if (re-search-backward ada-procedure-start-regexp nil t)
3482 (setq ff-function-name (buffer-substring (match-beginning 0)
3484 ; we didn't find a procedure start, perhaps there is a package
3485 (if (re-search-backward ada-package-start-regexp nil t)
3486 (setq ff-function-name (buffer-substring (match-beginning 0)
3491 ;;;---------------------------------------------------
3492 ;;; support for imenu
3493 ;;;---------------------------------------------------
3495 (defun imenu-create-ada-index (&optional regexp)
3496 "Create index alist for Ada files."
3497 (let ((index-alist '())
3499 (goto-char (point-min))
3500 ;(imenu-progress-message prev-pos 0)
3501 ;; Search for functions/procedures
3503 (while (re-search-forward
3504 (or regexp ada-procedure-start-regexp)
3506 ;(imenu-progress-message prev-pos)
3507 ;; do not store forward definitions
3508 ;; right now we store them. We want to avoid them only in
3509 ;; package bodies, not in the specs!! ???RE???
3511 ; (if (not (looking-at (concat
3513 ; "\([^)]+\)" ; parameterlist
3514 ; "\\([ \n\t]+return[ \n\t]+"; potential return
3515 ; "[a-zA-Z0-9_\\.]+\\)?"
3517 ; ";" ;; THIS is what we really look for
3519 ; ; (push (imenu-example--name-and-position) index-alist)
3520 (setq index-alist (cons (imenu-example--name-and-position)
3524 ;(imenu-progress-message 100)
3526 (nreverse index-alist)))
3528 ;;;---------------------------------------------------
3529 ;;; support for font-lock
3530 ;;;---------------------------------------------------
3532 ;; Strings are a real pain in Ada because both ' and " can appear in a
3533 ;; non-string quote context (the former as an operator, the latter as
3534 ;; a character string). We follow the least losing solution, in which
3535 ;; only " is a string quote. Therefore a character string of the form
3536 ;; '"' will throw fontification off on the wrong track.
3538 (defconst ada-font-lock-keywords-1
3541 ;; accept, entry, function, package (body), protected (body|type),
3542 ;; pragma, procedure, task (body) plus name.
3548 "package[ \t]+body\\|"
3552 "protected[ \t]+body\\|"
3553 "protected[ \t]+type\\|"
3555 ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\
3556 ;;\\|r\\(agma\\|ocedure\\)\\)\\|"
3560 ;; "task\\(\\|[ \t]+body\\)"
3562 "\\(\\sw+\\(\\.\\sw*\\)*\\)?")
3563 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t)))
3564 "Subdued level highlighting for Ada mode.")
3566 (defconst ada-font-lock-keywords-2
3567 (append ada-font-lock-keywords-1
3570 ;; Main keywords, except those treated specially below.
3572 ; ("abort" "abs" "abstract" "accept" "access" "aliased" "all"
3573 ; "and" "array" "at" "begin" "case" "declare" "delay" "delta"
3574 ; "digits" "do" "else" "elsif" "entry" "exception" "exit" "for"
3575 ; "generic" "if" "in" "is" "limited" "loop" "mod" "not"
3576 ; "null" "or" "others" "private" "protected"
3577 ; "range" "record" "rem" "renames" "requeue" "return" "reverse"
3578 ; "select" "separate" "tagged" "task" "terminate" "then" "until"
3580 "a\\(b\\(ort\\|s\\(\\|tract\\)\\)\\|cce\\(pt\\|ss\\)\\|"
3581 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|"
3582 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|"
3583 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|"
3584 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|"
3585 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|"
3586 "r\\(ange\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|"
3587 "se\\(lect\\|parate\\)\\|"
3588 "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed
3589 "wh\\(ile\\|en\\)\\|xor" ; "when" added
3592 ;; Anything following end and not already fontified is a body name.
3593 '("\\<\\(end\\)\\>[ \t]+\\([a-zA-Z0-9_\\.]+\\)?"
3594 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
3596 ;; Variable name plus optional keywords followed by a type name. Slow.
3597 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*"
3598 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*"
3600 ; '(1 font-lock-variable-name-face)
3601 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t))
3603 ;; Optional keywords followed by a type name.
3604 (list (concat ; ":[ \t]*"
3605 "\\<\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)\\>"
3608 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
3610 ;; Keywords followed by a type or function name.
3611 (list (concat "\\<\\("
3612 "new\\|of\\|subtype\\|type"
3613 "\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*\\((\\)?")
3614 '(1 font-lock-keyword-face)
3615 '(2 (if (match-beginning 4)
3616 font-lock-function-name-face
3617 font-lock-type-face) nil t))
3619 ;; Keywords followed by a (comma separated list of) reference.
3620 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)\\>" ; "when" removed
3621 ; "[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?") ; RE
3622 "[ \t]*\\([a-zA-Z0-9_\\.\\|, ]+\\)\\W")
3623 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
3626 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
3628 "Gaudy level highlighting for Ada mode.")
3630 (defvar ada-font-lock-keywords ada-font-lock-keywords-2
3631 "Default Expressions to highlight in Ada mode.
3632 See the doc to `font-lock-maximum-decoration' for user configuration.")
3637 (defun ada-gen-comment-until-proc ()
3638 ;; comment until spec of a procedure or a function.
3640 (set-mark-command (point))
3641 (if (re-search-forward ada-procedure-start-regexp nil t)
3642 (progn (goto-char (match-beginning 1))
3643 (comment-region (mark) (point)))
3644 (error "No more functions/procedures")))
3647 (defun ada-gen-treat-proc (match)
3648 ;; make dummy body of a procedure/function specification.
3649 ;; MATCH is a cons cell containing the start and end location of the
3650 ;; last search for ada-procedure-start-regexp.
3651 (goto-char (car match))
3652 (let (proc-found func-found procname functype)
3654 ((or (setq proc-found (looking-at "^[ \t]*procedure"))
3655 (setq func-found (looking-at "^[ \t]*function")))
3656 ;; treat it as a proc/func
3659 (setq procname (buffer-substring (point) (cdr match))) ; store proc name
3661 ;; goto end of procname
3662 (goto-char (cdr match))
3664 ;; skip over parameterlist
3666 ;; if function, skip over 'return' and result type.
3670 (skip-chars-forward " \t\n")
3671 (setq functype (buffer-substring (point)
3676 ;; look for next non WS
3678 ((looking-at "[ \t]*;")
3679 (delete-region (match-beginning 0) (match-end 0)) ;; delete the ';'
3680 (ada-indent-newline-indent)
3682 (ada-indent-newline-indent)
3685 (insert "Result : ")
3688 (ada-indent-newline-indent)))
3689 (insert "begin -- ")
3691 (ada-indent-newline-indent)
3693 (ada-indent-newline-indent)
3696 (insert "return Result;")
3697 (ada-indent-newline-indent)))
3701 (ada-indent-newline-indent)
3704 ((looking-at "[ \t\n]*is")
3707 ((looking-at "[ \t\n]*rename")
3711 (message "unknown syntax")))
3715 (defun ada-make-body ()
3716 "Create an Ada package body in the current buffer.
3717 The potential old buffer contents is deleted first, then we copy the
3718 spec buffer in here and modify it to make it a body.
3720 This function typically is to be hooked into `ff-file-created-hooks'."
3722 (delete-region (point-min) (point-max))
3723 (insert-buffer (car (cdr (buffer-list))))
3728 (ada-search-ignore-string-comment ada-package-start-regexp))
3729 (progn (goto-char (cdr found))
3731 ;; (forward-line -1)
3732 ;;(comment-region (point-min) (point))
3734 (error "No package"))
3736 ;; (comment-until-proc)
3737 ;; does not work correctly
3738 ;; must be done by hand
3741 (ada-search-ignore-string-comment ada-procedure-start-regexp))
3742 (ada-gen-treat-proc found))))
3749 ;;; ada-mode.el ends here