Merge from emacs-24; up to 2014-05-01T10:21:17Z!rgm@gnu.org
[bpt/emacs.git] / lisp / progmodes / ada-mode.el
index d8768dd..68b6c87 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ada-mode.el --- major-mode for editing Ada sources
 
-;; Copyright (C) 1994-1995, 1997-201 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1995, 1997-2014 Free Software Foundation, Inc.
 
 ;; Author: Rolf Ebert      <ebert@inf.enst.fr>
 ;;      Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
 ;; should be loaded before the ada-mode, which will then setup some variables
 ;; to improve the support for Ada code.
 ;; Here is the list of these modes:
-;;   `which-function-mode': Display in the modeline the name of the subprogram
+;;   `which-function-mode': Display in the mode line the name of the subprogram
 ;;      the cursor is in.
 ;;   `outline-mode': Provides the capability to collapse or expand the code
 ;;      for specific language constructs, for instance if you want to hide the
 (defvar ispell-check-comments)
 (defvar skeleton-further-elements)
 
+(define-error 'ada-mode-errors nil)
+
 (defun ada-mode-version ()
   "Return Ada mode version."
   (interactive)
       version-string)))
 
 (defvar ada-mode-hook nil
-  "*List of functions to call when Ada mode is invoked.
+  "List of functions to call when Ada mode is invoked.
 This hook is automatically executed after the `ada-mode' is
 fully loaded.
 This is a good place to add Ada environment specific bindings.")
