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