Add arch taglines
[bpt/emacs.git] / lisp / progmodes / ada-stmt.el
index 9f822dd..7b9f764 100644 (file)
@@ -1,20 +1,20 @@
-;;; ada-stmt.el - An extension to Ada mode for inserting statement templates.
+;;; ada-stmt.el --- an extension to Ada mode for inserting statement templates
 
-;; Copyright (C) 1987, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright(C) 1987, 93, 94, 96, 97, 98, 99, 2000
+;;   Free Software Foundation, Inc.
 
-;; Ada Core Technologies's version:   $Revision: 1.1 $ 
+;; Ada Core Technologies's version:   $Revision: 1.16 $
+
+;; This file is part of GNU Emacs.
 
 ;; Authors: Daniel Pfeiffer, Markus Heritsch, Rolf Ebert <ebert@waporo.muc.de>
-;; Maintainer: Rolf Ebert <ebert@waporo.muc.de>
+;; Maintainer: Emmanuel Briot <briot@gnat.com>
 ;; Keywords: languages, ada
 ;; Rolf Ebert's version: 2.26
 
 ;;; Commentary:
-
-;;
-;; put the following statement in your .emacs:
-;; (require 'ada-stmt)
-;;
+;; This file is now automatically loaded from ada-mode.el, and creates a submenu
+;; in Ada/ on the menu bar.
 
 ;;; History:
 
@@ -29,7 +29,7 @@
 ;; Nov 1993. Rolf Ebert <ebert@enpc.fr> (RE) Moved the
 ;; skeleton generation into this separate file. The code still is
 ;; essentially written by DP
-;; 
+;;
 ;; Adapted Jun 1994. Markus Heritsch
 ;; <Markus.Heritsch@studbox.uni-stuttgart.de> (MH)
 ;; added menu bar support for templates
@@ -38,7 +38,7 @@
 ;; General cleanup and bug fixes.
 ;;
 ;; 1995/12/20  John Hutchison <hutchiso@epi.syr.ge.com>
-;; made it work with skeleton.el from emacs-19.30. Several
+;; made it work with skeleton.el from Emacs-19.30. Several
 ;; enhancements and bug fixes.
 
 ;; BUGS:
 \f
 ;;; Code:
 
-(eval-when-compile
-  (condition-case nil  (require 'skeleton)
-    (error nil)))
+(require 'skeleton nil t)
 (require 'easymenu)
+(require 'ada-mode)
 
-(defun ada-stmt-add-to-ada-menu ()
-  "Add a new submenu to the Ada menu"
-  (interactive)
-  (let ((menu  '(["Header" ada-header t]
-                ["-" nil nil]
-                ["Package Body" ada-package-body t]
-                ["Package Spec" ada-package-spec t]
-                ["Function Spec" ada-function-spec t]
-                ["Procedure Spec" ada-procedure-spec t]
-                ["Proc/func Body" ada-subprogram-body t]
-                ["Task Body" ada-task-body t]
-                ["Task Spec" ada-task-spec t]
-                ["Declare Block" ada-declare-block t]
-                ["Exception Block" ada-exception-block t]
-                ["--" nil nil]
-                ["Entry" ada-entry t]
-                ["Entry family" ada-entry-family t]
-                ["Select" ada-select t]
-                ["Accept" ada-accept t]
-                ["Or accept" ada-or-accep t]
-                ["Or delay" ada-or-delay t]
-                ["Or terminate" ada-or-terminate t]
-                ["---" nil nil]
-                ["Type" ada-type t]
-                ["Private" ada-private t]
-                ["Subtype" ada-subtype t]
-                ["Record" ada-record t]
-                ["Array" ada-array t]
-                ["----" nil nil]
-                ["If" ada-if t]
-                ["Else" ada-else t]
-                ["Elsif" ada-elsif t]
-                ["Case" ada-case t]
-                ["-----" nil nil]
-                ["While Loop" ada-while-loop t]
-                ["For Loop" ada-for-loop t]
-                ["Loop" ada-loop t]
-                ["------" nil nil]
-                ["Exception" ada-exception t]
-                ["Exit" ada-exit t]
-                ["When" ada-when t])))
-    (if ada-xemacs
-       (progn
-         (add-to-list 'menu "Statements")
-         (add-submenu '("Ada") menu))
-
-      (define-key-after (lookup-key ada-mode-map [menu-bar Ada]) [Statements]
-       (cons "Statements" (easy-menu-create-menu "Statements" menu)) t))
-    ))
-
-
-
-\f
 (defun ada-func-or-proc-name ()
   ;; Get the name of the current function or procedure."
   (save-excursion
     (let ((case-fold-search t))
       (if (re-search-backward ada-procedure-start-regexp nil t)
-         (buffer-substring (match-beginning 2) (match-end 2))
+         (buffer-substring (match-beginning 3) (match-end 3))
        "NAME?"))))
 
-(defvar ada-template-map nil
-  "Keymap used in Ada mode for smart template operations.")
-
-(define-key ada-mode-map "\C-cth" 'ada-header)
-(define-key ada-mode-map "\C-ct\C-a" 'ada-array)
-(define-key ada-mode-map "\C-ctb" 'ada-exception-block)
-(define-key ada-mode-map "\C-ctd" 'ada-declare-block)
-(define-key ada-mode-map "\C-ctc" 'ada-case)
-(define-key ada-mode-map "\C-ct\C-e"  'ada-elsif)
-(define-key ada-mode-map "\C-cte"      'ada-else)
-(define-key ada-mode-map "\C-ct\C-k"   'ada-package-spec)
-(define-key ada-mode-map "\C-ctk"      'ada-package-body)
-(define-key ada-mode-map "\C-ct\C-p"   'ada-procedure-spec)
-(define-key ada-mode-map "\C-ctp"      'ada-subprogram-body)
-(define-key ada-mode-map "\C-ct\C-f"   'ada-function-spec)
-(define-key ada-mode-map "\C-ctf"      'ada-for-loop)
-(define-key ada-mode-map "\C-cti"      'ada-if)
-(define-key ada-mode-map "\C-ctl"      'ada-loop)
-(define-key ada-mode-map "\C-ct\C-r"   'ada-record)
-(define-key ada-mode-map "\C-ct\C-s"   'ada-subtype)
-(define-key ada-mode-map "\C-ctS"      'ada-tabsize)
-(define-key ada-mode-map "\C-ct\C-t"   'ada-task-spec)
-(define-key ada-mode-map "\C-ctt"      'ada-task-body)
-(define-key ada-mode-map "\C-ct\C-y"   'ada-type)
-(define-key ada-mode-map "\C-ct\C-v"   'ada-private)
-(define-key ada-mode-map "\C-ctu"      'ada-use)
-(define-key ada-mode-map "\C-ct\C-u"   'ada-with)
-(define-key ada-mode-map "\C-ct\C-w"   'ada-when)
-(define-key ada-mode-map "\C-ctw"      'ada-while-loop)
-(define-key ada-mode-map "\C-ct\C-x"   'ada-exception)
-(define-key ada-mode-map "\C-ctx"      'ada-exit)
-
 ;;; ---- statement skeletons ------------------------------------------
 
 (define-skeleton ada-array
   "Insert array type definition.
-Uses the minibuffer to prompt for component type and index subtypes."
+Prompt for component type and index subtypes."
   ()
   "array (" ("index definition: " str ", " ) -2 ") of " _ ?\;)
 
@@ -225,9 +139,7 @@ Indent for the first line of code."
 (define-skeleton ada-exit
   "Insert an exit statement, prompting for loop name and condition."
   "[name of loop to exit]: "
-  "exit " str & ?\ 
-  (ada-exit-1)
-  | -1 ?\;)
+  "exit " str & ?\ (ada-exit-1) | -1 ?\;)
 
 ;;;###autoload
 (defun ada-header ()
@@ -236,7 +148,7 @@ Indent for the first line of code."
   (save-excursion
     (goto-char (point-min))
     (if (fboundp 'make-header)
-       (make-header)
+       (funcall (symbol-function 'make-header))
       (ada-header-tmpl))))
 
 
@@ -244,21 +156,21 @@ Indent for the first line of code."
   "Insert a comment block containing the module title, author, etc."
   "[Description]: "
   "--                              -*- Mode: Ada -*-"
-  "\n-- Filename        : " (buffer-name)
-  "\n-- Description     : " str
-  "\n-- Author          : " (user-full-name) 
-  "\n-- Created On      : " (current-time-string)
-  "\n-- Last Modified By: ."
-  "\n-- Last Modified On: ."
-  "\n-- Update Count    : 0"
-  "\n-- Status          : Unknown, Use with caution!"
+  "\n" ada-fill-comment-prefix "Filename        : " (buffer-name)
+  "\n" ada-fill-comment-prefix "Description     : " str
+  "\n" ada-fill-comment-prefix "Author          : " (user-full-name)
+  "\n" ada-fill-comment-prefix "Created On      : " (current-time-string)
+  "\n" ada-fill-comment-prefix "Last Modified By: ."
+  "\n" ada-fill-comment-prefix "Last Modified On: ."
+  "\n" ada-fill-comment-prefix "Update Count    : 0"
+  "\n" ada-fill-comment-prefix "Status          : Unknown, Use with caution!"
   "\n")
 
 
 (define-skeleton ada-display-comment
   "Inserts three comment lines, making a display comment."
   ()
-  "--\n-- " _ "\n--")
+  "--\n" ada-fill-comment-prefix _ "\n--")
 
 
 (define-skeleton ada-if
@@ -270,7 +182,7 @@ Indent for the first line of code."
 
 
 (define-skeleton ada-elsif
-  "Add an elsif clause to an if statement, 
+  "Add an elsif clause to an if statement,
 prompting for the boolean-expression."
   "[condition]: "
   < "elsif " str " then" \n
@@ -368,7 +280,7 @@ prompting for the boolean-expression."
 (define-skeleton ada-function-spec
   "Insert a function specification.  Prompts for name and arguments."
   "[function name]: "
-  "function " str 
+  "function " str
   " (" ("[parameter_specification]: " str "; " ) -2 ")"
   " return "
   (ada-function-spec-prompt-return)
@@ -378,7 +290,7 @@ prompting for the boolean-expression."
 (define-skeleton ada-procedure-spec
   "Insert a procedure specification, prompting for its name and arguments."
   "[procedure name]: "
-  "procedure " str 
+  "procedure " str
   " (" ("[parameter_specification]: " str "; " ) -2 ")"
   ";" \n )
 
@@ -391,11 +303,9 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
   (save-excursion
     (let ((pos (1+ (point))))
       (ada-search-ignore-string-comment ada-subprog-start-re t nil)
-      (if (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
-         (progn
-           (backward-char 1)
-           (forward-sexp 1)))
-      )
+      (when (ada-search-ignore-string-comment "(" nil pos t 'search-forward)
+       (backward-char 1)
+       (forward-sexp 1)))
     (if (looking-at ";")
         (delete-char 1)))
   " is" \n
@@ -425,7 +335,7 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
 ;  "Inserts a use clause, prompting for the list of packages used."
 ;  "[list of packages used]: "
 ;  "use " str ?\;)
+
 
 (define-skeleton ada-record
   "Insert a skeleton record type declaration."
@@ -464,35 +374,31 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
 (define-skeleton ada-task-spec
   "Insert a task specification, prompting for the task name."
   "[task name]: "
-  "task " str 
+  "task " str
   " (" ("[discriminant]: " str "; ") ") is\n"
   > "entry " _ \n
   <"end " str ";" )
-  
+
 
 (define-skeleton ada-get-param1
   "Prompt for arguments and if any enclose them in brackets."
   ()
-  ("[parameter_specification]: " str "; " ) & -2 & ")"
-  )
+  ("[parameter_specification]: " str "; " ) & -2 & ")")
 
 
 (define-skeleton ada-get-param
   "Prompt for arguments and if any enclose them in brackets."
   ()
-  " (" 
-  (ada-get-param1) | -2
-  )
+  " ("
+  (ada-get-param1) | -2)
 
 
 (define-skeleton ada-entry
   "Insert a task entry, prompting for the entry name."
   "[entry name]: "
-  "entry " str   
+  "entry " str
   (ada-get-param)
-  ";" \n
-;  (ada-indent-current)
-)
+  ";" \n)
 
 
 (define-skeleton ada-entry-family-prompt-discriminant
@@ -507,9 +413,7 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
   "entry " str
   " (" (ada-entry-family-prompt-discriminant) ")"
   (ada-get-param)
-  ";" \n
-  ;(ada-indent-current)
-)
+  ";" \n)
 
 
 (define-skeleton ada-select
@@ -522,16 +426,15 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
 
 (define-skeleton ada-accept-1
   "Insert a condition statement, prompting for the condition name."
-  "[condition]: " 
+  "[condition]: "
   "when " str | -5 )
 
 
 (define-skeleton ada-accept-2
   "Insert an accept statement, prompting for the name and arguments."
-  "[accept name]: " 
-  > "accept " str 
+  "[accept name]: "
+  > "accept " str
   (ada-get-param)
-;  " (" ("[parameter_specification]: " str "; ") -2 ")"
   " do" \n
   > _ \n
   < "end " str ";" )
@@ -541,24 +444,22 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
   "Insert an accept statement (prompt for condition, name and arguments)."
   ()
   > (ada-accept-1) & " =>\n"
-  (ada-accept-2)
-)
+  (ada-accept-2))
 
 
 (define-skeleton ada-or-accept
-  "Insert a or statement, prompting for the condition name."
+  "Insert an or statement, prompting for the condition name."
   ()
   < "or\n"
-  (ada-accept)
-)
+  (ada-accept))
 
 
 (define-skeleton ada-or-delay
   "Insert a delay statement, prompting for the delay value."
-  "[delay value]: " 
+  "[delay value]: "
   < "or\n"
   > "delay " str ";")
-  
+
 
 (define-skeleton ada-or-terminate
   "Insert a terminate statement."
@@ -567,24 +468,23 @@ Invoke right after `ada-function-spec' or `ada-procedure-spec'."
   > "terminate;")
 
 
-;; ---- 
 (defun ada-adjust-case-skeleton ()
-  "Adjusts the case of the text inserted by a skeleton."
-  (save-excursion 
+  "Adjust the case of the text inserted by a skeleton."
+  (save-excursion
     (let ((aa-end (point)))
-      (ada-adjust-case-region 
-       (progn (goto-char beg) (forward-word -1) (point)) 
-       (goto-char aa-end))
-      )))
-(add-hook 'ada-mode-hook '(lambda ()
-                            (setq skeleton-further-elements 
-                                  '((< '(backward-delete-char-untabify
-                                         (min ada-indent (current-column))))))
-                            (add-hook 'skeleton-end-hook
-                                      'ada-adjust-case-skeleton)))
-
-(add-hook 'ada-mode-hook 'ada-stmt-add-to-ada-menu)
+      (ada-adjust-case-region
+       (progn (goto-char (symbol-value 'beg)) (forward-word -1) (point))
+       (goto-char aa-end)))))
+
+(defun ada-stmt-mode-hook ()
+  (set (make-local-variable 'skeleton-further-elements)
+       '((< '(backward-delete-char-untabify
+             (min ada-indent (current-column))))))
+  (add-hook 'skeleton-end-hook  'ada-adjust-case-skeleton nil t))
+
+(add-hook 'ada-mode-hook 'ada-stmt-mode-hook)
 
 (provide 'ada-stmt)
 
+;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
 ;;; ada-stmt.el ends here