Mercurial > emacs
annotate lisp/progmodes/ada-mode.el @ 13756:7d48799c80b5
Just "solaris" now defaults to version 2.4.
Add sunos4.1.n-noshare as alternative.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 21 Dec 1995 07:59:49 +0000 |
parents | 84acc3adcd63 |
children | a62c62ac5102 |
rev | line source |
---|---|
13337 | 1 ;;; ada-mode.el --- An Emacs major-mode for editing Ada source. |
11231 | 2 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
10705 | 3 |
4 ;;; Authors: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> | |
5 ;;; Rolf Ebert <ebert@inf.enst.fr> | |
6 | |
7 ;;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; This mode is a complete rewrite of a major mode for editing Ada 83 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
24 ;;; and Ada 95 source code under Emacs-19. It contains completely new |
10705 | 25 ;;; indenting code and support for code browsing (see ada-xref). |
26 | |
27 | |
28 ;;; USAGE | |
29 ;;; ===== | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
30 ;;; Emacs should enter ada-mode when you load an ada source (*.ad[abs]). |
10705 | 31 ;;; |
32 ;;; When you have entered ada-mode, you may get more info by pressing | |
33 ;;; C-h m. You may also get online help describing various functions by: | |
34 ;;; C-h d <Name of function you want described> | |
35 | |
36 | |
37 ;;; HISTORY | |
38 ;;; ======= | |
11199 | 39 ;;; The first Ada mode for GNU Emacs was written by V. Broman in |
40 ;;; 1985. He based his work on the already existing Modula-2 mode. | |
41 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29. | |
10705 | 42 ;;; |
43 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of | |
44 ;;; several files with support for dired commands and other nice | |
45 ;;; things. It is currently available from the PAL | |
46 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z. | |
47 ;;; | |
48 ;;; The probably very first Ada mode (called electric-ada.el) was | |
49 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the | |
50 ;;; Gosling Emacs. L. Slater based his development on ada.el and | |
51 ;;; electric-ada.el. | |
52 ;;; | |
53 ;;; The current Ada mode is a complete rewrite by M. Heritsch and | |
54 ;;; R. Ebert. Some ideas from the ada-mode mailing list have been | |
55 ;;; added. Some of the functionality of L. Slater's mode has not | |
56 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking | |
57 ;;; to his version. | |
58 | |
59 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
60 ;;; KNOWN BUGS |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
61 ;;; ========== |
10705 | 62 ;;; |
63 ;;; In the presence of comments and/or incorrect syntax | |
64 ;;; ada-format-paramlist produces weird results. | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
65 ;;; ------------------- |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
66 ;;; Indenting of some tasking constructs is still buggy. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
67 ;;; ------------------- |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
68 ;;; package Test is |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
69 ;;; -- If I hit return on the "type" line it will indent the next line |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
70 ;;; -- in another 3 space instead of heading out to the "(". If I hit |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
71 ;;; -- tab or return it reindents the line correctly but does not initially. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
72 ;;; type Wait_Return is (Read_Success, Read_Timeout, Wait_Timeout, |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
73 ;;; Nothing_To_Wait_For_In_Wait_List); |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
74 ;;; ------------------- |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
75 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
76 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
77 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
78 ;;; CREDITS |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
79 ;;; ======= |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
80 ;;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
81 ;;; Many thanks to |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
82 ;;; Philippe Warroquiers (PW) <philippe@cfmu.eurocontrol.be> in particular, |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
83 ;;; woodruff@stc.llnl.gov (John Woodruff) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
84 ;;; jj@ddci.dk (Jesper Joergensen) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
85 ;;; gse@ocsystems.com (Scott Evans) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
86 ;;; comar@LANG8.CS.NYU.EDU (Cyrille Comar) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
87 ;;; and others for their valuable hints. |
10705 | 88 |
89 ;;;-------------------- | |
90 ;;; USER OPTIONS | |
91 ;;;-------------------- | |
92 | |
93 ;; ---- configure indentation | |
94 | |
95 (defvar ada-indent 3 | |
96 "*Defines the size of Ada indentation.") | |
97 | |
98 (defvar ada-broken-indent 2 | |
99 "*# of columns to indent the continuation of a broken line.") | |
100 | |
101 (defvar ada-label-indent -4 | |
102 "*# of columns to indent a label.") | |
103 | |
104 (defvar ada-stmt-end-indent 0 | |
105 "*# of columns to indent a statement end keyword in a separate line. | |
106 Examples are 'is', 'loop', 'record', ...") | |
107 | |
108 (defvar ada-when-indent 3 | |
109 "*Defines the indentation for 'when' relative to 'exception' or 'case'.") | |
110 | |
111 (defvar ada-indent-record-rel-type 3 | |
112 "*Defines the indentation for 'record' relative to 'type' or 'use'.") | |
113 | |
114 (defvar ada-indent-comment-as-code t | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
115 "*If non-nil, comment-lines get indented as Ada code.") |
10705 | 116 |
117 (defvar ada-indent-is-separate t | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
118 "*If non-nil, 'is separate' or 'is abstract' on a single line are indented.") |
10705 | 119 |
120 (defvar ada-indent-to-open-paren t | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
121 "*If non-nil, indent according to the innermost open parenthesis.") |
10705 | 122 |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
123 (defvar ada-search-paren-char-count-limit 3000 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
124 "*Search that many characters for an open parenthesis.") |
10705 | 125 |
126 | |
127 ;; ---- other user options | |
128 | |
129 (defvar ada-tab-policy 'indent-auto | |
130 "*Control behaviour of the TAB key. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
131 Must be one of `indent-rigidly', `indent-auto', `gei', `indent-af' |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
132 or `always-tab'. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
133 |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
134 `indent-rigidly' : always adds ada-indent blanks at the beginning of the line. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
135 `indent-auto' : use indentation functions in this file. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
136 `gei' : use David Kågedal's Generic Indentation Engine. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
137 `indent-af' : use Gary E. Barnes' ada-format.el |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
138 `always-tab' : do indent-relative.") |
10705 | 139 |
140 (defvar ada-move-to-declaration nil | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
141 "*If non-nil, `ada-move-to-start' moves point to the subprog declaration, |
10705 | 142 not to 'begin'.") |
143 | |
144 (defvar ada-spec-suffix ".ads" | |
145 "*Suffix of Ada specification files.") | |
146 | |
147 (defvar ada-body-suffix ".adb" | |
148 "*Suffix of Ada body files.") | |
149 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
150 (defvar ada-language-version 'ada95 |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
151 "*Do we program in `ada83' or `ada95'?") |
10705 | 152 |
153 (defvar ada-case-keyword 'downcase-word | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
154 "*Function to call to adjust the case of Ada keyworrds. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
155 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
156 `capitalize-word'.") |
10705 | 157 |
158 (defvar ada-case-identifier 'ada-loose-case-word | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
159 "*Function to call to adjust the case of an Ada identifier. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
160 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
161 `capitalize-word'.") |
10705 | 162 |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
163 (defvar ada-case-attribute 'capitalize-word |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
164 "*Function to call to adjust the case of Ada attributes. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
165 It may be `downcase-word', `upcase-word', `ada-loose-case-word' or |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
166 `capitalize-word'.") |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
167 |
10705 | 168 (defvar ada-auto-case t |
169 "*Non-nil automatically changes casing of preceeding word while typing. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
170 Casing is done according to `ada-case-keyword', `ada-case-identifier' |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
171 and `ada-cacse-attribute'.") |
10705 | 172 |
173 (defvar ada-clean-buffer-before-saving nil | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
174 "*If non-nil, `remove-trailing-spaces' and `untabify' buffer before saving.") |
10705 | 175 |
176 (defvar ada-mode-hook nil | |
177 "*List of functions to call when Ada Mode is invoked. | |
178 This is a good place to add Ada environment specific bindings.") | |
179 | |
180 (defvar ada-external-pretty-print-program "aimap" | |
181 "*External pretty printer to call from within Ada Mode.") | |
182 | |
183 (defvar ada-tmp-directory "/tmp/" | |
184 "*Directory to store the temporary file for the Ada pretty printer.") | |
185 | |
186 (defvar ada-fill-comment-prefix "-- " | |
187 "*This is inserted in the first columns when filling a comment paragraph.") | |
188 | |
189 (defvar ada-fill-comment-postfix " --" | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
190 "*This is inserted at the end of each line when filling a comment paragraph. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
191 with `ada-fill-comment-paragraph-postfix'.") |
10705 | 192 |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
193 (defvar ada-krunch-args "0" |
10705 | 194 "*Argument of gnatk8, a string containing the max number of characters. |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
195 Set to 0, if you dont use crunched filenames.") |
10705 | 196 |
197 ;;; ---- end of user configurable variables | |
198 | |
199 | |
200 (defvar ada-mode-abbrev-table nil | |
201 "Abbrev table used in Ada mode.") | |
202 (define-abbrev-table 'ada-mode-abbrev-table ()) | |
203 | |
204 (defvar ada-mode-map () | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
205 "Local keymap used for Ada Mode.") |
10705 | 206 |
207 (defvar ada-mode-syntax-table nil | |
208 "Syntax table to be used for editing Ada source code.") | |
209 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
210 (defvar ada-mode-symbol-syntax-table nil |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
211 "Syntax table for Ada, where `_' is a word constituent.") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
212 |
10705 | 213 (defconst ada-83-keywords |
214 "\\<\\(abort\\|abs\\|accept\\|access\\|all\\|and\\|array\\|\ | |
215 at\\|begin\\|body\\|case\\|constant\\|declare\\|delay\\|delta\\|\ | |
216 digits\\|do\\|else\\|elsif\\|end\\|entry\\|exception\\|exit\\|for\\|\ | |
217 function\\|generic\\|goto\\|if\\|in\\|is\\|limited\\|loop\\|mod\\|\ | |
218 new\\|not\\|null\\|of\\|or\\|others\\|out\\|package\\|pragma\\|\ | |
219 private\\|procedure\\|raise\\|range\\|record\\|rem\\|renames\\|\ | |
220 return\\|reverse\\|select\\|separate\\|subtype\\|task\\|terminate\\|\ | |
221 then\\|type\\|use\\|when\\|while\\|with\\|xor\\)\\>" | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
222 ; "\\<\\(a\\(b\\(ort\\|s\\)\\|cce\\(pt\\|ss\\)\\|ll\\|nd\\|rray\\|t\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
223 ;b\\(egin\\|ody\\)\\|c\\(ase\\|onstant\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
224 ;d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
225 ;e\\(ls\\(e\\|if\\)\\|n\\(d\\|try\\)\\|x\\(ception\\|it\\)\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
226 ;f\\(or\\|unction\\)\\|g\\(eneric\\|oto\\)\\|i[fns]\\|l\\(imited\\|oop\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
227 ;mod\\|n\\(ew\\|ot\\|ull\\)\\|o\\([fr]\\|thers\\|ut\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
228 ;p\\(ackage\\|r\\(agma\\|ivate\\|ocedure\\)\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
229 ;r\\(a\\(ise\\|nge\\)\\|e\\(cord\\|m\\|names\\|turn\\|verse\\)\\)\\|\ |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
230 ;s\\(e\\(lect\\|parate\\)\\|ubtype\\)\\|use\\| |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
231 ;t\\(ask\\|erminate\\|hen\\|ype\\)\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\|xor\\)\\>" |
10705 | 232 "regular expression for looking at Ada83 keywords.") |
233 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
234 (defconst ada-95-keywords |
10705 | 235 "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\ |
236 all\\|and\\|array\\|at\\|begin\\|body\\|case\\|constant\\|declare\\|\ | |
237 delay\\|delta\\|digits\\|do\\|else\\|elsif\\|end\\|entry\\|\ | |
238 exception\\|exit\\|for\\|function\\|generic\\|goto\\|if\\|in\\|\ | |
239 is\\|limited\\|loop\\|mod\\|new\\|not\\|null\\|of\\|or\\|others\\|\ | |
240 out\\|package\\|pragma\\|private\\|procedure\\|protected\\|raise\\|\ | |
241 range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\ | |
242 select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\ | |
243 type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>" | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
244 "regular expression for looking at Ada95 keywords.") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
245 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
246 (defvar ada-keywords ada-95-keywords |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
247 "Regular expression for looking at Ada keywords.") |
10705 | 248 |
249 (defvar ada-ret-binding nil | |
250 "Variable to save key binding of RET when casing is activated.") | |
251 | |
252 (defvar ada-lfd-binding nil | |
253 "Variable to save key binding of LFD when casing is activated.") | |
254 | |
255 ;;; ---- Regexps to find procedures/functions/packages | |
256 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
257 (defconst ada-ident-re |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
258 "[a-zA-Z0-9_\\.]+" |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
259 "Regexp matching Ada (qualified) identifiers.") |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
260 |
10705 | 261 (defvar ada-procedure-start-regexp |
262 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\([a-zA-Z0-9_\\.]+\\)" | |
263 "Regexp used to find Ada procedures/functions.") | |
264 | |
265 (defvar ada-package-start-regexp | |
266 "^[ \t]*\\(package\\)" | |
267 "Regexp used to find Ada packages") | |
268 | |
269 | |
270 ;;; ---- regexps for indentation functions | |
271 | |
272 (defvar ada-block-start-re | |
273 "\\<\\(begin\\|select\\|declare\\|private\\|or\\|generic\\|\ | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
274 exception\\|loop\\|else\\|\ |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
275 \\(\\(limited\\|abstract\\|tagged\\)[ \t]+\\)*record\\)\\>" |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
276 "Regexp for keywords starting Ada blocks.") |
10705 | 277 |
278 (defvar ada-end-stmt-re | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
279 "\\(;\\|=>\\|^[ \t]*separate[ \t]+([a-zA-Z0-9_\\.]+)\\|\ |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
280 \\<\\(begin\\|else\\|record\\|loop\\|select\\|do\\|\ |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
281 declare\\|generic\\|private\\)\\>\\|\ |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
282 ^[ \t]*\\(package\\|procedure\\|function\\)[ \ta-zA-Z0-9_\\.]+is\\|\ |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
283 ^[ \t]*exception\\>\\)" |
10705 | 284 "Regexp of possible ends for a non-broken statement. |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
285 A new statement starts after these.") |
10705 | 286 |
287 (defvar ada-loop-start-re | |
288 "\\<\\(for\\|while\\|loop\\)\\>" | |
289 "Regexp for the start of a loop.") | |
290 | |
291 (defvar ada-subprog-start-re | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
292 "\\<\\(procedure\\|protected\\|package\\|function\\|\ |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
293 task\\|accept\\|entry\\)\\>" |
10705 | 294 "Regexp for the start of a subprogram.") |
295 | |
296 | |
12702
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
297 ;; Written by Christian Egli <Christian.Egli@hcsd.hac.com> |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
298 ;; |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
299 (defvar ada-imenu-generic-expression |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
300 '((nil "^\\s-*\\(procedure\\|function\\)\\s-+\\([A-Za-z0-9_]+\\)" 2) |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
301 ("Type Defs" "^\\s-*\\(sub\\)?type\\s-+\\([A-Za-z0-9_]+\\)" 2)) |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
302 |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
303 "Imenu generic expression for Ada mode. See `imenu-generic-expression'.") |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
304 |
10705 | 305 ;;;------------- |
306 ;;; functions | |
307 ;;;------------- | |
308 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
309 (defun ada-xemacs () |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
310 (or (string-match "Lucid" emacs-version) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
311 (string-match "XEmacs" emacs-version))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
312 |
10705 | 313 (defun ada-create-syntax-table () |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
314 "Create the syntax table for Ada Mode." |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
315 ;; There are two different syntax-tables. The standard one declares |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
316 ;; `_' as a symbol constituent, in the second one, it is a word |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
317 ;; constituent. For some search and replacing routines we |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
318 ;; temporarily switch between the two. |
10705 | 319 (setq ada-mode-syntax-table (make-syntax-table)) |
320 (set-syntax-table ada-mode-syntax-table) | |
321 | |
322 ;; define string brackets (% is alternative string bracket) | |
323 (modify-syntax-entry ?% "\"" ada-mode-syntax-table) | |
324 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table) | |
325 | |
326 (modify-syntax-entry ?\# "$" ada-mode-syntax-table) | |
327 | |
328 (modify-syntax-entry ?: "." ada-mode-syntax-table) | |
329 (modify-syntax-entry ?\; "." ada-mode-syntax-table) | |
330 (modify-syntax-entry ?& "." ada-mode-syntax-table) | |
331 (modify-syntax-entry ?\| "." ada-mode-syntax-table) | |
332 (modify-syntax-entry ?+ "." ada-mode-syntax-table) | |
333 (modify-syntax-entry ?* "." ada-mode-syntax-table) | |
334 (modify-syntax-entry ?/ "." ada-mode-syntax-table) | |
335 (modify-syntax-entry ?= "." ada-mode-syntax-table) | |
336 (modify-syntax-entry ?< "." ada-mode-syntax-table) | |
337 (modify-syntax-entry ?> "." ada-mode-syntax-table) | |
338 (modify-syntax-entry ?$ "." ada-mode-syntax-table) | |
339 (modify-syntax-entry ?\[ "." ada-mode-syntax-table) | |
340 (modify-syntax-entry ?\] "." ada-mode-syntax-table) | |
341 (modify-syntax-entry ?\{ "." ada-mode-syntax-table) | |
342 (modify-syntax-entry ?\} "." ada-mode-syntax-table) | |
343 (modify-syntax-entry ?. "." ada-mode-syntax-table) | |
344 (modify-syntax-entry ?\\ "." ada-mode-syntax-table) | |
345 (modify-syntax-entry ?\' "." ada-mode-syntax-table) | |
346 | |
347 ;; a single hyphen is punctuation, but a double hyphen starts a comment | |
348 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table) | |
349 | |
350 ;; and \f and \n end a comment | |
351 (modify-syntax-entry ?\f "> " ada-mode-syntax-table) | |
352 (modify-syntax-entry ?\n "> " ada-mode-syntax-table) | |
353 | |
354 ;; define what belongs in ada symbols | |
355 (modify-syntax-entry ?_ "_" ada-mode-syntax-table) | |
356 | |
357 ;; define parentheses to match | |
358 (modify-syntax-entry ?\( "()" ada-mode-syntax-table) | |
359 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
360 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
361 (setq ada-mode-symbol-syntax-table (copy-syntax-table ada-mode-syntax-table)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
362 (modify-syntax-entry ?_ "w" ada-mode-symbol-syntax-table) |
10705 | 363 ) |
364 | |
365 | |
10707 | 366 ;;;###autoload |
10705 | 367 (defun ada-mode () |
368 "Ada Mode is the major mode for editing Ada code. | |
369 | |
370 Bindings are as follows: (Note: 'LFD' is control-j.) | |
371 | |
372 Indent line '\\[ada-tab]' | |
373 Indent line, insert newline and indent the new line. '\\[newline-and-indent]' | |
374 | |
375 Re-format the parameter-list point is in '\\[ada-format-paramlist]' | |
376 Indent all lines in region '\\[ada-indent-region]' | |
377 Call external pretty printer program '\\[ada-call-pretty-printer]' | |
378 | |
379 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]' | |
380 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]' | |
381 | |
382 Call EXTERNAL pretty printer (if you have one) '\\[ada-call-pretty-printer]' | |
383 | |
384 Fill comment paragraph '\\[ada-fill-comment-paragraph]' | |
385 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]' | |
386 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]' | |
387 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
388 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]' |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
389 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]' |
10705 | 390 |
391 Goto matching start of current 'end ...;' '\\[ada-move-to-start]' | |
392 Goto end of current block '\\[ada-move-to-end]' | |
393 | |
394 Comments are handled using standard GNU Emacs conventions, including: | |
395 Start a comment '\\[indent-for-comment]' | |
396 Comment region '\\[comment-region]' | |
397 Uncomment region '\\[ada-uncomment-region]' | |
398 Continue comment on next line '\\[indent-new-comment-line]' | |
399 | |
400 If you use imenu.el: | |
401 Display index-menu of functions & procedures '\\[imenu]' | |
402 | |
403 If you use find-file.el: | |
404 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]' | |
405 or '\\[ff-mouse-find-other-file] | |
406 Switch to other file in other window '\\[ada-ff-other-window]' | |
407 or '\\[ff-mouse-find-other-file-other-window] | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
408 If you use this function in a spec and no body is available, it gets created |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
409 with body stubs. |
10705 | 410 |
411 If you use ada-xref.el: | |
412 Goto declaration: '\\[ada-point-and-xref]' on the identifier | |
413 or '\\[ada-goto-declaration]' with point on the identifier | |
414 Complete identifier: '\\[ada-complete-identifier]' | |
415 Execute Gnatf: '\\[ada-gnatf-current]'" | |
416 | |
417 (interactive) | |
418 (kill-all-local-variables) | |
419 | |
420 (make-local-variable 'require-final-newline) | |
421 (setq require-final-newline t) | |
422 | |
423 (make-local-variable 'comment-start) | |
424 (setq comment-start "-- ") | |
425 | |
426 ;; comment end must be set because it may hold a wrong value if | |
427 ;; this buffer had been in another mode before. RE | |
428 (make-local-variable 'comment-end) | |
429 (setq comment-end "") | |
430 | |
431 (make-local-variable 'comment-start-skip) ;; used by autofill | |
432 (setq comment-start-skip "--+[ \t]*") | |
433 | |
434 (make-local-variable 'indent-line-function) | |
435 (setq indent-line-function 'ada-indent-current-function) | |
436 | |
437 (make-local-variable 'fill-column) | |
438 (setq fill-column 75) | |
439 | |
440 (make-local-variable 'comment-column) | |
441 (setq comment-column 40) | |
442 | |
443 (make-local-variable 'parse-sexp-ignore-comments) | |
444 (setq parse-sexp-ignore-comments t) | |
445 | |
446 (make-local-variable 'case-fold-search) | |
447 (setq case-fold-search t) | |
448 | |
10707 | 449 (make-local-variable 'fill-paragraph-function) |
450 (setq fill-paragraph-function 'ada-fill-comment-paragraph) | |
451 | |
12702
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
452 (make-local-variable 'imenu-generic-expression) |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
453 (setq imenu-generic-expression ada-imenu-generic-expression) |
b0355a012c1d
(ada-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents:
12586
diff
changeset
|
454 |
10705 | 455 (make-local-variable 'font-lock-defaults) |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
456 (setq font-lock-defaults '((ada-font-lock-keywords |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
457 ada-font-lock-keywords-1 |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
458 ada-font-lock-keywords-2) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
459 nil t |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
460 ((?\_ . "w")) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
461 beginning-of-line)) |
10705 | 462 |
463 (setq major-mode 'ada-mode) | |
464 (setq mode-name "Ada") | |
465 | |
466 (setq blink-matching-paren t) | |
467 | |
468 (use-local-map ada-mode-map) | |
469 | |
470 (if ada-mode-syntax-table | |
471 (set-syntax-table ada-mode-syntax-table) | |
472 (ada-create-syntax-table)) | |
473 | |
474 (if ada-clean-buffer-before-saving | |
475 (progn | |
476 ;; remove all spaces at the end of lines in the whole buffer. | |
477 (add-hook 'local-write-file-hooks 'ada-remove-trailing-spaces) | |
478 ;; convert all tabs to the correct number of spaces. | |
479 (add-hook 'local-write-file-hooks 'ada-untabify-buffer))) | |
480 | |
481 | |
482 ;; add menu 'Ada' to the menu bar | |
483 (ada-add-ada-menu) | |
484 | |
485 (run-hooks 'ada-mode-hook) | |
486 | |
487 ;; the following has to be done after running the ada-mode-hook | |
488 ;; because users might want to set the values of these variable | |
489 ;; inside the hook (MH) | |
490 | |
491 (cond ((eq ada-language-version 'ada83) | |
492 (setq ada-keywords ada-83-keywords)) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
493 ((eq ada-language-version 'ada95) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
494 (setq ada-keywords ada-95-keywords))) |
10705 | 495 |
496 (if ada-auto-case | |
497 (ada-activate-keys-for-case))) | |
498 | |
499 | |
500 ;;;-------------------------- | |
501 ;;; Fill Comment Paragraph | |
502 ;;;-------------------------- | |
503 | |
504 (defun ada-fill-comment-paragraph-justify () | |
505 "Fills current comment paragraph and justifies each line as well." | |
506 (interactive) | |
507 (ada-fill-comment-paragraph t)) | |
508 | |
509 | |
510 (defun ada-fill-comment-paragraph-postfix () | |
511 "Fills current comment paragraph and justifies each line as well. | |
512 Prompts for a postfix to be appended to each line." | |
513 (interactive) | |
514 (ada-fill-comment-paragraph t t)) | |
515 | |
516 | |
517 (defun ada-fill-comment-paragraph (&optional justify postfix) | |
518 "Fills the current comment paragraph. | |
519 If JUSTIFY is non-nil, each line is justified as well. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
520 If POSTFIX and JUSTIFY are non-nil, `ada-fill-comment-postfix' is appended |
10705 | 521 to each filled and justified line. |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
522 If `ada-indent-comment-as-code' is non-nil, the paragraph is idented." |
10705 | 523 (interactive "P") |
524 (let ((opos (point-marker)) | |
525 (begin nil) | |
526 (end nil) | |
527 (end-2 nil) | |
528 (indent nil) | |
529 (ada-fill-comment-old-postfix "") | |
530 (fill-prefix nil)) | |
531 | |
532 ;; check if inside comment | |
533 (if (not (ada-in-comment-p)) | |
534 (error "not inside comment")) | |
535 | |
536 ;; prompt for postfix if wanted | |
537 (if (and justify | |
538 postfix) | |
539 (setq ada-fill-comment-postfix | |
540 (read-from-minibuffer "enter new postfix string: " | |
541 ada-fill-comment-postfix))) | |
542 | |
543 ;; prompt for old postfix to remove if necessary | |
544 (if (and justify | |
545 postfix) | |
546 (setq ada-fill-comment-old-postfix | |
547 (read-from-minibuffer "enter already existing postfix string: " | |
548 ada-fill-comment-postfix))) | |
549 | |
550 ;; | |
551 ;; find limits of paragraph | |
552 ;; | |
553 (message "filling comment paragraph ...") | |
554 (save-excursion | |
555 (back-to-indentation) | |
556 ;; find end of paragraph | |
557 (while (and (looking-at "--.*$") | |
558 (not (looking-at "--[ \t]*$"))) | |
559 (forward-line 1) | |
560 (back-to-indentation)) | |
561 (beginning-of-line) | |
562 (setq end (point-marker)) | |
563 (goto-char opos) | |
564 ;; find begin of paragraph | |
565 (back-to-indentation) | |
566 (while (and (looking-at "--.*$") | |
567 (not (looking-at "--[ \t]*$"))) | |
568 (forward-line -1) | |
569 (back-to-indentation)) | |
570 (forward-line 1) | |
571 ;; get indentation to calculate width for filling | |
572 (ada-indent-current) | |
573 (back-to-indentation) | |
574 (setq indent (current-column)) | |
575 (setq begin (point-marker))) | |
576 | |
577 ;; delete old postfix if necessary | |
578 (if (and justify | |
579 postfix) | |
580 (save-excursion | |
581 (goto-char begin) | |
582 (while (re-search-forward (concat ada-fill-comment-old-postfix | |
583 "\n") | |
584 end t) | |
585 (replace-match "\n")))) | |
586 | |
587 ;; delete leading whitespace and uncomment | |
588 (save-excursion | |
589 (goto-char begin) | |
590 (beginning-of-line) | |
591 (while (re-search-forward "^[ \t]*--[ \t]*" end t) | |
592 (replace-match ""))) | |
593 | |
594 ;; calculate fill width | |
595 (setq fill-column (- fill-column indent | |
596 (length ada-fill-comment-prefix) | |
597 (if postfix | |
598 (length ada-fill-comment-postfix) | |
599 0))) | |
600 ;; fill paragraph | |
601 (fill-region begin (1- end) justify) | |
602 (setq fill-column (+ fill-column indent | |
603 (length ada-fill-comment-prefix) | |
604 (if postfix | |
605 (length ada-fill-comment-postfix) | |
606 0))) | |
607 ;; find end of second last line | |
608 (save-excursion | |
609 (goto-char end) | |
610 (forward-line -2) | |
611 (end-of-line) | |
612 (setq end-2 (point-marker))) | |
613 | |
614 ;; re-comment and re-indent region | |
615 (save-excursion | |
616 (goto-char begin) | |
617 (indent-to indent) | |
618 (insert ada-fill-comment-prefix) | |
619 (while (re-search-forward "\n" (1- end-2) t) | |
620 (replace-match (concat "\n" ada-fill-comment-prefix)) | |
621 (beginning-of-line) | |
622 (indent-to indent))) | |
623 | |
624 ;; append postfix if wanted | |
625 (if (and justify | |
626 postfix | |
627 ada-fill-comment-postfix) | |
628 (progn | |
629 ;; append postfix up to there | |
630 (save-excursion | |
631 (goto-char begin) | |
632 (while (re-search-forward "\n" (1- end-2) t) | |
633 (replace-match (concat ada-fill-comment-postfix "\n"))) | |
634 | |
635 ;; fill last line and append postfix | |
636 (end-of-line) | |
637 (insert-char ? | |
638 (- fill-column | |
639 (current-column) | |
640 (length ada-fill-comment-postfix))) | |
641 (insert ada-fill-comment-postfix)))) | |
642 | |
643 ;; delete the extra line that gets inserted somehow(??) | |
644 (save-excursion | |
645 (goto-char (1- end)) | |
646 (end-of-line) | |
647 (delete-char 1)) | |
648 | |
649 (message "filling comment paragraph ... done") | |
10707 | 650 (goto-char opos)) |
651 t) | |
10705 | 652 |
653 | |
654 ;;;--------------------------------;;; | |
655 ;;; Call External Pretty Printer ;;; | |
656 ;;;--------------------------------;;; | |
657 | |
658 (defun ada-call-pretty-printer () | |
659 "Calls the external Pretty Printer. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
660 The name is specified in `ada-external-pretty-print-program'. Saves the |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
661 current buffer in a directory specified by `ada-tmp-directory', |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
662 starts the pretty printer as external process on that file and then |
10705 | 663 reloads the beautyfied program in the buffer and cleans up |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
664 `ada-tmp-directory'." |
10705 | 665 (interactive) |
666 (let ((filename-with-path buffer-file-name) | |
667 (curbuf (current-buffer)) | |
668 (orgpos (point)) | |
669 (mesgbuf nil) ;; for byte-compiling | |
670 (file-path (file-name-directory buffer-file-name)) | |
671 (filename-without-path (file-name-nondirectory buffer-file-name)) | |
672 (tmp-file-with-directory | |
673 (concat ada-tmp-directory | |
674 (file-name-nondirectory buffer-file-name)))) | |
675 ;; | |
676 ;; save buffer in temporary file | |
677 ;; | |
678 (message "saving current buffer to temporary file ...") | |
679 (write-file tmp-file-with-directory) | |
680 (auto-save-mode nil) | |
681 (message "saving current buffer to temporary file ... done") | |
682 ;; | |
683 ;; call external pretty printer program | |
684 ;; | |
685 | |
686 (message "running external pretty printer ...") | |
687 ;; create a temporary buffer for messages of pretty printer | |
688 (setq mesgbuf (get-buffer-create "Pretty Printer Messages")) | |
689 ;; execute pretty printer on temporary file | |
690 (call-process ada-external-pretty-print-program | |
691 nil mesgbuf t | |
692 tmp-file-with-directory) | |
693 ;; display messages if there are some | |
694 (if (buffer-modified-p mesgbuf) | |
695 ;; show the message buffer | |
696 (display-buffer mesgbuf t) | |
697 ;; kill the message buffer | |
698 (kill-buffer mesgbuf)) | |
699 (message "running external pretty printer ... done") | |
700 ;; | |
701 ;; kill current buffer and load pretty printer output | |
702 ;; or restore old buffer | |
703 ;; | |
704 (if (y-or-n-p | |
705 "Really replace current buffer with pretty printer output ? ") | |
706 (progn | |
707 (set-buffer-modified-p nil) | |
708 (kill-buffer curbuf) | |
709 (find-file tmp-file-with-directory)) | |
710 (message "old buffer contents restored")) | |
711 ;; | |
712 ;; delete temporary file and restore information of current buffer | |
713 ;; | |
714 (delete-file tmp-file-with-directory) | |
715 (set-visited-file-name filename-with-path) | |
716 (auto-save-mode t) | |
717 (goto-char orgpos))) | |
718 | |
719 | |
720 ;;;--------------- | |
721 ;;; auto-casing | |
722 ;;;--------------- | |
723 | |
724 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be> | |
725 ;; modifiedby RE and MH | |
726 | |
727 (defun ada-after-keyword-p () | |
728 ;; returns t if cursor is after a keyword. | |
729 (save-excursion | |
730 (forward-word -1) | |
731 (and (save-excursion | |
732 (or | |
733 (= (point) (point-min)) | |
734 (backward-char 1)) | |
735 (not (looking-at "_"))) ; (MH) | |
736 (looking-at (concat ada-keywords "[^_]"))))) | |
737 | |
738 (defun ada-after-char-p () | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
739 ;; returns t if after ada character "'". This is interpreted as being |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
740 ;; in a character constant. |
10705 | 741 (save-excursion |
742 (if (> (point) 2) | |
743 (progn | |
744 (forward-char -2) | |
745 (looking-at "'")) | |
746 nil))) | |
747 | |
748 | |
749 (defun ada-adjust-case (&optional force-identifier) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
750 "Adjust the case of the word before the just typed character. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
751 Respect options `ada-case-keyword', `ada-case-identifier', and |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
752 `ada-case-attribute'. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
753 If FORCE-IDENTIFIER is non-nil then also adjust keyword as identifier." ; (MH) |
10705 | 754 (forward-char -1) |
755 (if (and (> (point) 1) (not (or (ada-in-string-p) | |
756 (ada-in-comment-p) | |
757 (ada-after-char-p)))) | |
758 (if (eq (char-syntax (char-after (1- (point)))) ?w) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
759 (if (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
760 (forward-word -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
761 (or (= (point) (point-min)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
762 (backward-char 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
763 (looking-at "'")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
764 (funcall ada-case-attribute -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
765 (if (and |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
766 (not force-identifier) ; (MH) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
767 (ada-after-keyword-p)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
768 (funcall ada-case-keyword -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
769 (funcall ada-case-identifier -1))))) |
10705 | 770 (forward-char 1)) |
771 | |
772 | |
773 (defun ada-adjust-case-interactive (arg) | |
774 (interactive "P") | |
775 (let ((lastk last-command-char)) | |
776 (cond ((or (eq lastk ?\n) | |
777 (eq lastk ?\r)) | |
778 ;; horrible kludge | |
779 (insert " ") | |
780 (ada-adjust-case) | |
781 ;; horrible dekludge | |
782 (delete-backward-char 1) | |
783 ;; some special keys and their bindings | |
784 (cond | |
785 ((eq lastk ?\n) | |
786 (funcall ada-lfd-binding)) | |
787 ((eq lastk ?\r) | |
788 (funcall ada-ret-binding)))) | |
789 ((eq lastk ?\C-i) (ada-tab)) | |
790 ((self-insert-command (prefix-numeric-value arg)))) | |
791 ;; if there is a keyword in front of the underscore | |
792 ;; then it should be part of an identifier (MH) | |
793 (if (eq lastk ?_) | |
794 (ada-adjust-case t) | |
795 (ada-adjust-case)))) | |
796 | |
797 | |
798 (defun ada-activate-keys-for-case () | |
799 ;; save original keybindings to allow swapping ret/lfd | |
800 ;; when casing is activated | |
801 ;; the 'or ...' is there to be sure that the value will not | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
802 ;; be changed again when Ada Mode is called more than once (MH) |
10705 | 803 (or ada-ret-binding |
804 (setq ada-ret-binding (key-binding "\C-M"))) | |
805 (or ada-lfd-binding | |
806 (setq ada-lfd-binding (key-binding "\C-j"))) | |
807 ;; call case modifying function after certain keys. | |
808 (mapcar (function (lambda(key) (define-key | |
809 ada-mode-map | |
810 (char-to-string key) | |
811 'ada-adjust-case-interactive))) | |
812 '( ?` ?~ ?! ?@ ?# ?$ ?% ?^ ?& ?* ?( ?) ?- ?= ?+ ?[ ?{ ?] ?} | |
813 ?_ ?\\ ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?? ?/ ?\n 32 ?\r ))) | |
814 ;; deleted ?\t from above list | |
815 | |
816 ;; | |
817 ;; added by MH | |
818 ;; | |
819 (defun ada-loose-case-word (&optional arg) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
820 "Capitalizes the first letter and the letters following `_'. |
10705 | 821 ARG is ignored, it's there to fit the standard casing functions' style." |
822 (let ((pos (point)) | |
823 (first t)) | |
824 (skip-chars-backward "a-zA-Z0-9_") | |
825 (while (or first | |
826 (search-forward "_" pos t)) | |
827 (and first | |
828 (setq first nil)) | |
829 (insert-char (upcase (following-char)) 1) | |
830 (delete-char 1)) | |
831 (goto-char pos))) | |
832 | |
833 | |
834 ;; | |
835 ;; added by MH | |
836 ;; | |
837 (defun ada-adjust-case-region (from to) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
838 "Adjusts the case of all words in the region. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
839 Attention: This function might take very long for big regions !" |
10705 | 840 (interactive "*r") |
841 (let ((begin nil) | |
842 (end nil) | |
843 (keywordp nil) | |
844 (reldiff nil)) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
845 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
846 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
847 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
848 (goto-char to) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
849 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
850 ;; loop: look for all identifiers and keywords |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
851 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
852 (while (re-search-backward |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
853 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
854 from |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
855 t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
856 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
857 ;; print status message |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
858 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
859 (setq reldiff (- (point) from)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
860 (message (format "adjusting case ... %5d characters left" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
861 (- (point) from))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
862 (forward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
863 (or |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
864 ;; do nothing if it is a string or comment |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
865 (ada-in-string-or-comment-p) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
866 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
867 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
868 ;; get the identifier or keyword |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
869 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
870 (setq begin (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
871 (setq keywordp (looking-at (concat ada-keywords "[^_]"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
872 (skip-chars-forward "a-zA-Z0-9_") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
873 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
874 ;; casing according to user-option |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
875 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
876 (if keywordp |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
877 (funcall ada-case-keyword -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
878 (funcall ada-case-identifier -1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
879 (goto-char begin)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
880 (message "adjusting case ... done")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
881 (set-syntax-table ada-mode-syntax-table)))) |
10705 | 882 |
883 | |
884 ;; | |
885 ;; added by MH | |
886 ;; | |
887 (defun ada-adjust-case-buffer () | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
888 "Adjusts the case of all words in the whole buffer. |
10705 | 889 ATTENTION: This function might take very long for big buffers !" |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
890 (interactive "*") |
10705 | 891 (ada-adjust-case-region (point-min) (point-max))) |
892 | |
893 | |
894 ;;;------------------------;;; | |
895 ;;; Format Parameter Lists ;;; | |
896 ;;;------------------------;;; | |
897 | |
898 (defun ada-format-paramlist () | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
899 "Reformats a parameter list. |
10705 | 900 ATTENTION: 1) Comments inside the list are killed ! |
901 2) If the syntax is not correct (especially, if there are | |
902 semicolons missing), it can get totally confused ! | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
903 In such a case, use `undo', correct the syntax and try again." |
10705 | 904 |
905 (interactive) | |
906 (let ((begin nil) | |
907 (end nil) | |
908 (delend nil) | |
909 (paramlist nil)) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
910 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
911 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
912 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
913 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
914 ;; check if really inside parameter list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
915 (or (ada-in-paramlist-p) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
916 (error "not in parameter list")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
917 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
918 ;; find start of current parameter-list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
919 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
920 (ada-search-ignore-string-comment |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
921 (concat ada-subprog-start-re "\\|\\<body\\>" ) t nil) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
922 (ada-search-ignore-string-comment "(" nil nil t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
923 (backward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
924 (setq begin (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
925 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
926 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
927 ;; find end of parameter-list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
928 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
929 (forward-sexp 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
930 (setq delend (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
931 (delete-char -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
932 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
933 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
934 ;; find end of last parameter-declaration |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
935 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
936 (ada-search-ignore-string-comment "[^ \t\n]" t nil t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
937 (forward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
938 (setq end (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
939 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
940 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
941 ;; build a list of all elements of the parameter-list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
942 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
943 (setq paramlist (ada-scan-paramlist (1+ begin) end)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
944 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
945 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
946 ;; delete the original parameter-list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
947 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
948 (delete-region begin (1- delend)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
949 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
950 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
951 ;; insert the new parameter-list |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
952 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
953 (goto-char begin) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
954 (ada-insert-paramlist paramlist)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
955 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
956 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
957 ;; restore syntax-table |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
958 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
959 (set-syntax-table ada-mode-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
960 ))) |
10705 | 961 |
962 | |
963 (defun ada-scan-paramlist (begin end) | |
964 ;; Scans a parameter-list between BEGIN and END and returns a list | |
965 ;; of its contents. | |
966 ;; The list has the following format: | |
967 ;; | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
968 ;; Name of Param in? out? access? Name of Type Default-Exp or nil |
10705 | 969 ;; |
970 ;; ( ('Name_Param_1' t nil t Type_Param_1 ':= expression') | |
971 ;; ('Name_Param_2' nil nil t Type_Param_2 nil) ) | |
972 | |
973 (let ((paramlist (list)) | |
974 (param (list)) | |
975 (notend t) | |
976 (apos nil) | |
977 (epos nil) | |
978 (semipos nil) | |
979 (match-cons nil)) | |
980 | |
981 (goto-char begin) | |
982 ;; | |
983 ;; loop until end of last parameter | |
984 ;; | |
985 (while notend | |
986 | |
987 ;; | |
988 ;; find first character of parameter-declaration | |
989 ;; | |
990 (ada-goto-next-non-ws) | |
991 (setq apos (point)) | |
992 | |
993 ;; | |
994 ;; find last character of parameter-declaration | |
995 ;; | |
996 (if (setq match-cons | |
997 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t)) | |
998 (progn | |
999 (setq epos (car match-cons)) | |
1000 (setq semipos (cdr match-cons))) | |
1001 (setq epos end)) | |
1002 | |
1003 ;; | |
1004 ;; read name(s) of parameter(s) | |
1005 ;; | |
1006 (goto-char apos) | |
1007 (looking-at "\\([a-zA-Z0-9_, \t\n]*[a-zA-Z0-9_]\\)[ \t\n]*:[^=]") | |
1008 | |
1009 (setq param (list (buffer-substring (match-beginning 1) | |
1010 (match-end 1)))) | |
1011 (ada-search-ignore-string-comment ":" nil epos t) | |
1012 | |
1013 ;; | |
1014 ;; look for 'in' | |
1015 ;; | |
1016 (setq apos (point)) | |
1017 (setq param | |
1018 (append param | |
1019 (list | |
1020 (consp | |
1021 (ada-search-ignore-string-comment "\\<in\\>" | |
1022 nil | |
1023 epos | |
1024 t))))) | |
1025 | |
1026 ;; | |
1027 ;; look for 'out' | |
1028 ;; | |
1029 (goto-char apos) | |
1030 (setq param | |
1031 (append param | |
1032 (list | |
1033 (consp | |
1034 (ada-search-ignore-string-comment "\\<out\\>" | |
1035 nil | |
1036 epos | |
1037 t))))) | |
1038 | |
1039 ;; | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1040 ;; look for 'access' |
10705 | 1041 ;; |
1042 (goto-char apos) | |
1043 (setq param | |
1044 (append param | |
1045 (list | |
1046 (consp | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1047 (ada-search-ignore-string-comment "\\<access\\>" |
10705 | 1048 nil |
1049 epos | |
1050 t))))) | |
1051 | |
1052 ;; | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1053 ;; skip 'in'/'out'/'access' |
10705 | 1054 ;; |
1055 (goto-char apos) | |
1056 (ada-goto-next-non-ws) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1057 (while (looking-at "\\<\\(in\\|out\\|access\\)\\>") |
10705 | 1058 (forward-word 1) |
1059 (ada-goto-next-non-ws)) | |
1060 | |
1061 ;; | |
1062 ;; read type of parameter | |
1063 ;; | |
1064 (looking-at "\\<[a-zA-Z0-9_\\.]+\\>") | |
1065 (setq param | |
1066 (append param | |
1067 (list | |
1068 (buffer-substring (match-beginning 0) | |
1069 (match-end 0))))) | |
1070 | |
1071 ;; | |
1072 ;; read default-expression, if there is one | |
1073 ;; | |
1074 (goto-char (setq apos (match-end 0))) | |
1075 (setq param | |
1076 (append param | |
1077 (list | |
1078 (if (setq match-cons | |
1079 (ada-search-ignore-string-comment ":=" | |
1080 nil | |
1081 epos | |
1082 t)) | |
1083 (buffer-substring (car match-cons) | |
1084 epos) | |
1085 nil)))) | |
1086 ;; | |
1087 ;; add this parameter-declaration to the list | |
1088 ;; | |
1089 (setq paramlist (append paramlist (list param))) | |
1090 | |
1091 ;; | |
1092 ;; check if it was the last parameter | |
1093 ;; | |
1094 (if (eq epos end) | |
1095 (setq notend nil) | |
1096 (goto-char semipos)) | |
1097 | |
1098 ) ; end of loop | |
1099 | |
1100 (reverse paramlist))) | |
1101 | |
1102 | |
1103 (defun ada-insert-paramlist (paramlist) | |
1104 ;; Inserts a formatted PARAMLIST in the buffer. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1105 ;; See doc of `ada-scan-paramlist' for the format. |
10705 | 1106 (let ((i (length paramlist)) |
1107 (parlen 0) | |
1108 (typlen 0) | |
1109 (temp 0) | |
1110 (inp nil) | |
1111 (outp nil) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1112 (accessp nil) |
10705 | 1113 (column nil) |
1114 (orgpoint 0) | |
1115 (firstcol nil)) | |
1116 | |
1117 ;; | |
1118 ;; loop until last parameter | |
1119 ;; | |
1120 (while (not (zerop i)) | |
1121 (setq i (1- i)) | |
1122 | |
1123 ;; | |
1124 ;; get max length of parameter-name | |
1125 ;; | |
1126 (setq parlen | |
1127 (if (<= parlen (setq temp | |
1128 (length (nth 0 (nth i paramlist))))) | |
1129 temp | |
1130 parlen)) | |
1131 | |
1132 ;; | |
1133 ;; get max length of type-name | |
1134 ;; | |
1135 (setq typlen | |
1136 (if (<= typlen (setq temp | |
1137 (length (nth 4 (nth i paramlist))))) | |
1138 temp | |
1139 typlen)) | |
1140 | |
1141 ;; | |
1142 ;; is there any 'in' ? | |
1143 ;; | |
1144 (setq inp | |
1145 (or inp | |
1146 (nth 1 (nth i paramlist)))) | |
1147 | |
1148 ;; | |
1149 ;; is there any 'out' ? | |
1150 ;; | |
1151 (setq outp | |
1152 (or outp | |
1153 (nth 2 (nth i paramlist)))) | |
1154 | |
1155 ;; | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1156 ;; is there any 'access' ? |
10705 | 1157 ;; |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1158 (setq accessp |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1159 (or accessp |
10705 | 1160 (nth 3 (nth i paramlist))))) ; end of loop |
1161 | |
1162 ;; | |
1163 ;; does paramlist already start on a separate line ? | |
1164 ;; | |
1165 (if (save-excursion | |
1166 (re-search-backward "^.\\|[^ \t]" nil t) | |
1167 (looking-at "^.")) | |
1168 ;; yes => re-indent it | |
1169 (ada-indent-current) | |
1170 ;; | |
1171 ;; no => insert newline and indent it | |
1172 ;; | |
1173 (progn | |
1174 (ada-indent-current) | |
1175 (newline) | |
1176 (delete-horizontal-space) | |
1177 (setq orgpoint (point)) | |
1178 (setq column (save-excursion | |
1179 (funcall (ada-indent-function) orgpoint))) | |
1180 (indent-to column) | |
1181 )) | |
1182 | |
1183 (insert "(") | |
1184 | |
1185 (setq firstcol (current-column)) | |
1186 (setq i (length paramlist)) | |
1187 | |
1188 ;; | |
1189 ;; loop until last parameter | |
1190 ;; | |
1191 (while (not (zerop i)) | |
1192 (setq i (1- i)) | |
1193 (setq column firstcol) | |
1194 | |
1195 ;; | |
1196 ;; insert parameter-name, space and colon | |
1197 ;; | |
1198 (insert (nth 0 (nth i paramlist))) | |
1199 (indent-to (+ column parlen 1)) | |
1200 (insert ": ") | |
1201 (setq column (current-column)) | |
1202 | |
1203 ;; | |
1204 ;; insert 'in' or space | |
1205 ;; | |
1206 (if (nth 1 (nth i paramlist)) | |
1207 (insert "in ") | |
1208 (if (and | |
1209 (or inp | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1210 accessp) |
10705 | 1211 (not (nth 3 (nth i paramlist)))) |
1212 (insert " "))) | |
1213 | |
1214 ;; | |
1215 ;; insert 'out' or space | |
1216 ;; | |
1217 (if (nth 2 (nth i paramlist)) | |
1218 (insert "out ") | |
1219 (if (and | |
1220 (or outp | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1221 accessp) |
10705 | 1222 (not (nth 3 (nth i paramlist)))) |
1223 (insert " "))) | |
1224 | |
1225 ;; | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1226 ;; insert 'access' |
10705 | 1227 ;; |
1228 (if (nth 3 (nth i paramlist)) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1229 (insert "access ")) |
10705 | 1230 |
1231 (setq column (current-column)) | |
1232 | |
1233 ;; | |
1234 ;; insert type-name and, if necessary, space and default-expression | |
1235 ;; | |
1236 (insert (nth 4 (nth i paramlist))) | |
1237 (if (nth 5 (nth i paramlist)) | |
1238 (progn | |
1239 (indent-to (+ column typlen 1)) | |
1240 (insert (nth 5 (nth i paramlist))))) | |
1241 | |
1242 ;; | |
1243 ;; check if it was the last parameter | |
1244 ;; | |
1245 (if (not (zerop i)) | |
1246 ;; no => insert ';' and newline and indent | |
1247 (progn | |
1248 (insert ";") | |
1249 (newline) | |
1250 (indent-to firstcol)) | |
1251 ;; yes | |
1252 (insert ")")) | |
1253 | |
1254 ) ; end of loop | |
1255 | |
1256 ;; | |
1257 ;; if anything follows, except semicolon: | |
1258 ;; put it in a new line and indent it | |
1259 ;; | |
1260 (if (not (looking-at "[ \t]*[;\n]")) | |
1261 (ada-indent-newline-indent)) | |
1262 | |
1263 )) | |
1264 | |
1265 | |
1266 ;;;----------------------------;;; | |
1267 ;;; Move To Matching Start/End ;;; | |
1268 ;;;----------------------------;;; | |
1269 | |
1270 (defun ada-move-to-start () | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1271 "Moves point to the matching start of the current Ada structure." |
10705 | 1272 (interactive) |
1273 (let ((pos (point))) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1274 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1275 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1276 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1277 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1278 (message "searching for block start ...") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1279 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1280 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1281 ;; do nothing if in string or comment or not on 'end ...;' |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1282 ;; or if an error occurs during processing |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1283 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1284 (or |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1285 (ada-in-string-or-comment-p) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1286 (and (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1287 (or (looking-at "[ \t]*\\<end\\>") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1288 (backward-word 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1289 (or (looking-at "[ \t]*\\<end\\>") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1290 (backward-word 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1291 (or (looking-at "[ \t]*\\<end\\>") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1292 (error "not on end ...;"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1293 (ada-goto-matching-start 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1294 (setq pos (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1295 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1296 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1297 ;; on 'begin' => go on, according to user option |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1298 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1299 ada-move-to-declaration |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1300 (looking-at "\\<begin\\>") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1301 (ada-goto-matching-decl-start) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1302 (setq pos (point)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1303 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1304 ) ; end of save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1305 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1306 ;; now really move to the found position |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1307 (goto-char pos) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1308 (message "searching for block start ... done")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1309 |
10705 | 1310 ;; |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1311 ;; restore syntax-table |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1312 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1313 (set-syntax-table ada-mode-syntax-table)))) |
10705 | 1314 |
1315 | |
1316 (defun ada-move-to-end () | |
1317 "Moves point to the matching end of the current block around point. | |
1318 Moves to 'begin' if in a declarative part." | |
1319 (interactive) | |
1320 (let ((pos (point)) | |
1321 (decstart nil) | |
1322 (packdecl nil)) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1323 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1324 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1325 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1326 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1327 (message "searching for block end ...") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1328 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1329 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1330 (forward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1331 (cond |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1332 ;; directly on 'begin' |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1333 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1334 (ada-goto-previous-word) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1335 (looking-at "\\<begin\\>")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1336 (ada-goto-matching-end 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1337 ;; on first line of defun declaration |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1338 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1339 (and (ada-goto-stmt-start) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1340 (looking-at "\\<function\\>\\|\\<procedure\\>" ))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1341 (ada-search-ignore-string-comment "\\<begin\\>")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1342 ;; on first line of task declaration |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1343 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1344 (and (ada-goto-stmt-start) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1345 (looking-at "\\<task\\>" ) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1346 (forward-word 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1347 (ada-search-ignore-string-comment "[^ \n\t]") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1348 (not (backward-char 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1349 (looking-at "\\<body\\>"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1350 (ada-search-ignore-string-comment "\\<begin\\>")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1351 ;; accept block start |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1352 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1353 (and (ada-goto-stmt-start) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1354 (looking-at "\\<accept\\>" ))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1355 (ada-goto-matching-end 0)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1356 ;; package start |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1357 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1358 (and (ada-goto-matching-decl-start t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1359 (looking-at "\\<package\\>"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1360 (ada-goto-matching-end 1)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1361 ;; inside a 'begin' ... 'end' block |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1362 ((save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1363 (ada-goto-matching-decl-start t)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1364 (ada-search-ignore-string-comment "\\<begin\\>")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1365 ;; (hopefully ;-) everything else |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1366 (t |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1367 (ada-goto-matching-end 1))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1368 (setq pos (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1369 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1370 ) ; end of save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1371 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1372 ;; now really move to the found position |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1373 (goto-char pos) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1374 (message "searching for block end ... done")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1375 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1376 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1377 ;; restore syntax-table |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1378 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1379 (set-syntax-table ada-mode-syntax-table)))) |
10705 | 1380 |
1381 | |
1382 ;;;-----------------------------;;; | |
1383 ;;; Functions For Indentation ;;; | |
1384 ;;;-----------------------------;;; | |
1385 | |
1386 ;; ---- main functions for indentation | |
1387 | |
1388 (defun ada-indent-region (beg end) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1389 "Indents the region using `ada-indent-current' on each line." |
10705 | 1390 (interactive "*r") |
1391 (goto-char beg) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1392 (let ((block-done 0) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1393 (lines-remaining (count-lines beg end)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1394 (msg (format "indenting %4d lines %%4d lines remaining ..." |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1395 (count-lines beg end))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1396 (endmark (copy-marker end))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1397 ;; catch errors while indenting |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1398 (condition-case err |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1399 (while (< (point) endmark) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1400 (if (> block-done 9) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1401 (progn (message (format msg lines-remaining)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1402 (setq block-done 0))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1403 (if (looking-at "^$") nil |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1404 (ada-indent-current)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1405 (forward-line 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1406 (setq block-done (1+ block-done)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1407 (setq lines-remaining (1- lines-remaining))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1408 ;; show line number where the error occured |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1409 (error |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1410 (error (format "line %d: %s" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1411 (1+ (count-lines (point-min) (point))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1412 err) nil))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1413 (message "indenting ... done"))) |
10705 | 1414 |
1415 | |
1416 (defun ada-indent-newline-indent () | |
1417 "Indents the current line, inserts a newline and then indents the new line." | |
1418 (interactive "*") | |
1419 (let ((column) | |
1420 (orgpoint)) | |
1421 | |
1422 (ada-indent-current) | |
1423 (newline) | |
1424 (delete-horizontal-space) | |
1425 (setq orgpoint (point)) | |
1426 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1427 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1428 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1429 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1430 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1431 (setq column (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1432 (funcall (ada-indent-function) orgpoint)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1433 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1434 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1435 ;; restore syntax-table |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1436 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1437 (set-syntax-table ada-mode-syntax-table)) |
10705 | 1438 |
1439 (indent-to column) | |
1440 | |
1441 ;; The following is needed to ensure that indentation will still be | |
1442 ;; correct if something follows behind point when typing LFD | |
1443 ;; For example: Imagine point to be there (*) when LFD is typed: | |
1444 ;; while cond loop | |
1445 ;; null; *end loop; | |
1446 ;; Result without the following statement would be: | |
1447 ;; while cond loop | |
1448 ;; null; | |
1449 ;; *end loop; | |
1450 ;; You would then have to type TAB to correct it. | |
1451 ;; If that doesn't bother you, you can comment out the following | |
1452 ;; statement to speed up indentation a LITTLE bit. | |
1453 | |
1454 (if (not (looking-at "[ \t]*$")) | |
1455 (ada-indent-current)) | |
1456 )) | |
1457 | |
1458 | |
1459 (defun ada-indent-current () | |
1460 "Indents current line as Ada code. | |
1461 This works by two steps: | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
1462 1) It moves point to the end of the previous code line. |
10705 | 1463 Then it calls the function to calculate the indentation for the |
1464 following line as if a newline would be inserted there. | |
1465 The calculated column # is saved and the old position of point | |
1466 is restored. | |
1467 2) Then another function is called to calculate the indentation for | |
1468 the current line, based on the previously calculated column #." | |
1469 | |
1470 (interactive) | |
1471 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1472 (unwind-protect |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1473 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1474 (set-syntax-table ada-mode-symbol-syntax-table) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1475 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1476 (let ((line-end) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1477 (orgpoint (point-marker)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1478 (cur-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1479 (prev-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1480 (prevline t)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1481 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1482 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1483 ;; first step |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1484 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1485 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1486 (if (ada-goto-prev-nonblank-line t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1487 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1488 ;; we are not in the first accessible line in the buffer |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1489 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1490 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1491 ;;(end-of-line) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1492 ;;(forward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1493 ;; we are already at the BOL |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1494 (forward-line 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1495 (setq line-end (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1496 (setq prev-indent |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1497 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1498 (funcall (ada-indent-function) line-end)))) |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1499 (progn ; first line of buffer -> set indent |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1500 (beginning-of-line) ; to 0 |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1501 (delete-horizontal-space) |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1502 (setq prevline nil)))) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1503 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1504 (if prevline |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1505 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1506 ;; we are not in the first accessible line in the buffer |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1507 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1508 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1509 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1510 ;; second step |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1511 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1512 (back-to-indentation) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1513 (setq cur-indent (ada-get-current-indent prev-indent)) |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1514 ;; only reindent if indentation is different then the current |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1515 (if (= (current-column) cur-indent) |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1516 nil |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1517 (delete-horizontal-space) |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
1518 (indent-to cur-indent)) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1519 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1520 ;; restore position of point |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1521 ;; |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1522 (goto-char orgpoint) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1523 (if (< (current-column) (current-indentation)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1524 (back-to-indentation)))))) |
10705 | 1525 |
1526 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1527 ;; restore syntax-table |
10705 | 1528 ;; |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1529 (set-syntax-table ada-mode-syntax-table))) |
10705 | 1530 |
1531 | |
1532 (defun ada-get-current-indent (prev-indent) | |
1533 ;; Returns the column # to indent the current line to. | |
1534 ;; PREV-INDENT is the indentation resulting from the previous lines. | |
1535 (let ((column nil) | |
1536 (pos nil) | |
1537 (match-cons nil)) | |
1538 | |
1539 (cond | |
1540 ;; | |
1541 ;; in open parenthesis, but not in parameter-list | |
1542 ;; | |
1543 ((and | |
1544 ada-indent-to-open-paren | |
1545 (not (ada-in-paramlist-p)) | |
1546 (setq column (ada-in-open-paren-p))) | |
1547 ;; check if we have something like this (Table_Component_Type => | |
1548 ;; Source_File_Record,) | |
1549 (save-excursion | |
1550 (if (and (ada-search-ignore-string-comment "[^ \t]" t nil) | |
1551 (looking-at "\n") | |
1552 (ada-search-ignore-string-comment "[^ \t\n]" t nil) | |
1553 (looking-at ">")) | |
1554 (setq column (+ ada-broken-indent column)))) | |
1555 column) | |
1556 | |
1557 ;; | |
1558 ;; end | |
1559 ;; | |
1560 ((looking-at "\\<end\\>") | |
1561 (save-excursion | |
1562 (ada-goto-matching-start 1) | |
1563 | |
1564 ;; | |
1565 ;; found 'loop' => skip back to 'while' or 'for' | |
1566 ;; if 'loop' is not on a separate line | |
1567 ;; | |
1568 (if (and | |
1569 (looking-at "\\<loop\\>") | |
1570 (save-excursion | |
1571 (back-to-indentation) | |
1572 (not (looking-at "\\<loop\\>")))) | |
1573 (if (save-excursion | |
1574 (and | |
1575 (setq match-cons | |
1576 (ada-search-ignore-string-comment | |
1577 ada-loop-start-re t nil)) | |
1578 (not (looking-at "\\<loop\\>")))) | |
1579 (goto-char (car match-cons)))) | |
1580 | |
1581 (current-indentation))) | |
1582 ;; | |
1583 ;; exception | |
1584 ;; | |
1585 ((looking-at "\\<exception\\>") | |
1586 (save-excursion | |
1587 (ada-goto-matching-start 1) | |
1588 (current-indentation))) | |
1589 ;; | |
1590 ;; when | |
1591 ;; | |
1592 ((looking-at "\\<when\\>") | |
1593 (save-excursion | |
1594 (ada-goto-matching-start 1) | |
1595 (+ (current-indentation) ada-when-indent))) | |
1596 ;; | |
1597 ;; else | |
1598 ;; | |
1599 ((looking-at "\\<else\\>") | |
1600 (if (save-excursion | |
1601 (ada-goto-previous-word) | |
1602 (looking-at "\\<or\\>")) | |
1603 prev-indent | |
1604 (save-excursion | |
1605 (ada-goto-matching-start 1 nil t) | |
1606 (current-indentation)))) | |
1607 ;; | |
1608 ;; elsif | |
1609 ;; | |
1610 ((looking-at "\\<elsif\\>") | |
1611 (save-excursion | |
1612 (ada-goto-matching-start 1 nil t) | |
1613 (current-indentation))) | |
1614 ;; | |
1615 ;; then | |
1616 ;; | |
1617 ((looking-at "\\<then\\>") | |
1618 (if (save-excursion | |
1619 (ada-goto-previous-word) | |
1620 (looking-at "\\<and\\>")) | |
1621 prev-indent | |
1622 (save-excursion | |
1623 (ada-search-ignore-string-comment "\\<elsif\\>\\|\\<if\\>" t nil) | |
1624 (+ (current-indentation) ada-stmt-end-indent)))) | |
1625 ;; | |
1626 ;; loop | |
1627 ;; | |
1628 ((looking-at "\\<loop\\>") | |
1629 (setq pos (point)) | |
1630 (save-excursion | |
1631 (goto-char (match-end 0)) | |
1632 (ada-goto-stmt-start) | |
1633 (if (looking-at "\\<loop\\>\\|\\<if\\>") | |
1634 prev-indent | |
1635 (progn | |
1636 (if (not (looking-at ada-loop-start-re)) | |
1637 (ada-search-ignore-string-comment ada-loop-start-re | |
1638 nil pos)) | |
1639 (if (looking-at "\\<loop\\>") | |
1640 prev-indent | |
1641 (+ (current-indentation) ada-stmt-end-indent)))))) | |
1642 ;; | |
1643 ;; begin | |
1644 ;; | |
1645 ((looking-at "\\<begin\\>") | |
1646 (save-excursion | |
1647 (if (ada-goto-matching-decl-start t) | |
1648 (current-indentation) | |
1649 (progn | |
1650 (message "no matching declaration start") | |
1651 prev-indent)))) | |
1652 ;; | |
1653 ;; is | |
1654 ;; | |
1655 ((looking-at "\\<is\\>") | |
1656 (if (and | |
1657 ada-indent-is-separate | |
1658 (save-excursion | |
1659 (goto-char (match-end 0)) | |
1660 (ada-goto-next-non-ws (save-excursion | |
1661 (end-of-line) | |
1662 (point))) | |
1663 (looking-at "\\<abstract\\>\\|\\<separate\\>"))) | |
1664 (save-excursion | |
1665 (ada-goto-stmt-start) | |
1666 (+ (current-indentation) ada-indent)) | |
1667 (save-excursion | |
1668 (ada-goto-stmt-start) | |
1669 (+ (current-indentation) ada-stmt-end-indent)))) | |
1670 ;; | |
1671 ;; record | |
1672 ;; | |
1673 ((looking-at "\\<record\\>") | |
1674 (save-excursion | |
1675 (ada-search-ignore-string-comment | |
1676 "\\<\\(type\\|use\\)\\>" t nil) | |
1677 (if (looking-at "\\<use\\>") | |
1678 (ada-search-ignore-string-comment "\\<for\\>" t nil)) | |
1679 (+ (current-indentation) ada-indent-record-rel-type))) | |
1680 ;; | |
1681 ;; or as statement-start | |
1682 ;; | |
1683 ((ada-looking-at-semi-or) | |
1684 (save-excursion | |
1685 (ada-goto-matching-start 1) | |
1686 (current-indentation))) | |
1687 ;; | |
1688 ;; private as statement-start | |
1689 ;; | |
1690 ((ada-looking-at-semi-private) | |
1691 (save-excursion | |
1692 (ada-goto-matching-decl-start) | |
1693 (current-indentation))) | |
1694 ;; | |
1695 ;; new/abstract/separate | |
1696 ;; | |
1697 ((looking-at "\\<\\(new\\|abstract\\|separate\\)\\>") | |
1698 (- prev-indent ada-indent (- ada-broken-indent))) | |
1699 ;; | |
1700 ;; return | |
1701 ;; | |
1702 ((looking-at "\\<return\\>") | |
1703 (save-excursion | |
1704 (forward-sexp -1) | |
1705 (if (and (looking-at "(") | |
1706 (save-excursion | |
1707 (backward-sexp 2) | |
1708 (looking-at "\\<function\\>"))) | |
1709 (1+ (current-column)) | |
1710 prev-indent))) | |
1711 ;; | |
1712 ;; do | |
1713 ;; | |
1714 ((looking-at "\\<do\\>") | |
1715 (save-excursion | |
1716 (ada-goto-stmt-start) | |
1717 (+ (current-indentation) ada-stmt-end-indent))) | |
1718 ;; | |
1719 ;; package/function/procedure | |
1720 ;; | |
1721 ((and (looking-at "\\<\\(package\\|function\\|procedure\\)\\>") | |
1722 (save-excursion | |
1723 (forward-char 1) | |
1724 (ada-goto-stmt-start) | |
1725 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>"))) | |
1726 (save-excursion | |
1727 ;; look for 'generic' | |
1728 (if (and (ada-goto-matching-decl-start t) | |
1729 (looking-at "generic")) | |
1730 (current-column) | |
1731 prev-indent))) | |
1732 ;; | |
1733 ;; label | |
1734 ;; | |
1735 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*:[^=]") | |
1736 (if (ada-in-decl-p) | |
1737 prev-indent | |
1738 (+ prev-indent ada-label-indent))) | |
1739 ;; | |
1740 ;; identifier and other noindent-statements | |
1741 ;; | |
1742 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*") | |
1743 prev-indent) | |
1744 ;; | |
1745 ;; beginning of a parameter list | |
1746 ;; | |
1747 ((looking-at "(") | |
1748 prev-indent) | |
1749 ;; | |
1750 ;; end of a parameter list | |
1751 ;; | |
1752 ((looking-at ")") | |
1753 (save-excursion | |
1754 (forward-char 1) | |
1755 (backward-sexp 1) | |
1756 (current-column))) | |
1757 ;; | |
1758 ;; comment | |
1759 ;; | |
1760 ((looking-at "--") | |
1761 (if ada-indent-comment-as-code | |
1762 prev-indent | |
1763 (current-indentation))) | |
1764 ;; | |
1765 ;; unknown syntax - maybe this should signal an error ? | |
1766 ;; | |
1767 (t | |
1768 prev-indent)))) | |
1769 | |
1770 | |
1771 (defun ada-indent-function (&optional nomove) | |
1772 ;; Returns the function to calculate the indentation for the current | |
1773 ;; line according to the previous statement, ignoring the contents | |
1774 ;; of the current line after point. Moves point to the beginning of | |
1775 ;; the current statement, if NOMOVE is nil. | |
1776 | |
1777 (let ((orgpoint (point)) | |
1778 (func nil) | |
1779 (stmt-start nil)) | |
1780 ;; | |
1781 ;; inside a parameter-list | |
1782 ;; | |
1783 (if (ada-in-paramlist-p) | |
1784 (setq func 'ada-get-indent-paramlist) | |
1785 (progn | |
1786 ;; | |
1787 ;; move to beginning of current statement | |
1788 ;; | |
1789 (if (not nomove) | |
1790 (setq stmt-start (ada-goto-stmt-start))) | |
1791 ;; | |
1792 ;; no beginning found => don't change indentation | |
1793 ;; | |
1794 (if (and | |
1795 (eq orgpoint (point)) | |
1796 (not nomove)) | |
1797 (setq func 'ada-get-indent-nochange) | |
1798 | |
1799 (cond | |
1800 ;; | |
1801 ((and | |
1802 ada-indent-to-open-paren | |
1803 (ada-in-open-paren-p)) | |
1804 (setq func 'ada-get-indent-open-paren)) | |
1805 ;; | |
1806 ((looking-at "\\<end\\>") | |
1807 (setq func 'ada-get-indent-end)) | |
1808 ;; | |
1809 ((looking-at ada-loop-start-re) | |
1810 (setq func 'ada-get-indent-loop)) | |
1811 ;; | |
1812 ((looking-at ada-subprog-start-re) | |
1813 (setq func 'ada-get-indent-subprog)) | |
1814 ;; | |
1815 ((looking-at "\\<package\\>") | |
1816 (setq func 'ada-get-indent-subprog)) ; maybe it needs a | |
1817 ; special function | |
1818 ; sometimes ? | |
1819 ;; | |
1820 ((looking-at ada-block-start-re) | |
1821 (setq func 'ada-get-indent-block-start)) | |
1822 ;; | |
1823 ((looking-at "\\<type\\>") | |
1824 (setq func 'ada-get-indent-type)) | |
1825 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1826 ((looking-at "\\<\\(els\\)?if\\>") |
10705 | 1827 (setq func 'ada-get-indent-if)) |
1828 ;; | |
1829 ((looking-at "\\<case\\>") | |
1830 (setq func 'ada-get-indent-case)) | |
1831 ;; | |
1832 ((looking-at "\\<when\\>") | |
1833 (setq func 'ada-get-indent-when)) | |
1834 ;; | |
1835 ((looking-at "--") | |
1836 (setq func 'ada-get-indent-comment)) | |
1837 ;; | |
1838 ((looking-at "[a-zA-Z0-9_]+[ \t\n]*:[^=]") | |
1839 (setq func 'ada-get-indent-label)) | |
1840 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1841 ((looking-at "\\<separate\\>") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1842 (setq func 'ada-get-indent-nochange)) |
10705 | 1843 (t |
1844 (setq func 'ada-get-indent-noindent)))))) | |
1845 | |
1846 func)) | |
1847 | |
1848 | |
1849 ;; ---- functions to return indentation for special cases | |
1850 | |
1851 (defun ada-get-indent-open-paren (orgpoint) | |
1852 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
1853 ;; Assumes point to be behind an open paranthesis not yet closed. | |
1854 (ada-in-open-paren-p)) | |
1855 | |
1856 | |
1857 (defun ada-get-indent-nochange (orgpoint) | |
1858 ;; Returns the indentation (column #) of the current line. | |
1859 (save-excursion | |
1860 (forward-line -1) | |
1861 (current-indentation))) | |
1862 | |
1863 | |
1864 (defun ada-get-indent-paramlist (orgpoint) | |
1865 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
1866 ;; Assumes point to be inside a parameter-list. | |
1867 (save-excursion | |
1868 (ada-search-ignore-string-comment "[^ \t\n]" t nil t) | |
1869 (cond | |
1870 ;; | |
1871 ;; in front of the first parameter | |
1872 ;; | |
1873 ((looking-at "(") | |
1874 (goto-char (match-end 0)) | |
1875 (current-column)) | |
1876 ;; | |
1877 ;; in front of another parameter | |
1878 ;; | |
1879 ((looking-at ";") | |
1880 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t))) | |
1881 (ada-goto-next-non-ws) | |
1882 (current-column)) | |
1883 ;; | |
1884 ;; inside a parameter declaration | |
1885 ;; | |
1886 (t | |
1887 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t))) | |
1888 (ada-goto-next-non-ws) | |
1889 (+ (current-column) ada-broken-indent))))) | |
1890 | |
1891 | |
1892 (defun ada-get-indent-end (orgpoint) | |
1893 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
1894 ;; Assumes point to be at the beginning of an end-statement. | |
1895 ;; Therefore it has to find the corresponding start. This can be a little | |
1896 ;; slow, if it has to search through big files with many nested blocks. | |
1897 ;; Signals an error if the corresponding block-start doesn't match. | |
1898 (let ((defun-name nil) | |
1899 (indent nil)) | |
1900 ;; | |
1901 ;; is the line already terminated by ';' ? | |
1902 ;; | |
1903 (if (save-excursion | |
1904 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
1905 ;; | |
1906 ;; yes, look what's following 'end' | |
1907 ;; | |
1908 (progn | |
1909 (forward-word 1) | |
1910 (ada-goto-next-non-ws) | |
1911 (cond | |
1912 ;; | |
1913 ;; loop/select/if/case/record/select | |
1914 ;; | |
1915 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\|record\\)\\>") | |
1916 (save-excursion | |
1917 (ada-check-matching-start | |
1918 (buffer-substring (match-beginning 0) | |
1919 (match-end 0))) | |
1920 (if (looking-at "\\<\\(loop\\|record\\)\\>") | |
1921 (progn | |
1922 (forward-word 1) | |
1923 (ada-goto-stmt-start))) | |
1924 ;; a label ? => skip it | |
1925 (if (looking-at "[a-zA-Z0-9_]+[ \n\t]+:") | |
1926 (progn | |
1927 (goto-char (match-end 0)) | |
1928 (ada-goto-next-non-ws))) | |
1929 ;; really looking-at the right thing ? | |
1930 (or (looking-at (concat "\\<\\(" | |
1931 "loop\\|select\\|if\\|case\\|" | |
1932 "record\\|while\\|type\\)\\>")) | |
1933 (progn | |
1934 (ada-search-ignore-string-comment | |
1935 (concat "\\<\\(" | |
1936 "loop\\|select\\|if\\|case\\|" | |
1937 "record\\|while\\|type\\)\\>"))) | |
1938 (backward-word 1)) | |
1939 (current-indentation))) | |
1940 ;; | |
1941 ;; a named block end | |
1942 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
1943 ((looking-at ada-ident-re) |
10705 | 1944 (setq defun-name (buffer-substring (match-beginning 0) |
1945 (match-end 0))) | |
1946 (save-excursion | |
1947 (ada-goto-matching-start 0) | |
1948 (ada-check-defun-name defun-name) | |
1949 (current-indentation))) | |
1950 ;; | |
1951 ;; a block-end without name | |
1952 ;; | |
1953 ((looking-at ";") | |
1954 (save-excursion | |
1955 (ada-goto-matching-start 0) | |
1956 (if (looking-at "\\<begin\\>") | |
1957 (progn | |
1958 (setq indent (current-column)) | |
1959 (if (ada-goto-matching-decl-start t) | |
1960 (current-indentation) | |
1961 indent))))) | |
1962 ;; | |
1963 ;; anything else - should maybe signal an error ? | |
1964 ;; | |
1965 (t | |
1966 (+ (current-indentation) ada-broken-indent)))) | |
1967 | |
1968 (+ (current-indentation) ada-broken-indent)))) | |
1969 | |
1970 | |
1971 (defun ada-get-indent-case (orgpoint) | |
1972 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
1973 ;; Assumes point to be at the beginning of an case-statement. | |
1974 (let ((cur-indent (current-indentation)) | |
1975 (match-cons nil) | |
1976 (opos (point))) | |
1977 (cond | |
1978 ;; | |
1979 ;; case..is..when..=> | |
1980 ;; | |
1981 ((save-excursion | |
1982 (setq match-cons (ada-search-ignore-string-comment | |
1983 "[ \t\n]+=>" nil orgpoint))) | |
1984 (save-excursion | |
1985 (goto-char (car match-cons)) | |
1986 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos)) | |
1987 (error "missing 'when' between 'case' and '=>'")) | |
1988 (+ (current-indentation) ada-indent))) | |
1989 ;; | |
1990 ;; case..is..when | |
1991 ;; | |
1992 ((save-excursion | |
1993 (setq match-cons (ada-search-ignore-string-comment | |
1994 "\\<when\\>" nil orgpoint))) | |
1995 (goto-char (cdr match-cons)) | |
1996 (+ (current-indentation) ada-broken-indent)) | |
1997 ;; | |
1998 ;; case..is | |
1999 ;; | |
2000 ((save-excursion | |
2001 (setq match-cons (ada-search-ignore-string-comment | |
2002 "\\<is\\>" nil orgpoint))) | |
2003 (+ (current-indentation) ada-when-indent)) | |
2004 ;; | |
2005 ;; incomplete case | |
2006 ;; | |
2007 (t | |
2008 (+ (current-indentation) ada-broken-indent))))) | |
2009 | |
2010 | |
2011 (defun ada-get-indent-when (orgpoint) | |
2012 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2013 ;; Assumes point to be at the beginning of an when-statement. | |
2014 (let ((cur-indent (current-indentation))) | |
2015 (if (ada-search-ignore-string-comment | |
2016 "[ \t\n]+=>" nil orgpoint) | |
2017 (+ cur-indent ada-indent) | |
2018 (+ cur-indent ada-broken-indent)))) | |
2019 | |
2020 | |
2021 (defun ada-get-indent-if (orgpoint) | |
2022 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2023 ;; Assumes point to be at the beginning of an if-statement. | |
2024 (let ((cur-indent (current-indentation)) | |
2025 (match-cons nil)) | |
2026 ;; | |
2027 ;; if..then ? | |
2028 ;; | |
2029 (if (ada-search-but-not | |
2030 "\\<then\\>" "\\<and\\>[ \t\n]+\\<then\\>" nil orgpoint) | |
2031 | |
2032 (progn | |
2033 ;; | |
2034 ;; 'then' first in separate line ? | |
2035 ;; => indent according to 'then' | |
2036 ;; | |
2037 (if (save-excursion | |
2038 (back-to-indentation) | |
2039 (looking-at "\\<then\\>")) | |
2040 (setq cur-indent (current-indentation))) | |
2041 (forward-word 1) | |
2042 ;; | |
2043 ;; something follows 'then' ? | |
2044 ;; | |
2045 (if (setq match-cons | |
2046 (ada-search-ignore-string-comment | |
2047 "[^ \t\n]" nil orgpoint)) | |
2048 (progn | |
2049 (goto-char (car match-cons)) | |
2050 (+ ada-indent | |
2051 (- cur-indent (current-indentation)) | |
2052 (funcall (ada-indent-function t) orgpoint))) | |
2053 | |
2054 (+ cur-indent ada-indent))) | |
2055 | |
2056 (+ cur-indent ada-broken-indent)))) | |
2057 | |
2058 | |
2059 (defun ada-get-indent-block-start (orgpoint) | |
2060 ;; Returns the indentation (column #) for the new line after | |
2061 ;; ORGPOINT. Assumes point to be at the beginning of a block start | |
2062 ;; keyword. | |
2063 (let ((cur-indent (current-indentation)) | |
2064 (pos nil)) | |
2065 (cond | |
2066 ((save-excursion | |
2067 (forward-word 1) | |
2068 (setq pos (car (ada-search-ignore-string-comment | |
2069 "[^ \t\n]" nil orgpoint)))) | |
2070 (goto-char pos) | |
2071 (save-excursion | |
2072 (funcall (ada-indent-function t) orgpoint))) | |
2073 ;; | |
2074 ;; nothing follows the block-start | |
2075 ;; | |
2076 (t | |
2077 (+ (current-indentation) ada-indent))))) | |
2078 | |
2079 | |
2080 (defun ada-get-indent-subprog (orgpoint) | |
2081 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2082 ;; Assumes point to be at the beginning of a subprog-/package-declaration. | |
2083 (let ((match-cons nil) | |
2084 (cur-indent (current-indentation)) | |
2085 (foundis nil) | |
2086 (addind 0) | |
2087 (fstart (point))) | |
2088 ;; | |
2089 ;; is there an 'is' in front of point ? | |
2090 ;; | |
2091 (if (save-excursion | |
2092 (setq match-cons | |
2093 (ada-search-ignore-string-comment | |
2094 "\\<is\\>\\|\\<do\\>" nil orgpoint))) | |
2095 ;; | |
2096 ;; yes, then skip to its end | |
2097 ;; | |
2098 (progn | |
2099 (setq foundis t) | |
2100 (goto-char (cdr match-cons))) | |
2101 ;; | |
2102 ;; no, then goto next non-ws, if there is one in front of point | |
2103 ;; | |
2104 (progn | |
2105 (if (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint) | |
2106 (ada-goto-next-non-ws) | |
2107 (goto-char orgpoint)))) | |
2108 | |
2109 (cond | |
2110 ;; | |
2111 ;; nothing follows 'is' | |
2112 ;; | |
2113 ((and | |
2114 foundis | |
2115 (save-excursion | |
2116 (not (ada-search-ignore-string-comment | |
2117 "[^ \t\n]" nil orgpoint t)))) | |
2118 (+ cur-indent ada-indent)) | |
2119 ;; | |
2120 ;; is abstract/separate/new ... | |
2121 ;; | |
2122 ((and | |
2123 foundis | |
2124 (save-excursion | |
2125 (setq match-cons | |
2126 (ada-search-ignore-string-comment | |
2127 "\\<\\(separate\\|new\\|abstract\\)\\>" | |
2128 nil orgpoint)))) | |
2129 (goto-char (car match-cons)) | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2130 (ada-search-ignore-string-comment ada-subprog-start-re t) |
10705 | 2131 (ada-get-indent-noindent orgpoint)) |
2132 ;; | |
2133 ;; something follows 'is' | |
2134 ;; | |
2135 ((and | |
2136 foundis | |
2137 (save-excursion | |
2138 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)) | |
2139 (ada-goto-next-non-ws) | |
2140 (funcall (ada-indent-function t) orgpoint))) | |
2141 ;; | |
2142 ;; no 'is' but ';' | |
2143 ;; | |
2144 ((save-excursion | |
2145 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
2146 cur-indent) | |
2147 ;; | |
2148 ;; no 'is' or ';' | |
2149 ;; | |
2150 (t | |
2151 (+ cur-indent ada-broken-indent))))) | |
2152 | |
2153 | |
2154 (defun ada-get-indent-noindent (orgpoint) | |
2155 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2156 ;; Assumes point to be at the beginning of a 'noindent statement'. | |
2157 (if (save-excursion | |
2158 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
2159 (current-indentation) | |
2160 (+ (current-indentation) ada-broken-indent))) | |
2161 | |
2162 | |
2163 (defun ada-get-indent-label (orgpoint) | |
2164 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2165 ;; Assumes point to be at the beginning of a label or variable declaration. | |
2166 ;; Checks the context to decide if it's a label or a variable declaration. | |
2167 ;; This check might be a bit slow. | |
2168 (let ((match-cons nil) | |
2169 (cur-indent (current-indentation))) | |
2170 (goto-char (cdr (ada-search-ignore-string-comment ":"))) | |
2171 (cond | |
2172 ;; | |
2173 ;; loop label | |
2174 ;; | |
2175 ((save-excursion | |
2176 (setq match-cons (ada-search-ignore-string-comment | |
2177 ada-loop-start-re nil orgpoint))) | |
2178 (goto-char (car match-cons)) | |
2179 (ada-get-indent-loop orgpoint)) | |
2180 ;; | |
2181 ;; declare label | |
2182 ;; | |
2183 ((save-excursion | |
2184 (setq match-cons (ada-search-ignore-string-comment | |
2185 "\\<declare\\>" nil orgpoint))) | |
2186 (save-excursion | |
2187 (goto-char (car match-cons)) | |
2188 (+ (current-indentation) ada-indent))) | |
2189 ;; | |
2190 ;; complete statement following colon | |
2191 ;; | |
2192 ((save-excursion | |
2193 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
2194 (if (ada-in-decl-p) | |
2195 cur-indent ; variable-declaration | |
2196 (- cur-indent ada-label-indent))) ; label | |
2197 ;; | |
2198 ;; broken statement | |
2199 ;; | |
2200 ((save-excursion | |
2201 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)) | |
2202 (if (ada-in-decl-p) | |
2203 (+ cur-indent ada-broken-indent) | |
2204 (+ cur-indent ada-broken-indent (- ada-label-indent)))) | |
2205 ;; | |
2206 ;; nothing follows colon | |
2207 ;; | |
2208 (t | |
2209 (if (ada-in-decl-p) | |
2210 (+ cur-indent ada-broken-indent) ; variable-declaration | |
2211 (- cur-indent ada-label-indent)))))) ; label | |
2212 | |
2213 | |
2214 (defun ada-get-indent-loop (orgpoint) | |
2215 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2216 ;; Assumes point to be at the beginning of a loop statement | |
2217 ;; or (unfortunately) also a for ... use statement. | |
2218 (let ((match-cons nil) | |
2219 (pos (point))) | |
2220 (cond | |
2221 | |
2222 ;; | |
2223 ;; statement complete | |
2224 ;; | |
2225 ((save-excursion | |
2226 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
2227 (current-indentation)) | |
2228 ;; | |
2229 ;; simple loop | |
2230 ;; | |
2231 ((looking-at "loop\\>") | |
2232 (ada-get-indent-block-start orgpoint)) | |
2233 | |
2234 ;; | |
2235 ;; 'for'- loop (or also a for ... use statement) | |
2236 ;; | |
2237 ((looking-at "for\\>") | |
2238 (cond | |
2239 ;; | |
2240 ;; for ... use | |
2241 ;; | |
2242 ((save-excursion | |
2243 (and | |
2244 (goto-char (match-end 0)) | |
2245 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint) | |
2246 (not (backward-char 1)) | |
2247 (not (zerop (skip-chars-forward "_a-zA-Z0-9'"))) | |
2248 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint) | |
2249 (not (backward-char 1)) | |
2250 (looking-at "\\<use\\>") | |
2251 ;; | |
2252 ;; check if there is a 'record' before point | |
2253 ;; | |
2254 (progn | |
2255 (setq match-cons (ada-search-ignore-string-comment | |
2256 "\\<record\\>" nil orgpoint)) | |
2257 t))) | |
2258 (if match-cons | |
2259 (goto-char (car match-cons))) | |
2260 (+ (current-indentation) ada-indent)) | |
2261 ;; | |
2262 ;; for..loop | |
2263 ;; | |
2264 ((save-excursion | |
2265 (setq match-cons (ada-search-ignore-string-comment | |
2266 "\\<loop\\>" nil orgpoint))) | |
2267 (goto-char (car match-cons)) | |
2268 ;; | |
2269 ;; indent according to 'loop', if it's first in the line; | |
2270 ;; otherwise to 'for' | |
2271 ;; | |
2272 (if (not (save-excursion | |
2273 (back-to-indentation) | |
2274 (looking-at "\\<loop\\>"))) | |
2275 (goto-char pos)) | |
2276 (+ (current-indentation) ada-indent)) | |
2277 ;; | |
2278 ;; for-statement is broken | |
2279 ;; | |
2280 (t | |
2281 (+ (current-indentation) ada-broken-indent)))) | |
2282 | |
2283 ;; | |
2284 ;; 'while'-loop | |
2285 ;; | |
2286 ((looking-at "while\\>") | |
2287 ;; | |
2288 ;; while..loop ? | |
2289 ;; | |
2290 (if (save-excursion | |
2291 (setq match-cons (ada-search-ignore-string-comment | |
2292 "\\<loop\\>" nil orgpoint))) | |
2293 | |
2294 (progn | |
2295 (goto-char (car match-cons)) | |
2296 ;; | |
2297 ;; indent according to 'loop', if it's first in the line; | |
2298 ;; otherwise to 'while'. | |
2299 ;; | |
2300 (if (not (save-excursion | |
2301 (back-to-indentation) | |
2302 (looking-at "\\<loop\\>"))) | |
2303 (goto-char pos)) | |
2304 (+ (current-indentation) ada-indent)) | |
2305 | |
2306 (+ (current-indentation) ada-broken-indent)))))) | |
2307 | |
2308 | |
2309 (defun ada-get-indent-type (orgpoint) | |
2310 ;; Returns the indentation (column #) for the new line after ORGPOINT. | |
2311 ;; Assumes point to be at the beginning of a type statement. | |
2312 (let ((match-dat nil)) | |
2313 (cond | |
2314 ;; | |
2315 ;; complete record declaration | |
2316 ;; | |
2317 ((save-excursion | |
2318 (and | |
2319 (setq match-dat (ada-search-ignore-string-comment "\\<end\\>" | |
2320 nil | |
2321 orgpoint)) | |
2322 (ada-goto-next-non-ws) | |
2323 (looking-at "\\<record\\>") | |
2324 (forward-word 1) | |
2325 (ada-goto-next-non-ws) | |
2326 (looking-at ";"))) | |
2327 (goto-char (car match-dat)) | |
2328 (current-indentation)) | |
2329 ;; | |
2330 ;; record type | |
2331 ;; | |
2332 ((save-excursion | |
2333 (setq match-dat (ada-search-ignore-string-comment "\\<record\\>" | |
2334 nil | |
2335 orgpoint))) | |
2336 (goto-char (car match-dat)) | |
2337 (+ (current-indentation) ada-indent)) | |
2338 ;; | |
2339 ;; complete type declaration | |
2340 ;; | |
2341 ((save-excursion | |
2342 (ada-search-ignore-string-comment ";" nil orgpoint)) | |
2343 (current-indentation)) | |
2344 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2345 ;; "type ... is", but not "type ... is ...", which is broken |
10705 | 2346 ;; |
2347 ((save-excursion | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2348 (and |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2349 (ada-search-ignore-string-comment "\\<is\\>" nil orgpoint) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2350 (not (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)))) |
10705 | 2351 (+ (current-indentation) ada-indent)) |
2352 ;; | |
2353 ;; broken statement | |
2354 ;; | |
2355 (t | |
2356 (+ (current-indentation) ada-broken-indent))))) | |
2357 | |
2358 | |
2359 ;;; ---- support-functions for indentation | |
2360 | |
2361 ;;; ---- searching and matching | |
2362 | |
2363 (defun ada-goto-stmt-start (&optional limit) | |
2364 ;; Moves point to the beginning of the statement that point is in or | |
2365 ;; after. Returns the new position of point. Beginnings are found | |
2366 ;; by searching for 'ada-end-stmt-re' and then moving to the | |
2367 ;; following non-ws that is not a comment. LIMIT is actually not | |
2368 ;; used by the indentation functions. | |
2369 (let ((match-dat nil) | |
2370 (orgpoint (point))) | |
2371 | |
2372 (setq match-dat (ada-search-prev-end-stmt limit)) | |
2373 (if match-dat | |
2374 ;; | |
2375 ;; found a previous end-statement => check if anything follows | |
2376 ;; | |
2377 (progn | |
2378 (if (not | |
2379 (save-excursion | |
2380 (goto-char (cdr match-dat)) | |
2381 (ada-search-ignore-string-comment | |
2382 "[^ \t\n]" nil orgpoint))) | |
2383 ;; | |
2384 ;; nothing follows => it's the end-statement directly in | |
2385 ;; front of point => search again | |
2386 ;; | |
2387 (setq match-dat (ada-search-prev-end-stmt limit))) | |
2388 ;; | |
2389 ;; if found the correct end-stetement => goto next non-ws | |
2390 ;; | |
2391 (if match-dat | |
2392 (goto-char (cdr match-dat))) | |
2393 (ada-goto-next-non-ws)) | |
2394 | |
2395 ;; | |
2396 ;; no previous end-statement => we are at the beginning of the | |
2397 ;; accessible part of the buffer | |
2398 ;; | |
2399 (progn | |
2400 (goto-char (point-min)) | |
2401 ;; | |
2402 ;; skip to the very first statement, if there is one | |
2403 ;; | |
2404 (if (setq match-dat | |
2405 (ada-search-ignore-string-comment | |
2406 "[^ \t\n]" nil orgpoint)) | |
2407 (goto-char (car match-dat)) | |
2408 (goto-char orgpoint)))) | |
2409 | |
2410 | |
2411 (point))) | |
2412 | |
2413 | |
2414 (defun ada-search-prev-end-stmt (&optional limit) | |
2415 ;; Moves point to previous end-statement. Returns a cons cell whose | |
2416 ;; car is the beginning and whose cdr the end of the match. | |
2417 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for | |
2418 ;; certain keywords if they follow 'end', which means they are no | |
2419 ;; end-statement there. | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2420 (interactive) ;; DEBUG |
10705 | 2421 (let ((match-dat nil) |
2422 (pos nil) | |
2423 (found nil)) | |
2424 ;; | |
2425 ;; search until found or beginning-of-buffer | |
2426 ;; | |
2427 (while | |
2428 (and | |
2429 (not found) | |
2430 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re | |
2431 t | |
2432 limit))) | |
2433 | |
2434 (goto-char (car match-dat)) | |
2435 | |
2436 (if (not (ada-in-open-paren-p)) | |
2437 ;; | |
2438 ;; check if there is an 'end' in front of the match | |
2439 ;; | |
2440 (if (not (and | |
2441 (looking-at "\\<\\(record\\|loop\\|select\\)\\>") | |
2442 (save-excursion | |
2443 (ada-goto-previous-word) | |
2444 (looking-at "\\<end\\>")))) | |
2445 (setq found t) | |
2446 | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2447 (forward-word -1)))) ; end of loop |
10705 | 2448 |
2449 (if found | |
2450 match-dat | |
2451 nil))) | |
2452 | |
2453 | |
2454 (defun ada-goto-next-non-ws (&optional limit) | |
2455 ;; Skips whitespaces, newlines and comments to next non-ws | |
2456 ;; character. Signals an error if there is no more such character | |
2457 ;; and limit is nil. | |
2458 (let ((match-cons nil)) | |
2459 (setq match-cons (ada-search-ignore-string-comment | |
2460 "[^ \t\n]" nil limit t)) | |
2461 (if match-cons | |
2462 (goto-char (car match-cons)) | |
2463 (if (not limit) | |
2464 (error "no more non-ws") | |
2465 nil)))) | |
2466 | |
2467 | |
2468 (defun ada-goto-stmt-end (&optional limit) | |
2469 ;; Moves point to the end of the statement that point is in or | |
2470 ;; before. Returns the new position of point or nil if not found. | |
2471 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit) | |
2472 (point) | |
2473 nil)) | |
2474 | |
2475 | |
2476 (defun ada-goto-previous-word () | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2477 ;; Moves point to the beginning of the previous word of Ada code. |
10705 | 2478 ;; Returns the new position of point or nil if not found. |
2479 (let ((match-cons nil) | |
2480 (orgpoint (point))) | |
2481 (if (setq match-cons | |
2482 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)) | |
2483 ;; | |
2484 ;; move to the beginning of the word found | |
2485 ;; | |
2486 (progn | |
2487 (goto-char (cdr match-cons)) | |
2488 (skip-chars-backward "_a-zA-Z0-9") | |
2489 (point)) | |
2490 ;; | |
2491 ;; if not found, restore old position of point | |
2492 ;; | |
2493 (progn | |
2494 (goto-char orgpoint) | |
2495 'nil)))) | |
2496 | |
2497 | |
2498 (defun ada-check-matching-start (keyword) | |
2499 ;; Signals an error if matching block start is not KEYWORD. | |
2500 ;; Moves point to the matching block start. | |
2501 (ada-goto-matching-start 0) | |
2502 (if (not (looking-at (concat "\\<" keyword "\\>"))) | |
2503 (error (concat | |
2504 "matching start is not '" | |
2505 keyword "'")))) | |
2506 | |
2507 | |
2508 (defun ada-check-defun-name (defun-name) | |
2509 ;; Checks if the name of the matching defun really is DEFUN-NAME. | |
2510 ;; Assumes point to be already positioned by 'ada-goto-matching-start'. | |
2511 ;; Moves point to the beginning of the declaration. | |
2512 | |
2513 ;; | |
2514 ;; 'accept' or 'package' ? | |
2515 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2516 (if (not (looking-at "\\<\\(accept\\|package\\|task\\|protected\\)\\>")) |
10705 | 2517 (ada-goto-matching-decl-start)) |
2518 ;; | |
2519 ;; 'begin' of 'procedure'/'function'/'task' or 'declare' | |
2520 ;; | |
2521 (save-excursion | |
2522 ;; | |
2523 ;; a named 'declare'-block ? | |
2524 ;; | |
2525 (if (looking-at "\\<declare\\>") | |
2526 (ada-goto-stmt-start) | |
2527 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2528 ;; no, => 'procedure'/'function'/'task'/'protected' |
10705 | 2529 ;; |
2530 (progn | |
2531 (forward-word 2) | |
2532 (backward-word 1) | |
2533 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2534 ;; skip 'body' 'protected' 'type' |
10705 | 2535 ;; |
2536 (if (looking-at "\\<\\(body\\|type\\)\\>") | |
2537 (forward-word 1)) | |
2538 (forward-sexp 1) | |
2539 (backward-sexp 1))) | |
2540 ;; | |
2541 ;; should be looking-at the correct name | |
2542 ;; | |
2543 (if (not (looking-at (concat "\\<" defun-name "\\>"))) | |
2544 (error | |
2545 (concat | |
2546 "matching defun has different name: " | |
2547 (buffer-substring | |
2548 (point) | |
2549 (progn | |
2550 (forward-sexp 1) | |
2551 (point)))))))) | |
2552 | |
2553 | |
2554 (defun ada-goto-matching-decl-start (&optional noerror nogeneric) | |
2555 ;; Moves point to the matching declaration start of the current 'begin'. | |
2556 ;; If NOERROR is non-nil, it only returns nil if no match was found. | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2557 (interactive) ;; DEBUG |
10705 | 2558 (let ((nest-count 1) |
2559 (pos nil) | |
2560 (first t) | |
2561 (flag nil)) | |
2562 ;; | |
2563 ;; search backward for interesting keywords | |
2564 ;; | |
2565 (while (and | |
2566 (not (zerop nest-count)) | |
2567 (ada-search-ignore-string-comment | |
2568 (concat "\\<\\(" | |
2569 "is\\|separate\\|end\\|declare\\|new\\|begin\\|generic" | |
2570 "\\)\\>") t)) | |
2571 ;; | |
2572 ;; calculate nest-depth | |
2573 ;; | |
2574 (cond | |
2575 ;; | |
2576 ((looking-at "end") | |
2577 (ada-goto-matching-start 1 noerror) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2578 (if (looking-at "begin") |
10705 | 2579 (setq nest-count (1+ nest-count)))) |
2580 ;; | |
2581 ((looking-at "declare\\|generic") | |
2582 (setq nest-count (1- nest-count)) | |
2583 (setq first nil)) | |
2584 ;; | |
2585 ((looking-at "is") | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2586 ;; check if it is only a type definition, but not a protected |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2587 ;; type definition, which should be handled like a procedure. |
10705 | 2588 (if (save-excursion |
2589 (ada-goto-previous-word) | |
2590 (skip-chars-backward "a-zA-Z0-9_.'") | |
2591 (if (save-excursion | |
2592 (backward-char 1) | |
2593 (looking-at ")")) | |
2594 (progn | |
2595 (forward-char 1) | |
2596 (backward-sexp 1) | |
2597 (skip-chars-backward "a-zA-Z0-9_.'") | |
2598 )) | |
2599 (ada-goto-previous-word) | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2600 (and |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2601 (looking-at "\\<type\\>") |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2602 (save-match-data |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2603 (ada-goto-previous-word) |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2604 (not (looking-at "\\<protected\\>")))) |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2605 ); end of save-excursion |
10705 | 2606 (goto-char (match-beginning 0)) |
2607 (progn | |
2608 (setq nest-count (1- nest-count)) | |
2609 (setq first nil)))) | |
2610 | |
2611 ;; | |
2612 ((looking-at "new") | |
2613 (if (save-excursion | |
2614 (ada-goto-previous-word) | |
2615 (looking-at "is")) | |
2616 (goto-char (match-beginning 0)))) | |
2617 ;; | |
2618 ((and first | |
2619 (looking-at "begin")) | |
2620 (setq nest-count 0) | |
2621 (setq flag t)) | |
2622 ;; | |
2623 (t | |
2624 (setq nest-count (1+ nest-count)) | |
2625 (setq first nil))) | |
2626 | |
2627 ) ;; end of loop | |
2628 | |
2629 ;; check if declaration-start is really found | |
2630 (if (not | |
2631 (and | |
2632 (zerop nest-count) | |
2633 (not flag) | |
2634 (progn | |
2635 (if (looking-at "is") | |
2636 (ada-search-ignore-string-comment | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2637 ada-subprog-start-re t) |
10705 | 2638 (looking-at "declare\\|generic"))))) |
2639 (if noerror nil | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
2640 (error "no matching proc/func/task/declare/package/protected")) |
10705 | 2641 t))) |
2642 | |
2643 | |
2644 (defun ada-goto-matching-start (&optional nest-level noerror gotothen) | |
2645 ;; Moves point to the beginning of a block-start. Which block | |
2646 ;; depends on the value of NEST-LEVEL, which defaults to zero. If | |
2647 ;; NOERROR is non-nil, it only returns nil if no matching start was | |
2648 ;; found. If GOTOTHEN is non-nil, point moves to the 'then' | |
2649 ;; following 'if'. | |
2650 (let ((nest-count (if nest-level nest-level 0)) | |
2651 (found nil) | |
2652 (pos nil)) | |
2653 | |
2654 ;; | |
2655 ;; search backward for interesting keywords | |
2656 ;; | |
2657 (while (and | |
2658 (not found) | |
2659 (ada-search-ignore-string-comment | |
2660 (concat "\\<\\(" | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2661 "end\\|loop\\|select\\|begin\\|case\\|do\\|" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2662 "if\\|task\\|package\\|record\\|protected\\)\\>") |
10705 | 2663 t)) |
2664 | |
2665 ;; | |
2666 ;; calculate nest-depth | |
2667 ;; | |
2668 (cond | |
2669 ;; found block end => increase nest depth | |
2670 ((looking-at "end") | |
2671 (setq nest-count (1+ nest-count))) | |
2672 ;; found loop/select/record/case/if => check if it starts or | |
2673 ;; ends a block | |
2674 ((looking-at "loop\\|select\\|record\\|case\\|if") | |
2675 (setq pos (point)) | |
2676 (save-excursion | |
2677 ;; | |
2678 ;; check if keyword follows 'end' | |
2679 ;; | |
2680 (ada-goto-previous-word) | |
2681 (if (looking-at "\\<end\\>") | |
2682 ;; it ends a block => increase nest depth | |
2683 (progn | |
2684 (setq nest-count (1+ nest-count)) | |
2685 (setq pos (point))) | |
2686 ;; it starts a block => decrease nest depth | |
2687 (setq nest-count (1- nest-count)))) | |
2688 (goto-char pos)) | |
2689 ;; found package start => check if it really is a block | |
2690 ((looking-at "package") | |
2691 (save-excursion | |
2692 (ada-search-ignore-string-comment "\\<is\\>") | |
2693 (ada-goto-next-non-ws) | |
2694 ;; ignore it if it is only a declaration with 'new' | |
2695 (if (not (looking-at "\\<new\\>")) | |
2696 (setq nest-count (1- nest-count))))) | |
2697 ;; found task start => check if it has a body | |
2698 ((looking-at "task") | |
2699 (save-excursion | |
2700 (forward-word 1) | |
2701 (ada-goto-next-non-ws) | |
2702 ;; ignore it if it has no body | |
2703 (if (not (looking-at "\\<body\\>")) | |
2704 (setq nest-count (1- nest-count))))) | |
2705 ;; all the other block starts | |
2706 (t | |
2707 (setq nest-count (1- nest-count)))) ; end of 'cond' | |
2708 | |
2709 ;; match is found, if nest-depth is zero | |
2710 ;; | |
2711 (setq found (zerop nest-count))) ; end of loop | |
2712 | |
2713 (if found | |
2714 ;; | |
2715 ;; match found => is there anything else to do ? | |
2716 ;; | |
2717 (progn | |
2718 (cond | |
2719 ;; | |
2720 ;; found 'if' => skip to 'then', if it's on a separate line | |
2721 ;; and GOTOTHEN is non-nil | |
2722 ;; | |
2723 ((and | |
2724 gotothen | |
2725 (looking-at "if") | |
2726 (save-excursion | |
2727 (ada-search-ignore-string-comment "\\<then\\>" nil nil) | |
2728 (back-to-indentation) | |
2729 (looking-at "\\<then\\>"))) | |
2730 (goto-char (match-beginning 0))) | |
2731 ;; | |
2732 ;; found 'do' => skip back to 'accept' | |
2733 ;; | |
2734 ((looking-at "do") | |
2735 (if (not (ada-search-ignore-string-comment "\\<accept\\>" t nil)) | |
2736 (error "missing 'accept' in front of 'do'")))) | |
2737 (point)) | |
2738 | |
2739 (if noerror | |
2740 nil | |
2741 (error "no matching start"))))) | |
2742 | |
2743 | |
2744 (defun ada-goto-matching-end (&optional nest-level noerror) | |
2745 ;; Moves point to the end of a block. Which block depends on the | |
2746 ;; value of NEST-LEVEL, which defaults to zero. If NOERROR is | |
2747 ;; non-nil, it only returns nil if found no matching start. | |
2748 (let ((nest-count (if nest-level nest-level 0)) | |
2749 (found nil)) | |
2750 | |
2751 ;; | |
2752 ;; search forward for interesting keywords | |
2753 ;; | |
2754 (while (and | |
2755 (not found) | |
2756 (ada-search-ignore-string-comment | |
2757 (concat "\\<\\(end\\|loop\\|select\\|begin\\|case\\|" | |
2758 "if\\|task\\|package\\|record\\|do\\)\\>"))) | |
2759 | |
2760 ;; | |
2761 ;; calculate nest-depth | |
2762 ;; | |
2763 (backward-word 1) | |
2764 (cond | |
2765 ;; found block end => decrease nest depth | |
2766 ((looking-at "\\<end\\>") | |
2767 (setq nest-count (1- nest-count)) | |
2768 ;; skip the following keyword | |
2769 (if (progn | |
2770 (skip-chars-forward "end") | |
2771 (ada-goto-next-non-ws) | |
2772 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>")) | |
2773 (forward-word 1))) | |
2774 ;; found package start => check if it really starts a block | |
2775 ((looking-at "\\<package\\>") | |
2776 (ada-search-ignore-string-comment "\\<is\\>") | |
2777 (ada-goto-next-non-ws) | |
2778 ;; ignore and skip it if it is only a 'new' package | |
2779 (if (not (looking-at "\\<new\\>")) | |
2780 (setq nest-count (1+ nest-count)) | |
2781 (skip-chars-forward "new"))) | |
2782 ;; all the other block starts | |
2783 (t | |
2784 (setq nest-count (1+ nest-count)) | |
2785 (forward-word 1))) ; end of 'cond' | |
2786 | |
2787 ;; match is found, if nest-depth is zero | |
2788 ;; | |
2789 (setq found (zerop nest-count))) ; end of loop | |
2790 | |
2791 (if (not found) | |
2792 (if noerror | |
2793 nil | |
2794 (error "no matching end")) | |
2795 t))) | |
2796 | |
2797 | |
2798 (defun ada-forward-sexp-ignore-comment () | |
2799 ;; Skips one sexp forward, ignoring comments. | |
2800 (while (looking-at "[ \t\n]*--") | |
2801 (skip-chars-forward "[ \t\n]") | |
2802 (end-of-line)) | |
2803 (forward-sexp 1)) | |
2804 | |
2805 | |
2806 (defun ada-search-ignore-string-comment | |
2807 (search-re &optional backward limit paramlists) | |
2808 ;; Regexp-Search for SEARCH-RE, ignoring comments, strings and | |
2809 ;; parameter lists, if PARAMLISTS is nil. Returns a cons cell of | |
2810 ;; begin and end of match data or nil, if not found. | |
2811 (let ((found nil) | |
2812 (begin nil) | |
2813 (end nil) | |
2814 (pos nil) | |
2815 (search-func | |
2816 (if backward 're-search-backward | |
2817 're-search-forward))) | |
2818 | |
2819 ;; | |
2820 ;; search until found or end-of-buffer | |
2821 ;; | |
2822 (while (and (not found) | |
2823 (funcall search-func search-re limit 1)) | |
2824 (setq begin (match-beginning 0)) | |
2825 (setq end (match-end 0)) | |
2826 | |
2827 (cond | |
2828 ;; | |
2829 ;; found in comment => skip it | |
2830 ;; | |
2831 ((ada-in-comment-p) | |
2832 (if backward | |
2833 (progn | |
2834 (re-search-backward "--" nil 1) | |
2835 (goto-char (match-beginning 0))) | |
2836 (progn | |
2837 (forward-line 1) | |
2838 (beginning-of-line)))) | |
2839 ;; | |
2840 ;; found in string => skip it | |
2841 ;; | |
2842 ((ada-in-string-p) | |
2843 (if backward | |
2844 (progn | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2845 (re-search-backward "\"" nil 1) ; "\"\\|#" don't treat # |
10705 | 2846 (goto-char (match-beginning 0)))) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2847 (re-search-forward "\"" nil 1)) |
10705 | 2848 ;; |
2849 ;; found character constant => ignore it | |
2850 ;; | |
2851 ((save-excursion | |
2852 (setq pos (- (point) (if backward 1 2))) | |
2853 (and (char-after pos) | |
2854 (= (char-after pos) ?') | |
2855 (= (char-after (+ pos 2)) ?'))) | |
2856 ()) | |
2857 ;; | |
2858 ;; found a parameter-list but should ignore it => skip it | |
2859 ;; | |
2860 ((and (not paramlists) | |
2861 (ada-in-paramlist-p)) | |
2862 (if backward | |
2863 (ada-search-ignore-string-comment "(" t nil t))) | |
2864 ;; | |
2865 ;; directly in front of a comment => skip it, if searching forward | |
2866 ;; | |
2867 ((save-excursion | |
2868 (goto-char begin) | |
2869 (looking-at "--")) | |
2870 (if (not backward) | |
2871 (progn | |
2872 (forward-line 1) | |
2873 (beginning-of-line)))) | |
2874 ;; | |
2875 ;; found what we were looking for | |
2876 ;; | |
2877 (t | |
2878 (setq found t)))) ; end of loop | |
2879 | |
2880 (if found | |
2881 (cons begin end) | |
2882 nil))) | |
2883 | |
2884 | |
2885 (defun ada-search-but-not (search-re not-search-re &optional backward limit) | |
2886 ;; Searches SEARCH-RE, ignoring parts of NOT-SEARCH-RE, strings, | |
2887 ;; comments and parameter-lists. | |
2888 (let ((begin nil) | |
2889 (end nil) | |
2890 (begin-not nil) | |
2891 (begin-end nil) | |
2892 (end-not nil) | |
2893 (ret-cons nil) | |
2894 (found nil)) | |
2895 | |
2896 ;; | |
2897 ;; search until found or end-of-buffer | |
2898 ;; | |
2899 (while (and | |
2900 (not found) | |
2901 (save-excursion | |
2902 (setq ret-cons | |
2903 (ada-search-ignore-string-comment search-re | |
2904 backward limit)) | |
2905 (if (consp ret-cons) | |
2906 (progn | |
2907 (setq begin (car ret-cons)) | |
2908 (setq end (cdr ret-cons)) | |
2909 t) | |
2910 nil))) | |
2911 | |
2912 (if (or | |
2913 ;; | |
2914 ;; if no NO-SEARCH-RE was found | |
2915 ;; | |
2916 (not | |
2917 (save-excursion | |
2918 (setq ret-cons | |
2919 (ada-search-ignore-string-comment not-search-re | |
2920 backward nil)) | |
2921 (if (consp ret-cons) | |
2922 (progn | |
2923 (setq begin-not (car ret-cons)) | |
2924 (setq end-not (cdr ret-cons)) | |
2925 t) | |
2926 nil))) | |
2927 ;; | |
2928 ;; or this NO-SEARCH-RE is not a part of the SEARCH-RE | |
2929 ;; found before. | |
2930 ;; | |
2931 (or | |
2932 (<= end-not begin) | |
2933 (>= begin-not end))) | |
2934 | |
2935 (setq found t) | |
2936 | |
2937 ;; | |
2938 ;; not found the correct match => skip this match | |
2939 ;; | |
2940 (goto-char (if backward | |
2941 begin | |
2942 end)))) ; end of loop | |
2943 | |
2944 (if found | |
2945 (progn | |
2946 (goto-char begin) | |
2947 (cons begin end)) | |
2948 nil))) | |
2949 | |
2950 | |
2951 (defun ada-goto-prev-nonblank-line ( &optional ignore-comment) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2952 ;; Moves point to the beginning of previous non-blank line, |
10705 | 2953 ;; ignoring comments if IGNORE-COMMENT is non-nil. |
2954 ;; It returns t if a matching line was found. | |
2955 (let ((notfound t) | |
2956 (newpoint nil)) | |
2957 | |
2958 (save-excursion | |
2959 ;; | |
2960 ;; backward one line, if there is one | |
2961 ;; | |
2962 (if (zerop (forward-line -1)) | |
2963 ;; | |
2964 ;; there is some kind of previous line | |
2965 ;; | |
2966 (progn | |
2967 (beginning-of-line) | |
2968 (setq newpoint (point)) | |
2969 | |
2970 ;; | |
2971 ;; search until found or beginning-of-buffer | |
2972 ;; | |
2973 (while (and (setq notfound | |
2974 (or (looking-at "[ \t]*$") | |
2975 (and (looking-at "[ \t]*--") | |
2976 ignore-comment))) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2977 (not (ada-in-limit-line-p))) |
10705 | 2978 (forward-line -1) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
2979 ;;(beginning-of-line) |
10705 | 2980 (setq newpoint (point))) ; end of loop |
2981 | |
2982 )) ; end of if | |
2983 | |
2984 ) ; end of save-excursion | |
2985 | |
2986 (if notfound nil | |
2987 (progn | |
2988 (goto-char newpoint) | |
2989 t)))) | |
2990 | |
2991 | |
2992 (defun ada-goto-next-nonblank-line ( &optional ignore-comment) | |
2993 ;; Moves point to next non-blank line, | |
2994 ;; ignoring comments if IGNORE-COMMENT is non-nil. | |
2995 ;; It returns t if a matching line was found. | |
2996 (let ((notfound t) | |
2997 (newpoint nil)) | |
2998 | |
2999 (save-excursion | |
3000 ;; | |
3001 ;; forward one line | |
3002 ;; | |
3003 (if (zerop (forward-line 1)) | |
3004 ;; | |
3005 ;; there is some kind of previous line | |
3006 ;; | |
3007 (progn | |
3008 (beginning-of-line) | |
3009 (setq newpoint (point)) | |
3010 | |
3011 ;; | |
3012 ;; search until found or end-of-buffer | |
3013 ;; | |
3014 (while (and (setq notfound | |
3015 (or (looking-at "[ \t]*$") | |
3016 (and (looking-at "[ \t]*--") | |
3017 ignore-comment))) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3018 (not (ada-in-limit-line-p))) |
10705 | 3019 (forward-line 1) |
3020 (beginning-of-line) | |
3021 (setq newpoint (point))) ; end of loop | |
3022 | |
3023 )) ; end of if | |
3024 | |
3025 ) ; end of save-excursion | |
3026 | |
3027 (if notfound nil | |
3028 (progn | |
3029 (goto-char newpoint) | |
3030 t)))) | |
3031 | |
3032 | |
3033 ;; ---- boolean functions for indentation | |
3034 | |
3035 (defun ada-in-decl-p () | |
3036 ;; Returns t if point is inside a declarative part. | |
3037 ;; Assumes point to be at the end of a statement. | |
3038 (or | |
3039 (ada-in-paramlist-p) | |
3040 (save-excursion | |
3041 (ada-goto-matching-decl-start t)))) | |
3042 | |
3043 | |
3044 (defun ada-looking-at-semi-or () | |
3045 ;; Returns t if looking-at an 'or' following a semicolon. | |
3046 (save-excursion | |
3047 (and (looking-at "\\<or\\>") | |
3048 (progn | |
3049 (forward-word 1) | |
3050 (ada-goto-stmt-start) | |
3051 (looking-at "\\<or\\>"))))) | |
3052 | |
3053 | |
3054 (defun ada-looking-at-semi-private () | |
3055 ;; Returns t if looking-at an 'private' following a semicolon. | |
3056 (save-excursion | |
3057 (and (looking-at "\\<private\\>") | |
3058 (progn | |
3059 (forward-word 1) | |
3060 (ada-goto-stmt-start) | |
3061 (looking-at "\\<private\\>"))))) | |
3062 | |
3063 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3064 ;;; make a faster??? ada-in-limit-line-p not using count-lines |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3065 (defun ada-in-limit-line-p () |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3066 ;; return t if point is in first or last accessible line. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3067 (or (save-excursion (beginning-of-line) (= (point-min) (point))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3068 (save-excursion (end-of-line) (= (point-max) (point))))) |
10705 | 3069 |
3070 | |
3071 (defun ada-in-comment-p () | |
3072 ;; Returns t if inside a comment. | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3073 ;; (save-excursion (and (re-search-backward "\\(--\\|\n\\)" nil 1) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3074 ;; (looking-at "-")))) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3075 (nth 4 (parse-partial-sexp |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3076 (save-excursion (beginning-of-line) (point)) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3077 (point)))) |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3078 |
10705 | 3079 |
3080 | |
3081 (defun ada-in-string-p () | |
3082 ;; Returns t if point is inside a string | |
3083 ;; (Taken from pascal-mode.el, modified by MH). | |
3084 (save-excursion | |
3085 (and | |
3086 (nth 3 (parse-partial-sexp | |
3087 (save-excursion | |
3088 (beginning-of-line) | |
3089 (point)) (point))) | |
3090 ;; check if 'string quote' is only a character constant | |
3091 (progn | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3092 (re-search-backward "\"" nil t) ; # not a string delimiter anymore |
10705 | 3093 (not (= (char-after (1- (point))) ?')))))) |
3094 | |
3095 | |
3096 (defun ada-in-string-or-comment-p () | |
3097 ;; Returns t if point is inside a string or a comment. | |
3098 (or (ada-in-comment-p) | |
3099 (ada-in-string-p))) | |
3100 | |
3101 | |
3102 (defun ada-in-paramlist-p () | |
3103 ;; Returns t if point is inside a parameter-list | |
3104 ;; following 'function'/'procedure'/'package'. | |
3105 (save-excursion | |
3106 (and | |
3107 (re-search-backward "(\\|)" nil t) | |
3108 ;; inside parentheses ? | |
3109 (looking-at "(") | |
3110 (backward-word 2) | |
3111 ;; right keyword before paranthesis ? | |
3112 (looking-at (concat "\\<\\(" | |
3113 "procedure\\|function\\|body\\|package\\|" | |
3114 "task\\|entry\\|accept\\)\\>")) | |
3115 (re-search-forward ")\\|:" nil t) | |
3116 ;; at least one ':' inside the parentheses ? | |
3117 (not (backward-char 1)) | |
3118 (looking-at ":")))) | |
3119 | |
3120 | |
3121 ;; not really a boolean function ... | |
3122 (defun ada-in-open-paren-p () | |
3123 ;; If point is somewhere behind an open parenthesis not yet closed, | |
3124 ;; it returns the column # of the first non-ws behind this open | |
3125 ;; parenthesis, otherwise nil." | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3126 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3127 (let ((start (if (< (point) ada-search-paren-char-count-limit) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3128 1 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3129 (- (point) ada-search-paren-char-count-limit))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3130 parse-result |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3131 (col nil)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3132 (setq parse-result (parse-partial-sexp start (point))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3133 (if (nth 1 parse-result) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3134 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3135 (goto-char (1+ (nth 1 parse-result))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3136 (if (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3137 (re-search-forward "[^ \t]" nil 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3138 (backward-char 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3139 (and |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3140 (not (looking-at "\n")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3141 (setq col (current-column)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3142 col |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3143 (current-column))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3144 nil))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3145 |
10705 | 3146 |
3147 | |
3148 ;;;----------------------;;; | |
3149 ;;; Behaviour Of TAB Key ;;; | |
3150 ;;;----------------------;;; | |
3151 | |
3152 (defun ada-tab () | |
3153 "Do indenting or tabbing according to `ada-tab-policy'." | |
3154 (interactive) | |
3155 (cond ((eq ada-tab-policy 'indent-and-tab) (error "not implemented")) | |
3156 ;; ada-indent-and-tab | |
3157 ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard)) | |
3158 ((eq ada-tab-policy 'indent-auto) (ada-indent-current)) | |
3159 ((eq ada-tab-policy 'gei) (ada-tab-gei)) | |
3160 ((eq ada-tab-policy 'indent-af) (af-indent-line)) ; GEB | |
3161 ((eq ada-tab-policy 'always-tab) (error "not implemented")) | |
3162 )) | |
3163 | |
3164 | |
3165 (defun ada-untab (arg) | |
3166 "Delete leading indenting according to `ada-tab-policy'." | |
3167 (interactive "P") | |
3168 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard)) | |
3169 ((eq ada-tab-policy 'indent-af) (backward-delete-char-untabify ; GEB | |
3170 (prefix-numeric-value arg) ; GEB | |
3171 arg)) ; GEB | |
3172 ((eq ada-tab-policy 'indent-auto) (error "not implemented")) | |
3173 ((eq ada-tab-policy 'always-tab) (error "not implemented")) | |
3174 )) | |
3175 | |
3176 | |
3177 (defun ada-indent-current-function () | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3178 "Ada Mode version of the indent-line-function." |
10705 | 3179 (interactive "*") |
3180 (let ((starting-point (point-marker))) | |
3181 (ada-beginning-of-line) | |
3182 (ada-tab) | |
3183 (if (< (point) starting-point) | |
3184 (goto-char starting-point)) | |
3185 (set-marker starting-point nil) | |
3186 )) | |
3187 | |
3188 | |
3189 (defun ada-tab-hard () | |
3190 "Indent current line to next tab stop." | |
3191 (interactive) | |
3192 (save-excursion | |
3193 (beginning-of-line) | |
3194 (insert-char ? ada-indent)) | |
3195 (if (save-excursion (= (point) (progn (beginning-of-line) (point)))) | |
3196 (forward-char ada-indent))) | |
3197 | |
3198 | |
3199 (defun ada-untab-hard () | |
3200 "indent current line to previous tab stop." | |
3201 (interactive) | |
3202 (let ((bol (save-excursion (progn (beginning-of-line) (point)))) | |
3203 (eol (save-excursion (progn (end-of-line) (point))))) | |
3204 (indent-rigidly bol eol (- 0 ada-indent)))) | |
3205 | |
3206 | |
3207 | |
3208 ;;;---------------;;; | |
3209 ;;; Miscellaneous ;;; | |
3210 ;;;---------------;;; | |
3211 | |
3212 (defun ada-remove-trailing-spaces () | |
3213 "remove trailing spaces in the whole buffer." | |
3214 (interactive) | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3215 (save-match-data |
10705 | 3216 (save-excursion |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3217 (save-restriction |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3218 (widen) |
10705 | 3219 (goto-char (point-min)) |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3220 (while (re-search-forward "[ \t]+$" (point-max) t) |
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3221 (replace-match "" nil nil)))))) |
10705 | 3222 |
3223 | |
3224 (defun ada-untabify-buffer () | |
3225 ;; change all tabs to spaces | |
3226 (save-excursion | |
3227 (untabify (point-min) (point-max)))) | |
3228 | |
3229 | |
3230 (defun ada-uncomment-region (beg end) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3231 "delete `comment-start' at the beginning of a line in the region." |
10705 | 3232 (interactive "r") |
3233 (comment-region beg end -1)) | |
3234 | |
3235 | |
3236 ;; define a function to support find-file.el if loaded | |
3237 (defun ada-ff-other-window () | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3238 "Find other file in other window using `ff-find-other-file'." |
10705 | 3239 (interactive) |
3240 (and (fboundp 'ff-find-other-file) | |
3241 (ff-find-other-file t))) | |
3242 | |
3243 | |
3244 ;;;-------------------------------;;; | |
3245 ;;; Moving To Procedures/Packages ;;; | |
3246 ;;;-------------------------------;;; | |
3247 | |
3248 (defun ada-next-procedure () | |
3249 "Moves point to next procedure." | |
3250 (interactive) | |
3251 (end-of-line) | |
3252 (if (re-search-forward ada-procedure-start-regexp nil t) | |
3253 (goto-char (match-beginning 1)) | |
3254 (error "No more functions/procedures/tasks"))) | |
3255 | |
3256 (defun ada-previous-procedure () | |
3257 "Moves point to previous procedure." | |
3258 (interactive) | |
3259 (beginning-of-line) | |
3260 (if (re-search-backward ada-procedure-start-regexp nil t) | |
3261 (goto-char (match-beginning 1)) | |
3262 (error "No more functions/procedures/tasks"))) | |
3263 | |
3264 (defun ada-next-package () | |
3265 "Moves point to next package." | |
3266 (interactive) | |
3267 (end-of-line) | |
3268 (if (re-search-forward ada-package-start-regexp nil t) | |
3269 (goto-char (match-beginning 1)) | |
3270 (error "No more packages"))) | |
3271 | |
3272 (defun ada-previous-package () | |
3273 "Moves point to previous package." | |
3274 (interactive) | |
3275 (beginning-of-line) | |
3276 (if (re-search-backward ada-package-start-regexp nil t) | |
3277 (goto-char (match-beginning 1)) | |
3278 (error "No more packages"))) | |
3279 | |
3280 | |
3281 ;;;----------------------- | |
3282 ;;; define keymap for Ada | |
3283 ;;;----------------------- | |
3284 | |
3285 (if (not ada-mode-map) | |
3286 (progn | |
3287 (setq ada-mode-map (make-sparse-keymap)) | |
3288 | |
3289 ;; Indentation and Formatting | |
3290 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent) | |
3291 (define-key ada-mode-map "\t" 'ada-tab) | |
3292 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3293 (if (ada-xemacs) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3294 (define-key ada-mode-map '(shift tab) 'ada-untab) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3295 (define-key ada-mode-map [S-tab] 'ada-untab)) |
10705 | 3296 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist) |
3297 (define-key ada-mode-map "\C-c\C-p" 'ada-call-pretty-printer) | |
10707 | 3298 ;;; We don't want to make meta-characters case-specific. |
3299 ;;; (define-key ada-mode-map "\M-Q" 'ada-fill-comment-paragraph-justify) | |
10705 | 3300 (define-key ada-mode-map "\M-\C-q" 'ada-fill-comment-paragraph-postfix) |
3301 | |
3302 ;; Movement | |
10707 | 3303 ;;; It isn't good to redefine these. What should be done instead? -- rms. |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3304 ;;; (define-key ada-mode-map "\M-e" 'ada-next-package) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3305 ;;; (define-key ada-mode-map "\M-a" 'ada-previous-package) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3306 (define-key ada-mode-map "\M-\C-e" 'ada-next-procedure) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3307 (define-key ada-mode-map "\M-\C-a" 'ada-previous-procedure) |
10705 | 3308 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start) |
3309 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end) | |
3310 | |
3311 ;; Compilation | |
3312 (define-key ada-mode-map "\C-c\C-c" 'compile) | |
3313 | |
3314 ;; Casing | |
3315 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region) | |
3316 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer) | |
3317 | |
3318 (define-key ada-mode-map "\177" 'backward-delete-char-untabify) | |
3319 | |
3320 ;; Use predefined function of emacs19 for comments (RE) | |
3321 (define-key ada-mode-map "\C-c;" 'comment-region) | |
3322 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region) | |
3323 | |
3324 ;; Change basic functionality | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3325 |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3326 ;; `substitute-key-definition' is not defined equally in GNU Emacs |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3327 ;; and XEmacs, you cannot put in an optional 4th parameter in |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3328 ;; XEmacs. I don't think it's necessary, so I leave it out for |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3329 ;; GNU Emacs as well. If you encounter any problems with the |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3330 ;; following three functions, please tell me. RE |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3331 (mapcar (function (lambda (pair) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3332 (substitute-key-definition (car pair) (cdr pair) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3333 ada-mode-map))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3334 '((beginning-of-line . ada-beginning-of-line) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3335 (end-of-line . ada-end-of-line) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3336 (forward-to-indentation . ada-forward-to-indentation) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3337 )) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3338 ;; else GNU Emacs |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3339 ;;(mapcar (lambda (pair) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3340 ;; (substitute-key-definition (car pair) (cdr pair) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3341 ;; ada-mode-map global-map)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3342 |
10705 | 3343 )) |
3344 | |
3345 | |
3346 ;;;------------------- | |
3347 ;;; define menu 'Ada' | |
3348 ;;;------------------- | |
3349 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3350 (require 'easymenu) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3351 |
10705 | 3352 (defun ada-add-ada-menu () |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3353 "Adds the menu 'Ada' to the menu bar in Ada Mode." |
11869
ab2739454f2a
(ada-add-ada-menu): Fix args to easy-menu-define.
Karl Heuer <kwzh@gnu.org>
parents:
11231
diff
changeset
|
3354 (easy-menu-define ada-mode-menu ada-mode-map "Menu keymap for Ada mode." |
10705 | 3355 '("Ada" |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3356 ["Next Package" ada-next-package t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3357 ["Previous Package" ada-previous-package t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3358 ["Next Procedure" ada-next-procedure t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3359 ["Previous Procedure" ada-previous-procedure t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3360 ["Goto Start" ada-move-to-start t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3361 ["Goto End" ada-move-to-end t] |
10705 | 3362 ["------------------" nil nil] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3363 ["Indent Current Line (TAB)" |
10705 | 3364 ada-indent-current-function t] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3365 ["Indent Lines in Region" ada-indent-region t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3366 ["Format Parameter List" ada-format-paramlist t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3367 ["Pretty Print Buffer" ada-call-pretty-printer t] |
10705 | 3368 ["------------" nil nil] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3369 ["Fill Comment Paragraph" |
10705 | 3370 ada-fill-comment-paragraph t] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3371 ["Justify Comment Paragraph" |
10705 | 3372 ada-fill-comment-paragraph-justify t] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3373 ["Postfix Comment Paragraph" |
10705 | 3374 ada-fill-comment-paragraph-postfix t] |
3375 ["------------" nil nil] | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3376 ["Adjust Case Region" ada-adjust-case-region t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3377 ["Adjust Case Buffer" ada-adjust-case-buffer t] |
10705 | 3378 ["----------" nil nil] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3379 ["Comment Region" comment-region t] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3380 ["Uncomment Region" ada-uncomment-region t] |
10705 | 3381 ["----------------" nil nil] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3382 ["Compile" compile (fboundp 'compile)] |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3383 ["Next Error" next-error (fboundp 'next-error)] |
10705 | 3384 ["---------------" nil nil] |
3385 ["Index" imenu (fboundp 'imenu)] | |
3386 ["--------------" nil nil] | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3387 ["Other File Other Window" ada-ff-other-window |
10705 | 3388 (fboundp 'ff-find-other-file)] |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3389 ["Other File" ff-find-other-file |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3390 (fboundp 'ff-find-other-file)])) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3391 (if (ada-xemacs) (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3392 (easy-menu-add ada-mode-menu) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3393 (setq mode-popup-menu (cons "Ada Mode" ada-mode-menu))))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3394 |
10705 | 3395 |
3396 | |
3397 ;;;------------------------------- | |
3398 ;;; Define Some Support Functions | |
3399 ;;;------------------------------- | |
3400 | |
3401 (defun ada-beginning-of-line (&optional arg) | |
3402 (interactive "P") | |
3403 (cond | |
3404 ((eq ada-tab-policy 'indent-af) (af-beginning-of-line arg)) | |
3405 (t (beginning-of-line arg)) | |
3406 )) | |
3407 | |
3408 (defun ada-end-of-line (&optional arg) | |
3409 (interactive "P") | |
3410 (cond | |
3411 ((eq ada-tab-policy 'indent-af) (af-end-of-line arg)) | |
3412 (t (end-of-line arg)) | |
3413 )) | |
3414 | |
3415 (defun ada-current-column () | |
3416 (cond | |
3417 ((eq ada-tab-policy 'indent-af) (af-current-column)) | |
3418 (t (current-column)) | |
3419 )) | |
3420 | |
3421 (defun ada-forward-to-indentation (&optional arg) | |
3422 (interactive "P") | |
3423 (cond | |
3424 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg)) | |
3425 (t (forward-to-indentation arg)) | |
3426 )) | |
3427 | |
3428 ;;;--------------------------------------------------- | |
3429 ;;; support for find-file | |
3430 ;;;--------------------------------------------------- | |
3431 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3432 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3433 ;;;###autoload |
10705 | 3434 (defun ada-make-filename-from-adaname (adaname) |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3435 "Determine the filename of a package/procedure from its own Ada name." |
10705 | 3436 ;; this is done simply by calling gkrunch, when we work with GNAT. It |
3437 ;; must be a more complex function in other compiler environments. | |
3438 (interactive "s") | |
3439 | |
3440 ;; things that should really be done by the external process | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3441 ;; since gnat-2.0, gnatk8 can do these things. If you still use a |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3442 ;; previous version, just uncomment the following lines. |
10705 | 3443 (let (krunch-buf) |
3444 (setq krunch-buf (generate-new-buffer "*gkrunch*")) | |
3445 (save-excursion | |
3446 (set-buffer krunch-buf) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3447 ; (insert (downcase adaname)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3448 ; (goto-char (point-min)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3449 ; (while (search-forward "." nil t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3450 ; (replace-match "-" nil t)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3451 ; (setq adaname (buffer-substring (point-min) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3452 ; (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3453 ; (goto-char (point-min)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3454 ; (end-of-line) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3455 ; (point)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3456 ; ;; clean the buffer |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3457 ; (delete-region (point-min) (point-max)) |
10705 | 3458 ;; send adaname to external process "gnatk8" |
3459 (call-process "gnatk8" nil krunch-buf nil | |
3460 adaname ada-krunch-args) | |
3461 ;; fetch output of that process | |
3462 (setq adaname (buffer-substring | |
3463 (point-min) | |
3464 (progn | |
3465 (goto-char (point-min)) | |
3466 (end-of-line) | |
3467 (point)))) | |
3468 (kill-buffer krunch-buf))) | |
3469 (setq adaname adaname) ;; can I avoid this statement? | |
3470 ) | |
3471 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3472 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3473 ;;; functions for placing the cursor on the corresponding subprogram |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3474 (defun ada-which-function-are-we-in () |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3475 "Determine whether we are on a function definition/declaration. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3476 If that is the case remember the name of that function." |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3477 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3478 (setq ff-function-name nil) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3479 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3480 (save-excursion |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3481 (if (re-search-backward ada-procedure-start-regexp nil t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3482 (setq ff-function-name (buffer-substring (match-beginning 0) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3483 (match-end 0))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3484 ; we didn't find a procedure start, perhaps there is a package |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3485 (if (re-search-backward ada-package-start-regexp nil t) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3486 (setq ff-function-name (buffer-substring (match-beginning 0) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3487 (match-end 0))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3488 )))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3489 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3490 |
10705 | 3491 ;;;--------------------------------------------------- |
3492 ;;; support for imenu | |
3493 ;;;--------------------------------------------------- | |
3494 | |
3495 (defun imenu-create-ada-index (&optional regexp) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3496 "Create index alist for Ada files." |
10705 | 3497 (let ((index-alist '()) |
3498 prev-pos char) | |
3499 (goto-char (point-min)) | |
3500 ;(imenu-progress-message prev-pos 0) | |
3501 ;; Search for functions/procedures | |
3502 (save-match-data | |
3503 (while (re-search-forward | |
3504 (or regexp ada-procedure-start-regexp) | |
3505 nil t) | |
3506 ;(imenu-progress-message prev-pos) | |
3507 ;; do not store forward definitions | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3508 ;; right now we store them. We want to avoid them only in |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3509 ;; package bodies, not in the specs!! ???RE??? |
10705 | 3510 (save-match-data |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3511 ; (if (not (looking-at (concat |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3512 ; "[ \t\n]*" ; WS |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3513 ; "\([^)]+\)" ; parameterlist |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3514 ; "\\([ \n\t]+return[ \n\t]+"; potential return |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3515 ; "[a-zA-Z0-9_\\.]+\\)?" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3516 ; "[ \t]*" ; WS |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3517 ; ";" ;; THIS is what we really look for |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3518 ; ))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3519 ; ; (push (imenu-example--name-and-position) index-alist) |
10705 | 3520 (setq index-alist (cons (imenu-example--name-and-position) |
3521 index-alist)) | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3522 ; ) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3523 ) |
10705 | 3524 ;(imenu-progress-message 100) |
3525 )) | |
3526 (nreverse index-alist))) | |
3527 | |
3528 ;;;--------------------------------------------------- | |
3529 ;;; support for font-lock | |
3530 ;;;--------------------------------------------------- | |
3531 | |
3532 ;; Strings are a real pain in Ada because both ' and " can appear in a | |
3533 ;; non-string quote context (the former as an operator, the latter as | |
3534 ;; a character string). We follow the least losing solution, in which | |
3535 ;; only " is a string quote. Therefore a character string of the form | |
3536 ;; '"' will throw fontification off on the wrong track. | |
3537 | |
3538 (defconst ada-font-lock-keywords-1 | |
3539 (list | |
3540 ;; | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3541 ;; accept, entry, function, package (body), protected (body|type), |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3542 ;; pragma, procedure, task (body) plus name. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3543 (list (concat |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3544 "\\<\\(" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3545 "accept\\|" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3546 "entry\\|" |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3547 "function\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3548 "package[ \t]+body\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3549 "package\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3550 "pragma\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3551 "procedure\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3552 "protected[ \t]+body\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3553 "protected[ \t]+type\\|" |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3554 "protected\\|" |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3555 ;; "p\\(\\(ackage\\|rotected\\)\\(\\|[ \t]+\\(body\\|type\\)\\)\ |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3556 ;;\\|r\\(agma\\|ocedure\\)\\)\\|" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3557 "task\\|" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3558 "task[ \t]+body\\|" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3559 "task[ \t]+type" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3560 ;; "task\\(\\|[ \t]+body\\)" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3561 "\\)\\>[ \t]*" |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3562 "\\(\\sw+\\(\\.\\sw*\\)*\\)?") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3563 '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t))) |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3564 "Subdued level highlighting for Ada mode.") |
10705 | 3565 |
3566 (defconst ada-font-lock-keywords-2 | |
3567 (append ada-font-lock-keywords-1 | |
3568 (list | |
3569 ;; | |
3570 ;; Main keywords, except those treated specially below. | |
3571 (concat "\\<\\(" | |
3572 ; ("abort" "abs" "abstract" "accept" "access" "aliased" "all" | |
3573 ; "and" "array" "at" "begin" "case" "declare" "delay" "delta" | |
3574 ; "digits" "do" "else" "elsif" "entry" "exception" "exit" "for" | |
3575 ; "generic" "if" "in" "is" "limited" "loop" "mod" "not" | |
3576 ; "null" "or" "others" "private" "protected" | |
3577 ; "range" "record" "rem" "renames" "requeue" "return" "reverse" | |
3578 ; "select" "separate" "tagged" "task" "terminate" "then" "until" | |
3579 ; "while" "xor") | |
3580 "a\\(b\\(ort\\|s\\(\\|tract\\)\\)\\|cce\\(pt\\|ss\\)\\|" | |
3581 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|" | |
3582 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|" | |
3583 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|" | |
3584 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|" | |
3585 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|" | |
3586 "r\\(ange\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|" | |
3587 "se\\(lect\\|parate\\)\\|" | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3588 "t\\(agged\\|erminate\\|hen\\)\\|until\\|" ; task removed |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3589 "wh\\(ile\\|en\\)\\|xor" ; "when" added |
10705 | 3590 "\\)\\>") |
3591 ;; | |
3592 ;; Anything following end and not already fontified is a body name. | |
12586
f8bbc7a3b87a
(ada-ident-re): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12053
diff
changeset
|
3593 '("\\<\\(end\\)\\>[ \t]+\\([a-zA-Z0-9_\\.]+\\)?" |
10705 | 3594 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) |
3595 ;; | |
3596 ;; Variable name plus optional keywords followed by a type name. Slow. | |
3597 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*" | |
3598 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*" | |
3599 ; "\\(\\sw+\\)?") | |
3600 ; '(1 font-lock-variable-name-face) | |
3601 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t)) | |
3602 ;; | |
3603 ;; Optional keywords followed by a type name. | |
3604 (list (concat ; ":[ \t]*" | |
3605 "\\<\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)\\>" | |
3606 "[ \t]*" | |
3607 "\\(\\sw+\\)?") | |
3608 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t)) | |
3609 ;; | |
3610 ;; Keywords followed by a type or function name. | |
3611 (list (concat "\\<\\(" | |
3612 "new\\|of\\|subtype\\|type" | |
3613 "\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*\\((\\)?") | |
3614 '(1 font-lock-keyword-face) | |
3615 '(2 (if (match-beginning 4) | |
3616 font-lock-function-name-face | |
3617 font-lock-type-face) nil t)) | |
3618 ;; | |
3619 ;; Keywords followed by a (comma separated list of) reference. | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3620 (list (concat "\\<\\(goto\\|raise\\|use\\|with\\)\\>" ; "when" removed |
10705 | 3621 ; "[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?") ; RE |
3622 "[ \t]*\\([a-zA-Z0-9_\\.\\|, ]+\\)\\W") | |
3623 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) | |
3624 ;; | |
3625 ;; Goto tags. | |
3626 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face) | |
3627 )) | |
13231
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3628 "Gaudy level highlighting for Ada mode.") |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3629 |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3630 (defvar ada-font-lock-keywords ada-font-lock-keywords-2 |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3631 "Default Expressions to highlight in Ada mode. |
fb78cec8e440
All doc strings changed to comply with standard Emacs conventions.
Richard M. Stallman <rms@gnu.org>
parents:
13160
diff
changeset
|
3632 See the doc to `font-lock-maximum-decoration' for user configuration.") |
10705 | 3633 |
3634 ;;; | |
3635 ;;; ???? | |
3636 ;;; | |
3637 (defun ada-gen-comment-until-proc () | |
3638 ;; comment until spec of a procedure or a function. | |
3639 (forward-line 1) | |
3640 (set-mark-command (point)) | |
3641 (if (re-search-forward ada-procedure-start-regexp nil t) | |
3642 (progn (goto-char (match-beginning 1)) | |
3643 (comment-region (mark) (point))) | |
3644 (error "No more functions/procedures"))) | |
3645 | |
3646 | |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3647 (defun ada-gen-treat-proc (match) |
10705 | 3648 ;; make dummy body of a procedure/function specification. |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3649 ;; MATCH is a cons cell containing the start and end location of the |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3650 ;; last search for ada-procedure-start-regexp. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3651 (goto-char (car match)) |
13160
1b2a4a45f089
(ada-gen-treat-proc): Bind `procname' and `functype'.
Erik Naggum <erik@naggum.no>
parents:
12702
diff
changeset
|
3652 (let (proc-found func-found procname functype) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3653 (cond |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3654 ((or (setq proc-found (looking-at "^[ \t]*procedure")) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3655 (setq func-found (looking-at "^[ \t]*function"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3656 ;; treat it as a proc/func |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3657 (forward-word 2) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3658 (forward-word -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3659 (setq procname (buffer-substring (point) (cdr match))) ; store proc name |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3660 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3661 ;; goto end of procname |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3662 (goto-char (cdr match)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3663 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3664 ;; skip over parameterlist |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3665 (forward-sexp) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3666 ;; if function, skip over 'return' and result type. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3667 (if func-found |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3668 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3669 (forward-word 1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3670 (skip-chars-forward " \t\n") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3671 (setq functype (buffer-substring (point) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3672 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3673 (skip-chars-forward |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3674 "a-zA-Z0-9_\.") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3675 (point)))))) |
10705 | 3676 ;; look for next non WS |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3677 (cond |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3678 ((looking-at "[ \t]*;") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3679 (delete-region (match-beginning 0) (match-end 0)) ;; delete the ';' |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3680 (ada-indent-newline-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3681 (insert " is") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3682 (ada-indent-newline-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3683 (if func-found |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3684 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3685 (insert "Result : ") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3686 (insert functype) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3687 (insert ";") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3688 (ada-indent-newline-indent))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3689 (insert "begin -- ") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3690 (insert procname) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3691 (ada-indent-newline-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3692 (insert "null;") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3693 (ada-indent-newline-indent) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3694 (if func-found |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3695 (progn |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3696 (insert "return Result;") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3697 (ada-indent-newline-indent))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3698 (insert "end ") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3699 (insert procname) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3700 (insert ";") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3701 (ada-indent-newline-indent) |
10705 | 3702 ) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3703 ;; else |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3704 ((looking-at "[ \t\n]*is") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3705 ;; do nothing |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3706 ) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3707 ((looking-at "[ \t\n]*rename") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3708 ;; do nothing |
10705 | 3709 ) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3710 (t |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3711 (message "unknown syntax"))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3712 )))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3713 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3714 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3715 (defun ada-make-body () |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3716 "Create an Ada package body in the current buffer. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3717 The potential old buffer contents is deleted first, then we copy the |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3718 spec buffer in here and modify it to make it a body. |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3719 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3720 This function typically is to be hooked into `ff-file-created-hooks'." |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3721 (interactive) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3722 (delete-region (point-min) (point-max)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3723 (insert-buffer (car (cdr (buffer-list)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3724 (ada-mode) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3725 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3726 (let (found) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3727 (if (setq found |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3728 (ada-search-ignore-string-comment ada-package-start-regexp)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3729 (progn (goto-char (cdr found)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3730 (insert " body") |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3731 ;; (forward-line -1) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3732 ;;(comment-region (point-min) (point)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3733 ) |
10705 | 3734 (error "No package")) |
12039
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3735 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3736 ;; (comment-until-proc) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3737 ;; does not work correctly |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3738 ;; must be done by hand |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3739 |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3740 (while (setq found |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3741 (ada-search-ignore-string-comment ada-procedure-start-regexp)) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3742 (ada-gen-treat-proc found)))) |
a75524689022
(initial comments): Copyright 1995; don't speak
Karl Heuer <kwzh@gnu.org>
parents:
11869
diff
changeset
|
3743 |
10705 | 3744 |
3745 ;;; provide ourself | |
3746 | |
3747 (provide 'ada-mode) | |
3748 | |
10707 | 3749 ;;; ada-mode.el ends here |