ada-stmt.el 12 KB

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