1 ;;; ada-stmt.el - An extension to Ada mode for inserting statement templates.
3 ;; Copyright (C) 1987, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
5 ;; Ada Core Technologies's version: $Revision: 1.10 $
7 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
8 ;; Maintainer: Rolf Ebert <ebert@waporo.muc.de>
9 ;; Keywords: languages, ada
10 ;; Rolf Ebert's version: 2.26
15 ;; put the following statement in your .emacs:
16 ;; (require 'ada-stmt)
22 ;; Original version from V. Bowman as in ada.el of Emacs-18
23 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
24 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
26 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
27 ;; Introduced statement.el for smaller code and user configurability.
29 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
30 ;; skeleton generation into this separate file. The code still is
31 ;; essentially written by DP
33 ;; Adapted Jun 1994. Markus Heritsch
34 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
35 ;; added menu bar support for templates
37 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
38 ;; General cleanup and bug fixes.
40 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
41 ;; made it work with skeleton.el from emacs-19.30. Several
42 ;; enhancements and bug fixes.
45 ;;;> I have the following suggestions for the function template: 1) I
46 ;;;> don't want it automatically assigning it a name for the return variable. I
47 ;;;> never want it to be called "Result" because that is nondescriptive. If you
48 ;;;> must define a variable, give me the ability to specify its name.
50 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
51 ;;;> as the function's return type, which the template knows, so why force me
55 ;;;It would be nice if one could configure such layout details separately
56 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
57 ;;;could be taken even further, providing the user with some nice syntax
58 ;;;for describing layout. Then my own hacks would survive the next
59 ;;;update of the package :-)
65 (condition-case nil (require 'skeleton)
69 (defun ada-stmt-add-to-ada-menu ()
70 "Add a new submenu to the Ada menu"
72 (let ((menu '(["Header" ada-header t]
74 ["Package Body" ada-package-body t]
75 ["Package Spec" ada-package-spec t]
76 ["Function Spec" ada-function-spec t]
77 ["Procedure Spec" ada-procedure-spec t]
78 ["Proc/func Body" ada-subprogram-body t]
79 ["Task Body" ada-task-body t]
80 ["Task Spec" ada-task-spec t]
81 ["Declare Block" ada-declare-block t]
82 ["Exception Block" ada-exception-block t]
85 ["Entry family" ada-entry-family t]
86 ["Select" ada-select t]
87 ["Accept" ada-accept t]
88 ["Or accept" ada-or-accep t]
89 ["Or delay" ada-or-delay t]
90 ["Or terminate" ada-or-terminate t]
93 ["Private" ada-private t]
94 ["Subtype" ada-subtype t]
95 ["Record" ada-record t]
100 ["Elsif" ada-elsif t]
103 ["While Loop" ada-while-loop t]
104 ["For Loop" ada-for-loop t]
107 ["Exception" ada-exception t]
109 ["When" ada-when t])))
112 (add-to-list 'menu "Statements")
113 (add-submenu '("Ada") menu))
115 (define-key-after (lookup-key ada-mode-map [menu-bar Ada]) [Statements]
116 (cons "Statements" (easy-menu-create-menu "Statements" menu)) t))
122 (defun ada-func-or-proc-name ()
123 ;; Get the name of the current function or procedure."
125 (let ((case-fold-search t))
126 (if (re-search-backward ada-procedure-start-regexp nil t)
127 (buffer-substring (match-beginning 2) (match-end 2))
130 (defvar ada-template-map nil
131 "Keymap used in Ada mode for smart template operations.")
133 (define-key ada-mode-map "\C-cth" 'ada-header)
134 (define-key ada-mode-map "\C-ct\C-a" 'ada-array)
135 (define-key ada-mode-map "\C-ctb" 'ada-exception-block)
136 (define-key ada-mode-map "\C-ctd" 'ada-declare-block)
137 (define-key ada-mode-map "\C-ctc" 'ada-case)
138 (define-key ada-mode-map "\C-ct\C-e" 'ada-elsif)
139 (define-key ada-mode-map "\C-cte" 'ada-else)
140 (define-key ada-mode-map "\C-ct\C-k" 'ada-package-spec)
141 (define-key ada-mode-map "\C-ctk" 'ada-package-body)
142 (define-key ada-mode-map "\C-ct\C-p" 'ada-procedure-spec)
143 (define-key ada-mode-map "\C-ctp" 'ada-subprogram-body)
144 (define-key ada-mode-map "\C-ct\C-f" 'ada-function-spec)
145 (define-key ada-mode-map "\C-ctf" 'ada-for-loop)
146 (define-key ada-mode-map "\C-cti" 'ada-if)
147 (define-key ada-mode-map "\C-ctl" 'ada-loop)
148 (define-key ada-mode-map "\C-ct\C-r" 'ada-record)
149 (define-key ada-mode-map "\C-ct\C-s" 'ada-subtype)
150 (define-key ada-mode-map "\C-ctS" 'ada-tabsize)
151 (define-key ada-mode-map "\C-ct\C-t" 'ada-task-spec)
152 (define-key ada-mode-map "\C-ctt" 'ada-task-body)
153 (define-key ada-mode-map "\C-ct\C-y" 'ada-type)
154 (define-key ada-mode-map "\C-ct\C-v" 'ada-private)
155 (define-key ada-mode-map "\C-ctu" 'ada-use)
156 (define-key ada-mode-map "\C-ct\C-u" 'ada-with)
157 (define-key ada-mode-map "\C-ct\C-w" 'ada-when)
158 (define-key ada-mode-map "\C-ctw" 'ada-while-loop)
159 (define-key ada-mode-map "\C-ct\C-x" 'ada-exception)
160 (define-key ada-mode-map "\C-ctx" 'ada-exit)
162 ;;; ---- statement skeletons ------------------------------------------
164 (define-skeleton ada-array
165 "Insert array type definition. Uses the minibuffer to prompt
166 for component type and index subtypes."
168 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
171 (define-skeleton ada-case
172 "Build skeleton case statement, prompting for the selector expression.
173 Also builds the first when clause."
174 "[selector expression]: "
176 > "when " ("discrete choice: " str " | ") -3 " =>" \n
181 (define-skeleton ada-when
182 "Start a case statement alternative with a when clause."
184 < "when " ("discrete choice: " str " | ") -3 " =>" \n
188 (define-skeleton ada-declare-block
189 "Insert a block with a declare part.
190 Indent for the first declaration."
197 < "end " str | -1 ?\;)
200 (define-skeleton ada-exception-block
201 "Insert a block with an exception part.
202 Indent for the first line of code."
209 < "end " str | -1 ?\;)
212 (define-skeleton ada-exception
213 "Insert an indented exception part into a block."
219 (define-skeleton ada-exit-1
220 "Insert then exit condition of the exit statement, prompting for condition."
225 (define-skeleton ada-exit
226 "Insert an exit statement, prompting for loop name and condition."
227 "[name of loop to exit]: "
234 "Insert a descriptive header at the top of the file."
237 (goto-char (point-min))
238 (if (fboundp 'make-header)
243 (define-skeleton ada-header-tmpl
244 "Insert a comment block containing the module title, author, etc."
246 "-- -*- Mode: Ada -*-"
247 "\n-- Filename : " (buffer-name)
248 "\n-- Description : " str
249 "\n-- Author : " (user-full-name)
250 "\n-- Created On : " (current-time-string)
251 "\n-- Last Modified By: ."
252 "\n-- Last Modified On: ."
253 "\n-- Update Count : 0"
254 "\n-- Status : Unknown, Use with caution!"
258 (define-skeleton ada-display-comment
259 "Inserts three comment lines, making a display comment."
264 (define-skeleton ada-if
265 "Insert skeleton if statment, prompting for a boolean-expression."
272 (define-skeleton ada-elsif
273 "Add an elsif clause to an if statement,
274 prompting for the boolean-expression."
276 < "elsif " str " then" \n
280 (define-skeleton ada-else
281 "Add an else clause inside an if-then-end-if clause."
287 (define-skeleton ada-loop
288 "Insert a skeleton loop statement. The exit statement is added by hand."
293 < "end loop " str | -1 ?\;)
296 (define-skeleton ada-for-loop-prompt-variable
297 "Prompt for the loop variable."
302 (define-skeleton ada-for-loop-prompt-range
303 "Prompt for the loop range."
308 (define-skeleton ada-for-loop
309 "Build a skeleton for-loop statement, prompting for the loop parameters."
313 (ada-for-loop-prompt-variable)
315 (ada-for-loop-prompt-range)
318 < "end loop " str | -1 ?\;)
321 (define-skeleton ada-while-loop-prompt-entry-condition
322 "Prompt for the loop entry condition."
323 "[entry condition]: "
327 (define-skeleton ada-while-loop
328 "Insert a skeleton while loop statement."
332 (ada-while-loop-prompt-entry-condition)
335 < "end loop " str | -1 ?\;)
338 (define-skeleton ada-package-spec
339 "Insert a skeleton package specification."
341 "package " str " is" \n
346 (define-skeleton ada-package-body
347 "Insert a skeleton package body -- includes a begin statement."
349 "package body " str " is" \n
355 (define-skeleton ada-private
356 "Undent and start a private section of a package spec. Reindent."
362 (define-skeleton ada-function-spec-prompt-return
363 "Prompts for function result type."
368 (define-skeleton ada-function-spec
369 "Insert a function specification. Prompts for name and arguments."
372 " (" ("[parameter_specification]: " str "; " ) -2 ")"
374 (ada-function-spec-prompt-return)
378 (define-skeleton ada-procedure-spec
379 "Insert a procedure specification, prompting for its name and arguments."
382 " (" ("[parameter_specification]: " str "; " ) -2 ")"
386 (define-skeleton ada-subprogram-body
387 "Insert frame for subprogram body.
388 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
390 ;; Remove `;' from subprogram decl
392 (let ((pos (1+ (point))))
393 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
394 (if (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
406 "when others => null;" \n
408 (ada-func-or-proc-name)
412 (define-skeleton ada-separate
413 "Finish a body stub with `separate'."
419 ;(define-skeleton ada-with
420 ; "Inserts a with clause, prompting for the list of units depended upon."
421 ; "[list of units depended upon]: "
424 ;(define-skeleton ada-use
425 ; "Inserts a use clause, prompting for the list of packages used."
426 ; "[list of packages used]: "
430 (define-skeleton ada-record
431 "Insert a skeleton record type declaration."
438 (define-skeleton ada-subtype
439 "Start insertion of a subtype declaration, prompting for the subtype name."
441 "subtype " str " is " _ ?\;
442 (not (message "insert subtype indication.")))
445 (define-skeleton ada-type
446 "Start insertion of a type declaration, prompting for the type name."
449 ("[discriminant specs]: " str " ")
450 | (backward-delete-char 1) | ?\)
452 (not (message "insert type definition.")))
455 (define-skeleton ada-task-body
456 "Insert a task body, prompting for the task name."
458 "task body " str " is\n"
464 (define-skeleton ada-task-spec
465 "Insert a task specification, prompting for the task name."
468 " (" ("[discriminant]: " str "; ") ") is\n"
473 (define-skeleton ada-get-param1
474 "Prompt for arguments and if any enclose them in brackets."
476 ("[parameter_specification]: " str "; " ) & -2 & ")"
480 (define-skeleton ada-get-param
481 "Prompt for arguments and if any enclose them in brackets."
484 (ada-get-param1) | -2
488 (define-skeleton ada-entry
489 "Insert a task entry, prompting for the entry name."
494 ; (ada-indent-current)
498 (define-skeleton ada-entry-family-prompt-discriminant
499 "Insert a entry specification, prompting for the entry name."
500 "[discriminant name]: "
504 (define-skeleton ada-entry-family
505 "Insert a entry specification, prompting for the entry name."
508 " (" (ada-entry-family-prompt-discriminant) ")"
511 ;(ada-indent-current)
515 (define-skeleton ada-select
516 "Insert a select block."
523 (define-skeleton ada-accept-1
524 "Insert a condition statement, prompting for the condition name."
529 (define-skeleton ada-accept-2
530 "Insert an accept statement, prompting for the name and arguments."
534 ; " (" ("[parameter_specification]: " str "; ") -2 ")"
540 (define-skeleton ada-accept
541 "Insert an accept statement (prompt for condition, name and arguments)."
543 > (ada-accept-1) & " =>\n"
548 (define-skeleton ada-or-accept
549 "Insert a or statement, prompting for the condition name."
556 (define-skeleton ada-or-delay
557 "Insert a delay statement, prompting for the delay value."
563 (define-skeleton ada-or-terminate
564 "Insert a terminate statement."
571 (defun ada-adjust-case-skeleton ()
572 "Adjusts the case of the text inserted by a skeleton."
574 (let ((aa-end (point)))
575 (ada-adjust-case-region
576 (progn (goto-char beg) (forward-word -1) (point))
579 (add-hook 'ada-mode-hook '(lambda ()
580 (setq skeleton-further-elements
581 '((< '(backward-delete-char-untabify
582 (min ada-indent (current-column))))))
583 (add-hook 'skeleton-end-hook
584 'ada-adjust-case-skeleton)))
586 (add-hook 'ada-mode-hook 'ada-stmt-add-to-ada-menu)
590 ;;; ada-stmt.el ends here