aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2003-04-29 23:35:40 +0000
committerJuanma Barranquero2003-04-29 23:35:40 +0000
commitf7a8090935a8972278e60dcc4a14a78a40f8b2f3 (patch)
treeaae4f71f83e0fcda84a5945922211e472ff8fd16
parentf62ebc65ab95313e46326ab1bf9733a028e103ab (diff)
downloademacs-f7a8090935a8972278e60dcc4a14a78a40f8b2f3.tar.gz
emacs-f7a8090935a8972278e60dcc4a14a78a40f8b2f3.zip
(ada-search-directories): Take into account ADA_INCLUDE_PATH for better
compatibility with GNAT. (ada-contextual-menu): Menu defined through `easy-menu-define' instead. Various adjustments to the indentation engine (handling of subtypes, begin blocks, etc.). (ada-create-menu): Major rewrite of the handling of menus to use `easy-menu-define' for cleaner code and better compatibility with XEmacs. All menus that were previously in ada-xref.el and ada-prj.el are now defined in this package, which makes it easier to edit menus. (ada-narrow-to-defun): Add support for `narrow-to-region'. No longer explicitely load ada-xref.el and ada-prj.el. Use autoload statements instead.
-rw-r--r--lisp/progmodes/ada-mode.el534
1 files changed, 371 insertions, 163 deletions
diff --git a/lisp/progmodes/ada-mode.el b/lisp/progmodes/ada-mode.el
index d5bd539b421..0ae30d74703 100644
--- a/lisp/progmodes/ada-mode.el
+++ b/lisp/progmodes/ada-mode.el
@@ -1,13 +1,13 @@
1;;; ada-mode.el --- major-mode for editing Ada sources 1;;; ada-mode.el --- major-mode for editing Ada sources
2 2
3;; Copyright (C) 1994, 95, 97, 98, 99, 2000, 2001, 2002 3;; Copyright (C) 1994, 95, 97, 98, 99, 2000, 2001, 2002, 2003
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
5 5
6;; Author: Rolf Ebert <ebert@inf.enst.fr> 6;; Author: Rolf Ebert <ebert@inf.enst.fr>
7;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> 7;; Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
8;; Emmanuel Briot <briot@gnat.com> 8;; Emmanuel Briot <briot@gnat.com>
9;; Maintainer: Emmanuel Briot <briot@gnat.com> 9;; Maintainer: Emmanuel Briot <briot@gnat.com>
10;; Ada Core Technologies's version: Revision: 1.164.2.2 (GNAT 3.15) 10;; Ada Core Technologies's version: Revision: 1.188
11;; Keywords: languages ada 11;; Keywords: languages ada
12 12
13;; This file is part of GNU Emacs. 13;; This file is part of GNU Emacs.
@@ -30,7 +30,7 @@
30;;; Commentary: 30;;; Commentary:
31;;; This mode is a major mode for editing Ada83 and Ada95 source code. 31;;; This mode is a major mode for editing Ada83 and Ada95 source code.
32;;; This is a major rewrite of the file packaged with Emacs-20. The 32;;; This is a major rewrite of the file packaged with Emacs-20. The
33;;; ada-mode is composed of four lisp file, ada-mode.el, ada-xref.el, 33;;; ada-mode is composed of four lisp files, ada-mode.el, ada-xref.el,
34;;; ada-prj.el and ada-stmt.el. Only this file (ada-mode.el) is 34;;; ada-prj.el and ada-stmt.el. Only this file (ada-mode.el) is
35;;; completely independent from the GNU Ada compiler Gnat, distributed 35;;; completely independent from the GNU Ada compiler Gnat, distributed
36;;; by Ada Core Technologies. All the other files rely heavily on 36;;; by Ada Core Technologies. All the other files rely heavily on
@@ -148,20 +148,17 @@ If IS-XEMACS is non-nil, check for XEmacs instead of Emacs."
148 (symbol-value 'running-xemacs)) 148 (symbol-value 'running-xemacs))
149 "Return t if we are using XEmacs.")) 149 "Return t if we are using XEmacs."))
150 150
151(unless ada-xemacs
152 (require 'outline))
153
154(eval-and-compile 151(eval-and-compile
155 (condition-case nil (require 'find-file) (error nil))) 152 (condition-case nil (require 'find-file) (error nil)))
156 153
157;; This call should not be made in the release that is done for the 154;; This call should not be made in the release that is done for the
158;; official Emacs, since it does nothing useful for the latest version 155;; official Emacs, since it does nothing useful for the latest version
159;; (if (not (ada-check-emacs-version 21 1)) 156;;(if (not (ada-check-emacs-version 21 1))
160;; (require 'ada-support)) 157;; (require 'ada-support))
161 158
162(defvar ada-mode-hook nil 159(defvar ada-mode-hook nil
163 "*List of functions to call when Ada mode is invoked. 160 "*List of functions to call when Ada mode is invoked.
164This hook is automatically executed after the ada-mode is 161This hook is automatically executed after the `ada-mode' is
165fully loaded. 162fully loaded.
166This is a good place to add Ada environment specific bindings.") 163This is a good place to add Ada environment specific bindings.")
167 164
@@ -379,8 +376,10 @@ If nil, no contextual menu is available."
379 :group 'ada) 376 :group 'ada)
380 377
381(defcustom ada-search-directories 378(defcustom ada-search-directories
382 '("." "$ADA_INCLUDE_PATH" "/usr/adainclude" "/usr/local/adainclude" 379 (append '(".")
383 "/opt/gnu/adainclude") 380 (split-string (or (getenv "ADA_INCLUDE_PATH") "") ":")
381 '("/usr/adainclude" "/usr/local/adainclude"
382 "/opt/gnu/adainclude"))
384 "*List of directories to search for Ada files. 383 "*List of directories to search for Ada files.
385See the description for the `ff-search-directories' variable. 384See the description for the `ff-search-directories' variable.
386Emacs will automatically add the paths defined in your project file, and if you 385Emacs will automatically add the paths defined in your project file, and if you
@@ -668,63 +667,23 @@ To get the original region, restore the point to this position before
668calling `region-end' and `region-beginning'. 667calling `region-end' and `region-beginning'.
669Modify this variable if you want to restore the point to another position.") 668Modify this variable if you want to restore the point to another position.")
670 669
671(defvar ada-contextual-menu 670(easy-menu-define ada-contextual-menu nil
672 (if ada-xemacs 671 "Menu to use when the user presses the right mouse button.
673 '("Ada"
674 ["Goto Declaration/Body"
675 (ada-call-from-contextual-menu 'ada-point-and-xref)
676 :included (and (functionp 'ada-point-and-xref)
677 ada-contextual-menu-on-identifier)]
678 ["Goto Previous Reference"
679 (ada-call-from-contextual-menu 'ada-xref-goto-previous-reference)
680 :included (functionp 'ada-xref-goto-previous-reference)]
681 ["List References" ada-find-references
682 :included ada-contextual-menu-on-identifier]
683 ["List Local References" ada-find-local-references
684 :included ada-contextual-menu-on-identifier]
685 ["-" nil nil]
686 ["Other File" ff-find-other-file]
687 ["Goto Parent Unit" ada-goto-parent]
688 )
689
690 (let ((map (make-sparse-keymap "Ada")))
691 ;; The identifier part
692 (if (equal ada-which-compiler 'gnat)
693 (progn
694 (define-key-after map [Ref]
695 '(menu-item "Goto Declaration/Body"
696 (lambda()(interactive)
697 (ada-call-from-contextual-menu
698 'ada-point-and-xref))
699 :visible
700 (and (functionp 'ada-point-and-xref)
701 ada-contextual-menu-on-identifier))
702 t)
703 (define-key-after map [Prev]
704 '(menu-item "Goto Previous Reference"
705 (lambda()(interactive)
706 (ada-call-from-contextual-menu
707 'ada-xref-goto-previous-reference))
708 :visible
709 (functionp 'ada-xref-goto-previous-reference))
710 t)
711 (define-key-after map [List]
712 '(menu-item "List References"
713 ada-find-references
714 :visible ada-contextual-menu-on-identifier) t)
715 (define-key-after map [List-Local]
716 '(menu-item "List Local References"
717 ada-find-local-references
718 :visible ada-contextual-menu-on-identifier) t)
719 (define-key-after map [-] '("-" nil) t)
720 ))
721 (define-key-after map [Other] '("Other file" . ff-find-other-file) t)
722 (define-key-after map [Parent] '("Goto Parent Unit" . ada-goto-parent)t)
723 map))
724 "Defines the menu to use when the user presses the right mouse button.
725The variable `ada-contextual-menu-on-identifier' will be set to t before 672The variable `ada-contextual-menu-on-identifier' will be set to t before
726displaying the menu if point was on an identifier." 673displaying the menu if point was on an identifier."
727 ) 674 '("Ada"
675 ["Goto Declaration/Body" ada-point-and-xref
676 :included ada-contextual-menu-on-identifier]
677 ["Goto Body" ada-point-and-xref-body
678 :included ada-contextual-menu-on-identifier]
679 ["Goto Previous Reference" ada-xref-goto-previous-reference]
680 ["List References" ada-find-references
681 :included ada-contextual-menu-on-identifier]
682 ["List Local References" ada-find-local-references
683 :included ada-contextual-menu-on-identifier]
684 ["-" nil nil]
685 ["Other File" ff-find-other-file]
686 ["Goto Parent Unit" ada-goto-parent]))
728 687
729 688
730;;------------------------------------------------------------------ 689;;------------------------------------------------------------------
@@ -789,15 +748,26 @@ both file locations can be clicked on and jumped to."
789 (looking-at 748 (looking-at
790 "\\([-_.a-zA-Z0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?")) 749 "\\([-_.a-zA-Z0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"))
791 (let ((line (match-string 2)) 750 (let ((line (match-string 2))
751 file
792 (error-pos (point-marker)) 752 (error-pos (point-marker))
793 source) 753 source)
794 (save-excursion 754 (save-excursion
795 (save-restriction 755 (save-restriction
796 (widen) 756 (widen)
797 ;; Use funcall so as to prevent byte-compiler warnings 757 ;; Use funcall so as to prevent byte-compiler warnings
798 (set-buffer (funcall (symbol-function 'compilation-find-file) 758 ;; `ada-find-file' is not defined if ada-xref wasn't loaded. But
799 (point-marker) (match-string 1) 759 ;; if we can find it, we should use it instead of
800 "./")) 760 ;; `compilation-find-file', since the latter doesn't know anything
761 ;; about source path.
762
763 (if (functionp 'ada-find-file)
764 (setq file (funcall (symbol-function 'ada-find-file)
765 (match-string 1)))
766 (setq file (funcall (symbol-function 'compilation-find-file)
767 (point-marker) (match-string 1)
768 "./")))
769 (set-buffer file)
770
801 (if (stringp line) 771 (if (stringp line)
802 (goto-line (string-to-number line))) 772 (goto-line (string-to-number line)))
803 (setq source (point-marker)))) 773 (setq source (point-marker))))
@@ -976,8 +946,7 @@ OLD-LEN indicates what the length of the replaced text was."
976 (beginning-of-line) 946 (beginning-of-line)
977 (if (looking-at "^[ \t]*#") 947 (if (looking-at "^[ \t]*#")
978 (add-text-properties (match-beginning 0) (match-end 0) 948 (add-text-properties (match-beginning 0) (match-end 0)
979 '(syntax-table (11 . 10)))) 949 '(syntax-table (11 . 10))))))))
980 ))))
981 950
982;;------------------------------------------------------------------ 951;;------------------------------------------------------------------
983;; Testing the grammatical context 952;; Testing the grammatical context
@@ -1045,13 +1014,13 @@ where the mouse button was clicked."
1045 (save-excursion (skip-syntax-forward "w") 1014 (save-excursion (skip-syntax-forward "w")
1046 (not (ada-after-keyword-p))) 1015 (not (ada-after-keyword-p)))
1047 )) 1016 ))
1048 (let (choice) 1017 (if (fboundp 'popup-menu)
1049 (if ada-xemacs 1018 (funcall (symbol-function 'popup-menu) ada-contextual-menu)
1050 (setq choice (funcall (symbol-function 'popup-menu) 1019 (let (choice)
1051 ada-contextual-menu)) 1020 (setq choice (x-popup-menu position ada-contextual-menu))
1052 (setq choice (x-popup-menu position ada-contextual-menu))) 1021 (if choice
1053 (if choice 1022 (funcall (lookup-key ada-contextual-menu (vector (car choice)))))))
1054 (funcall (lookup-key ada-contextual-menu (vector (car choice)))))) 1023
1055 (set-buffer (cadr ada-contextual-menu-last-point)) 1024 (set-buffer (cadr ada-contextual-menu-last-point))
1056 (goto-char (car ada-contextual-menu-last-point)) 1025 (goto-char (car ada-contextual-menu-last-point))
1057 )) 1026 ))
@@ -1090,9 +1059,8 @@ name"
1090 1059
1091 ;; Support for speedbar (Specifies that we want to see these files in 1060 ;; Support for speedbar (Specifies that we want to see these files in
1092 ;; speedbar) 1061 ;; speedbar)
1093 (condition-case nil 1062 (if (fboundp 'speedbar-add-supported-extension)
1094 (progn 1063 (progn
1095 (require 'speedbar)
1096 (funcall (symbol-function 'speedbar-add-supported-extension) 1064 (funcall (symbol-function 'speedbar-add-supported-extension)
1097 spec) 1065 spec)
1098 (funcall (symbol-function 'speedbar-add-supported-extension) 1066 (funcall (symbol-function 'speedbar-add-supported-extension)
@@ -1103,7 +1071,7 @@ name"
1103;;;###autoload 1071;;;###autoload
1104(defun ada-mode () 1072(defun ada-mode ()
1105 "Ada mode is the major mode for editing Ada code. 1073 "Ada mode is the major mode for editing Ada code.
1106This version was built on Date: 2002/05/21 11:58:02 . 1074This version was built on $Date: 2003/01/31 09:21:42 $.
1107 1075
1108Bindings are as follows: (Note: 'LFD' is control-j.) 1076Bindings are as follows: (Note: 'LFD' is control-j.)
1109\\{ada-mode-map} 1077\\{ada-mode-map}
@@ -1635,7 +1603,7 @@ word itself has a special casing."
1635 1603
1636 (save-excursion 1604 (save-excursion
1637 (while (re-search-forward re max t) 1605 (while (re-search-forward re max t)
1638 (replace-match (caar substrings)))) 1606 (replace-match (caar substrings) t)))
1639 (setq substrings (cdr substrings)) 1607 (setq substrings (cdr substrings))
1640 ) 1608 )
1641 ) 1609 )
@@ -3261,8 +3229,12 @@ ORGPOINT is the limit position used in the calculation."
3261 "record" nil orgpoint nil 'word-search-forward)) 3229 "record" nil orgpoint nil 'word-search-forward))
3262 t))) 3230 t)))
3263 (if match-cons 3231 (if match-cons
3264 (goto-char (car match-cons))) 3232 (progn
3265 (list (save-excursion (back-to-indentation) (point)) 'ada-indent)) 3233 (goto-char (car match-cons))
3234 (list (save-excursion (back-to-indentation) (point)) 'ada-indent))
3235 (list (save-excursion (back-to-indentation) (point)) 'ada-broken-indent))
3236 )
3237
3266 ;; 3238 ;;
3267 ;; for..loop 3239 ;; for..loop
3268 ;; 3240 ;;
@@ -3687,7 +3659,7 @@ If NOERROR is non-nil, it only returns nil if no match was found."
3687 (skip-chars-backward "a-zA-Z0-9_.'") 3659 (skip-chars-backward "a-zA-Z0-9_.'")
3688 (ada-goto-previous-word) 3660 (ada-goto-previous-word)
3689 (and 3661 (and
3690 (looking-at "\\<\\(sub\\)?type\\>") 3662 (looking-at "\\<\\(sub\\)?type\\|case\\>")
3691 (save-match-data 3663 (save-match-data
3692 (ada-goto-previous-word) 3664 (ada-goto-previous-word)
3693 (not (looking-at "\\<protected\\>")))) 3665 (not (looking-at "\\<protected\\>"))))
@@ -3715,7 +3687,7 @@ If NOERROR is non-nil, it only returns nil if no match was found."
3715 (progn 3687 (progn
3716 (if stop-at-when 3688 (if stop-at-when
3717 (setq nest-count (1- nest-count))) 3689 (setq nest-count (1- nest-count)))
3718 (setq first nil))))) 3690 ))))
3719 ;; 3691 ;;
3720 ((looking-at "begin") 3692 ((looking-at "begin")
3721 (setq first nil)) 3693 (setq first nil))
@@ -3896,7 +3868,8 @@ If NOERROR is non-nil, it only returns nil if found no matching start."
3896 "if" "task" "package" "record" "do" 3868 "if" "task" "package" "record" "do"
3897 "procedure" "function") t) 3869 "procedure" "function") t)
3898 "\\>"))) 3870 "\\>")))
3899 found 3871 found
3872 pos
3900 3873
3901 ;; First is used for subprograms: they are generally handled 3874 ;; First is used for subprograms: they are generally handled
3902 ;; recursively, but of course we do not want to do that the 3875 ;; recursively, but of course we do not want to do that the
@@ -3907,7 +3880,7 @@ If NOERROR is non-nil, it only returns nil if found no matching start."
3907 ;; in the nesting loop below, so we just make sure we don't count it. 3880 ;; in the nesting loop below, so we just make sure we don't count it.
3908 ;; "declare" is a special case because we need to look after the "begin" 3881 ;; "declare" is a special case because we need to look after the "begin"
3909 ;; keyword 3882 ;; keyword
3910 (if (looking-at "\\<if\\|loop\\|case\\>") 3883 (if (looking-at "\\<if\\|loop\\|case\\|begin\\>")
3911 (forward-char 1)) 3884 (forward-char 1))
3912 3885
3913 ;; 3886 ;;
@@ -3940,10 +3913,16 @@ If NOERROR is non-nil, it only returns nil if found no matching start."
3940 ((and (looking-at "\\<procedure\\|function\\>")) 3913 ((and (looking-at "\\<procedure\\|function\\>"))
3941 (if first 3914 (if first
3942 (forward-word 1) 3915 (forward-word 1)
3916
3917 (setq pos (point))
3943 (ada-search-ignore-string-comment "is\\|;") 3918 (ada-search-ignore-string-comment "is\\|;")
3944 (ada-goto-next-non-ws) 3919 (if (= (char-before) ?s)
3945 (unless (looking-at "\\<new\\>") 3920 (progn
3946 (ada-goto-matching-end 0 t)))) 3921 (ada-goto-next-non-ws)
3922 (unless (looking-at "\\<new\\>")
3923 (progn
3924 (goto-char pos)
3925 (ada-goto-matching-end 0 t)))))))
3947 3926
3948 ;; found block end => decrease nest depth 3927 ;; found block end => decrease nest depth
3949 ((looking-at "\\<end\\>") 3928 ((looking-at "\\<end\\>")
@@ -3970,8 +3949,9 @@ If NOERROR is non-nil, it only returns nil if found no matching start."
3970 3949
3971 ;; all the other block starts 3950 ;; all the other block starts
3972 (t 3951 (t
3973 (setq nest-count (1+ nest-count) 3952 (if (not first)
3974 found (<= nest-count 0)) 3953 (setq nest-count (1+ nest-count)))
3954 (setq found (<= nest-count 0))
3975 (forward-word 1))) ; end of 'cond' 3955 (forward-word 1))) ; end of 'cond'
3976 3956
3977 (setq first nil)) 3957 (setq first nil))
@@ -4404,7 +4384,8 @@ Moves to 'begin' if in a declarative part."
4404 ((save-excursion 4384 ((save-excursion
4405 (skip-syntax-backward "w") 4385 (skip-syntax-backward "w")
4406 (looking-at "\\<begin\\>")) 4386 (looking-at "\\<begin\\>"))
4407 (ada-goto-matching-end 1)) 4387 (ada-goto-matching-end 1)
4388 )
4408 4389
4409 ;; on first line of subprogram body 4390 ;; on first line of subprogram body
4410 ;; Do nothing for specs or generic instantion, since these are 4391 ;; Do nothing for specs or generic instantion, since these are
@@ -4543,74 +4524,223 @@ Moves to 'begin' if in a declarative part."
4543 ;; Use predefined function of Emacs19 for comments (RE) 4524 ;; Use predefined function of Emacs19 for comments (RE)
4544 (define-key ada-mode-map "\C-c;" 'comment-region) 4525 (define-key ada-mode-map "\C-c;" 'comment-region)
4545 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region) 4526 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
4527
4528 ;; The following keys are bound to functions defined in ada-xref.el or
4529 ;; ada-prj,el., However, RMS rightly thinks that the code should be shared,
4530 ;; and activated only if the right compiler is used
4531 (if ada-xemacs
4532 (progn
4533 (define-key ada-mode-map '(shift button3) 'ada-point-and-xref)
4534 (define-key ada-mode-map '(control tab) 'ada-complete-identifier))
4535 (define-key ada-mode-map [C-tab] 'ada-complete-identifier)
4536 (define-key ada-mode-map [S-mouse-3] 'ada-point-and-xref))
4537
4538 (define-key ada-mode-map "\C-co" 'ff-find-other-file)
4539 (define-key ada-mode-map "\C-c5\C-d" 'ada-goto-declaration-other-frame)
4540 (define-key ada-mode-map "\C-c\C-d" 'ada-goto-declaration)
4541 (define-key ada-mode-map "\C-c\C-s" 'ada-xref-goto-previous-reference)
4542 (define-key ada-mode-map "\C-c\C-c" 'ada-compile-application)
4543 (define-key ada-mode-map "\C-cc" 'ada-change-prj)
4544 (define-key ada-mode-map "\C-cd" 'ada-set-default-project-file)
4545 (define-key ada-mode-map "\C-cg" 'ada-gdb-application)
4546 (define-key ada-mode-map "\C-cr" 'ada-run-application)
4547 (define-key ada-mode-map "\C-c\C-o" 'ada-goto-parent)
4548 (define-key ada-mode-map "\C-c\C-r" 'ada-find-references)
4549 (define-key ada-mode-map "\C-cl" 'ada-find-local-references)
4550 (define-key ada-mode-map "\C-c\C-v" 'ada-check-current)
4551 (define-key ada-mode-map "\C-cf" 'ada-find-file)
4552
4553 (define-key ada-mode-map "\C-cu" 'ada-prj-edit)
4554
4555 ;; The templates, defined in ada-stmt.el
4556
4557 (let ((map (make-sparse-keymap)))
4558 (define-key map "h" 'ada-header)
4559 (define-key map "\C-a" 'ada-array)
4560 (define-key map "b" 'ada-exception-block)
4561 (define-key map "d" 'ada-declare-block)
4562 (define-key map "c" 'ada-case)
4563 (define-key map "\C-e" 'ada-elsif)
4564 (define-key map "e" 'ada-else)
4565 (define-key map "\C-k" 'ada-package-spec)
4566 (define-key map "k" 'ada-package-body)
4567 (define-key map "\C-p" 'ada-procedure-spec)
4568 (define-key map "p" 'ada-subprogram-body)
4569 (define-key map "\C-f" 'ada-function-spec)
4570 (define-key map "f" 'ada-for-loop)
4571 (define-key map "i" 'ada-if)
4572 (define-key map "l" 'ada-loop)
4573 (define-key map "\C-r" 'ada-record)
4574 (define-key map "\C-s" 'ada-subtype)
4575 (define-key map "S" 'ada-tabsize)
4576 (define-key map "\C-t" 'ada-task-spec)
4577 (define-key map "t" 'ada-task-body)
4578 (define-key map "\C-y" 'ada-type)
4579 (define-key map "\C-v" 'ada-private)
4580 (define-key map "u" 'ada-use)
4581 (define-key map "\C-u" 'ada-with)
4582 (define-key map "\C-w" 'ada-when)
4583 (define-key map "w" 'ada-while-loop)
4584 (define-key map "\C-x" 'ada-exception)
4585 (define-key map "x" 'ada-exit)
4586 (define-key ada-mode-map "\C-ct" map))
4546 ) 4587 )
4547 4588
4548 4589
4549(defun ada-create-menu () 4590(defun ada-create-menu ()
4550 "Create the ada menu as shown in the menu bar. 4591 "Create the ada menu as shown in the menu bar."
4551This function is designed to be extensible, so that each compiler-specific file 4592 (let ((m '("Ada"
4552can add its own items." 4593 ("Help"
4553 ;; Note that the separators must have different length in the submenus 4594 ["Ada Mode" (info "ada-mode") t]
4554 (autoload 'easy-menu-define "easymenu") 4595 ["GNAT User's Guide" (info "gnat_ugn")
4555 4596 (eq ada-which-compiler 'gnat)]
4556 (let ((m '("Ada" 4597 ["GNAT Reference Manual" (info "gnat_rm")
4557 ("Help" ["Ada Mode" (info "ada-mode") t]))) 4598 (eq ada-which-compiler 'gnat)]
4558 (option '(["Auto Casing" (setq ada-auto-case (not ada-auto-case)) 4599 ["Gcc Documentation" (info "gcc")
4559 :style toggle :selected ada-auto-case] 4600 (eq ada-which-compiler 'gnat)]
4560 ["Auto Indent After Return" 4601 ["Gdb Documentation" (info "gdb")
4561 (setq ada-indent-after-return (not ada-indent-after-return)) 4602 (eq ada-which-compiler 'gnat)]
4562 :style toggle :selected ada-indent-after-return])) 4603 ["Ada95 Reference Manual" (info "arm95")
4563 (goto '(["Next compilation error" next-error t] 4604 (eq ada-which-compiler 'gnat)])
4564 ["Previous Package" ada-previous-package t] 4605 ("Options" :included (eq major-mode 'ada-mode)
4565 ["Next Package" ada-next-package t] 4606 ["Auto Casing" (setq ada-auto-case (not ada-auto-case))
4566 ["Previous Procedure" ada-previous-procedure t] 4607 :style toggle :selected ada-auto-case]
4608 ["Auto Indent After Return"
4609 (setq ada-indent-after-return (not ada-indent-after-return))
4610 :style toggle :selected ada-indent-after-return]
4611 ["Automatically Recompile For Cross-references"
4612 (setq ada-xref-create-ali (not ada-xref-create-ali))
4613 :style toggle :selected ada-xref-create-ali
4614 :included (eq ada-which-compiler 'gnat)]
4615 ["Confirm Commands"
4616 (setq ada-xref-confirm-compile (not ada-xref-confirm-compile))
4617 :style toggle :selected ada-xref-confirm-compile
4618 :included (eq ada-which-compiler 'gnat)]
4619 ["Show Cross-references In Other Buffer"
4620 (setq ada-xref-other-buffer (not ada-xref-other-buffer))
4621 :style toggle :selected ada-xref-other-buffer
4622 :included (eq ada-which-compiler 'gnat)]
4623 ["Tight Integration With GNU Visual Debugger"
4624 (setq ada-tight-gvd-integration (not ada-tight-gvd-integration))
4625 :style toggle :selected ada-tight-gvd-integration
4626 :included (string-match "gvd" ada-prj-default-debugger)])
4627 ["Customize" (customize-group 'ada)
4628 :included (fboundp 'customize-group)]
4629 ["Check file" ada-check-current (eq ada-which-compiler 'gnat)]
4630 ["Compile file" ada-compile-current (eq ada-which-compiler 'gnat)]
4631 ["Build" ada-compile-application
4632 (eq ada-which-compiler 'gnat)]
4633 ["Run" ada-run-application t]
4634 ["Debug" ada-gdb-application (eq ada-which-compiler 'gnat)]
4635 ["------" nil nil]
4636 ("Project"
4637 :included (eq ada-which-compiler 'gnat)
4638 ["Load..." ada-set-default-project-file t]
4639 ["New..." ada-prj-new t]
4640 ["Edit..." ada-prj-edit t])
4641 ("Goto" :included (eq major-mode 'ada-mode)
4642 ["Goto Declaration/Body" ada-goto-declaration
4643 (eq ada-which-compiler 'gnat)]
4644 ["Goto Body" ada-goto-body
4645 (eq ada-which-compiler 'gnat)]
4646 ["Goto Declaration Other Frame"
4647 ada-goto-declaration-other-frame
4648 (eq ada-which-compiler 'gnat)]
4649 ["Goto Previous Reference" ada-xref-goto-previous-reference
4650 (eq ada-which-compiler 'gnat)]
4651 ["List Local References" ada-find-local-references
4652 (eq ada-which-compiler 'gnat)]
4653 ["List References" ada-find-references
4654 (eq ada-which-compiler 'gnat)]
4655 ["Goto Reference To Any Entity" ada-find-any-references
4656 (eq ada-which-compiler 'gnat)]
4657 ["Goto Parent Unit" ada-goto-parent
4658 (eq ada-which-compiler 'gnat)]
4659 ["--" nil nil]
4660 ["Next compilation error" next-error t]
4661 ["Previous Package" ada-previous-package t]
4662 ["Next Package" ada-next-package t]
4663 ["Previous Procedure" ada-previous-procedure t]
4567 ["Next Procedure" ada-next-procedure t] 4664 ["Next Procedure" ada-next-procedure t]
4568 ["Goto Start Of Statement" ada-move-to-start t] 4665 ["Goto Start Of Statement" ada-move-to-start t]
4569 ["Goto End Of Statement" ada-move-to-end t] 4666 ["Goto End Of Statement" ada-move-to-end t]
4570 ["-" nil nil] 4667 ["-" nil nil]
4571 ["Other File" ff-find-other-file t] 4668 ["Other File" ff-find-other-file t]
4572 ["Other File Other Window" ada-ff-other-window t])) 4669 ["Other File Other Window" ada-ff-other-window t])
4573 (edit '(["Indent Line" ada-indent-current-function t] 4670 ("Edit" :included (eq major-mode 'ada-mode)
4574 ["Justify Current Indentation" ada-justified-indent-current t] 4671 ["Search File On Source Path" ada-find-file t]
4575 ["Indent Lines in Selection" ada-indent-region t] 4672 ["------" nil nil]
4576 ["Indent Lines in File" (ada-indent-region (point-min) (point-max)) t] 4673 ["Complete Identifier" ada-complete-identifier t]
4577 ["Format Parameter List" ada-format-paramlist t] 4674 ["-----" nil nil]
4578 ["-" nil nil] 4675 ["Indent Line" ada-indent-current-function t]
4579 ["Comment Selection" comment-region t] 4676 ["Justify Current Indentation" ada-justified-indent-current t]
4580 ["Uncomment Selection" ada-uncomment-region t] 4677 ["Indent Lines in Selection" ada-indent-region t]
4581 ["--" nil nil] 4678 ["Indent Lines in File"
4582 ["Fill Comment Paragraph" fill-paragraph t] 4679 (ada-indent-region (point-min) (point-max)) t]
4583 ["Fill Comment Paragraph Justify" ada-fill-comment-paragraph-justify t] 4680 ["Format Parameter List" ada-format-paramlist t]
4584 ["Fill Comment Paragraph Postfix" ada-fill-comment-paragraph-postfix t] 4681 ["-" nil nil]
4585 ["---" nil nil] 4682 ["Comment Selection" comment-region t]
4586 ["Adjust Case Selection" ada-adjust-case-region t] 4683 ["Uncomment Selection" ada-uncomment-region t]
4587 ["Adjust Case in File" ada-adjust-case-buffer t] 4684 ["--" nil nil]
4685 ["Fill Comment Paragraph" fill-paragraph t]
4686 ["Fill Comment Paragraph Justify"
4687 ada-fill-comment-paragraph-justify t]
4688 ["Fill Comment Paragraph Postfix"
4689 ada-fill-comment-paragraph-postfix t]
4690 ["---" nil nil]
4691 ["Adjust Case Selection" ada-adjust-case-region t]
4692 ["Adjust Case in File" ada-adjust-case-buffer t]
4588 ["Create Case Exception" ada-create-case-exception t] 4693 ["Create Case Exception" ada-create-case-exception t]
4589 ["Create Case Exception Substring" 4694 ["Create Case Exception Substring"
4590 ada-create-case-exception-substring t] 4695 ada-create-case-exception-substring t]
4591 ["Reload Case Exceptions" ada-case-read-exceptions t] 4696 ["Reload Case Exceptions" ada-case-read-exceptions t]
4592 ["----" nil nil] 4697 ["----" nil nil]
4593 ["Make body for subprogram" ada-make-subprogram-body t])) 4698 ["Make body for subprogram" ada-make-subprogram-body t]
4594 4699 ["-----" nil nil]
4595 ) 4700 ["Narrow to subprogram" ada-narrow-to-defun t])
4596 4701 ("Templates"
4597 ;; Option menu present only if in Ada mode 4702 :included (eq major-mode 'ada-mode)
4598 (setq m (append m (list (append '("Options" 4703 ["Header" ada-header t]
4599 :included '(eq major-mode 'ada-mode)) 4704 ["-" nil nil]
4600 option)))) 4705 ["Package Body" ada-package-body t]
4601 4706 ["Package Spec" ada-package-spec t]
4602 ;; Customize menu always present 4707 ["Function Spec" ada-function-spec t]
4603 (when (fboundp 'customize-group) 4708 ["Procedure Spec" ada-procedure-spec t]
4604 (setq m (append m '(["Customize" (customize-group 'ada)])))) 4709 ["Proc/func Body" ada-subprogram-body t]
4605 4710 ["Task Body" ada-task-body t]
4606 ;; Goto and Edit menus present only if in Ada mode 4711 ["Task Spec" ada-task-spec t]
4607 (setq m (append m (list (append '("Goto" 4712 ["Declare Block" ada-declare-block t]
4608 :included (eq major-mode 'ada-mode)) 4713 ["Exception Block" ada-exception-block t]
4609 goto) 4714 ["--" nil nil]
4610 (append '("Edit" 4715 ["Entry" ada-entry t]
4611 :included (eq major-mode 'ada-mode)) 4716 ["Entry family" ada-entry-family t]
4612 edit)))) 4717 ["Select" ada-select t]
4613 4718 ["Accept" ada-accept t]
4719 ["Or accept" ada-or-accep t]
4720 ["Or delay" ada-or-delay t]
4721 ["Or terminate" ada-or-terminate t]
4722 ["---" nil nil]
4723 ["Type" ada-type t]
4724 ["Private" ada-private t]
4725 ["Subtype" ada-subtype t]
4726 ["Record" ada-record t]
4727 ["Array" ada-array t]
4728 ["----" nil nil]
4729 ["If" ada-if t]
4730 ["Else" ada-else t]
4731 ["Elsif" ada-elsif t]
4732 ["Case" ada-case t]
4733 ["-----" nil nil]
4734 ["While Loop" ada-while-loop t]
4735 ["For Loop" ada-for-loop t]
4736 ["Loop" ada-loop t]
4737 ["------" nil nil]
4738 ["Exception" ada-exception t]
4739 ["Exit" ada-exit t]
4740 ["When" ada-when t])
4741 )))
4742
4743; (autoload 'easy-menu-define "easymenu")
4614 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode" m) 4744 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode" m)
4615 (easy-menu-add ada-mode-menu ada-mode-map) 4745 (easy-menu-add ada-mode-menu ada-mode-map)
4616 (when ada-xemacs 4746 (when ada-xemacs
@@ -4648,7 +4778,7 @@ can add its own items."
4648 4778
4649 ;; This advice is not needed anymore with Emacs21. However, for older 4779 ;; This advice is not needed anymore with Emacs21. However, for older
4650 ;; versions, as well as for XEmacs, we still need to enable it. 4780 ;; versions, as well as for XEmacs, we still need to enable it.
4651 (if (or (<= emacs-major-version 20) (boundp 'running-xemacs)) 4781 (if (or (<= emacs-major-version 20) ada-xemacs)
4652 (progn 4782 (progn
4653 (ad-activate 'comment-region) 4783 (ad-activate 'comment-region)
4654 (comment-region beg end (- (or arg 2))) 4784 (comment-region beg end (- (or arg 2)))
@@ -5057,7 +5187,7 @@ Returns nil if no body was found."
5057 "null" "or" "others" "private" "protected" "raise" 5187 "null" "or" "others" "private" "protected" "raise"
5058 "range" "record" "rem" "renames" "requeue" "return" "reverse" 5188 "range" "record" "rem" "renames" "requeue" "return" "reverse"
5059 "select" "separate" "tagged" "task" "terminate" "then" "until" 5189 "select" "separate" "tagged" "task" "terminate" "then" "until"
5060 "when" "while" "xor") t) 5190 "when" "while" "with" "xor") t)
5061 "\\>") 5191 "\\>")
5062 ;; 5192 ;;
5063 ;; Anything following end and not already fontified is a body name. 5193 ;; Anything following end and not already fontified is a body name.
@@ -5079,6 +5209,7 @@ Returns nil if no body was found."
5079 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)" 5209 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)"
5080 "[ \t]+\\([a-zA-Z0-9_., \t]+\\)\\W") 5210 "[ \t]+\\([a-zA-Z0-9_., \t]+\\)\\W")
5081 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) 5211 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
5212
5082 ;; 5213 ;;
5083 ;; Goto tags. 5214 ;; Goto tags.
5084 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face) 5215 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
@@ -5106,6 +5237,33 @@ Returns nil if no body was found."
5106 (current-column)))) 5237 (current-column))))
5107 5238
5108;; --------------------------------------------------------- 5239;; ---------------------------------------------------------
5240;; Support for narrow-to-region
5241;; ---------------------------------------------------------
5242
5243(defun ada-narrow-to-defun (&optional arg)
5244 "make text outside current subprogram invisible.
5245The subprogram visible is the one that contains or follow point.
5246Optional ARG is ignored.
5247Use `M-x widen' to go back to the full visibility for the buffer"
5248
5249 (interactive)
5250 (save-excursion
5251 (let (end)
5252 (widen)
5253 (forward-line 1)
5254 (ada-previous-procedure)
5255
5256 (save-excursion
5257 (beginning-of-line)
5258 (setq end (point)))
5259
5260 (ada-move-to-end)
5261 (end-of-line)
5262 (narrow-to-region end (point))
5263 (message
5264 "Use M-x widen to get back to full visibility in the buffer"))))
5265
5266;; ---------------------------------------------------------
5109;; Automatic generation of code 5267;; Automatic generation of code
5110;; The Ada-mode has a set of function to automatically generate a subprogram 5268;; The Ada-mode has a set of function to automatically generate a subprogram
5111;; or package body from its spec. 5269;; or package body from its spec.
@@ -5239,7 +5397,7 @@ This function typically is to be hooked into `ff-file-created-hooks'."
5239 (setq body-file (ada-get-body-name)) 5397 (setq body-file (ada-get-body-name))
5240 (if body-file 5398 (if body-file
5241 (find-file body-file) 5399 (find-file body-file)
5242 (error "No body found for the package. Create it first")) 5400 (error "No body found for the package. Create it first."))
5243 5401
5244 (save-restriction 5402 (save-restriction
5245 (widen) 5403 (widen)
@@ -5278,15 +5436,65 @@ This function typically is to be hooked into `ff-file-created-hooks'."
5278;; Read the special cases for exceptions 5436;; Read the special cases for exceptions
5279(ada-case-read-exceptions) 5437(ada-case-read-exceptions)
5280 5438
5281;; include the other ada-mode files 5439;; Setup auto-loading of the other ada-mode files.
5282(if (equal ada-which-compiler 'gnat) 5440(if (equal ada-which-compiler 'gnat)
5283 (progn 5441 (progn
5284 ;; The order here is important: ada-xref defines the Project 5442 (autoload 'ada-change-prj "ada-xref" nil t)
5285 ;; submenu, and ada-prj adds to it. 5443 (autoload 'ada-check-current "ada-xref" nil t)
5286 (require 'ada-xref) 5444 (autoload 'ada-compile-application "ada-xref" nil t)
5287 (condition-case nil (require 'ada-prj) (error nil)) 5445 (autoload 'ada-compile-current "ada-xref" nil t)
5446 (autoload 'ada-complete-identifier "ada-xref" nil t)
5447 (autoload 'ada-find-file "ada-xref" nil t)
5448 (autoload 'ada-find-any-references "ada-xref" nil t)
5449 (autoload 'ada-find-src-file-in-dir "ada-xref" nil t)
5450 (autoload 'ada-find-local-references "ada-xref" nil t)
5451 (autoload 'ada-find-references "ada-xref" nil t)
5452 (autoload 'ada-gdb-application "ada-xref" nil t)
5453 (autoload 'ada-goto-declaration "ada-xref" nil t)
5454 (autoload 'ada-goto-declaration-other-frame "ada-xref" nil t)
5455 (autoload 'ada-goto-parent "ada-xref" nil t)
5456 (autoload 'ada-make-body-gnatstub "ada-xref" nil t)
5457 (autoload 'ada-point-and-xref "ada-xref" nil t)
5458 (autoload 'ada-reread-prj-file "ada-xref" nil t)
5459 (autoload 'ada-run-application "ada-xref" nil t)
5460 (autoload 'ada-set-default-project-file "ada-xref" nil nil)
5461 (autoload 'ada-set-default-project-file "ada-xref" nil t)
5462 (autoload 'ada-xref-goto-previous-reference "ada-xref" nil t)
5463
5464 (autoload 'ada-customize "ada-prj" nil t)
5465 (autoload 'ada-prj-edit "ada-prj" nil t)
5466 (autoload 'ada-prj-new "ada-prj" nil t)
5467 (autoload 'ada-prj-save "ada-prj" nil t)
5288 )) 5468 ))
5289(condition-case nil (require 'ada-stmt) (error nil)) 5469
5470(autoload 'ada-array "ada-stmt" nil t)
5471(autoload 'ada-case "ada-stmt" nil t)
5472(autoload 'ada-declare-block "ada-stmt" nil t)
5473(autoload 'ada-else "ada-stmt" nil t)
5474(autoload 'ada-elsif "ada-stmt" nil t)
5475(autoload 'ada-exception "ada-stmt" nil t)
5476(autoload 'ada-exception-block "ada-stmt" nil t)
5477(autoload 'ada-exit "ada-stmt" nil t)
5478(autoload 'ada-for-loop "ada-stmt" nil t)
5479(autoload 'ada-function-spec "ada-stmt" nil t)
5480(autoload 'ada-header "ada-stmt" nil t)
5481(autoload 'ada-if "ada-stmt" nil t)
5482(autoload 'ada-loop "ada-stmt" nil t)
5483(autoload 'ada-package-body "ada-stmt" nil t)
5484(autoload 'ada-package-spec "ada-stmt" nil t)
5485(autoload 'ada-private "ada-stmt" nil t)
5486(autoload 'ada-procedure-spec "ada-stmt" nil t)
5487(autoload 'ada-record "ada-stmt" nil t)
5488(autoload 'ada-subprogram-body "ada-stmt" nil t)
5489(autoload 'ada-subtype "ada-stmt" nil t)
5490(autoload 'ada-tabsize "ada-stmt" nil t)
5491(autoload 'ada-task-body "ada-stmt" nil t)
5492(autoload 'ada-task-spec "ada-stmt" nil t)
5493(autoload 'ada-type "ada-stmt" nil t)
5494(autoload 'ada-use "ada-stmt" nil t)
5495(autoload 'ada-when "ada-stmt" nil t)
5496(autoload 'ada-while-loop "ada-stmt" nil t)
5497(autoload 'ada-with "ada-stmt" nil t)
5290 5498
5291;;; provide ourselves 5499;;; provide ourselves
5292(provide 'ada-mode) 5500(provide 'ada-mode)