Commit | Line | Data |
---|---|---|
3afbc435 | 1 | ;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates |
fb98fa17 | 2 | |
ba318903 | 3 | ;; Copyright (C) 1987, 1993-1994, 1996-2014 Free Software Foundation, |
ab422c4d | 4 | ;; Inc. |
fb98fa17 | 5 | |
c5220417 GM |
6 | ;; Authors: Daniel Pfeiffer |
7 | ;; Markus Heritsch | |
8 | ;; Rolf Ebert <ebert@waporo.muc.de> | |
88581e61 | 9 | ;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org> |
fb98fa17 | 10 | ;; Keywords: languages, ada |
bd78fa1d | 11 | ;; Package: ada-mode |
fb98fa17 | 12 | |
fff2683b GM |
13 | ;; This file is part of GNU Emacs. |
14 | ||
b1fc2b50 | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
fff2683b | 16 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
17 | ;; the Free Software Foundation, either version 3 of the License, or |
18 | ;; (at your option) any later version. | |
fff2683b GM |
19 | |
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
fff2683b | 27 | |
fb98fa17 | 28 | ;;; Commentary: |
18f9934c SM |
29 | ;; This file is now automatically loaded from ada-mode.el, and creates a submenu |
30 | ;; in Ada/ on the menu bar. | |
fb98fa17 KH |
31 | |
32 | ;;; History: | |
33 | ||
34 | ;; Created May 1987. | |
35 | ;; Original version from V. Bowman as in ada.el of Emacs-18 | |
36 | ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU, | |
37 | ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.) | |
38 | ;; | |
39 | ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP) | |
40 | ;; Introduced statement.el for smaller code and user configurability. | |
41 | ;; | |
42 | ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the | |
43 | ;; skeleton generation into this separate file. The code still is | |
44 | ;; essentially written by DP | |
a1506d29 | 45 | ;; |
fb98fa17 KH |
46 | ;; Adapted Jun 1994. Markus Heritsch |
47 | ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH) | |
48 | ;; added menu bar support for templates | |
49 | ;; | |
50 | ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com> | |
51 | ;; General cleanup and bug fixes. | |
52 | ;; | |
53 | ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com> | |
fb8abe0d | 54 | ;; made it work with skeleton.el from Emacs-19.30. Several |
fb98fa17 KH |
55 | ;; enhancements and bug fixes. |
56 | ||
57 | ;; BUGS: | |
58 | ;;;> I have the following suggestions for the function template: 1) I | |
59 | ;;;> don't want it automatically assigning it a name for the return variable. I | |
6196cffe | 60 | ;;;> never want it to be called "Result" because that is nondescript. If you |
fb98fa17 KH |
61 | ;;;> must define a variable, give me the ability to specify its name. |
62 | ;;;> | |
63 | ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same | |
64 | ;;;> as the function's return type, which the template knows, so why force me | |
65 | ;;;> to type it in? | |
66 | ;;;> | |
67 | ||
68 | ;;;It would be nice if one could configure such layout details separately | |
69 | ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el | |
70 | ;;;could be taken even further, providing the user with some nice syntax | |
71 | ;;;for describing layout. Then my own hacks would survive the next | |
72 | ;;;update of the package :-) | |
73 | ||
74 | \f | |
75 | ;;; Code: | |
76 | ||
6f9a2614 | 77 | (require 'skeleton nil t) |
fb98fa17 | 78 | (require 'easymenu) |
6f9a2614 | 79 | (require 'ada-mode) |
fb98fa17 | 80 | |
fb98fa17 | 81 | (defun ada-func-or-proc-name () |
88581e61 | 82 | "Return the name of the current function or procedure." |
fb98fa17 KH |
83 | (save-excursion |
84 | (let ((case-fold-search t)) | |
85 | (if (re-search-backward ada-procedure-start-regexp nil t) | |
3b5b1ad9 | 86 | (match-string 5) |
fb98fa17 KH |
87 | "NAME?")))) |
88 | ||
fb98fa17 KH |
89 | ;;; ---- statement skeletons ------------------------------------------ |
90 | ||
91 | (define-skeleton ada-array | |
1a7244d9 | 92 | "Insert array type definition. |
fb8abe0d | 93 | Prompt for component type and index subtypes." |
fb98fa17 KH |
94 | () |
95 | "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;) | |
96 | ||
97 | ||
98 | (define-skeleton ada-case | |
1a7244d9 | 99 | "Build skeleton case statement. |
32b1a27f | 100 | Prompt for the selector expression. Also builds the first when clause." |
fb98fa17 KH |
101 | "[selector expression]: " |
102 | "case " str " is" \n | |
103 | > "when " ("discrete choice: " str " | ") -3 " =>" \n | |
104 | > _ \n | |
105 | < < "end case;") | |
106 | ||
107 | ||
108 | (define-skeleton ada-when | |
109 | "Start a case statement alternative with a when clause." | |
110 | () | |
111 | < "when " ("discrete choice: " str " | ") -3 " =>" \n | |
112 | >) | |
113 | ||
114 | ||
115 | (define-skeleton ada-declare-block | |
116 | "Insert a block with a declare part. | |
117 | Indent for the first declaration." | |
118 | "[block name]: " | |
119 | < str & ?: & \n | |
120 | > "declare" \n | |
121 | > _ \n | |
122 | < "begin" \n | |
123 | > \n | |
124 | < "end " str | -1 ?\;) | |
125 | ||
126 | ||
127 | (define-skeleton ada-exception-block | |
128 | "Insert a block with an exception part. | |
129 | Indent for the first line of code." | |
130 | "[block name]: " | |
131 | < str & ?: & \n | |
132 | > "begin" \n | |
133 | > _ \n | |
134 | < "exception" \n | |
135 | > \n | |
136 | < "end " str | -1 ?\;) | |
137 | ||
138 | ||
139 | (define-skeleton ada-exception | |
140 | "Insert an indented exception part into a block." | |
141 | () | |
142 | < "exception" \n | |
143 | >) | |
144 | ||
145 | ||
146 | (define-skeleton ada-exit-1 | |
147 | "Insert then exit condition of the exit statement, prompting for condition." | |
148 | "[exit condition]: " | |
149 | "when " str | -5) | |
150 | ||
151 | ||
152 | (define-skeleton ada-exit | |
153 | "Insert an exit statement, prompting for loop name and condition." | |
154 | "[name of loop to exit]: " | |
18f9934c | 155 | "exit " str & ?\ (ada-exit-1) | -1 ?\;) |
fb98fa17 | 156 | |
3d8e3891 | 157 | ;;;###autoload |
fb98fa17 KH |
158 | (defun ada-header () |
159 | "Insert a descriptive header at the top of the file." | |
160 | (interactive "*") | |
161 | (save-excursion | |
162 | (goto-char (point-min)) | |
163 | (if (fboundp 'make-header) | |
cf543c1c | 164 | (funcall (symbol-function 'make-header)) |
fb98fa17 KH |
165 | (ada-header-tmpl)))) |
166 | ||
167 | ||
168 | (define-skeleton ada-header-tmpl | |
169 | "Insert a comment block containing the module title, author, etc." | |
170 | "[Description]: " | |
171 | "-- -*- Mode: Ada -*-" | |
cf543c1c GM |
172 | "\n" ada-fill-comment-prefix "Filename : " (buffer-name) |
173 | "\n" ada-fill-comment-prefix "Description : " str | |
9dd7cdcc | 174 | "\n" ada-fill-comment-prefix "Author : " (user-full-name) |
cf543c1c GM |
175 | "\n" ada-fill-comment-prefix "Created On : " (current-time-string) |
176 | "\n" ada-fill-comment-prefix "Last Modified By: ." | |
177 | "\n" ada-fill-comment-prefix "Last Modified On: ." | |
178 | "\n" ada-fill-comment-prefix "Update Count : 0" | |
179 | "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!" | |
fb98fa17 KH |
180 | "\n") |
181 | ||
182 | ||
183 | (define-skeleton ada-display-comment | |
184 | "Inserts three comment lines, making a display comment." | |
185 | () | |
cf543c1c | 186 | "--\n" ada-fill-comment-prefix _ "\n--") |
fb98fa17 KH |
187 | |
188 | ||
189 | (define-skeleton ada-if | |
d1f18ec0 | 190 | "Insert skeleton if statement, prompting for a boolean-expression." |
fb98fa17 KH |
191 | "[condition]: " |
192 | "if " str " then" \n | |
193 | > _ \n | |
194 | < "end if;") | |
195 | ||
196 | ||
197 | (define-skeleton ada-elsif | |
9dd7cdcc | 198 | "Add an elsif clause to an if statement, |
fb98fa17 KH |
199 | prompting for the boolean-expression." |
200 | "[condition]: " | |
201 | < "elsif " str " then" \n | |
202 | >) | |
203 | ||
204 | ||
205 | (define-skeleton ada-else | |
206 | "Add an else clause inside an if-then-end-if clause." | |
207 | () | |
208 | < "else" \n | |
209 | >) | |
210 | ||
211 | ||
212 | (define-skeleton ada-loop | |
213 | "Insert a skeleton loop statement. The exit statement is added by hand." | |
214 | "[loop name]: " | |
215 | < str & ?: & \n | |
216 | > "loop" \n | |
217 | > _ \n | |
218 | < "end loop " str | -1 ?\;) | |
219 | ||
220 | ||
221 | (define-skeleton ada-for-loop-prompt-variable | |
222 | "Prompt for the loop variable." | |
223 | "[loop variable]: " | |
224 | str) | |
225 | ||
226 | ||
227 | (define-skeleton ada-for-loop-prompt-range | |
228 | "Prompt for the loop range." | |
229 | "[loop range]: " | |
230 | str) | |
231 | ||
232 | ||
233 | (define-skeleton ada-for-loop | |
234 | "Build a skeleton for-loop statement, prompting for the loop parameters." | |
235 | "[loop name]: " | |
236 | < str & ?: & \n | |
237 | > "for " | |
238 | (ada-for-loop-prompt-variable) | |
239 | " in " | |
240 | (ada-for-loop-prompt-range) | |
241 | " loop" \n | |
242 | > _ \n | |
243 | < "end loop " str | -1 ?\;) | |
244 | ||
245 | ||
246 | (define-skeleton ada-while-loop-prompt-entry-condition | |
247 | "Prompt for the loop entry condition." | |
248 | "[entry condition]: " | |
249 | str) | |
250 | ||
251 | ||
252 | (define-skeleton ada-while-loop | |
253 | "Insert a skeleton while loop statement." | |
254 | "[loop name]: " | |
255 | < str & ?: & \n | |
256 | > "while " | |
257 | (ada-while-loop-prompt-entry-condition) | |
258 | " loop" \n | |
259 | > _ \n | |
260 | < "end loop " str | -1 ?\;) | |
261 | ||
262 | ||
263 | (define-skeleton ada-package-spec | |
264 | "Insert a skeleton package specification." | |
265 | "[package name]: " | |
266 | "package " str " is" \n | |
267 | > _ \n | |
268 | < "end " str ?\;) | |
269 | ||
270 | ||
271 | (define-skeleton ada-package-body | |
32b1a27f | 272 | "Insert a skeleton package body -- includes a begin statement." |
fb98fa17 KH |
273 | "[package name]: " |
274 | "package body " str " is" \n | |
275 | > _ \n | |
276 | ; < "begin" \n | |
277 | < "end " str ?\;) | |
278 | ||
279 | ||
280 | (define-skeleton ada-private | |
32b1a27f | 281 | "Undent and start a private section of a package spec. Reindent." |
fb98fa17 KH |
282 | () |
283 | < "private" \n | |
284 | >) | |
285 | ||
286 | ||
287 | (define-skeleton ada-function-spec-prompt-return | |
288 | "Prompts for function result type." | |
289 | "[result type]: " | |
290 | str) | |
291 | ||
292 | ||
293 | (define-skeleton ada-function-spec | |
294 | "Insert a function specification. Prompts for name and arguments." | |
295 | "[function name]: " | |
9dd7cdcc | 296 | "function " str |
fb98fa17 KH |
297 | " (" ("[parameter_specification]: " str "; " ) -2 ")" |
298 | " return " | |
299 | (ada-function-spec-prompt-return) | |
300 | ";" \n ) | |
301 | ||
302 | ||
303 | (define-skeleton ada-procedure-spec | |
304 | "Insert a procedure specification, prompting for its name and arguments." | |
305 | "[procedure name]: " | |
9dd7cdcc | 306 | "procedure " str |
fb98fa17 KH |
307 | " (" ("[parameter_specification]: " str "; " ) -2 ")" |
308 | ";" \n ) | |
309 | ||
310 | ||
311 | (define-skeleton ada-subprogram-body | |
312 | "Insert frame for subprogram body. | |
313 | Invoke right after `ada-function-spec' or `ada-procedure-spec'." | |
314 | () | |
315 | ;; Remove `;' from subprogram decl | |
316 | (save-excursion | |
3d8e3891 GM |
317 | (let ((pos (1+ (point)))) |
318 | (ada-search-ignore-string-comment ada-subprog-start-re t nil) | |
9dd7cdcc SM |
319 | (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward) |
320 | (backward-char 1) | |
321 | (forward-sexp 1))) | |
fb98fa17 | 322 | (if (looking-at ";") |
88581e61 | 323 | (delete-char 1))) |
3d8e3891 GM |
324 | " is" \n |
325 | _ \n | |
326 | < "begin" \n | |
327 | \n | |
328 | < "exception" \n | |
329 | "when others => null;" \n | |
330 | < < "end " | |
fb98fa17 | 331 | (ada-func-or-proc-name) |
3d8e3891 | 332 | ";" \n) |
fb98fa17 KH |
333 | |
334 | ||
335 | (define-skeleton ada-separate | |
336 | "Finish a body stub with `separate'." | |
337 | () | |
338 | > "separate;" \n | |
339 | <) | |
340 | ||
341 | ||
342 | ;(define-skeleton ada-with | |
343 | ; "Inserts a with clause, prompting for the list of units depended upon." | |
344 | ; "[list of units depended upon]: " | |
345 | ; "with " str ?\;) | |
346 | ||
347 | ;(define-skeleton ada-use | |
348 | ; "Inserts a use clause, prompting for the list of packages used." | |
349 | ; "[list of packages used]: " | |
350 | ; "use " str ?\;) | |
a1506d29 | 351 | |
fb98fa17 KH |
352 | |
353 | (define-skeleton ada-record | |
354 | "Insert a skeleton record type declaration." | |
355 | () | |
356 | "record" \n | |
357 | > _ \n | |
358 | < "end record;") | |
359 | ||
360 | ||
361 | (define-skeleton ada-subtype | |
362 | "Start insertion of a subtype declaration, prompting for the subtype name." | |
363 | "[subtype name]: " | |
364 | "subtype " str " is " _ ?\; | |
365 | (not (message "insert subtype indication."))) | |
366 | ||
367 | ||
368 | (define-skeleton ada-type | |
369 | "Start insertion of a type declaration, prompting for the type name." | |
370 | "[type name]: " | |
371 | "type " str ?\( | |
372 | ("[discriminant specs]: " str " ") | |
373 | | (backward-delete-char 1) | ?\) | |
374 | " is " | |
375 | (not (message "insert type definition."))) | |
376 | ||
377 | ||
378 | (define-skeleton ada-task-body | |
379 | "Insert a task body, prompting for the task name." | |
380 | "[task name]: " | |
381 | "task body " str " is\n" | |
382 | "begin\n" | |
383 | > _ \n | |
384 | < "end " str ";" ) | |
385 | ||
386 | ||
387 | (define-skeleton ada-task-spec | |
388 | "Insert a task specification, prompting for the task name." | |
389 | "[task name]: " | |
9dd7cdcc | 390 | "task " str |
fb98fa17 KH |
391 | " (" ("[discriminant]: " str "; ") ") is\n" |
392 | > "entry " _ \n | |
393 | <"end " str ";" ) | |
a1506d29 | 394 | |
fb98fa17 KH |
395 | |
396 | (define-skeleton ada-get-param1 | |
397 | "Prompt for arguments and if any enclose them in brackets." | |
398 | () | |
9dd7cdcc | 399 | ("[parameter_specification]: " str "; " ) & -2 & ")") |
fb98fa17 KH |
400 | |
401 | ||
402 | (define-skeleton ada-get-param | |
403 | "Prompt for arguments and if any enclose them in brackets." | |
404 | () | |
9dd7cdcc SM |
405 | " (" |
406 | (ada-get-param1) | -2) | |
fb98fa17 KH |
407 | |
408 | ||
409 | (define-skeleton ada-entry | |
410 | "Insert a task entry, prompting for the entry name." | |
411 | "[entry name]: " | |
9dd7cdcc | 412 | "entry " str |
fb98fa17 | 413 | (ada-get-param) |
9dd7cdcc | 414 | ";" \n) |
fb98fa17 KH |
415 | |
416 | ||
417 | (define-skeleton ada-entry-family-prompt-discriminant | |
418 | "Insert a entry specification, prompting for the entry name." | |
419 | "[discriminant name]: " | |
420 | str) | |
421 | ||
422 | ||
423 | (define-skeleton ada-entry-family | |
424 | "Insert a entry specification, prompting for the entry name." | |
425 | "[entry name]: " | |
426 | "entry " str | |
427 | " (" (ada-entry-family-prompt-discriminant) ")" | |
428 | (ada-get-param) | |
9dd7cdcc | 429 | ";" \n) |
fb98fa17 KH |
430 | |
431 | ||
432 | (define-skeleton ada-select | |
433 | "Insert a select block." | |
434 | () | |
435 | "select\n" | |
436 | > _ \n | |
437 | < "end select;") | |
438 | ||
439 | ||
440 | (define-skeleton ada-accept-1 | |
441 | "Insert a condition statement, prompting for the condition name." | |
9dd7cdcc | 442 | "[condition]: " |
fb98fa17 KH |
443 | "when " str | -5 ) |
444 | ||
445 | ||
446 | (define-skeleton ada-accept-2 | |
447 | "Insert an accept statement, prompting for the name and arguments." | |
9dd7cdcc SM |
448 | "[accept name]: " |
449 | > "accept " str | |
fb98fa17 | 450 | (ada-get-param) |
fb98fa17 KH |
451 | " do" \n |
452 | > _ \n | |
453 | < "end " str ";" ) | |
454 | ||
455 | ||
456 | (define-skeleton ada-accept | |
457 | "Insert an accept statement (prompt for condition, name and arguments)." | |
458 | () | |
459 | > (ada-accept-1) & " =>\n" | |
9dd7cdcc | 460 | (ada-accept-2)) |
fb98fa17 KH |
461 | |
462 | ||
463 | (define-skeleton ada-or-accept | |
3b5b1ad9 | 464 | "Insert an accept alternative, prompting for the condition name." |
fb98fa17 KH |
465 | () |
466 | < "or\n" | |
9dd7cdcc | 467 | (ada-accept)) |
fb98fa17 KH |
468 | |
469 | ||
470 | (define-skeleton ada-or-delay | |
3b5b1ad9 | 471 | "Insert a delay alternative, prompting for the delay value." |
9dd7cdcc | 472 | "[delay value]: " |
fb98fa17 KH |
473 | < "or\n" |
474 | > "delay " str ";") | |
a1506d29 | 475 | |
fb98fa17 KH |
476 | |
477 | (define-skeleton ada-or-terminate | |
3b5b1ad9 | 478 | "Insert a terminate alternative." |
fb98fa17 KH |
479 | () |
480 | < "or\n" | |
481 | > "terminate;") | |
482 | ||
483 | ||
fb98fa17 KH |
484 | (provide 'ada-stmt) |
485 | ||
486 | ;;; ada-stmt.el ends here |