(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / progmodes / ada-stmt.el
blob362ec87ba0463f735497a60bae1b744c6027021d
1 ;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates
3 ;; Copyright(C) 1987, 93, 94, 96, 97, 98, 99, 2000
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
9 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
10 ;; Keywords: languages, ada
11 ;; Rolf Ebert's version: 2.26
13 ;;; Commentary:
14 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
15 ;; in Ada/ on the menu bar.
17 ;;; History:
19 ;; Created May 1987.
20 ;; Original version from V. Bowman as in ada.el of Emacs-18
21 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
22 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
24 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
25 ;; Introduced statement.el for smaller code and user configurability.
27 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
28 ;; skeleton generation into this separate file. The code still is
29 ;; essentially written by DP
31 ;; Adapted Jun 1994. Markus Heritsch
32 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
33 ;; added menu bar support for templates
35 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
36 ;; General cleanup and bug fixes.
38 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
39 ;; made it work with skeleton.el from Emacs-19.30. Several
40 ;; enhancements and bug fixes.
42 ;; BUGS:
43 ;;;> I have the following suggestions for the function template: 1) I
44 ;;;> don't want it automatically assigning it a name for the return variable. I
45 ;;;> never want it to be called "Result" because that is nondescriptive. If you
46 ;;;> must define a variable, give me the ability to specify its name.
47 ;;;>
48 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
49 ;;;> as the function's return type, which the template knows, so why force me
50 ;;;> to type it in?
51 ;;;>
53 ;;;It would be nice if one could configure such layout details separately
54 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
55 ;;;could be taken even further, providing the user with some nice syntax
56 ;;;for describing layout. Then my own hacks would survive the next
57 ;;;update of the package :-)
60 ;;; Code:
62 (require 'skeleton nil t)
63 (require 'easymenu)
64 (require 'ada-mode)
66 (defun ada-func-or-proc-name ()
67 ;; Get the name of the current function or procedure."
68 (save-excursion
69 (let ((case-fold-search t))
70 (if (re-search-backward ada-procedure-start-regexp nil t)
71 (buffer-substring (match-beginning 3) (match-end 3))
72 "NAME?"))))
74 ;;; ---- statement skeletons ------------------------------------------
76 (define-skeleton ada-array
77 "Insert array type definition.
78 Prompt for component type and index subtypes."
80 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
83 (define-skeleton ada-case
84 "Build skeleton case statement.
85 Prompt for the selector expression. Also builds the first when clause."
86 "[selector expression]: "
87 "case " str " is" \n
88 > "when " ("discrete choice: " str " | ") -3 " =>" \n
89 > _ \n
90 < < "end case;")
93 (define-skeleton ada-when
94 "Start a case statement alternative with a when clause."
96 < "when " ("discrete choice: " str " | ") -3 " =>" \n
100 (define-skeleton ada-declare-block
101 "Insert a block with a declare part.
102 Indent for the first declaration."
103 "[block name]: "
104 < str & ?: & \n
105 > "declare" \n
106 > _ \n
107 < "begin" \n
108 > \n
109 < "end " str | -1 ?\;)
112 (define-skeleton ada-exception-block
113 "Insert a block with an exception part.
114 Indent for the first line of code."
115 "[block name]: "
116 < str & ?: & \n
117 > "begin" \n
118 > _ \n
119 < "exception" \n
120 > \n
121 < "end " str | -1 ?\;)
124 (define-skeleton ada-exception
125 "Insert an indented exception part into a block."
127 < "exception" \n
131 (define-skeleton ada-exit-1
132 "Insert then exit condition of the exit statement, prompting for condition."
133 "[exit condition]: "
134 "when " str | -5)
137 (define-skeleton ada-exit
138 "Insert an exit statement, prompting for loop name and condition."
139 "[name of loop to exit]: "
140 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
142 ;;;###autoload
143 (defun ada-header ()
144 "Insert a descriptive header at the top of the file."
145 (interactive "*")
146 (save-excursion
147 (goto-char (point-min))
148 (if (fboundp 'make-header)
149 (funcall (symbol-function 'make-header))
150 (ada-header-tmpl))))
153 (define-skeleton ada-header-tmpl
154 "Insert a comment block containing the module title, author, etc."
155 "[Description]: "
156 "-- -*- Mode: Ada -*-"
157 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
158 "\n" ada-fill-comment-prefix "Description : " str
159 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
160 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
161 "\n" ada-fill-comment-prefix "Last Modified By: ."
162 "\n" ada-fill-comment-prefix "Last Modified On: ."
163 "\n" ada-fill-comment-prefix "Update Count : 0"
164 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
165 "\n")
168 (define-skeleton ada-display-comment
169 "Inserts three comment lines, making a display comment."
171 "--\n" ada-fill-comment-prefix _ "\n--")
174 (define-skeleton ada-if
175 "Insert skeleton if statment, prompting for a boolean-expression."
176 "[condition]: "
177 "if " str " then" \n
178 > _ \n
179 < "end if;")
182 (define-skeleton ada-elsif
183 "Add an elsif clause to an if statement,
184 prompting for the boolean-expression."
185 "[condition]: "
186 < "elsif " str " then" \n
190 (define-skeleton ada-else
191 "Add an else clause inside an if-then-end-if clause."
193 < "else" \n
197 (define-skeleton ada-loop
198 "Insert a skeleton loop statement. The exit statement is added by hand."
199 "[loop name]: "
200 < str & ?: & \n
201 > "loop" \n
202 > _ \n
203 < "end loop " str | -1 ?\;)
206 (define-skeleton ada-for-loop-prompt-variable
207 "Prompt for the loop variable."
208 "[loop variable]: "
209 str)
212 (define-skeleton ada-for-loop-prompt-range
213 "Prompt for the loop range."
214 "[loop range]: "
215 str)
218 (define-skeleton ada-for-loop
219 "Build a skeleton for-loop statement, prompting for the loop parameters."
220 "[loop name]: "
221 < str & ?: & \n
222 > "for "
223 (ada-for-loop-prompt-variable)
224 " in "
225 (ada-for-loop-prompt-range)
226 " loop" \n
227 > _ \n
228 < "end loop " str | -1 ?\;)
231 (define-skeleton ada-while-loop-prompt-entry-condition
232 "Prompt for the loop entry condition."
233 "[entry condition]: "
234 str)
237 (define-skeleton ada-while-loop
238 "Insert a skeleton while loop statement."
239 "[loop name]: "
240 < str & ?: & \n
241 > "while "
242 (ada-while-loop-prompt-entry-condition)
243 " loop" \n
244 > _ \n
245 < "end loop " str | -1 ?\;)
248 (define-skeleton ada-package-spec
249 "Insert a skeleton package specification."
250 "[package name]: "
251 "package " str " is" \n
252 > _ \n
253 < "end " str ?\;)
256 (define-skeleton ada-package-body
257 "Insert a skeleton package body -- includes a begin statement."
258 "[package name]: "
259 "package body " str " is" \n
260 > _ \n
261 ; < "begin" \n
262 < "end " str ?\;)
265 (define-skeleton ada-private
266 "Undent and start a private section of a package spec. Reindent."
268 < "private" \n
272 (define-skeleton ada-function-spec-prompt-return
273 "Prompts for function result type."
274 "[result type]: "
275 str)
278 (define-skeleton ada-function-spec
279 "Insert a function specification. Prompts for name and arguments."
280 "[function name]: "
281 "function " str
282 " (" ("[parameter_specification]: " str "; " ) -2 ")"
283 " return "
284 (ada-function-spec-prompt-return)
285 ";" \n )
288 (define-skeleton ada-procedure-spec
289 "Insert a procedure specification, prompting for its name and arguments."
290 "[procedure name]: "
291 "procedure " str
292 " (" ("[parameter_specification]: " str "; " ) -2 ")"
293 ";" \n )
296 (define-skeleton ada-subprogram-body
297 "Insert frame for subprogram body.
298 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
300 ;; Remove `;' from subprogram decl
301 (save-excursion
302 (let ((pos (1+ (point))))
303 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
304 (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
305 (backward-char 1)
306 (forward-sexp 1)))
307 (if (looking-at ";")
308 (delete-char 1)))
309 " is" \n
310 _ \n
311 < "begin" \n
313 < "exception" \n
314 "when others => null;" \n
315 < < "end "
316 (ada-func-or-proc-name)
317 ";" \n)
320 (define-skeleton ada-separate
321 "Finish a body stub with `separate'."
323 > "separate;" \n
327 ;(define-skeleton ada-with
328 ; "Inserts a with clause, prompting for the list of units depended upon."
329 ; "[list of units depended upon]: "
330 ; "with " str ?\;)
332 ;(define-skeleton ada-use
333 ; "Inserts a use clause, prompting for the list of packages used."
334 ; "[list of packages used]: "
335 ; "use " str ?\;)
338 (define-skeleton ada-record
339 "Insert a skeleton record type declaration."
341 "record" \n
342 > _ \n
343 < "end record;")
346 (define-skeleton ada-subtype
347 "Start insertion of a subtype declaration, prompting for the subtype name."
348 "[subtype name]: "
349 "subtype " str " is " _ ?\;
350 (not (message "insert subtype indication.")))
353 (define-skeleton ada-type
354 "Start insertion of a type declaration, prompting for the type name."
355 "[type name]: "
356 "type " str ?\(
357 ("[discriminant specs]: " str " ")
358 | (backward-delete-char 1) | ?\)
359 " is "
360 (not (message "insert type definition.")))
363 (define-skeleton ada-task-body
364 "Insert a task body, prompting for the task name."
365 "[task name]: "
366 "task body " str " is\n"
367 "begin\n"
368 > _ \n
369 < "end " str ";" )
372 (define-skeleton ada-task-spec
373 "Insert a task specification, prompting for the task name."
374 "[task name]: "
375 "task " str
376 " (" ("[discriminant]: " str "; ") ") is\n"
377 > "entry " _ \n
378 <"end " str ";" )
381 (define-skeleton ada-get-param1
382 "Prompt for arguments and if any enclose them in brackets."
384 ("[parameter_specification]: " str "; " ) & -2 & ")")
387 (define-skeleton ada-get-param
388 "Prompt for arguments and if any enclose them in brackets."
390 " ("
391 (ada-get-param1) | -2)
394 (define-skeleton ada-entry
395 "Insert a task entry, prompting for the entry name."
396 "[entry name]: "
397 "entry " str
398 (ada-get-param)
399 ";" \n)
402 (define-skeleton ada-entry-family-prompt-discriminant
403 "Insert a entry specification, prompting for the entry name."
404 "[discriminant name]: "
405 str)
408 (define-skeleton ada-entry-family
409 "Insert a entry specification, prompting for the entry name."
410 "[entry name]: "
411 "entry " str
412 " (" (ada-entry-family-prompt-discriminant) ")"
413 (ada-get-param)
414 ";" \n)
417 (define-skeleton ada-select
418 "Insert a select block."
420 "select\n"
421 > _ \n
422 < "end select;")
425 (define-skeleton ada-accept-1
426 "Insert a condition statement, prompting for the condition name."
427 "[condition]: "
428 "when " str | -5 )
431 (define-skeleton ada-accept-2
432 "Insert an accept statement, prompting for the name and arguments."
433 "[accept name]: "
434 > "accept " str
435 (ada-get-param)
436 " do" \n
437 > _ \n
438 < "end " str ";" )
441 (define-skeleton ada-accept
442 "Insert an accept statement (prompt for condition, name and arguments)."
444 > (ada-accept-1) & " =>\n"
445 (ada-accept-2))
448 (define-skeleton ada-or-accept
449 "Insert an or statement, prompting for the condition name."
451 < "or\n"
452 (ada-accept))
455 (define-skeleton ada-or-delay
456 "Insert a delay statement, prompting for the delay value."
457 "[delay value]: "
458 < "or\n"
459 > "delay " str ";")
462 (define-skeleton ada-or-terminate
463 "Insert a terminate statement."
465 < "or\n"
466 > "terminate;")
469 (provide 'ada-stmt)
471 ;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
472 ;;; ada-stmt.el ends here