Add "Package:" file headers to denote built-in packages.
[emacs.git] / lisp / progmodes / ada-stmt.el
blobb618b26c73a84e856e8b890c8127b4d16595daeb
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
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Daniel Pfeiffer
8 ;; Markus Heritsch
9 ;; Rolf Ebert <ebert@waporo.muc.de>
10 ;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
11 ;; Keywords: languages, ada
12 ;; Package: ada-mode
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/>.
29 ;;; Commentary:
30 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
31 ;; in Ada/ on the menu bar.
33 ;;; History:
35 ;; Created May 1987.
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.
58 ;; BUGS:
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.
63 ;;;>
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
66 ;;;> to type it in?
67 ;;;>
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 :-)
76 ;;; Code:
78 (require 'skeleton nil t)
79 (require 'easymenu)
80 (require 'ada-mode)
82 (defun ada-func-or-proc-name ()
83 "Return the name of the current function or procedure."
84 (save-excursion
85 (let ((case-fold-search t))
86 (if (re-search-backward ada-procedure-start-regexp nil t)
87 (match-string 5)
88 "NAME?"))))
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]: "
103 "case " str " is" \n
104 > "when " ("discrete choice: " str " | ") -3 " =>" \n
105 > _ \n
106 < < "end case;")
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."
119 "[block name]: "
120 < str & ?: & \n
121 > "declare" \n
122 > _ \n
123 < "begin" \n
124 > \n
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."
131 "[block name]: "
132 < str & ?: & \n
133 > "begin" \n
134 > _ \n
135 < "exception" \n
136 > \n
137 < "end " str | -1 ?\;)
140 (define-skeleton ada-exception
141 "Insert an indented exception part into a block."
143 < "exception" \n
147 (define-skeleton ada-exit-1
148 "Insert then exit condition of the exit statement, prompting for condition."
149 "[exit condition]: "
150 "when " str | -5)
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 ?\;)
158 ;;;###autoload
159 (defun ada-header ()
160 "Insert a descriptive header at the top of the file."
161 (interactive "*")
162 (save-excursion
163 (goto-char (point-min))
164 (if (fboundp 'make-header)
165 (funcall (symbol-function 'make-header))
166 (ada-header-tmpl))))
169 (define-skeleton ada-header-tmpl
170 "Insert a comment block containing the module title, author, etc."
171 "[Description]: "
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!"
181 "\n")
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."
192 "[condition]: "
193 "if " str " then" \n
194 > _ \n
195 < "end if;")
198 (define-skeleton ada-elsif
199 "Add an elsif clause to an if statement,
200 prompting for the boolean-expression."
201 "[condition]: "
202 < "elsif " str " then" \n
206 (define-skeleton ada-else
207 "Add an else clause inside an if-then-end-if clause."
209 < "else" \n
213 (define-skeleton ada-loop
214 "Insert a skeleton loop statement. The exit statement is added by hand."
215 "[loop name]: "
216 < str & ?: & \n
217 > "loop" \n
218 > _ \n
219 < "end loop " str | -1 ?\;)
222 (define-skeleton ada-for-loop-prompt-variable
223 "Prompt for the loop variable."
224 "[loop variable]: "
225 str)
228 (define-skeleton ada-for-loop-prompt-range
229 "Prompt for the loop range."
230 "[loop range]: "
231 str)
234 (define-skeleton ada-for-loop
235 "Build a skeleton for-loop statement, prompting for the loop parameters."
236 "[loop name]: "
237 < str & ?: & \n
238 > "for "
239 (ada-for-loop-prompt-variable)
240 " in "
241 (ada-for-loop-prompt-range)
242 " loop" \n
243 > _ \n
244 < "end loop " str | -1 ?\;)
247 (define-skeleton ada-while-loop-prompt-entry-condition
248 "Prompt for the loop entry condition."
249 "[entry condition]: "
250 str)
253 (define-skeleton ada-while-loop
254 "Insert a skeleton while loop statement."
255 "[loop name]: "
256 < str & ?: & \n
257 > "while "
258 (ada-while-loop-prompt-entry-condition)
259 " loop" \n
260 > _ \n
261 < "end loop " str | -1 ?\;)
264 (define-skeleton ada-package-spec
265 "Insert a skeleton package specification."
266 "[package name]: "
267 "package " str " is" \n
268 > _ \n
269 < "end " str ?\;)
272 (define-skeleton ada-package-body
273 "Insert a skeleton package body -- includes a begin statement."
274 "[package name]: "
275 "package body " str " is" \n
276 > _ \n
277 ; < "begin" \n
278 < "end " str ?\;)
281 (define-skeleton ada-private
282 "Undent and start a private section of a package spec. Reindent."
284 < "private" \n
288 (define-skeleton ada-function-spec-prompt-return
289 "Prompts for function result type."
290 "[result type]: "
291 str)
294 (define-skeleton ada-function-spec
295 "Insert a function specification. Prompts for name and arguments."
296 "[function name]: "
297 "function " str
298 " (" ("[parameter_specification]: " str "; " ) -2 ")"
299 " return "
300 (ada-function-spec-prompt-return)
301 ";" \n )
304 (define-skeleton ada-procedure-spec
305 "Insert a procedure specification, prompting for its name and arguments."
306 "[procedure name]: "
307 "procedure " str
308 " (" ("[parameter_specification]: " str "; " ) -2 ")"
309 ";" \n )
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
317 (save-excursion
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)
321 (backward-char 1)
322 (forward-sexp 1)))
323 (if (looking-at ";")
324 (delete-char 1)))
325 " is" \n
326 _ \n
327 < "begin" \n
329 < "exception" \n
330 "when others => null;" \n
331 < < "end "
332 (ada-func-or-proc-name)
333 ";" \n)
336 (define-skeleton ada-separate
337 "Finish a body stub with `separate'."
339 > "separate;" \n
343 ;(define-skeleton ada-with
344 ; "Inserts a with clause, prompting for the list of units depended upon."
345 ; "[list of units depended upon]: "
346 ; "with " str ?\;)
348 ;(define-skeleton ada-use
349 ; "Inserts a use clause, prompting for the list of packages used."
350 ; "[list of packages used]: "
351 ; "use " str ?\;)
354 (define-skeleton ada-record
355 "Insert a skeleton record type declaration."
357 "record" \n
358 > _ \n
359 < "end record;")
362 (define-skeleton ada-subtype
363 "Start insertion of a subtype declaration, prompting for the subtype name."
364 "[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."
371 "[type name]: "
372 "type " str ?\(
373 ("[discriminant specs]: " str " ")
374 | (backward-delete-char 1) | ?\)
375 " is "
376 (not (message "insert type definition.")))
379 (define-skeleton ada-task-body
380 "Insert a task body, prompting for the task name."
381 "[task name]: "
382 "task body " str " is\n"
383 "begin\n"
384 > _ \n
385 < "end " str ";" )
388 (define-skeleton ada-task-spec
389 "Insert a task specification, prompting for the task name."
390 "[task name]: "
391 "task " str
392 " (" ("[discriminant]: " str "; ") ") is\n"
393 > "entry " _ \n
394 <"end " str ";" )
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."
406 " ("
407 (ada-get-param1) | -2)
410 (define-skeleton ada-entry
411 "Insert a task entry, prompting for the entry name."
412 "[entry name]: "
413 "entry " str
414 (ada-get-param)
415 ";" \n)
418 (define-skeleton ada-entry-family-prompt-discriminant
419 "Insert a entry specification, prompting for the entry name."
420 "[discriminant name]: "
421 str)
424 (define-skeleton ada-entry-family
425 "Insert a entry specification, prompting for the entry name."
426 "[entry name]: "
427 "entry " str
428 " (" (ada-entry-family-prompt-discriminant) ")"
429 (ada-get-param)
430 ";" \n)
433 (define-skeleton ada-select
434 "Insert a select block."
436 "select\n"
437 > _ \n
438 < "end select;")
441 (define-skeleton ada-accept-1
442 "Insert a condition statement, prompting for the condition name."
443 "[condition]: "
444 "when " str | -5 )
447 (define-skeleton ada-accept-2
448 "Insert an accept statement, prompting for the name and arguments."
449 "[accept name]: "
450 > "accept " str
451 (ada-get-param)
452 " do" \n
453 > _ \n
454 < "end " str ";" )
457 (define-skeleton ada-accept
458 "Insert an accept statement (prompt for condition, name and arguments)."
460 > (ada-accept-1) & " =>\n"
461 (ada-accept-2))
464 (define-skeleton ada-or-accept
465 "Insert an accept alternative, prompting for the condition name."
467 < "or\n"
468 (ada-accept))
471 (define-skeleton ada-or-delay
472 "Insert a delay alternative, prompting for the delay value."
473 "[delay value]: "
474 < "or\n"
475 > "delay " str ";")
478 (define-skeleton ada-or-terminate
479 "Insert a terminate alternative."
481 < "or\n"
482 > "terminate;")
485 (provide 'ada-stmt)
487 ;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
488 ;;; ada-stmt.el ends here