1 ;;; ada-stmt.el --- An extension to Ada mode for inserting statement templates.
3 ;; Copyright(C) 1987, 1993, 1994, 1996, 1997, 1998, 1999
4 ;; Free Software Foundation, Inc.
6 ;; Ada Core Technologies's version: $Revision: 1.6 $
8 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
9 ;; Maintainer: Rolf Ebert <ebert@waporo.muc.de>
10 ;; Keywords: languages, ada
11 ;; Rolf Ebert's version: 2.26
16 ;; put the following statement in your .emacs:
17 ;; (require 'ada-stmt)
23 ;; Original version from V. Bowman as in ada.el of Emacs-18
24 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
25 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
27 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
28 ;; Introduced statement.el for smaller code and user configurability.
30 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
31 ;; skeleton generation into this separate file. The code still is
32 ;; essentially written by DP
34 ;; Adapted Jun 1994. Markus Heritsch
35 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
36 ;; added menu bar support for templates
38 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
39 ;; General cleanup and bug fixes.
41 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
42 ;; made it work with skeleton.el from Emacs-19.30. Several
43 ;; enhancements and bug fixes.
46 ;;;> I have the following suggestions for the function template: 1) I
47 ;;;> don't want it automatically assigning it a name for the return variable. I
48 ;;;> never want it to be called "Result" because that is nondescriptive. If you
49 ;;;> must define a variable, give me the ability to specify its name.
51 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
52 ;;;> as the function's return type, which the template knows, so why force me
56 ;;;It would be nice if one could configure such layout details separately
57 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
58 ;;;could be taken even further, providing the user with some nice syntax
59 ;;;for describing layout. Then my own hacks would survive the next
60 ;;;update of the package :-)
66 (condition-case nil
(require 'skeleton
)
71 (defun ada-stmt-add-to-ada-menu ()
72 "Add a new submenu to the Ada menu"
74 (let ((menu '(["Header" ada-header t
]
76 ["Package Body" ada-package-body t
]
77 ["Package Spec" ada-package-spec t
]
78 ["Function Spec" ada-function-spec t
]
79 ["Procedure Spec" ada-procedure-spec t
]
80 ["Proc/func Body" ada-subprogram-body t
]
81 ["Task Body" ada-task-body t
]
82 ["Task Spec" ada-task-spec t
]
83 ["Declare Block" ada-declare-block t
]
84 ["Exception Block" ada-exception-block t
]
87 ["Entry family" ada-entry-family t
]
88 ["Select" ada-select t
]
89 ["Accept" ada-accept t
]
90 ["Or accept" ada-or-accep t
]
91 ["Or delay" ada-or-delay t
]
92 ["Or terminate" ada-or-terminate t
]
95 ["Private" ada-private t
]
96 ["Subtype" ada-subtype t
]
97 ["Record" ada-record t
]
102 ["Elsif" ada-elsif t
]
105 ["While Loop" ada-while-loop t
]
106 ["For Loop" ada-for-loop t
]
109 ["Exception" ada-exception t
]
111 ["When" ada-when t
])))
113 (funcall (symbol-function 'add-submenu
)
114 '("Ada") (append (list "Statements"
115 :included
'(string= mode-name
"Ada"))
118 (define-key-after (lookup-key ada-mode-map
[menu-bar Ada
]) [Statements]
121 (easy-menu-create-menu "Statements" menu)
122 :visible '(string= mode-name "Ada"))
129 (defun ada-func-or-proc-name ()
130 ;; Get the name of the current function or procedure."
132 (let ((case-fold-search t))
133 (if (re-search-backward ada-procedure-start-regexp nil t)
134 (buffer-substring (match-beginning 2) (match-end 2))
137 (defvar ada-template-map nil
138 "Keymap used in Ada mode for smart template operations.")
140 (define-key ada-mode-map "\C-cth" 'ada-header)
141 (define-key ada-mode-map "\C-ct\C-a" 'ada-array)
142 (define-key ada-mode-map "\C-ctb" 'ada-exception-block)
143 (define-key ada-mode-map "\C-ctd" 'ada-declare-block)
144 (define-key ada-mode-map "\C-ctc" 'ada-case)
145 (define-key ada-mode-map "\C-ct\C-e" 'ada-elsif)
146 (define-key ada-mode-map "\C-cte" 'ada-else)
147 (define-key ada-mode-map "\C-ct\C-k" 'ada-package-spec)
148 (define-key ada-mode-map "\C-ctk" 'ada-package-body)
149 (define-key ada-mode-map "\C-ct\C-p" 'ada-procedure-spec)
150 (define-key ada-mode-map "\C-ctp" 'ada-subprogram-body)
151 (define-key ada-mode-map "\C-ct\C-f" 'ada-function-spec)
152 (define-key ada-mode-map "\C-ctf" 'ada-for-loop)
153 (define-key ada-mode-map "\C-cti" 'ada-if)
154 (define-key ada-mode-map "\C-ctl" 'ada-loop)
155 (define-key ada-mode-map "\C-ct\C-r" 'ada-record)
156 (define-key ada-mode-map "\C-ct\C-s" 'ada-subtype)
157 (define-key ada-mode-map "\C-ctS" 'ada-tabsize)
158 (define-key ada-mode-map "\C-ct\C-t" 'ada-task-spec)
159 (define-key ada-mode-map "\C-ctt" 'ada-task-body)
160 (define-key ada-mode-map "\C-ct\C-y" 'ada-type)
161 (define-key ada-mode-map "\C-ct\C-v" 'ada-private)
162 (define-key ada-mode-map "\C-ctu" 'ada-use)
163 (define-key ada-mode-map "\C-ct\C-u" 'ada-with)
164 (define-key ada-mode-map "\C-ct\C-w" 'ada-when)
165 (define-key ada-mode-map "\C-ctw" 'ada-while-loop)
166 (define-key ada-mode-map "\C-ct\C-x" 'ada-exception)
167 (define-key ada-mode-map "\C-ctx" 'ada-exit)
169 ;;; ---- statement skeletons ------------------------------------------
171 (define-skeleton ada-array
172 "Insert array type definition.
173 Prompt for component type and index subtypes."
175 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
178 (define-skeleton ada-case
179 "Build skeleton case statement.
180 Prompt for the selector expression. Also builds the first when clause."
181 "[selector expression]: "
183 > "when " ("discrete choice: " str " | ") -3 " =>" \n
188 (define-skeleton ada-when
189 "Start a case statement alternative with a when clause."
191 < "when " ("discrete choice: " str " | ") -3 " =>" \n
195 (define-skeleton ada-declare-block
196 "Insert a block with a declare part.
197 Indent for the first declaration."
204 < "end " str | -1 ?\;)
207 (define-skeleton ada-exception-block
208 "Insert a block with an exception part.
209 Indent for the first line of code."
216 < "end " str | -1 ?\;)
219 (define-skeleton ada-exception
220 "Insert an indented exception part into a block."
226 (define-skeleton ada-exit-1
227 "Insert then exit condition of the exit statement, prompting for condition."
232 (define-skeleton ada-exit
233 "Insert an exit statement, prompting for loop name and condition."
234 "[name of loop to exit]: "
241 "Insert a descriptive header at the top of the file."
244 (goto-char (point-min))
245 (if (fboundp 'make-header)
246 (funcall (symbol-function 'make-header))
250 (define-skeleton ada-header-tmpl
251 "Insert a comment block containing the module title, author, etc."
253 "-- -*- Mode: Ada -*-"
254 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
255 "\n" ada-fill-comment-prefix "Description : " str
256 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
257 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
258 "\n" ada-fill-comment-prefix "Last Modified By: ."
259 "\n" ada-fill-comment-prefix "Last Modified On: ."
260 "\n" ada-fill-comment-prefix "Update Count : 0"
261 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
265 (define-skeleton ada-display-comment
266 "Inserts three comment lines, making a display comment."
268 "--\n" ada-fill-comment-prefix _ "\n--")
271 (define-skeleton ada-if
272 "Insert skeleton if statment, prompting for a boolean-expression."
279 (define-skeleton ada-elsif
280 "Add an elsif clause to an if statement,
281 prompting for the boolean-expression."
283 < "elsif " str " then" \n
287 (define-skeleton ada-else
288 "Add an else clause inside an if-then-end-if clause."
294 (define-skeleton ada-loop
295 "Insert a skeleton loop statement. The exit statement is added by hand."
300 < "end loop " str | -1 ?\;)
303 (define-skeleton ada-for-loop-prompt-variable
304 "Prompt for the loop variable."
309 (define-skeleton ada-for-loop-prompt-range
310 "Prompt for the loop range."
315 (define-skeleton ada-for-loop
316 "Build a skeleton for-loop statement, prompting for the loop parameters."
320 (ada-for-loop-prompt-variable)
322 (ada-for-loop-prompt-range)
325 < "end loop " str | -1 ?\;)
328 (define-skeleton ada-while-loop-prompt-entry-condition
329 "Prompt for the loop entry condition."
330 "[entry condition]: "
334 (define-skeleton ada-while-loop
335 "Insert a skeleton while loop statement."
339 (ada-while-loop-prompt-entry-condition)
342 < "end loop " str | -1 ?\;)
345 (define-skeleton ada-package-spec
346 "Insert a skeleton package specification."
348 "package " str " is" \n
353 (define-skeleton ada-package-body
354 "Insert a skeleton package body -- includes a begin statement."
356 "package body " str " is" \n
362 (define-skeleton ada-private
363 "Undent and start a private section of a package spec. Reindent."
369 (define-skeleton ada-function-spec-prompt-return
370 "Prompts for function result type."
375 (define-skeleton ada-function-spec
376 "Insert a function specification. Prompts for name and arguments."
379 " (" ("[parameter_specification]: " str "; " ) -2 ")"
381 (ada-function-spec-prompt-return)
385 (define-skeleton ada-procedure-spec
386 "Insert a procedure specification, prompting for its name and arguments."
389 " (" ("[parameter_specification]: " str "; " ) -2 ")"
393 (define-skeleton ada-subprogram-body
394 "Insert frame for subprogram body.
395 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
397 ;; Remove `;' from subprogram decl
399 (let ((pos (1+ (point))))
400 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
401 (if (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
413 "when others => null;" \n
415 (ada-func-or-proc-name)
419 (define-skeleton ada-separate
420 "Finish a body stub with `separate'."
426 ;(define-skeleton ada-with
427 ; "Inserts a with clause, prompting for the list of units depended upon."
428 ; "[list of units depended upon]: "
431 ;(define-skeleton ada-use
432 ; "Inserts a use clause, prompting for the list of packages used."
433 ; "[list of packages used]: "
437 (define-skeleton ada-record
438 "Insert a skeleton record type declaration."
445 (define-skeleton ada-subtype
446 "Start insertion of a subtype declaration, prompting for the subtype name."
448 "subtype " str " is " _ ?\;
449 (not (message "insert subtype indication.")))
452 (define-skeleton ada-type
453 "Start insertion of a type declaration, prompting for the type name."
456 ("[discriminant specs]: " str " ")
457 | (backward-delete-char 1) | ?\)
459 (not (message "insert type definition.")))
462 (define-skeleton ada-task-body
463 "Insert a task body, prompting for the task name."
465 "task body " str " is\n"
471 (define-skeleton ada-task-spec
472 "Insert a task specification, prompting for the task name."
475 " (" ("[discriminant]: " str "; ") ") is\n"
480 (define-skeleton ada-get-param1
481 "Prompt for arguments and if any enclose them in brackets."
483 ("[parameter_specification]: " str "; " ) & -2 & ")"
487 (define-skeleton ada-get-param
488 "Prompt for arguments and if any enclose them in brackets."
491 (ada-get-param1) | -2
495 (define-skeleton ada-entry
496 "Insert a task entry, prompting for the entry name."
501 ; (ada-indent-current)
505 (define-skeleton ada-entry-family-prompt-discriminant
506 "Insert a entry specification, prompting for the entry name."
507 "[discriminant name]: "
511 (define-skeleton ada-entry-family
512 "Insert a entry specification, prompting for the entry name."
515 " (" (ada-entry-family-prompt-discriminant) ")"
518 ;(ada-indent-current)
522 (define-skeleton ada-select
523 "Insert a select block."
530 (define-skeleton ada-accept-1
531 "Insert a condition statement, prompting for the condition name."
536 (define-skeleton ada-accept-2
537 "Insert an accept statement, prompting for the name and arguments."
541 ; " (" ("[parameter_specification]: " str "; ") -2 ")"
547 (define-skeleton ada-accept
548 "Insert an accept statement (prompt for condition, name and arguments)."
550 > (ada-accept-1) & " =>\n"
555 (define-skeleton ada-or-accept
556 "Insert a or statement, prompting for the condition name."
563 (define-skeleton ada-or-delay
564 "Insert a delay statement, prompting for the delay value."
570 (define-skeleton ada-or-terminate
571 "Insert a terminate statement."
578 (defun ada-adjust-case-skeleton ()
579 "Adjusts the case of the text inserted by a skeleton."
581 (let ((aa-end (point)))
582 (ada-adjust-case-region
583 (progn (goto-char (symbol-value 'beg)) (forward-word -1) (point))
587 (add-hook 'ada-mode-hook '(lambda ()
588 (setq skeleton-further-elements
589 '((< '(backward-delete-char-untabify
590 (min ada-indent (current-column))))))
591 (add-hook 'skeleton-end-hook
592 'ada-adjust-case-skeleton)))
594 (add-hook 'ada-mode-hook 'ada-stmt-add-to-ada-menu)
598 ;;; ada-stmt.el ends here