@@ -147,16 +149,18 @@ This is a good place to add Ada environment specific bindings.")
 (defgroup ada nil
   "Major mode for editing and compiling Ada source in Emacs."
   :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
+  :link '(custom-manual "(ada-mode) Top")
+  :link '(emacs-commentary-link :tag "Commentary" "ada-mode.el")
   :group 'languages)
 
 (defcustom ada-auto-case t
-  "*Non-nil means automatically change case of preceding word while typing.
+  "Non-nil means automatically change case of preceding word while typing.
 Casing is done according to `ada-case-keyword', `ada-case-identifier'
 and `ada-case-attribute'."
   :type 'boolean :group 'ada)
 
 (defcustom ada-broken-decl-indent 0
-  "*Number of columns to indent a broken declaration.
+  "Number of columns to indent a broken declaration.
 
 An example is :
   declare
@@ -165,7 +169,7 @@ An example is :
   :type 'integer :group 'ada)
 
 (defcustom ada-broken-indent 2
-  "*Number of columns to indent the continuation of a broken line.
+  "Number of columns to indent the continuation of a broken line.
 
 An example is :
    My_Var : My_Type := (Field1 =>
@@ -173,7 +177,7 @@ An example is :
   :type 'integer :group 'ada)
 
 (defcustom ada-continuation-indent ada-broken-indent
-  "*Number of columns to indent the continuation of broken lines in parenthesis.
+  "Number of columns to indent the continuation of broken lines in parenthesis.
 
 An example is :
    Func (Param1,
@@ -181,7 +185,7 @@ An example is :
   :type 'integer :group 'ada)
 
 (defcustom ada-case-attribute 'ada-capitalize-word
-  "*Function to call to adjust the case of Ada attributes.
+  "Function to call to adjust the case of Ada attributes.
 It may be `downcase-word', `upcase-word', `ada-loose-case-word',
 `ada-capitalize-word' or `ada-no-auto-case'."
   :type '(choice (const downcase-word)
@@ -193,7 +197,7 @@ It may be `downcase-word', `upcase-word', `ada-loose-case-word',
 
 (defcustom ada-case-exception-file
   (list (convert-standard-filename' "~/.emacs_case_exceptions"))
-  "*List of special casing exceptions dictionaries for identifiers.
+  "List of special casing exceptions dictionaries for identifiers.
 The first file is the one where new exceptions will be saved by Emacs
 when you call `ada-create-case-exception'.
 
@@ -207,7 +211,7 @@ by a comment."
   :group 'ada)
 
 (defcustom ada-case-keyword 'downcase-word
-  "*Function to call to adjust the case of an Ada keywords.
+  "Function to call to adjust the case of an Ada keywords.
 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
 `ada-capitalize-word'."
   :type '(choice (const downcase-word)
@@ -218,7 +222,7 @@ It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
   :group 'ada)
 
 (defcustom ada-case-identifier 'ada-loose-case-word
-  "*Function to call to adjust the case of an Ada identifier.
+  "Function to call to adjust the case of an Ada identifier.
 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
 `ada-capitalize-word'."
   :type '(choice (const downcase-word)
@@ -229,7 +233,7 @@ It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
   :group 'ada)
 
 (defcustom ada-clean-buffer-before-saving t
-  "*Non-nil means remove trailing spaces and untabify the buffer before saving."
+  "Non-nil means remove trailing spaces and untabify the buffer before saving."
   :type 'boolean :group 'ada)
 (make-obsolete-variable 'ada-clean-buffer-before-saving
                        "use the `write-file-functions' hook."
@@ -237,7 +241,7 @@ It may be `downcase-word', `upcase-word', `ada-loose-case-word' or
 
 
 (defcustom ada-indent 3
-  "*Size of Ada indentation.
+  "Size of Ada indentation.
 
 An example is :
 procedure Foo is
@@ -246,11 +250,11 @@ begin
   :type 'integer  :group 'ada)
 
 (defcustom ada-indent-after-return t
-  "*Non-nil means automatically indent after RET or LFD."
+  "Non-nil means automatically indent after RET or LFD."
   :type 'boolean :group 'ada)
 
 (defcustom ada-indent-align-comments t
-  "*Non-nil means align comments on previous line comments, if any.
+  "Non-nil means align comments on previous line comments, if any.
 If nil, indentation is calculated as usual.
 Note that indentation is calculated only if `ada-indent-comment-as-code' is t.
 
@@ -260,12 +264,12 @@ For instance:
   :type 'boolean :group 'ada)
 
 (defcustom ada-indent-comment-as-code t
-  "*Non-nil means indent comment lines as code.
+  "Non-nil means indent comment lines as code.
 A nil value means do not auto-indent comments."
   :type 'boolean :group 'ada)
 
 (defcustom ada-indent-handle-comment-special nil
-  "*Non-nil if comment lines should be handled specially inside parenthesis.
+  "Non-nil if comment lines should be handled specially inside parenthesis.
 By default, if the line that contains the open parenthesis has some
 text following it, then the following lines will be indented in the
 same column as this text.  This will not be true if the first line is
@@ -287,11 +291,11 @@ type A is
   :type 'boolean :group 'ada)
 
 (defcustom ada-indent-is-separate t
-  "*Non-nil means indent 'is separate' or 'is abstract' if on a single line."
+  "Non-nil means indent 'is separate' or 'is abstract' if on a single line."
   :type 'boolean :group 'ada)
 
 (defcustom ada-indent-record-rel-type 3
-  "*Indentation for 'record' relative to 'type' or 'use'.
+  "Indentation for 'record' relative to 'type' or 'use'.
 
 An example is:
    type A is
@@ -299,7 +303,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-indent-renames ada-broken-indent
-  "*Indentation for renames relative to the matching function statement.
+  "Indentation for renames relative to the matching function statement.
 If `ada-indent-return' is null or negative, the indentation is done relative to
 the open parenthesis (if there is no parenthesis, `ada-broken-indent' is used).
 
@@ -310,7 +314,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-indent-return 0
-  "*Indentation for 'return' relative to the matching 'function' statement.
+  "Indentation for 'return' relative to the matching 'function' statement.
 If `ada-indent-return' is null or negative, the indentation is done relative to
 the open parenthesis (if there is no parenthesis, `ada-broken-indent' is used).
 
@@ -320,22 +324,22 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-indent-to-open-paren t
-  "*Non-nil means indent according to the innermost open parenthesis."
+  "Non-nil means indent according to the innermost open parenthesis."
   :type 'boolean :group 'ada)
 
 (defcustom ada-fill-comment-prefix "--  "
-  "*Text inserted in the first columns when filling a comment paragraph.
+  "Text inserted in the first columns when filling a comment paragraph.
 Note: if you modify this variable, you will have to invoke `ada-mode'
 again to take account of the new value."
   :type 'string :group 'ada)
 
 (defcustom ada-fill-comment-postfix " --"
-  "*Text inserted at the end of each line when filling a comment paragraph.
+  "Text inserted at the end of each line when filling a comment paragraph.
 Used by `ada-fill-comment-paragraph-postfix'."
   :type 'string :group 'ada)
 
 (defcustom ada-label-indent -4
-  "*Number of columns to indent a label.
+  "Number of columns to indent a label.
 
 An example is:
 procedure Foo is
@@ -346,15 +350,15 @@ This is also used for <<..>> labels"
   :type 'integer :group 'ada)
 
 (defcustom ada-language-version 'ada95
-  "*Ada language version; one of `ada83', `ada95', `ada2005'."
+  "Ada language version; one of `ada83', `ada95', `ada2005'."
   :type '(choice (const ada83) (const ada95) (const ada2005)) :group 'ada)
 
 (defcustom ada-move-to-declaration nil
-  "*Non-nil means `ada-move-to-start' moves to the subprogram declaration, not to 'begin'."
+  "Non-nil means `ada-move-to-start' moves to the subprogram declaration, not to 'begin'."
   :type 'boolean :group 'ada)
 
 (defcustom ada-popup-key '[down-mouse-3]
-  "*Key used for binding the contextual menu.
+  "Key used for binding the contextual menu.
 If nil, no contextual menu is available."
   :type '(restricted-sexp :match-alternatives (stringp vectorp))
   :group 'ada)
@@ -364,7 +368,7 @@ If nil, no contextual menu is available."
          (split-string (or (getenv "ADA_INCLUDE_PATH") "") ":")
          '("/usr/adainclude" "/usr/local/adainclude"
            "/opt/gnu/adainclude"))
-  "*Default list of directories to search for Ada files.
+  "Default list of directories to search for Ada files.
 See the description for the `ff-search-directories' variable.  This variable
 is the initial value of `ada-search-directories-internal'."
   :type '(repeat (choice :tag "Directory"
@@ -379,7 +383,7 @@ and the standard runtime location, and the value of the user-defined
 `ada-search-directories'.")
 
 (defcustom ada-stmt-end-indent 0
-  "*Number of columns to indent the end of a statement on a separate line.
+  "Number of columns to indent the end of a statement on a separate line.
 
 An example is:
    if A = B
@@ -387,7 +391,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-tab-policy 'indent-auto
-  "*Control the behavior of the TAB key.
+  "Control the behavior of the TAB key.
 Must be one of :
 `indent-rigidly' : always adds `ada-indent' blanks at the beginning of the line.
 `indent-auto'    : use indentation functions in this file.
@@ -398,7 +402,7 @@ Must be one of :
   :group 'ada)
 
 (defcustom ada-use-indent ada-broken-indent
-  "*Indentation for the lines in a 'use' statement.
+  "Indentation for the lines in a 'use' statement.
 
 An example is:
    use Ada.Text_IO,
@@ -406,7 +410,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-when-indent 3
-  "*Indentation for 'when' relative to 'exception' or 'case'.
+  "Indentation for 'when' relative to 'exception' or 'case'.
 
 An example is:
    case A is
@@ -414,7 +418,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-with-indent ada-broken-indent
-  "*Indentation for the lines in a 'with' statement.
+  "Indentation for the lines in a 'with' statement.
 
 An example is:
    with Ada.Text_IO,
@@ -422,7 +426,7 @@ An example is:
   :type 'integer :group 'ada)
 
 (defcustom ada-which-compiler 'gnat
-  "*Name of the compiler to use.
+  "Name of the compiler to use.
 This will determine what features are made available through the Ada mode.
 The possible choices are:
 `gnat': Use Ada Core Technologies' GNAT compiler.  Add some cross-referencing
@@ -457,15 +461,8 @@ The extensions should include a `.' if needed.")
 (defvar ada-mode-extra-prefix "\C-c\C-q"
   "Prefix key to access `ada-mode-extra-map' functions.")
 
-(defvar ada-mode-abbrev-table nil
+(define-abbrev-table 'ada-mode-abbrev-table ()
   "Local abbrev table for Ada mode.")
-(define-abbrev-table 'ada-mode-abbrev-table ())
-
-(defvar ada-mode-syntax-table nil
-  "Syntax table to be used for editing Ada source code.")
-
-(defvar ada-mode-symbol-syntax-table nil
-  "Syntax table for Ada, where `_' is a word constituent.")
 
 (eval-when-compile
   ;; These values are used in eval-when-compile expressions.
@@ -845,61 +842,58 @@ the 4 file locations can be clicked on and jumped to."
 ;; better is available on XEmacs.
 ;;-------------------------------------------------------------------------
 
-(defun ada-create-syntax-table ()
-  "Create the two syntax tables use in the Ada mode.
-The standard table declares `_' as a symbol constituent, the second one
-declares it as a word constituent."
-  (interactive)
-  (setq ada-mode-syntax-table (make-syntax-table))
-
-  ;; define string brackets (`%' is alternative string bracket, but
-  ;; almost never used as such and throws font-lock and indentation
-  ;; off the track.)
-  (modify-syntax-entry ?%  "$" ada-mode-syntax-table)
-  (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
-
-  (modify-syntax-entry ?:  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\; "." ada-mode-syntax-table)
-  (modify-syntax-entry ?&  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\|  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?+  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?*  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?/  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?=  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?<  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?>  "." ada-mode-syntax-table)
-  (modify-syntax-entry ?$ "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\[ "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\] "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\{ "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\} "." ada-mode-syntax-table)
-  (modify-syntax-entry ?. "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
-  (modify-syntax-entry ?\' "." ada-mode-syntax-table)
-
-  ;; a single hyphen is punctuation, but a double hyphen starts a comment
-  (modify-syntax-entry ?-  ". 12" ada-mode-syntax-table)
-
-  ;; See the comment above on grammar related function for the special
-  ;; setup for '#'.
-  (if (featurep 'xemacs)
-      (modify-syntax-entry ?#  "<" ada-mode-syntax-table)
-    (modify-syntax-entry ?#  "$" ada-mode-syntax-table))
-
-  ;; and \f and \n end a comment
-  (modify-syntax-entry ?\f  ">   " ada-mode-syntax-table)
-  (modify-syntax-entry ?\n  ">   " ada-mode-syntax-table)
-
-  ;; define what belongs in Ada symbols
-  (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
-
-  ;; define parentheses to match
-  (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
-  (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
-
-  (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table))
-  (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table)
-  )
+(defvar ada-mode-syntax-table
+  (let ((st (make-syntax-table)))
+    ;; Define string brackets (`%' is alternative string bracket, but
+    ;; almost never used as such and throws font-lock and indentation
+    ;; off the track.)
+    (modify-syntax-entry ?%  "$" st)
+    (modify-syntax-entry ?\" "\"" st)
+
+    (modify-syntax-entry ?:  "." st)
+    (modify-syntax-entry ?\; "." st)
+    (modify-syntax-entry ?&  "." st)
+    (modify-syntax-entry ?\|  "." st)
+    (modify-syntax-entry ?+  "." st)
+    (modify-syntax-entry ?*  "." st)
+    (modify-syntax-entry ?/  "." st)
+    (modify-syntax-entry ?=  "." st)
+    (modify-syntax-entry ?<  "." st)
+    (modify-syntax-entry ?>  "." st)
+    (modify-syntax-entry ?$ "." st)
+    (modify-syntax-entry ?\[ "." st)
+    (modify-syntax-entry ?\] "." st)
+    (modify-syntax-entry ?\{ "." st)
+    (modify-syntax-entry ?\} "." st)
+    (modify-syntax-entry ?. "." st)
+    (modify-syntax-entry ?\\ "." st)
+    (modify-syntax-entry ?\' "." st)
+
+    ;; A single hyphen is punctuation, but a double hyphen starts a comment.
+    (modify-syntax-entry ?-  ". 12" st)
+
+    ;; See the comment above on grammar related function for the special
+    ;; setup for '#'.
+    (modify-syntax-entry ?# (if (featurep 'xemacs) "<" "$") st)
+
+    ;; And \f and \n end a comment.
+    (modify-syntax-entry ?\f  ">   " st)
+    (modify-syntax-entry ?\n  ">   " st)
+
+    ;; Define what belongs in Ada symbols.
+    (modify-syntax-entry ?_ "_" st)
+
+    ;; Define parentheses to match.
+    (modify-syntax-entry ?\( "()" st)
+    (modify-syntax-entry ?\) ")(" st)
+    st)
+  "Syntax table to be used for editing Ada source code.")
+
+(defvar ada-mode-symbol-syntax-table
+  (let ((st (make-syntax-table ada-mode-syntax-table)))
+    (modify-syntax-entry ?_ "w" st)
+    st)
+  "Syntax table for Ada, where `_' is a word constituent.")
 
 ;;  Support of special characters in XEmacs (see the comments at the beginning
 ;;  of the section on Grammar related functions).
@@ -1293,7 +1287,7 @@ the file name."
   (if ada-popup-key
       (define-key ada-mode-map ada-popup-key 'ada-popup-menu))
 
-  ;;  Support for Abbreviations (the user still need to "M-x abbrev-mode"
+  ;;  Support for Abbreviations (the user still needs to "M-x abbrev-mode").
   (setq local-abbrev-table ada-mode-abbrev-table)
 
   ;;  Support for which-function mode
@@ -1625,9 +1619,8 @@ ARG is the prefix the user entered with \\[universal-argument]."
       (let ((lastk last-command-event))
 
         (with-syntax-table ada-mode-symbol-syntax-table
-          (cond ((or (eq lastk ?\n)
-                     (eq lastk ?\r))
-                 ;; horrible kludge
+          (cond ((memq lastk '(?\n ?\r))
+                 ;; Horrible kludge.
                  (insert " ")
                  (ada-adjust-case)
                  ;; horrible dekludge
@@ -1706,9 +1699,7 @@ ARG is ignored, and is there for compatibility with `capitalize-word' only."
   (interactive)
   (let ((end   (save-excursion (skip-syntax-forward  "w") (point)))
        (begin (save-excursion (skip-syntax-backward "w") (point))))
-    (modify-syntax-entry ?_ "_")
-    (capitalize-region begin end)
-    (modify-syntax-entry ?_ "w")))
+    (capitalize-region begin end)))
 
 (defun ada-adjust-case-region (from to)
   "Adjust the case of all words in the region between FROM and TO.
@@ -2165,7 +2156,7 @@ and the offset."
     (unwind-protect
        (with-syntax-table ada-mode-symbol-syntax-table
 
-         ;;  This need to be done here so that the advice is not always
+         ;;  This needs to be done here so that the advice is not always
          ;;  activated (this might interact badly with other modes)
          (if (featurep 'xemacs)
              (ad-activate 'parse-partial-sexp t))
@@ -3419,27 +3410,23 @@ Stop the search at LIMIT."
 If BACKWARD is non-nil, jump to the beginning of the previous word.
 Return the new position of point or nil if not found."
   (let ((match-cons nil)
-       (orgpoint (point))
-       (old-syntax (char-to-string (char-syntax ?_))))
-    (modify-syntax-entry ?_ "w")
+       (orgpoint (point)))
     (unless backward
-      (skip-syntax-forward "w"))
+      (skip-syntax-forward "w_"))
     (if (setq match-cons
-              (ada-search-ignore-string-comment "\\w" backward nil t))
+              (ada-search-ignore-string-comment "\\sw\\|\\s_" backward nil t))
        ;;
        ;; move to the beginning of the word found
        ;;
        (progn
          (goto-char (car match-cons))
-         (skip-syntax-backward "w")
+         (skip-syntax-backward "w_")
          (point))
       ;;
       ;; if not found, restore old position of point
       ;;
       (goto-char orgpoint)
-      'nil)
-    (modify-syntax-entry ?_ old-syntax))
-  )
+      'nil)))
 
 
 (defun ada-check-matching-start (keyword)
@@ -5055,7 +5042,7 @@ Since the search can be long, the results are cached."
                    (re-search-backward ada-imenu-subprogram-menu-re nil t))
 
          ;; Get the function name, but not the properties, or this changes
-         ;; the face in the modeline on Emacs 21
+         ;; the face in the mode line on Emacs 21
          (setq func-name (match-string-no-properties 3))
          (if (and (not (ada-in-comment-p))
                   (not (save-excursion
@@ -5218,11 +5205,11 @@ Return nil if no body was found."
      ;; correctly highlight a with_clause that spans multiple lines.
      (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)"
                   "[ \t]+\\([a-zA-Z0-9_., \t]+\\)\\W")
-          '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
+          '(1 font-lock-keyword-face) '(2 font-lock-constant-face nil t))
 
      ;;
      ;; Goto tags.
-     '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
+     '("<<\\(\\sw+\\)>>" 1 font-lock-constant-face)
 
      ;; Highlight based-numbers (R. Reagan <robin-reply@reagans.org>)
      (list "\\([0-9]+#[0-9a-fA-F_]+#\\)" '(1 font-lock-constant-face t))
@@ -5431,9 +5418,6 @@ This function typically is to be hooked into `ff-file-created-hook'."
 (ada-create-keymap)
 (ada-create-menu)
 
-;;  Create the syntax tables, but do not activate them
-(ada-create-syntax-table)
-
 ;;  Add the default extensions (and set up speedbar)
 (ada-add-extensions ".ads" ".adb")
 ;; This two files are generated by GNAT when running with -gnatD