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 Free Software Foundation, Inc.
6 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
7 ;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
8 ;; Keywords: languages, ada
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
28 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
29 ;; in Ada/ on the menu bar.
34 ;; Original version from V. Bowman as in ada.el of Emacs-18
35 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
36 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
38 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
39 ;; Introduced statement.el for smaller code and user configurability.
41 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
42 ;; skeleton generation into this separate file. The code still is
43 ;; essentially written by DP
45 ;; Adapted Jun 1994. Markus Heritsch
46 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
47 ;; added menu bar support for templates
49 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
50 ;; General cleanup and bug fixes.
52 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
53 ;; made it work with skeleton.el from Emacs-19.30. Several
54 ;; enhancements and bug fixes.
57 ;;;> I have the following suggestions for the function template: 1) I
58 ;;;> don't want it automatically assigning it a name for the return variable. I
59 ;;;> never want it to be called "Result" because that is nondescriptive. If you
60 ;;;> must define a variable, give me the ability to specify its name.
62 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
63 ;;;> as the function's return type, which the template knows, so why force me
67 ;;;It would be nice if one could configure such layout details separately
68 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
69 ;;;could be taken even further, providing the user with some nice syntax
70 ;;;for describing layout. Then my own hacks would survive the next
71 ;;;update of the package :-)
76 (require 'skeleton nil t
)
80 (defun ada-func-or-proc-name ()
81 "Return the name of the current function or procedure."
83 (let ((case-fold-search t
))
84 (if (re-search-backward ada-procedure-start-regexp nil t
)
88 ;;; ---- statement skeletons ------------------------------------------
90 (define-skeleton ada-array
91 "Insert array type definition.
92 Prompt for component type and index subtypes."
94 "array (" ("index definition: " str
", " ) -
2 ") of " _ ?\
;)
97 (define-skeleton ada-case
98 "Build skeleton case statement.
99 Prompt for the selector expression. Also builds the first when clause."
100 "[selector expression]: "
102 > "when " ("discrete choice: " str
" | ") -
3 " =>" \n
107 (define-skeleton ada-when
108 "Start a case statement alternative with a when clause."
110 < "when " ("discrete choice: " str
" | ") -
3 " =>" \n
114 (define-skeleton ada-declare-block
115 "Insert a block with a declare part.
116 Indent for the first declaration."
123 < "end " str | -
1 ?\
;)
126 (define-skeleton ada-exception-block
127 "Insert a block with an exception part.
128 Indent for the first line of code."
135 < "end " str | -
1 ?\
;)
138 (define-skeleton ada-exception
139 "Insert an indented exception part into a block."
145 (define-skeleton ada-exit-1
146 "Insert then exit condition of the exit statement, prompting for condition."
151 (define-skeleton ada-exit
152 "Insert an exit statement, prompting for loop name and condition."
153 "[name of loop to exit]: "
154 "exit " str
& ?\
(ada-exit-1) | -
1 ?\
;)
158 "Insert a descriptive header at the top of the file."
161 (goto-char (point-min))
162 (if (fboundp 'make-header
)
163 (funcall (symbol-function 'make-header
))
167 (define-skeleton ada-header-tmpl
168 "Insert a comment block containing the module title, author, etc."
170 "-- -*- Mode: Ada -*-"
171 "\n" ada-fill-comment-prefix
"Filename : " (buffer-name)
172 "\n" ada-fill-comment-prefix
"Description : " str
173 "\n" ada-fill-comment-prefix
"Author : " (user-full-name)
174 "\n" ada-fill-comment-prefix
"Created On : " (current-time-string)
175 "\n" ada-fill-comment-prefix
"Last Modified By: ."
176 "\n" ada-fill-comment-prefix
"Last Modified On: ."
177 "\n" ada-fill-comment-prefix
"Update Count : 0"
178 "\n" ada-fill-comment-prefix
"Status : Unknown, Use with caution!"
182 (define-skeleton ada-display-comment
183 "Inserts three comment lines, making a display comment."
185 "--\n" ada-fill-comment-prefix _
"\n--")
188 (define-skeleton ada-if
189 "Insert skeleton if statment, prompting for a boolean-expression."
196 (define-skeleton ada-elsif
197 "Add an elsif clause to an if statement,
198 prompting for the boolean-expression."
200 < "elsif " str
" then" \n
204 (define-skeleton ada-else
205 "Add an else clause inside an if-then-end-if clause."
211 (define-skeleton ada-loop
212 "Insert a skeleton loop statement. The exit statement is added by hand."
217 < "end loop " str | -
1 ?\
;)
220 (define-skeleton ada-for-loop-prompt-variable
221 "Prompt for the loop variable."
226 (define-skeleton ada-for-loop-prompt-range
227 "Prompt for the loop range."
232 (define-skeleton ada-for-loop
233 "Build a skeleton for-loop statement, prompting for the loop parameters."
237 (ada-for-loop-prompt-variable)
239 (ada-for-loop-prompt-range)
242 < "end loop " str | -
1 ?\
;)
245 (define-skeleton ada-while-loop-prompt-entry-condition
246 "Prompt for the loop entry condition."
247 "[entry condition]: "
251 (define-skeleton ada-while-loop
252 "Insert a skeleton while loop statement."
256 (ada-while-loop-prompt-entry-condition)
259 < "end loop " str | -
1 ?\
;)
262 (define-skeleton ada-package-spec
263 "Insert a skeleton package specification."
265 "package " str
" is" \n
270 (define-skeleton ada-package-body
271 "Insert a skeleton package body -- includes a begin statement."
273 "package body " str
" is" \n
279 (define-skeleton ada-private
280 "Undent and start a private section of a package spec. Reindent."
286 (define-skeleton ada-function-spec-prompt-return
287 "Prompts for function result type."
292 (define-skeleton ada-function-spec
293 "Insert a function specification. Prompts for name and arguments."
296 " (" ("[parameter_specification]: " str
"; " ) -
2 ")"
298 (ada-function-spec-prompt-return)
302 (define-skeleton ada-procedure-spec
303 "Insert a procedure specification, prompting for its name and arguments."
306 " (" ("[parameter_specification]: " str
"; " ) -
2 ")"
310 (define-skeleton ada-subprogram-body
311 "Insert frame for subprogram body.
312 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
314 ;; Remove `;' from subprogram decl
316 (let ((pos (1+ (point))))
317 (ada-search-ignore-string-comment ada-subprog-start-re t nil
)
318 (when (ada-search-ignore-string-comment "(" nil pos t
'search-forward
)
328 "when others => null;" \n
330 (ada-func-or-proc-name)
334 (define-skeleton ada-separate
335 "Finish a body stub with `separate'."
341 ;(define-skeleton ada-with
342 ; "Inserts a with clause, prompting for the list of units depended upon."
343 ; "[list of units depended upon]: "
346 ;(define-skeleton ada-use
347 ; "Inserts a use clause, prompting for the list of packages used."
348 ; "[list of packages used]: "
352 (define-skeleton ada-record
353 "Insert a skeleton record type declaration."
360 (define-skeleton ada-subtype
361 "Start insertion of a subtype declaration, prompting for the subtype name."
363 "subtype " str
" is " _ ?\
;
364 (not (message "insert subtype indication.")))
367 (define-skeleton ada-type
368 "Start insertion of a type declaration, prompting for the type name."
371 ("[discriminant specs]: " str
" ")
372 |
(backward-delete-char 1) | ?\
)
374 (not (message "insert type definition.")))
377 (define-skeleton ada-task-body
378 "Insert a task body, prompting for the task name."
380 "task body " str
" is\n"
386 (define-skeleton ada-task-spec
387 "Insert a task specification, prompting for the task name."
390 " (" ("[discriminant]: " str
"; ") ") is\n"
395 (define-skeleton ada-get-param1
396 "Prompt for arguments and if any enclose them in brackets."
398 ("[parameter_specification]: " str
"; " ) & -
2 & ")")
401 (define-skeleton ada-get-param
402 "Prompt for arguments and if any enclose them in brackets."
405 (ada-get-param1) | -
2)
408 (define-skeleton ada-entry
409 "Insert a task entry, prompting for the entry name."
416 (define-skeleton ada-entry-family-prompt-discriminant
417 "Insert a entry specification, prompting for the entry name."
418 "[discriminant name]: "
422 (define-skeleton ada-entry-family
423 "Insert a entry specification, prompting for the entry name."
426 " (" (ada-entry-family-prompt-discriminant) ")"
431 (define-skeleton ada-select
432 "Insert a select block."
439 (define-skeleton ada-accept-1
440 "Insert a condition statement, prompting for the condition name."
445 (define-skeleton ada-accept-2
446 "Insert an accept statement, prompting for the name and arguments."
455 (define-skeleton ada-accept
456 "Insert an accept statement (prompt for condition, name and arguments)."
458 > (ada-accept-1) & " =>\n"
462 (define-skeleton ada-or-accept
463 "Insert an accept alternative, prompting for the condition name."
469 (define-skeleton ada-or-delay
470 "Insert a delay alternative, prompting for the delay value."
476 (define-skeleton ada-or-terminate
477 "Insert a terminate alternative."
485 ;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
486 ;;; ada-stmt.el ends here