ada-stmt.el 12 KB

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