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