;;; ada-mode.el --- major-mode for editing Ada sources
-;; Copyright (C) 1994-1995, 1997-2012 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>
;; independent from the GNU Ada compiler GNAT, distributed by Ada
;; Core Technologies. All the other files rely heavily on features
;; provided only by GNAT.
-;;
-;; Note: this mode will not work with Emacs 19. If you are on a VMS
-;; system, where the latest version of Emacs is 19.28, you will need
-;; another file, called ada-vms.el, that provides some required
-;; functions.
;;; Usage:
;; Emacs should enter Ada mode automatically when you load an Ada file.
;; 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)
(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
(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.
;; 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).
(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
(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
(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.
(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))
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)
(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
;; 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))
(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