1 ;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates
3 ;; Copyright (C) 1987, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
9 ;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
10 ;; Keywords: languages, ada
13 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
14 ;; in Ada/ on the menu bar.
19 ;; Original version from V. Bowman as in ada.el of Emacs-18
20 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
21 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
23 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
24 ;; Introduced statement.el for smaller code and user configurability.
26 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
27 ;; skeleton generation into this separate file. The code still is
28 ;; essentially written by DP
30 ;; Adapted Jun 1994. Markus Heritsch
31 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
32 ;; added menu bar support for templates
34 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
35 ;; General cleanup and bug fixes.
37 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
38 ;; made it work with skeleton.el from Emacs-19.30. Several
39 ;; enhancements and bug fixes.
42 ;;;> I have the following suggestions for the function template: 1) I
43 ;;;> don't want it automatically assigning it a name for the return variable. I
44 ;;;> never want it to be called "Result" because that is nondescriptive. If you
45 ;;;> must define a variable, give me the ability to specify its name.
47 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
48 ;;;> as the function's return type, which the template knows, so why force me
52 ;;;It would be nice if one could configure such layout details separately
53 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
54 ;;;could be taken even further, providing the user with some nice syntax
55 ;;;for describing layout. Then my own hacks would survive the next
56 ;;;update of the package :-)
61 (require 'skeleton nil t)
65 (defun ada-func-or-proc-name ()
66 "Return the name of the current function or procedure."
68 (let ((case-fold-search t))
69 (if (re-search-backward ada-procedure-start-regexp nil t)
73 ;;; ---- statement skeletons ------------------------------------------
75 (define-skeleton ada-array
76 "Insert array type definition.
77 Prompt for component type and index subtypes."
79 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
82 (define-skeleton ada-case
83 "Build skeleton case statement.
84 Prompt for the selector expression. Also builds the first when clause."
85 "[selector expression]: "
87 > "when " ("discrete choice: " str " | ") -3 " =>" \n
92 (define-skeleton ada-when
93 "Start a case statement alternative with a when clause."
95 < "when " ("discrete choice: " str " | ") -3 " =>" \n
99 (define-skeleton ada-declare-block
100 "Insert a block with a declare part.
101 Indent for the first declaration."
108 < "end " str | -1 ?\;)
111 (define-skeleton ada-exception-block
112 "Insert a block with an exception part.
113 Indent for the first line of code."
120 < "end " str | -1 ?\;)
123 (define-skeleton ada-exception
124 "Insert an indented exception part into a block."
130 (define-skeleton ada-exit-1
131 "Insert then exit condition of the exit statement, prompting for condition."
136 (define-skeleton ada-exit
137 "Insert an exit statement, prompting for loop name and condition."
138 "[name of loop to exit]: "
139 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
143 "Insert a descriptive header at the top of the file."
146 (goto-char (point-min))
147 (if (fboundp 'make-header)
148 (funcall (symbol-function 'make-header))
152 (define-skeleton ada-header-tmpl
153 "Insert a comment block containing the module title, author, etc."
155 "-- -*- Mode: Ada -*-"
156 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
157 "\n" ada-fill-comment-prefix "Description : " str
158 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
159 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
160 "\n" ada-fill-comment-prefix "Last Modified By: ."
161 "\n" ada-fill-comment-prefix "Last Modified On: ."
162 "\n" ada-fill-comment-prefix "Update Count : 0"
163 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
167 (define-skeleton ada-display-comment
168 "Inserts three comment lines, making a display comment."
170 "--\n" ada-fill-comment-prefix _ "\n--")
173 (define-skeleton ada-if
174 "Insert skeleton if statment, prompting for a boolean-expression."
181 (define-skeleton ada-elsif
182 "Add an elsif clause to an if statement,
183 prompting for the boolean-expression."
185 < "elsif " str " then" \n
189 (define-skeleton ada-else
190 "Add an else clause inside an if-then-end-if clause."
196 (define-skeleton ada-loop
197 "Insert a skeleton loop statement. The exit statement is added by hand."
202 < "end loop " str | -1 ?\;)
205 (define-skeleton ada-for-loop-prompt-variable
206 "Prompt for the loop variable."
211 (define-skeleton ada-for-loop-prompt-range
212 "Prompt for the loop range."
217 (define-skeleton ada-for-loop
218 "Build a skeleton for-loop statement, prompting for the loop parameters."
222 (ada-for-loop-prompt-variable)
224 (ada-for-loop-prompt-range)
227 < "end loop " str | -1 ?\;)
230 (define-skeleton ada-while-loop-prompt-entry-condition
231 "Prompt for the loop entry condition."
232 "[entry condition]: "
236 (define-skeleton ada-while-loop
237 "Insert a skeleton while loop statement."
241 (ada-while-loop-prompt-entry-condition)
244 < "end loop " str | -1 ?\;)
247 (define-skeleton ada-package-spec
248 "Insert a skeleton package specification."
250 "package " str " is" \n
255 (define-skeleton ada-package-body
256 "Insert a skeleton package body -- includes a begin statement."
258 "package body " str " is" \n
264 (define-skeleton ada-private
265 "Undent and start a private section of a package spec. Reindent."
271 (define-skeleton ada-function-spec-prompt-return
272 "Prompts for function result type."
277 (define-skeleton ada-function-spec
278 "Insert a function specification. Prompts for name and arguments."
281 " (" ("[parameter_specification]: " str "; " ) -2 ")"
283 (ada-function-spec-prompt-return)
287 (define-skeleton ada-procedure-spec
288 "Insert a procedure specification, prompting for its name and arguments."
291 " (" ("[parameter_specification]: " str "; " ) -2 ")"
295 (define-skeleton ada-subprogram-body
296 "Insert frame for subprogram body.
297 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
299 ;; Remove `;' from subprogram decl
301 (let ((pos (1+ (point))))
302 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
303 (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
313 "when others => null;" \n
315 (ada-func-or-proc-name)
319 (define-skeleton ada-separate
320 "Finish a body stub with `separate'."
326 ;(define-skeleton ada-with
327 ; "Inserts a with clause, prompting for the list of units depended upon."
328 ; "[list of units depended upon]: "
331 ;(define-skeleton ada-use
332 ; "Inserts a use clause, prompting for the list of packages used."
333 ; "[list of packages used]: "
337 (define-skeleton ada-record
338 "Insert a skeleton record type declaration."
345 (define-skeleton ada-subtype
346 "Start insertion of a subtype declaration, prompting for the subtype name."
348 "subtype " str " is " _ ?\;
349 (not (message "insert subtype indication.")))
352 (define-skeleton ada-type
353 "Start insertion of a type declaration, prompting for the type name."
356 ("[discriminant specs]: " str " ")
357 | (backward-delete-char 1) | ?\)
359 (not (message "insert type definition.")))
362 (define-skeleton ada-task-body
363 "Insert a task body, prompting for the task name."
365 "task body " str " is\n"
371 (define-skeleton ada-task-spec
372 "Insert a task specification, prompting for the task name."
375 " (" ("[discriminant]: " str "; ") ") is\n"
380 (define-skeleton ada-get-param1
381 "Prompt for arguments and if any enclose them in brackets."
383 ("[parameter_specification]: " str "; " ) & -2 & ")")
386 (define-skeleton ada-get-param
387 "Prompt for arguments and if any enclose them in brackets."
390 (ada-get-param1) | -2)
393 (define-skeleton ada-entry
394 "Insert a task entry, prompting for the entry name."
401 (define-skeleton ada-entry-family-prompt-discriminant
402 "Insert a entry specification, prompting for the entry name."
403 "[discriminant name]: "
407 (define-skeleton ada-entry-family
408 "Insert a entry specification, prompting for the entry name."
411 " (" (ada-entry-family-prompt-discriminant) ")"
416 (define-skeleton ada-select
417 "Insert a select block."
424 (define-skeleton ada-accept-1
425 "Insert a condition statement, prompting for the condition name."
430 (define-skeleton ada-accept-2
431 "Insert an accept statement, prompting for the name and arguments."
440 (define-skeleton ada-accept
441 "Insert an accept statement (prompt for condition, name and arguments)."
443 > (ada-accept-1) & " =>\n"
447 (define-skeleton ada-or-accept
448 "Insert an accept alternative, prompting for the condition name."
454 (define-skeleton ada-or-delay
455 "Insert a delay alternative, prompting for the delay value."
461 (define-skeleton ada-or-terminate
462 "Insert a terminate alternative."
470 ;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
471 ;;; ada-stmt.el ends here