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 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: Emmanuel Briot <briot@gnat.com>
10 ;; Keywords: languages, ada
11 ;; Rolf Ebert's version: 2.26
14 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
15 ;; in Ada/ on the menu bar.
20 ;; Original version from V. Bowman as in ada.el of Emacs-18
21 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
22 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
24 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
25 ;; Introduced statement.el for smaller code and user configurability.
27 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
28 ;; skeleton generation into this separate file. The code still is
29 ;; essentially written by DP
31 ;; Adapted Jun 1994. Markus Heritsch
32 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
33 ;; added menu bar support for templates
35 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
36 ;; General cleanup and bug fixes.
38 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
39 ;; made it work with skeleton.el from Emacs-19.30. Several
40 ;; enhancements and bug fixes.
43 ;;;> I have the following suggestions for the function template: 1) I
44 ;;;> don't want it automatically assigning it a name for the return variable. I
45 ;;;> never want it to be called "Result" because that is nondescriptive. If you
46 ;;;> must define a variable, give me the ability to specify its name.
48 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
49 ;;;> as the function's return type, which the template knows, so why force me
53 ;;;It would be nice if one could configure such layout details separately
54 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
55 ;;;could be taken even further, providing the user with some nice syntax
56 ;;;for describing layout. Then my own hacks would survive the next
57 ;;;update of the package :-)
62 (require 'skeleton nil t)
66 (defun ada-func-or-proc-name ()
67 ;; Get the name of the current function or procedure."
69 (let ((case-fold-search t))
70 (if (re-search-backward ada-procedure-start-regexp nil t)
71 (buffer-substring (match-beginning 3) (match-end 3))
74 ;;; ---- statement skeletons ------------------------------------------
76 (define-skeleton ada-array
77 "Insert array type definition.
78 Prompt for component type and index subtypes."
80 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
83 (define-skeleton ada-case
84 "Build skeleton case statement.
85 Prompt for the selector expression. Also builds the first when clause."
86 "[selector expression]: "
88 > "when " ("discrete choice: " str " | ") -3 " =>" \n
93 (define-skeleton ada-when
94 "Start a case statement alternative with a when clause."
96 < "when " ("discrete choice: " str " | ") -3 " =>" \n
100 (define-skeleton ada-declare-block
101 "Insert a block with a declare part.
102 Indent for the first declaration."
109 < "end " str | -1 ?\;)
112 (define-skeleton ada-exception-block
113 "Insert a block with an exception part.
114 Indent for the first line of code."
121 < "end " str | -1 ?\;)
124 (define-skeleton ada-exception
125 "Insert an indented exception part into a block."
131 (define-skeleton ada-exit-1
132 "Insert then exit condition of the exit statement, prompting for condition."
137 (define-skeleton ada-exit
138 "Insert an exit statement, prompting for loop name and condition."
139 "[name of loop to exit]: "
140 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
144 "Insert a descriptive header at the top of the file."
147 (goto-char (point-min))
148 (if (fboundp 'make-header)
149 (funcall (symbol-function 'make-header))
153 (define-skeleton ada-header-tmpl
154 "Insert a comment block containing the module title, author, etc."
156 "-- -*- Mode: Ada -*-"
157 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
158 "\n" ada-fill-comment-prefix "Description : " str
159 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
160 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
161 "\n" ada-fill-comment-prefix "Last Modified By: ."
162 "\n" ada-fill-comment-prefix "Last Modified On: ."
163 "\n" ada-fill-comment-prefix "Update Count : 0"
164 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
168 (define-skeleton ada-display-comment
169 "Inserts three comment lines, making a display comment."
171 "--\n" ada-fill-comment-prefix _ "\n--")
174 (define-skeleton ada-if
175 "Insert skeleton if statment, prompting for a boolean-expression."
182 (define-skeleton ada-elsif
183 "Add an elsif clause to an if statement,
184 prompting for the boolean-expression."
186 < "elsif " str " then" \n
190 (define-skeleton ada-else
191 "Add an else clause inside an if-then-end-if clause."
197 (define-skeleton ada-loop
198 "Insert a skeleton loop statement. The exit statement is added by hand."
203 < "end loop " str | -1 ?\;)
206 (define-skeleton ada-for-loop-prompt-variable
207 "Prompt for the loop variable."
212 (define-skeleton ada-for-loop-prompt-range
213 "Prompt for the loop range."
218 (define-skeleton ada-for-loop
219 "Build a skeleton for-loop statement, prompting for the loop parameters."
223 (ada-for-loop-prompt-variable)
225 (ada-for-loop-prompt-range)
228 < "end loop " str | -1 ?\;)
231 (define-skeleton ada-while-loop-prompt-entry-condition
232 "Prompt for the loop entry condition."
233 "[entry condition]: "
237 (define-skeleton ada-while-loop
238 "Insert a skeleton while loop statement."
242 (ada-while-loop-prompt-entry-condition)
245 < "end loop " str | -1 ?\;)
248 (define-skeleton ada-package-spec
249 "Insert a skeleton package specification."
251 "package " str " is" \n
256 (define-skeleton ada-package-body
257 "Insert a skeleton package body -- includes a begin statement."
259 "package body " str " is" \n
265 (define-skeleton ada-private
266 "Undent and start a private section of a package spec. Reindent."
272 (define-skeleton ada-function-spec-prompt-return
273 "Prompts for function result type."
278 (define-skeleton ada-function-spec
279 "Insert a function specification. Prompts for name and arguments."
282 " (" ("[parameter_specification]: " str "; " ) -2 ")"
284 (ada-function-spec-prompt-return)
288 (define-skeleton ada-procedure-spec
289 "Insert a procedure specification, prompting for its name and arguments."
292 " (" ("[parameter_specification]: " str "; " ) -2 ")"
296 (define-skeleton ada-subprogram-body
297 "Insert frame for subprogram body.
298 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
300 ;; Remove `;' from subprogram decl
302 (let ((pos (1+ (point))))
303 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
304 (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
314 "when others => null;" \n
316 (ada-func-or-proc-name)
320 (define-skeleton ada-separate
321 "Finish a body stub with `separate'."
327 ;(define-skeleton ada-with
328 ; "Inserts a with clause, prompting for the list of units depended upon."
329 ; "[list of units depended upon]: "
332 ;(define-skeleton ada-use
333 ; "Inserts a use clause, prompting for the list of packages used."
334 ; "[list of packages used]: "
338 (define-skeleton ada-record
339 "Insert a skeleton record type declaration."
346 (define-skeleton ada-subtype
347 "Start insertion of a subtype declaration, prompting for the subtype name."
349 "subtype " str " is " _ ?\;
350 (not (message "insert subtype indication.")))
353 (define-skeleton ada-type
354 "Start insertion of a type declaration, prompting for the type name."
357 ("[discriminant specs]: " str " ")
358 | (backward-delete-char 1) | ?\)
360 (not (message "insert type definition.")))
363 (define-skeleton ada-task-body
364 "Insert a task body, prompting for the task name."
366 "task body " str " is\n"
372 (define-skeleton ada-task-spec
373 "Insert a task specification, prompting for the task name."
376 " (" ("[discriminant]: " str "; ") ") is\n"
381 (define-skeleton ada-get-param1
382 "Prompt for arguments and if any enclose them in brackets."
384 ("[parameter_specification]: " str "; " ) & -2 & ")")
387 (define-skeleton ada-get-param
388 "Prompt for arguments and if any enclose them in brackets."
391 (ada-get-param1) | -2)
394 (define-skeleton ada-entry
395 "Insert a task entry, prompting for the entry name."
402 (define-skeleton ada-entry-family-prompt-discriminant
403 "Insert a entry specification, prompting for the entry name."
404 "[discriminant name]: "
408 (define-skeleton ada-entry-family
409 "Insert a entry specification, prompting for the entry name."
412 " (" (ada-entry-family-prompt-discriminant) ")"
417 (define-skeleton ada-select
418 "Insert a select block."
425 (define-skeleton ada-accept-1
426 "Insert a condition statement, prompting for the condition name."
431 (define-skeleton ada-accept-2
432 "Insert an accept statement, prompting for the name and arguments."
441 (define-skeleton ada-accept
442 "Insert an accept statement (prompt for condition, name and arguments)."
444 > (ada-accept-1) & " =>\n"
448 (define-skeleton ada-or-accept
449 "Insert an or statement, prompting for the condition name."
455 (define-skeleton ada-or-delay
456 "Insert a delay statement, prompting for the delay value."
462 (define-skeleton ada-or-terminate
463 "Insert a terminate statement."
471 ;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
472 ;;; ada-stmt.el ends here