* lisp/progmodes/compile.el (compilation-error-regexp-alist-alist)
[bpt/emacs.git] / lisp / progmodes / ada-stmt.el
CommitLineData
3afbc435 1;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates
fb98fa17 2
d7a0267c 3;; Copyright (C) 1987, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
114f9c96 4;; 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
c5220417 5;; Free Software Foundation, Inc.
fb98fa17 6
c5220417
GM
7;; Authors: Daniel Pfeiffer
8;; Markus Heritsch
9;; Rolf Ebert <ebert@waporo.muc.de>
88581e61 10;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
fb98fa17 11;; Keywords: languages, ada
bd78fa1d 12;; Package: ada-mode
fb98fa17 13
fff2683b
GM
14;; This file is part of GNU Emacs.
15
b1fc2b50 16;; GNU Emacs is free software: you can redistribute it and/or modify
fff2683b 17;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
18;; the Free Software Foundation, either version 3 of the License, or
19;; (at your option) any later version.
fff2683b
GM
20
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.
25
26;; You should have received a copy of the GNU General Public License
b1fc2b50 27;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
fff2683b 28
fb98fa17 29;;; Commentary:
18f9934c
SM
30;; This file is now automatically loaded from ada-mode.el, and creates a submenu
31;; in Ada/ on the menu bar.
fb98fa17
KH
32
33;;; History:
34
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.)
39;;
40;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
41;; Introduced statement.el for smaller code and user configurability.
42;;
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
a1506d29 46;;
fb98fa17
KH
47;; Adapted Jun 1994. Markus Heritsch
48;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
49;; added menu bar support for templates
50;;
51;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
52;; General cleanup and bug fixes.
53;;
54;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
fb8abe0d 55;; made it work with skeleton.el from Emacs-19.30. Several
fb98fa17
KH
56;; enhancements and bug fixes.
57
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;;;>
68
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 :-)
74
75\f
76;;; Code:
77
6f9a2614 78(require 'skeleton nil t)
fb98fa17 79(require 'easymenu)
6f9a2614 80(require 'ada-mode)
fb98fa17 81
fb98fa17 82(defun ada-func-or-proc-name ()
88581e61 83 "Return the name of the current function or procedure."
fb98fa17
KH
84 (save-excursion
85 (let ((case-fold-search t))
86 (if (re-search-backward ada-procedure-start-regexp nil t)
3b5b1ad9 87 (match-string 5)
fb98fa17
KH
88 "NAME?"))))
89
fb98fa17
KH
90;;; ---- statement skeletons ------------------------------------------
91
92(define-skeleton ada-array
1a7244d9 93 "Insert array type definition.
fb8abe0d 94Prompt for component type and index subtypes."
fb98fa17
KH
95 ()
96 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
97
98
99(define-skeleton ada-case
1a7244d9 100 "Build skeleton case statement.
32b1a27f 101Prompt for the selector expression. Also builds the first when clause."
fb98fa17
KH
102 "[selector expression]: "
103 "case " str " is" \n
104 > "when " ("discrete choice: " str " | ") -3 " =>" \n
105 > _ \n
106 < < "end case;")
107
108
109(define-skeleton ada-when
110 "Start a case statement alternative with a when clause."
111 ()
112 < "when " ("discrete choice: " str " | ") -3 " =>" \n
113 >)
114
115
116(define-skeleton ada-declare-block
117 "Insert a block with a declare part.
118Indent for the first declaration."
119 "[block name]: "
120 < str & ?: & \n
121 > "declare" \n
122 > _ \n
123 < "begin" \n
124 > \n
125 < "end " str | -1 ?\;)
126
127
128(define-skeleton ada-exception-block
129 "Insert a block with an exception part.
130Indent 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 ?\;)
138
139
140(define-skeleton ada-exception
141 "Insert an indented exception part into a block."
142 ()
143 < "exception" \n
144 >)
145
146
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)
151
152
153(define-skeleton ada-exit
154 "Insert an exit statement, prompting for loop name and condition."
155 "[name of loop to exit]: "
18f9934c 156 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
fb98fa17 157
3d8e3891 158;;;###autoload
fb98fa17
KH
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)
cf543c1c 165 (funcall (symbol-function 'make-header))
fb98fa17
KH
166 (ada-header-tmpl))))
167
168
169(define-skeleton ada-header-tmpl
170 "Insert a comment block containing the module title, author, etc."
171 "[Description]: "
172 "-- -*- Mode: Ada -*-"
cf543c1c
GM
173 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
174 "\n" ada-fill-comment-prefix "Description : " str
9dd7cdcc 175 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
cf543c1c
GM
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!"
fb98fa17
KH
181 "\n")
182
183
184(define-skeleton ada-display-comment
185 "Inserts three comment lines, making a display comment."
186 ()
cf543c1c 187 "--\n" ada-fill-comment-prefix _ "\n--")
fb98fa17
KH
188
189
190(define-skeleton ada-if
d1f18ec0 191 "Insert skeleton if statement, prompting for a boolean-expression."
fb98fa17
KH
192 "[condition]: "
193 "if " str " then" \n
194 > _ \n
195 < "end if;")
196
197
198(define-skeleton ada-elsif
9dd7cdcc 199 "Add an elsif clause to an if statement,
fb98fa17
KH
200prompting for the boolean-expression."
201 "[condition]: "
202 < "elsif " str " then" \n
203 >)
204
205
206(define-skeleton ada-else
207 "Add an else clause inside an if-then-end-if clause."
208 ()
209 < "else" \n
210 >)
211
212
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 ?\;)
220
221
222(define-skeleton ada-for-loop-prompt-variable
223 "Prompt for the loop variable."
224 "[loop variable]: "
225 str)
226
227
228(define-skeleton ada-for-loop-prompt-range
229 "Prompt for the loop range."
230 "[loop range]: "
231 str)
232
233
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 ?\;)
245
246
247(define-skeleton ada-while-loop-prompt-entry-condition
248 "Prompt for the loop entry condition."
249 "[entry condition]: "
250 str)
251
252
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 ?\;)
262
263
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 ?\;)
270
271
272(define-skeleton ada-package-body
32b1a27f 273 "Insert a skeleton package body -- includes a begin statement."
fb98fa17
KH
274 "[package name]: "
275 "package body " str " is" \n
276 > _ \n
277; < "begin" \n
278 < "end " str ?\;)
279
280
281(define-skeleton ada-private
32b1a27f 282 "Undent and start a private section of a package spec. Reindent."
fb98fa17
KH
283 ()
284 < "private" \n
285 >)
286
287
288(define-skeleton ada-function-spec-prompt-return
289 "Prompts for function result type."
290 "[result type]: "
291 str)
292
293
294(define-skeleton ada-function-spec
295 "Insert a function specification. Prompts for name and arguments."
296 "[function name]: "
9dd7cdcc 297 "function " str
fb98fa17
KH
298 " (" ("[parameter_specification]: " str "; " ) -2 ")"
299 " return "
300 (ada-function-spec-prompt-return)
301 ";" \n )
302
303
304(define-skeleton ada-procedure-spec
305 "Insert a procedure specification, prompting for its name and arguments."
306 "[procedure name]: "
9dd7cdcc 307 "procedure " str
fb98fa17
KH
308 " (" ("[parameter_specification]: " str "; " ) -2 ")"
309 ";" \n )
310
311
312(define-skeleton ada-subprogram-body
313 "Insert frame for subprogram body.
314Invoke right after `ada-function-spec' or `ada-procedure-spec'."
315 ()
316 ;; Remove `;' from subprogram decl
317 (save-excursion
3d8e3891
GM
318 (let ((pos (1+ (point))))
319 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
9dd7cdcc
SM
320 (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
321 (backward-char 1)
322 (forward-sexp 1)))
fb98fa17 323 (if (looking-at ";")
88581e61 324 (delete-char 1)))
3d8e3891
GM
325 " is" \n
326 _ \n
327 < "begin" \n
328 \n
329 < "exception" \n
330 "when others => null;" \n
331 < < "end "
fb98fa17 332 (ada-func-or-proc-name)
3d8e3891 333 ";" \n)
fb98fa17
KH
334
335
336(define-skeleton ada-separate
337 "Finish a body stub with `separate'."
338 ()
339 > "separate;" \n
340 <)
341
342
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 ?\;)
347
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 ?\;)
a1506d29 352
fb98fa17
KH
353
354(define-skeleton ada-record
355 "Insert a skeleton record type declaration."
356 ()
357 "record" \n
358 > _ \n
359 < "end record;")
360
361
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.")))
367
368
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.")))
377
378
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 ";" )
386
387
388(define-skeleton ada-task-spec
389 "Insert a task specification, prompting for the task name."
390 "[task name]: "
9dd7cdcc 391 "task " str
fb98fa17
KH
392 " (" ("[discriminant]: " str "; ") ") is\n"
393 > "entry " _ \n
394 <"end " str ";" )
a1506d29 395
fb98fa17
KH
396
397(define-skeleton ada-get-param1
398 "Prompt for arguments and if any enclose them in brackets."
399 ()
9dd7cdcc 400 ("[parameter_specification]: " str "; " ) & -2 & ")")
fb98fa17
KH
401
402
403(define-skeleton ada-get-param
404 "Prompt for arguments and if any enclose them in brackets."
405 ()
9dd7cdcc
SM
406 " ("
407 (ada-get-param1) | -2)
fb98fa17
KH
408
409
410(define-skeleton ada-entry
411 "Insert a task entry, prompting for the entry name."
412 "[entry name]: "
9dd7cdcc 413 "entry " str
fb98fa17 414 (ada-get-param)
9dd7cdcc 415 ";" \n)
fb98fa17
KH
416
417
418(define-skeleton ada-entry-family-prompt-discriminant
419 "Insert a entry specification, prompting for the entry name."
420 "[discriminant name]: "
421 str)
422
423
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)
9dd7cdcc 430 ";" \n)
fb98fa17
KH
431
432
433(define-skeleton ada-select
434 "Insert a select block."
435 ()
436 "select\n"
437 > _ \n
438 < "end select;")
439
440
441(define-skeleton ada-accept-1
442 "Insert a condition statement, prompting for the condition name."
9dd7cdcc 443 "[condition]: "
fb98fa17
KH
444 "when " str | -5 )
445
446
447(define-skeleton ada-accept-2
448 "Insert an accept statement, prompting for the name and arguments."
9dd7cdcc
SM
449 "[accept name]: "
450 > "accept " str
fb98fa17 451 (ada-get-param)
fb98fa17
KH
452 " do" \n
453 > _ \n
454 < "end " str ";" )
455
456
457(define-skeleton ada-accept
458 "Insert an accept statement (prompt for condition, name and arguments)."
459 ()
460 > (ada-accept-1) & " =>\n"
9dd7cdcc 461 (ada-accept-2))
fb98fa17
KH
462
463
464(define-skeleton ada-or-accept
3b5b1ad9 465 "Insert an accept alternative, prompting for the condition name."
fb98fa17
KH
466 ()
467 < "or\n"
9dd7cdcc 468 (ada-accept))
fb98fa17
KH
469
470
471(define-skeleton ada-or-delay
3b5b1ad9 472 "Insert a delay alternative, prompting for the delay value."
9dd7cdcc 473 "[delay value]: "
fb98fa17
KH
474 < "or\n"
475 > "delay " str ";")
a1506d29 476
fb98fa17
KH
477
478(define-skeleton ada-or-terminate
3b5b1ad9 479 "Insert a terminate alternative."
fb98fa17
KH
480 ()
481 < "or\n"
482 > "terminate;")
483
484
fb98fa17
KH
485(provide 'ada-stmt)
486
cbee283d 487;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
fb98fa17 488;;; ada-stmt.el ends here