]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/ada-stmt.el
(ada-func-or-proc-name): Match changes to ada-procedure-start-regexp.
[gnu-emacs] / lisp / progmodes / ada-stmt.el
index 7d09c68a10ef2c741f3589f372efc32aad03960c..fa6c680779a4fb0f2077f9af9ecff51e6eacfa95 100644 (file)
@@ -1,21 +1,17 @@
-;;; 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, 1998, 1999
-;;   Free Software Foundation, Inc.
+;; Copyright(C) 1987, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+;;              2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
-;; Ada Core Technologies's version:   $Revision: 1.6 $ 
+;; 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: Stephen Leake <stephen_leake@stephe-leake.org>
 ;; 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:
 
@@ -30,7 +26,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
 \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
-       (funcall (symbol-function 'add-submenu)
-                '("Ada") (append (list "Statements"
-                                       :included '(string= mode-name "Ada"))
-                                 menu))
-
-      (define-key-after (lookup-key ada-mode-map [menu-bar Ada]) [Statements]
-       (list 'menu-item
-             "Statements"
-             (easy-menu-create-menu "Statements" menu)
-             :visible '(string= mode-name "Ada"))
-       t))
-    ))
-
-
-
-\f
 (defun ada-func-or-proc-name ()
-  ;; Get the name of the current function or procedure."
+  "Return 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))
+         (match-string 5)
        "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
@@ -232,9 +136,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 ()
@@ -253,7 +155,7 @@ Indent for the first line of code."
   "--                              -*- Mode: Ada -*-"
   "\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 "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: ."
@@ -277,7 +179,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
@@ -375,7 +277,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)
@@ -385,7 +287,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 )
 
@@ -398,13 +300,11 @@ 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)))
+       (delete-char 1)))
   " is" \n
    _ \n
    < "begin" \n
@@ -432,7 +332,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."
@@ -471,35 +371,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
@@ -514,9 +410,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
@@ -529,16 +423,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 ";" )
@@ -548,51 +441,31 @@ 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 accept alternative, 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]: " 
+  "Insert a delay alternative, prompting for the delay value."
+  "[delay value]: "
   < "or\n"
   > "delay " str ";")
-  
+
 
 (define-skeleton ada-or-terminate
-  "Insert a terminate statement."
+  "Insert a terminate alternative."
   ()
   < "or\n"
   > "terminate;")
 
 
-;; ---- 
-(defun ada-adjust-case-skeleton ()
-  "Adjusts the case of the text inserted by a skeleton."
-  (save-excursion 
-    (let ((aa-end (point)))
-      (ada-adjust-case-region 
-       (progn (goto-char (symbol-value '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)
-
 (provide 'ada-stmt)
 
+;;; arch-tag: 94f51555-cc0e-44e5-8865-8788aae8ecd3
 ;;; ada-stmt.el ends here