1 ;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates
3 ;; Copyright(C) 1987, 93, 94, 96, 97, 98, 99, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
6 ;; Ada Core Technologies's version: Revision: 1.21 (GNAT 3.15)
8 ;; This file is part of GNU Emacs.
10 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
11 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
12 ;; Keywords: languages, ada
13 ;; Rolf Ebert's version: 2.26
16 ;; This file is now automatically loaded from ada-mode.el, and creates a submenu
17 ;; in Ada/ on the menu bar.
22 ;; Original version from V. Bowman as in ada.el of Emacs-18
23 ;; (borrowed heavily from Mick Jordan's Modula-2 package for GNU,
24 ;; as modified by Peter Robinson, Michael Schmidt, and Tom Perrine.)
26 ;; Sep 1993. Daniel Pfeiffer <pfeiffer@cict.fr> (DP)
27 ;; Introduced statement.el for smaller code and user configurability.
29 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
30 ;; skeleton generation into this separate file. The code still is
31 ;; essentially written by DP
33 ;; Adapted Jun 1994. Markus Heritsch
34 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
35 ;; added menu bar support for templates
37 ;; 1994/12/02 Christian Egli <cegli@hcsd.hac.com>
38 ;; General cleanup and bug fixes.
40 ;; 1995/12/20 John Hutchison <hutchiso@epi.syr.ge.com>
41 ;; made it work with skeleton.el from Emacs-19.30. Several
42 ;; enhancements and bug fixes.
45 ;;;> I have the following suggestions for the function template: 1) I
46 ;;;> don't want it automatically assigning it a name for the return variable. I
47 ;;;> never want it to be called "Result" because that is nondescriptive. If you
48 ;;;> must define a variable, give me the ability to specify its name.
50 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
51 ;;;> as the function's return type, which the template knows, so why force me
55 ;;;It would be nice if one could configure such layout details separately
56 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
57 ;;;could be taken even further, providing the user with some nice syntax
58 ;;;for describing layout. Then my own hacks would survive the next
59 ;;;update of the package :-)
65 (condition-case nil
(require 'skeleton
)
70 (defun ada-stmt-add-to-ada-menu ()
71 "Add a new submenu to the Ada menu."
73 (let ((menu '(["Header" ada-header t
]
75 ["Package Body" ada-package-body t
]
76 ["Package Spec" ada-package-spec t
]
77 ["Function Spec" ada-function-spec t
]
78 ["Procedure Spec" ada-procedure-spec t
]
79 ["Proc/func Body" ada-subprogram-body t
]
80 ["Task Body" ada-task-body t
]
81 ["Task Spec" ada-task-spec t
]
82 ["Declare Block" ada-declare-block t
]
83 ["Exception Block" ada-exception-block t
]
86 ["Entry family" ada-entry-family t
]
87 ["Select" ada-select t
]
88 ["Accept" ada-accept t
]
89 ["Or accept" ada-or-accep t
]
90 ["Or delay" ada-or-delay t
]
91 ["Or terminate" ada-or-terminate t
]
94 ["Private" ada-private t
]
95 ["Subtype" ada-subtype t
]
96 ["Record" ada-record t
]
101 ["Elsif" ada-elsif t
]
104 ["While Loop" ada-while-loop t
]
105 ["For Loop" ada-for-loop t
]
108 ["Exception" ada-exception t
]
110 ["When" ada-when t
])))
112 (funcall (symbol-function 'add-submenu
)
113 '("Ada") (append (list "Templates"
114 :included
'(string= mode-name
"Ada"))
117 (define-key-after (or
118 (lookup-key ada-mode-map
[menu-bar Ada
])
119 (lookup-key ada-mode-map
[menu-bar ada
]))
123 (easy-menu-create-menu "Templates" menu)
124 :visible '(string= mode-name "Ada"))
130 (defun ada-func-or-proc-name ()
131 ;; Get the name of the current function or procedure."
133 (let ((case-fold-search t))
134 (if (re-search-backward ada-procedure-start-regexp nil t)
135 (buffer-substring (match-beginning 3) (match-end 3))
138 (defvar ada-template-map
139 (let ((map (make-sparse-keymap)))
140 (define-key map "h" 'ada-header)
141 (define-key map "\C-a" 'ada-array)
142 (define-key map "b" 'ada-exception-block)
143 (define-key map "d" 'ada-declare-block)
144 (define-key map "c" 'ada-case)
145 (define-key map "\C-e" 'ada-elsif)
146 (define-key map "e" 'ada-else)
147 (define-key map "\C-k" 'ada-package-spec)
148 (define-key map "k" 'ada-package-body)
149 (define-key map "\C-p" 'ada-procedure-spec)
150 (define-key map "p" 'ada-subprogram-body)
151 (define-key map "\C-f" 'ada-function-spec)
152 (define-key map "f" 'ada-for-loop)
153 (define-key map "i" 'ada-if)
154 (define-key map "l" 'ada-loop)
155 (define-key map "\C-r" 'ada-record)
156 (define-key map "\C-s" 'ada-subtype)
157 (define-key map "S" 'ada-tabsize)
158 (define-key map "\C-t" 'ada-task-spec)
159 (define-key map "t" 'ada-task-body)
160 (define-key map "\C-y" 'ada-type)
161 (define-key map "\C-v" 'ada-private)
162 (define-key map "u" 'ada-use)
163 (define-key map "\C-u" 'ada-with)
164 (define-key map "\C-w" 'ada-when)
165 (define-key map "w" 'ada-while-loop)
166 (define-key map "\C-x" 'ada-exception)
167 (define-key map "x" 'ada-exit)
169 "Keymap used in Ada mode for smart template operations.")
171 (define-key ada-mode-map "\C-ct" ada-template-map)
173 ;;; ---- statement skeletons ------------------------------------------
175 (define-skeleton ada-array
176 "Insert array type definition.
177 Prompt for component type and index subtypes."
179 "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
182 (define-skeleton ada-case
183 "Build skeleton case statement.
184 Prompt for the selector expression. Also builds the first when clause."
185 "[selector expression]: "
187 > "when " ("discrete choice: " str " | ") -3 " =>" \n
192 (define-skeleton ada-when
193 "Start a case statement alternative with a when clause."
195 < "when " ("discrete choice: " str " | ") -3 " =>" \n
199 (define-skeleton ada-declare-block
200 "Insert a block with a declare part.
201 Indent for the first declaration."
208 < "end " str | -1 ?\;)
211 (define-skeleton ada-exception-block
212 "Insert a block with an exception part.
213 Indent for the first line of code."
220 < "end " str | -1 ?\;)
223 (define-skeleton ada-exception
224 "Insert an indented exception part into a block."
230 (define-skeleton ada-exit-1
231 "Insert then exit condition of the exit statement, prompting for condition."
236 (define-skeleton ada-exit
237 "Insert an exit statement, prompting for loop name and condition."
238 "[name of loop to exit]: "
239 "exit " str & ?\ (ada-exit-1) | -1 ?\;)
243 "Insert a descriptive header at the top of the file."
246 (goto-char (point-min))
247 (if (fboundp 'make-header)
248 (funcall (symbol-function 'make-header))
252 (define-skeleton ada-header-tmpl
253 "Insert a comment block containing the module title, author, etc."
255 "-- -*- Mode: Ada -*-"
256 "\n" ada-fill-comment-prefix "Filename : " (buffer-name)
257 "\n" ada-fill-comment-prefix "Description : " str
258 "\n" ada-fill-comment-prefix "Author : " (user-full-name)
259 "\n" ada-fill-comment-prefix "Created On : " (current-time-string)
260 "\n" ada-fill-comment-prefix "Last Modified By: ."
261 "\n" ada-fill-comment-prefix "Last Modified On: ."
262 "\n" ada-fill-comment-prefix "Update Count : 0"
263 "\n" ada-fill-comment-prefix "Status : Unknown, Use with caution!"
267 (define-skeleton ada-display-comment
268 "Inserts three comment lines, making a display comment."
270 "--\n" ada-fill-comment-prefix _ "\n--")
273 (define-skeleton ada-if
274 "Insert skeleton if statment, prompting for a boolean-expression."
281 (define-skeleton ada-elsif
282 "Add an elsif clause to an if statement,
283 prompting for the boolean-expression."
285 < "elsif " str " then" \n
289 (define-skeleton ada-else
290 "Add an else clause inside an if-then-end-if clause."
296 (define-skeleton ada-loop
297 "Insert a skeleton loop statement. The exit statement is added by hand."
302 < "end loop " str | -1 ?\;)
305 (define-skeleton ada-for-loop-prompt-variable
306 "Prompt for the loop variable."
311 (define-skeleton ada-for-loop-prompt-range
312 "Prompt for the loop range."
317 (define-skeleton ada-for-loop
318 "Build a skeleton for-loop statement, prompting for the loop parameters."
322 (ada-for-loop-prompt-variable)
324 (ada-for-loop-prompt-range)
327 < "end loop " str | -1 ?\;)
330 (define-skeleton ada-while-loop-prompt-entry-condition
331 "Prompt for the loop entry condition."
332 "[entry condition]: "
336 (define-skeleton ada-while-loop
337 "Insert a skeleton while loop statement."
341 (ada-while-loop-prompt-entry-condition)
344 < "end loop " str | -1 ?\;)
347 (define-skeleton ada-package-spec
348 "Insert a skeleton package specification."
350 "package " str " is" \n
355 (define-skeleton ada-package-body
356 "Insert a skeleton package body -- includes a begin statement."
358 "package body " str " is" \n
364 (define-skeleton ada-private
365 "Undent and start a private section of a package spec. Reindent."
371 (define-skeleton ada-function-spec-prompt-return
372 "Prompts for function result type."
377 (define-skeleton ada-function-spec
378 "Insert a function specification. Prompts for name and arguments."
381 " (" ("[parameter_specification]: " str "; " ) -2 ")"
383 (ada-function-spec-prompt-return)
387 (define-skeleton ada-procedure-spec
388 "Insert a procedure specification, prompting for its name and arguments."
391 " (" ("[parameter_specification]: " str "; " ) -2 ")"
395 (define-skeleton ada-subprogram-body
396 "Insert frame for subprogram body.
397 Invoke right after `ada-function-spec' or `ada-procedure-spec'."
399 ;; Remove `;' from subprogram decl
401 (let ((pos (1+ (point))))
402 (ada-search-ignore-string-comment ada-subprog-start-re t nil)
403 (when (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 & ")")
486 (define-skeleton ada-get-param
487 "Prompt for arguments and if any enclose them in brackets."
490 (ada-get-param1) | -2)
493 (define-skeleton ada-entry
494 "Insert a task entry, prompting for the entry name."
501 (define-skeleton ada-entry-family-prompt-discriminant
502 "Insert a entry specification, prompting for the entry name."
503 "[discriminant name]: "
507 (define-skeleton ada-entry-family
508 "Insert a entry specification, prompting for the entry name."
511 " (" (ada-entry-family-prompt-discriminant) ")"
516 (define-skeleton ada-select
517 "Insert a select block."
524 (define-skeleton ada-accept-1
525 "Insert a condition statement, prompting for the condition name."
530 (define-skeleton ada-accept-2
531 "Insert an accept statement, prompting for the name and arguments."
540 (define-skeleton ada-accept
541 "Insert an accept statement (prompt for condition, name and arguments)."
543 > (ada-accept-1) & " =>\n"
547 (define-skeleton ada-or-accept
548 "Insert an or statement, prompting for the condition name."
554 (define-skeleton ada-or-delay
555 "Insert a delay statement, prompting for the delay value."
561 (define-skeleton ada-or-terminate
562 "Insert a terminate statement."
568 (defun ada-adjust-case-skeleton ()
569 "Adjust the case of the text inserted by a skeleton."
571 (let ((aa-end (point)))
572 (ada-adjust-case-region
573 (progn (goto-char (symbol-value 'beg)) (forward-word -1) (point))
574 (goto-char aa-end)))))
576 (defun ada-stmt-mode-hook ()
577 (set (make-local-variable 'skeleton-further-elements)
578 '((< '(backward-delete-char-untabify
579 (min ada-indent (current-column))))))
580 (add-hook 'skeleton-end-hook
581 'ada-adjust-case-skeleton nil t)
582 (ada-stmt-add-to-ada-menu))
584 (add-hook 'ada-mode-hook 'ada-stmt-mode-hook)
588 ;;; ada-stmt.el ends here