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, 2008, 2009, 2010, 2011
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Daniel Pfeiffer
9 ;; Rolf Ebert <ebert@waporo.muc.de>
10 ;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
11 ;; Keywords: languages, ada
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
31 ;; in Ada/ on the menu bar.
36 ;; Original version from V. Bowman as in ada.el of Emacs-18
37 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
38 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
40 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
41 ;; Introduced statement.el for smaller code and user configurability.
43 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
44 ;; skeleton generation into this separate file. The code still is
45 ;; essentially written by DP
47 ;; Adapted Jun 1994. Markus Heritsch
48 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
49 ;; added menu bar support for templates
51 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
52 ;; General cleanup and bug fixes.
54 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
55 ;; made it work with skeleton.el from Emacs-19.30. Several
56 ;; enhancements and bug fixes.
59 ;;;> I have the following suggestions for the function template: 1) I
60 ;;;> don't want it automatically assigning it a name for the return variable. I
61 ;;;> never want it to be called "Result" because that is nondescriptive. If you
62 ;;;> must define a variable, give me the ability to specify its name.
64 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
65 ;;;> as the function's return type, which the template knows, so why force me
69 ;;;It would be nice if one could configure such layout details separately
70 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
71 ;;;could be taken even further, providing the user with some nice syntax
72 ;;;for describing layout. Then my own hacks would survive the next
73 ;;;update of the package :-)
78 (require 'skeleton nil t)
82 (defun ada-func-or-proc-name ()
83 "Return the name of the current function or procedure."
85 (let ((case-fold-search t))
86 (if (re-search-backward ada-procedure-start-regexp nil t)
90 ;;; ---- statement skeletons ------------------------------------------
92 (define-skeleton ada-array
93 "Insert array type definition.
94 Prompt for component type and index subtypes."
96 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
99 (define-skeleton ada-case
100 "Build skeleton case statement.
101 Prompt for the selector expression. Also builds the first when clause."
102 "[selector expression]: "
104 > "when " ("discrete choice: " str " | ") -3 " =>" \n
109 (define-skeleton ada-when
110 "Start a case statement alternative with a when clause."
112 < "when " ("discrete choice: " str " | ") -3 " =>" \n
116 (define-skeleton ada-declare-block
117 "Insert a block with a declare part.
118 Indent for the first declaration."
125 < "end " str | -1 ?\;)
128 (define-skeleton ada-exception-block
129 "Insert a block with an exception part.
130 Indent for the first line of code."
137 < "end " str | -1 ?\;)
140 (define-skeleton ada-exception
141 "Insert an indented exception part into a block."
147 (define-skeleton ada-exit-1
148 "Insert then exit condition of the exit statement, prompting for condition."
153 (define-skeleton ada-exit
154 "Insert an exit statement, prompting for loop name and condition."
155 "[name of loop to exit]: "
156 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
160 "Insert a descriptive header at the top of the file."
163 (goto-char (point-min))
164 (if (fboundp 'make-header)
165 (funcall (symbol-function 'make-header))
169 (define-skeleton ada-header-tmpl
170 "Insert a comment block containing the module title, author, etc."
172 "-- -*- Mode: Ada -*-"
173 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
174 "\n" ada-fill-comment-prefix "Description : " str
175 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
176 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
177 "\n" ada-fill-comment-prefix "Last Modified By: ."
178 "\n" ada-fill-comment-prefix "Last Modified On: ."
179 "\n" ada-fill-comment-prefix "Update Count : 0"
180 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
184 (define-skeleton ada-display-comment
185 "Inserts three comment lines, making a display comment."
187 "--\n" ada-fill-comment-prefix _ "\n--")
190 (define-skeleton ada-if
191 "Insert skeleton if statement, prompting for a boolean-expression."
198 (define-skeleton ada-elsif
199 "Add an elsif clause to an if statement,
200 prompting for the boolean-expression."
202 < "elsif " str " then" \n
206 (define-skeleton ada-else
207 "Add an else clause inside an if-then-end-if clause."
213 (define-skeleton ada-loop
214 "Insert a skeleton loop statement. The exit statement is added by hand."
219 < "end loop " str | -1 ?\;)
222 (define-skeleton ada-for-loop-prompt-variable
223 "Prompt for the loop variable."
228 (define-skeleton ada-for-loop-prompt-range
229 "Prompt for the loop range."
234 (define-skeleton ada-for-loop
235 "Build a skeleton for-loop statement, prompting for the loop parameters."
239 (ada-for-loop-prompt-variable)
241 (ada-for-loop-prompt-range)
244 < "end loop " str | -1 ?\;)
247 (define-skeleton ada-while-loop-prompt-entry-condition
248 "Prompt for the loop entry condition."
249 "[entry condition]: "
253 (define-skeleton ada-while-loop
254 "Insert a skeleton while loop statement."
258 (ada-while-loop-prompt-entry-condition)
261 < "end loop " str | -1 ?\;)
264 (define-skeleton ada-package-spec
265 "Insert a skeleton package specification."
267 "package " str " is" \n
272 (define-skeleton ada-package-body
273 "Insert a skeleton package body -- includes a begin statement."
275 "package body " str " is" \n
281 (define-skeleton ada-private
282 "Undent and start a private section of a package spec. Reindent."
288 (define-skeleton ada-function-spec-prompt-return
289 "Prompts for function result type."
294 (define-skeleton ada-function-spec
295 "Insert a function specification. Prompts for name and arguments."
298 " (" ("[parameter_specification]: " str "; " ) -2 ")"
300 (ada-function-spec-prompt-return)
304 (define-skeleton ada-procedure-spec
305 "Insert a procedure specification, prompting for its name and arguments."
308 " (" ("[parameter_specification]: " str "; " ) -2 ")"
312 (define-skeleton ada-subprogram-body
313 "Insert frame for subprogram body.
314 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
316 ;; Remove `;' from subprogram decl
318 (let ((pos (1+ (point))))
319 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
320 (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
330 "when others => null;" \n
332 (ada-func-or-proc-name)
336 (define-skeleton ada-separate
337 "Finish a body stub with `separate'."
343 ;(define-skeleton ada-with
344 ; "Inserts a with clause, prompting for the list of units depended upon."
345 ; "[list of units depended upon]: "
348 ;(define-skeleton ada-use
349 ; "Inserts a use clause, prompting for the list of packages used."
350 ; "[list of packages used]: "
354 (define-skeleton ada-record
355 "Insert a skeleton record type declaration."
362 (define-skeleton ada-subtype
363 "Start insertion of a subtype declaration, prompting for the subtype name."
365 "subtype " str " is " _ ?\;
366 (not (message "insert subtype indication.")))
369 (define-skeleton ada-type
370 "Start insertion of a type declaration, prompting for the type name."
373 ("[discriminant specs]: " str " ")
374 | (backward-delete-char 1) | ?\)
376 (not (message "insert type definition.")))
379 (define-skeleton ada-task-body
380 "Insert a task body, prompting for the task name."
382 "task body " str " is\n"
388 (define-skeleton ada-task-spec
389 "Insert a task specification, prompting for the task name."
392 " (" ("[discriminant]: " str "; ") ") is\n"
397 (define-skeleton ada-get-param1
398 "Prompt for arguments and if any enclose them in brackets."
400 ("[parameter_specification]: " str "; " ) & -2 & ")")
403 (define-skeleton ada-get-param
404 "Prompt for arguments and if any enclose them in brackets."
407 (ada-get-param1) | -2)
410 (define-skeleton ada-entry
411 "Insert a task entry, prompting for the entry name."
418 (define-skeleton ada-entry-family-prompt-discriminant
419 "Insert a entry specification, prompting for the entry name."
420 "[discriminant name]: "
424 (define-skeleton ada-entry-family
425 "Insert a entry specification, prompting for the entry name."
428 " (" (ada-entry-family-prompt-discriminant) ")"
433 (define-skeleton ada-select
434 "Insert a select block."
441 (define-skeleton ada-accept-1
442 "Insert a condition statement, prompting for the condition name."
447 (define-skeleton ada-accept-2
448 "Insert an accept statement, prompting for the name and arguments."
457 (define-skeleton ada-accept
458 "Insert an accept statement (prompt for condition, name and arguments)."
460 > (ada-accept-1) & " =>\n"
464 (define-skeleton ada-or-accept
465 "Insert an accept alternative, prompting for the condition name."
471 (define-skeleton ada-or-delay
472 "Insert a delay alternative, prompting for the delay value."
478 (define-skeleton ada-or-terminate
479 "Insert a terminate alternative."
487 ;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
488 ;;; ada-stmt.el ends here