annotate lisp/progmodes/ada-mode.el @ 11297:056c7266a614

(resize-minibuffer-window): Make sure minibuffer window is selected. (resize-minibuffer-window-restore): Likewise.
author Noah Friedman <friedman@splode.com>
date Sat, 08 Apr 1995 08:22:07 +0000
parents 3cf67df24e7f
children ab2739454f2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; ada-mode.el - An Emacs major-mode for editing Ada source.
11231
3cf67df24e7f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11199
diff changeset
2 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;;; Authors: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;;; Rolf Ebert <ebert@inf.enst.fr>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;;; This file is part of GNU Emacs.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; This mode is a complete rewrite of a major mode for editing Ada 83
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; and Ada 94 source code under Emacs-19. It contains completely new
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; indenting code and support for code browsing (see ada-xref).
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; USAGE
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; =====
11199
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
30 ;;; Emacs should enter ada-mode when you load an ada source (*.ada).
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; When you have entered ada-mode, you may get more info by pressing
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; C-h m. You may also get online help describing various functions by:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; C-h d <Name of function you want described>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; HISTORY
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; =======
11199
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
39 ;;; The first Ada mode for GNU Emacs was written by V. Broman in
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
40 ;;; 1985. He based his work on the already existing Modula-2 mode.
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
41 ;;; This was distributed as ada.el in versions of Emacs prior to 19.29.
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; Lynn Slater wrote an extensive Ada mode in 1989. It consisted of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; several files with support for dired commands and other nice
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; things. It is currently available from the PAL
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; (wuarchive.wustl.edu:/languages/ada) as ada-mode-1.06a.tar.Z.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; The probably very first Ada mode (called electric-ada.el) was
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; written by Steven D. Litvintchouk and Steven M. Rosen for the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; Gosling Emacs. L. Slater based his development on ada.el and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; electric-ada.el.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; The current Ada mode is a complete rewrite by M. Heritsch and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; R. Ebert. Some ideas from the ada-mode mailing list have been
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; added. Some of the functionality of L. Slater's mode has not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; (yet) been recoded in this new mode. Perhaps you prefer sticking
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; to his version.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; KNOWN BUGS / BUGREPORTS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; =======================
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; In the presence of comments and/or incorrect syntax
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;; ada-format-paramlist produces weird results.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;; Indentation is sometimes wrong at the very beginning of the buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;; So please try it on different locations. If it's still wrong then
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; report the bug.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; At the moment the browsing functions are limited to the use of the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; separate packages "find-file.el" and "ada-xref.el" (ada-xref.el is
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; only for GNAT users).
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; indenting of some tasking constructs is not yet supported.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;; `reformat-region' sometimes generates some weird indentation.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;;> I have the following suggestions for the function template: 1) I
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;;> don't want it automatically assigning it a name for the return variable. I
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;;> never want it to be called "Result" because that is nondescriptive. If you
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;;> must define a variable, give me the ability to specify its name.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;;>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;;> 2) You do not provide a type for variable 'Result'. Its type is the same
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;;> as the function's return type, which the template knows, so why force me
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;;> to type it in?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;;>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
11199
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
88 ;;;As always, different users have different tastes.
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;;It would be nice if one could configure such layout details separately
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;;without patching the LISP code. Maybe the metalanguage used in ada-stmt.el
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;;could be taken even further, providing the user with some nice syntax
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;;;for describing layout. Then my own hacks would survive the next
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;;update of the package :-)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
11199
394f205af26d Fix comments.
Karl Heuer <kwzh@gnu.org>
parents: 10880
diff changeset
95 ;;;By the way, there are some more quirks:
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;;1) text entered in prompt mode (*) is not converted to upper case (I have
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;; choosen upper case for indentifiers).
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;;; (*) I would like to suggest the term "template code" instead of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;;; "pseudo code".
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;;; There are quite a few problems in the crossreferencing part. These
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;; are partly due to errors in gnatf. One of the major bugs in
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;;; ada-xref is, that we do not wait for gnatf to rebuild the xref file.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;;; We start the job, but do not wait for finishing.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;;; LCD Archive Entry:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;; ada-mode|Rolf Ebert|<ebert@inf.enst.fr>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;;; |Major-mode for Ada
11231
3cf67df24e7f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11199
diff changeset
111 ;;; |$Date: 1995/04/04 03:00:59 $|$Revision: 1.4 $|
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
11231
3cf67df24e7f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11199
diff changeset
114 (defconst ada-mode-version (substring "$Revision: 1.4 $" 11 -2)
3cf67df24e7f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11199
diff changeset
115 "$Id: ada-mode.el,v 1.4 1995/04/04 03:00:59 kwzh Exp kwzh $
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 Report bugs to: Rolf Ebert <ebert@inf.enst.fr>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;;;--------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;;; USER OPTIONS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;;;--------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; ---- configure indentation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defvar ada-indent 3
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "*Defines the size of Ada indentation.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defvar ada-broken-indent 2
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 "*# of columns to indent the continuation of a broken line.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (defvar ada-label-indent -4
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 "*# of columns to indent a label.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (defvar ada-stmt-end-indent 0
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 "*# of columns to indent a statement end keyword in a separate line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 Examples are 'is', 'loop', 'record', ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defvar ada-when-indent 3
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "*Defines the indentation for 'when' relative to 'exception' or 'case'.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (defvar ada-indent-record-rel-type 3
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 "*Defines the indentation for 'record' relative to 'type' or 'use'.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (defvar ada-indent-comment-as-code t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 "*If non-nil, comment-lines get indented as ada-code.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defvar ada-indent-is-separate t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 "*If non-nil, 'is separate' or 'is abstract' on a separate line are
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 indented.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (defvar ada-indent-to-open-paren t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 "*If non-nil, following lines get indented according to the innermost
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 open parenthesis.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defvar ada-search-paren-line-count-limit 5
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 "*Search that many non-blank non-comment lines for an open parenthesis.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 Values higher than about 5 horribly slow down the indenting.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; ---- other user options
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (defvar ada-tab-policy 'indent-auto
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 "*Control behaviour of the TAB key.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 Must be one of 'indent-rigidly, 'indent-auto, 'gei, 'indent-af or 'always-tab.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 'indent-rigidly : always adds ada-indent blanks at the beginning of the line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 'indent-auto : use indentation functions in this file.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 'gei : use David K}gedal's Generic Indentation Engine.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 'indent-af : use Gary E. Barnes' ada-format.el
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 'always-tab : do indent-relative.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (defvar ada-move-to-declaration nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 "*If non-nil, ada-move-to-start moves point to the subprog-declaration,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 not to 'begin'.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (defvar ada-spec-suffix ".ads"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 "*Suffix of Ada specification files.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (defvar ada-body-suffix ".adb"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 "*Suffix of Ada body files.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (defvar ada-language-version 'ada94
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 "*Do we program in 'ada83 or 'ada94?")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defvar ada-case-keyword 'downcase-word
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 "*downcase-word, upcase-word, ada-loose-case-word or capitalize-word
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 to adjust ada keywords case.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (defvar ada-case-identifier 'ada-loose-case-word
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 "*downcase-word, upcase-word, ada-loose-case-word or capitalize-word
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 to adjust ada identifier case.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defvar ada-auto-case t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "*Non-nil automatically changes casing of preceeding word while typing.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 Casing is done according to ada-case-keyword and ada-case-identifier.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (defvar ada-clean-buffer-before-saving nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "*If non-nil, remove-trailing-spaces and untabify buffer before saving.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (defvar ada-mode-hook nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 "*List of functions to call when Ada Mode is invoked.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 This is a good place to add Ada environment specific bindings.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (defvar ada-external-pretty-print-program "aimap"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 "*External pretty printer to call from within Ada Mode.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (defvar ada-tmp-directory "/tmp/"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 "*Directory to store the temporary file for the Ada pretty printer.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (defvar ada-fill-comment-prefix "-- "
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 "*This is inserted in the first columns when filling a comment paragraph.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defvar ada-fill-comment-postfix " --"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 "*This is inserted at the end of each line when filling a comment paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 with ada-fill-comment-paragraph postfix.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defvar ada-krunch-args "250"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 "*Argument of gnatk8, a string containing the max number of characters.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 Set to a big number, if you dont use crunched filenames.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;;; ---- end of user configurable variables
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (defvar ada-mode-abbrev-table nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 "Abbrev table used in Ada mode.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (define-abbrev-table 'ada-mode-abbrev-table ())
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (defvar ada-mode-map ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 "Local keymap used for ada-mode.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (defvar ada-mode-syntax-table nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 "Syntax table to be used for editing Ada source code.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (defconst ada-83-keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 "\\<\\(abort\\|abs\\|accept\\|access\\|all\\|and\\|array\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 at\\|begin\\|body\\|case\\|constant\\|declare\\|delay\\|delta\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 digits\\|do\\|else\\|elsif\\|end\\|entry\\|exception\\|exit\\|for\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 function\\|generic\\|goto\\|if\\|in\\|is\\|limited\\|loop\\|mod\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 new\\|not\\|null\\|of\\|or\\|others\\|out\\|package\\|pragma\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 private\\|procedure\\|raise\\|range\\|record\\|rem\\|renames\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 return\\|reverse\\|select\\|separate\\|subtype\\|task\\|terminate\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 then\\|type\\|use\\|when\\|while\\|with\\|xor\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 "regular expression for looking at Ada83 keywords.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (defconst ada-94-keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 "\\<\\(abort\\|abs\\|abstract\\|accept\\|access\\|aliased\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 all\\|and\\|array\\|at\\|begin\\|body\\|case\\|constant\\|declare\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 delay\\|delta\\|digits\\|do\\|else\\|elsif\\|end\\|entry\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 exception\\|exit\\|for\\|function\\|generic\\|goto\\|if\\|in\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 is\\|limited\\|loop\\|mod\\|new\\|not\\|null\\|of\\|or\\|others\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 out\\|package\\|pragma\\|private\\|procedure\\|protected\\|raise\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 range\\|record\\|rem\\|renames\\|requeue\\|return\\|reverse\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 select\\|separate\\|subtype\\|tagged\\|task\\|terminate\\|then\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 type\\|until\\|use\\|when\\|while\\|with\\|xor\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 "regular expression for looking at Ad94 keywords.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defvar ada-keywords ada-94-keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "regular expression for looking at Ada keywords.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (defvar ada-ret-binding nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 "Variable to save key binding of RET when casing is activated.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (defvar ada-lfd-binding nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 "Variable to save key binding of LFD when casing is activated.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;;; ---- Regexps to find procedures/functions/packages
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (defvar ada-procedure-start-regexp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 "^[ \t]*\\(procedure\\|function\\|task\\)[ \t\n]+\\([a-zA-Z0-9_\\.]+\\)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 "Regexp used to find Ada procedures/functions.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (defvar ada-package-start-regexp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 "^[ \t]*\\(package\\)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 "Regexp used to find Ada packages")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;;; ---- regexps for indentation functions
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (defvar ada-block-start-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 "\\<\\(begin\\|select\\|declare\\|private\\|or\\|generic\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 exception\\|loop\\|record\\|else\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 "Regexp for keywords starting ada-blocks.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (defvar ada-end-stmt-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 "\\(;\\|=>\\|\\<\\(begin\\|record\\|loop\\|select\\|do\\|\
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 exception\\|declare\\|generic\\|private\\)\\>\\)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 "Regexp of possible ends for a non-broken statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 'end' means that there has to start a new statement after these.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defvar ada-loop-start-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 "\\<\\(for\\|while\\|loop\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 "Regexp for the start of a loop.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (defvar ada-subprog-start-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 "\\<\\(procedure\\|function\\|task\\|accept\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 "Regexp for the start of a subprogram.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;;;-------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ;;; functions
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;;;-------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defun ada-create-syntax-table ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 "Create the syntax table for ada-mode."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 ;; This syntax table is a merge of two syntax tables I found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; in the two ada modes in the old ada.el and the old
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ;; electric-ada.el. (jsl)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;; There still remains the problem, if the underscore '_' is a word
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;; constituent or not. (re)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;; The Emacs doc clearly states that it is a symbol, and that is what most
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;; on the ada-mode list prefer. (re)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; For some functions, the syntactical meaning of '_' is temporaryly
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; changed to 'w'. (mh)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (setq ada-mode-syntax-table (make-syntax-table))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (set-syntax-table ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;; define string brackets (% is alternative string bracket)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (modify-syntax-entry ?% "\"" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (modify-syntax-entry ?\" "\"" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (modify-syntax-entry ?\# "$" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (modify-syntax-entry ?: "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (modify-syntax-entry ?\; "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (modify-syntax-entry ?& "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (modify-syntax-entry ?\| "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (modify-syntax-entry ?+ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (modify-syntax-entry ?* "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (modify-syntax-entry ?/ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (modify-syntax-entry ?= "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (modify-syntax-entry ?< "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (modify-syntax-entry ?> "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (modify-syntax-entry ?$ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (modify-syntax-entry ?\[ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (modify-syntax-entry ?\] "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (modify-syntax-entry ?\{ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (modify-syntax-entry ?\} "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (modify-syntax-entry ?. "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (modify-syntax-entry ?\\ "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (modify-syntax-entry ?\' "." ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 ;; a single hyphen is punctuation, but a double hyphen starts a comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (modify-syntax-entry ?- ". 12" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;; and \f and \n end a comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (modify-syntax-entry ?\f "> " ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (modify-syntax-entry ?\n "> " ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ;; define what belongs in ada symbols
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (modify-syntax-entry ?_ "_" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 ;; define parentheses to match
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (modify-syntax-entry ?\( "()" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (modify-syntax-entry ?\) ")(" ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
359 ;;;###autoload
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (defun ada-mode ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 "Ada Mode is the major mode for editing Ada code.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 Bindings are as follows: (Note: 'LFD' is control-j.)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 Indent line '\\[ada-tab]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 Indent line, insert newline and indent the new line. '\\[newline-and-indent]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 Re-format the parameter-list point is in '\\[ada-format-paramlist]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 Indent all lines in region '\\[ada-indent-region]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 Call external pretty printer program '\\[ada-call-pretty-printer]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 Adjust case of identifiers and keywords in region '\\[ada-adjust-case-region]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 Adjust case of identifiers and keywords in buffer '\\[ada-adjust-case-buffer]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 Call EXTERNAL pretty printer (if you have one) '\\[ada-call-pretty-printer]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 Fill comment paragraph '\\[ada-fill-comment-paragraph]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 Fill comment paragraph and justify each line '\\[ada-fill-comment-paragraph-justify]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 Fill comment paragraph, justify and append postfix '\\[ada-fill-comment-paragraph-postfix]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 Next func/proc/task '\\[ada-next-procedure]' Previous func/proc/task '\\[ada-previous-procedure]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 Next package '\\[ada-next-package]' Previous package '\\[ada-previous-package]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 Goto matching start of current 'end ...;' '\\[ada-move-to-start]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 Goto end of current block '\\[ada-move-to-end]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 Comments are handled using standard GNU Emacs conventions, including:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 Start a comment '\\[indent-for-comment]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 Comment region '\\[comment-region]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 Uncomment region '\\[ada-uncomment-region]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 Continue comment on next line '\\[indent-new-comment-line]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 If you use imenu.el:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 Display index-menu of functions & procedures '\\[imenu]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 If you use find-file.el:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 Switch to other file (Body <-> Spec) '\\[ff-find-other-file]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 or '\\[ff-mouse-find-other-file]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 Switch to other file in other window '\\[ada-ff-other-window]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 or '\\[ff-mouse-find-other-file-other-window]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 If you use ada-xref.el:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 Goto declaration: '\\[ada-point-and-xref]' on the identifier
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 or '\\[ada-goto-declaration]' with point on the identifier
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 Complete identifier: '\\[ada-complete-identifier]'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 Execute Gnatf: '\\[ada-gnatf-current]'"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (kill-all-local-variables)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (make-local-variable 'require-final-newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (setq require-final-newline t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (make-local-variable 'comment-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (setq comment-start "-- ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 ;; comment end must be set because it may hold a wrong value if
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ;; this buffer had been in another mode before. RE
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (make-local-variable 'comment-end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (setq comment-end "")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (make-local-variable 'comment-start-skip) ;; used by autofill
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq comment-start-skip "--+[ \t]*")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (make-local-variable 'indent-line-function)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (setq indent-line-function 'ada-indent-current-function)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (make-local-variable 'fill-column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (setq fill-column 75)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (make-local-variable 'comment-column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (setq comment-column 40)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (make-local-variable 'parse-sexp-ignore-comments)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (setq parse-sexp-ignore-comments t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (make-local-variable 'case-fold-search)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (setq case-fold-search t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
440 (make-local-variable 'fill-paragraph-function)
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
441 (setq fill-paragraph-function 'ada-fill-comment-paragraph)
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
442
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (make-local-variable 'font-lock-defaults)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq font-lock-defaults '(ada-font-lock-keywords nil t ((?\_ . "w"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (setq major-mode 'ada-mode)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (setq mode-name "Ada")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (setq blink-matching-paren t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (use-local-map ada-mode-map)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (if ada-mode-syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (set-syntax-table ada-mode-syntax-table)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (ada-create-syntax-table))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (if ada-clean-buffer-before-saving
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; remove all spaces at the end of lines in the whole buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (add-hook 'local-write-file-hooks 'ada-remove-trailing-spaces)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 ;; convert all tabs to the correct number of spaces.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (add-hook 'local-write-file-hooks 'ada-untabify-buffer)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ;; add menu 'Ada' to the menu bar
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (ada-add-ada-menu)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (run-hooks 'ada-mode-hook)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 ;; the following has to be done after running the ada-mode-hook
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 ;; because users might want to set the values of these variable
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 ;; inside the hook (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (cond ((eq ada-language-version 'ada83)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (setq ada-keywords ada-83-keywords))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 ((eq ada-language-version 'ada94)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (setq ada-keywords ada-94-keywords)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (if ada-auto-case
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (ada-activate-keys-for-case)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 ;;;--------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 ;;; Fill Comment Paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 ;;;--------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (defun ada-fill-comment-paragraph-justify ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 "Fills current comment paragraph and justifies each line as well."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (ada-fill-comment-paragraph t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (defun ada-fill-comment-paragraph-postfix ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 "Fills current comment paragraph and justifies each line as well.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 Prompts for a postfix to be appended to each line."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (ada-fill-comment-paragraph t t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (defun ada-fill-comment-paragraph (&optional justify postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 "Fills the current comment paragraph.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 If JUSTIFY is non-nil, each line is justified as well.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 If POSTFIX and JUSTIFY are non-nil, ada-fill-comment-postfix is appended
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 to each filled and justified line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 If ada-indent-comment-as code is non-nil, the paragraph is idented."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (let ((opos (point-marker))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (begin nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (end-2 nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (indent nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (ada-fill-comment-old-postfix "")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (fill-prefix nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 ;; check if inside comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (if (not (ada-in-comment-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (error "not inside comment"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 ;; prompt for postfix if wanted
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (if (and justify
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (setq ada-fill-comment-postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (read-from-minibuffer "enter new postfix string: "
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 ada-fill-comment-postfix)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 ;; prompt for old postfix to remove if necessary
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (if (and justify
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (setq ada-fill-comment-old-postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (read-from-minibuffer "enter already existing postfix string: "
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 ada-fill-comment-postfix)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 ;; find limits of paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (message "filling comment paragraph ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 ;; find end of paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (while (and (looking-at "--.*$")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (not (looking-at "--[ \t]*$")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (back-to-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (setq end (point-marker))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (goto-char opos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 ;; find begin of paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (while (and (looking-at "--.*$")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (not (looking-at "--[ \t]*$")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (forward-line -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (back-to-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 ;; get indentation to calculate width for filling
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (ada-indent-current)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (setq indent (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (setq begin (point-marker)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 ;; delete old postfix if necessary
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (if (and justify
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (while (re-search-forward (concat ada-fill-comment-old-postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 "\n")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 end t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (replace-match "\n"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 ;; delete leading whitespace and uncomment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (while (re-search-forward "^[ \t]*--[ \t]*" end t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (replace-match "")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 ;; calculate fill width
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (setq fill-column (- fill-column indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (length ada-fill-comment-prefix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (if postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (length ada-fill-comment-postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 ;; fill paragraph
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (fill-region begin (1- end) justify)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (setq fill-column (+ fill-column indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (length ada-fill-comment-prefix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (if postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (length ada-fill-comment-postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 ;; find end of second last line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (goto-char end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (forward-line -2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (setq end-2 (point-marker)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 ;; re-comment and re-indent region
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (indent-to indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (insert ada-fill-comment-prefix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (while (re-search-forward "\n" (1- end-2) t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (replace-match (concat "\n" ada-fill-comment-prefix))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (indent-to indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 ;; append postfix if wanted
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (if (and justify
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 ada-fill-comment-postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 ;; append postfix up to there
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (while (re-search-forward "\n" (1- end-2) t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (replace-match (concat ada-fill-comment-postfix "\n")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 ;; fill last line and append postfix
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (insert-char ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (- fill-column
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (current-column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (length ada-fill-comment-postfix)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (insert ada-fill-comment-postfix))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 ;; delete the extra line that gets inserted somehow(??)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (goto-char (1- end))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (delete-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (message "filling comment paragraph ... done")
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
633 (goto-char opos))
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
634 t)
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 ;;;--------------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 ;;; Call External Pretty Printer ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 ;;;--------------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 (defun ada-call-pretty-printer ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 "Calls the external Pretty Printer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 The name is specified in ada-external-pretty-print-program. Saves the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 current buffer in a directory specified by ada-tmp-directory,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 starts the Pretty Printer as external process on that file and then
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 reloads the beautyfied program in the buffer and cleans up
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 ada-tmp-directory."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (let ((filename-with-path buffer-file-name)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 (curbuf (current-buffer))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (orgpos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (mesgbuf nil) ;; for byte-compiling
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (file-path (file-name-directory buffer-file-name))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (filename-without-path (file-name-nondirectory buffer-file-name))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 (tmp-file-with-directory
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (concat ada-tmp-directory
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (file-name-nondirectory buffer-file-name))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 ;; save buffer in temporary file
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (message "saving current buffer to temporary file ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (write-file tmp-file-with-directory)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (auto-save-mode nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (message "saving current buffer to temporary file ... done")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 ;; call external pretty printer program
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (message "running external pretty printer ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 ;; create a temporary buffer for messages of pretty printer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (setq mesgbuf (get-buffer-create "Pretty Printer Messages"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 ;; execute pretty printer on temporary file
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (call-process ada-external-pretty-print-program
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 nil mesgbuf t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 tmp-file-with-directory)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 ;; display messages if there are some
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (if (buffer-modified-p mesgbuf)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 ;; show the message buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (display-buffer mesgbuf t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 ;; kill the message buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (kill-buffer mesgbuf))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (message "running external pretty printer ... done")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 ;; kill current buffer and load pretty printer output
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 ;; or restore old buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (if (y-or-n-p
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 "Really replace current buffer with pretty printer output ? ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (set-buffer-modified-p nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (kill-buffer curbuf)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 (find-file tmp-file-with-directory))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (message "old buffer contents restored"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 ;; delete temporary file and restore information of current buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (delete-file tmp-file-with-directory)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 (set-visited-file-name filename-with-path)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (auto-save-mode t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (goto-char orgpos)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 ;;;---------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 ;;; auto-casing
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 ;;;---------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 ;; from Philippe Waroquiers <philippe@cfmu.eurocontrol.be>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 ;; modifiedby RE and MH
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (defun ada-after-keyword-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 ;; returns t if cursor is after a keyword.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (forward-word -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (and (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (= (point) (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (backward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (not (looking-at "_"))) ; (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (looking-at (concat ada-keywords "[^_]")))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (defun ada-after-char-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ;; returns t if after ada character "'".
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (if (> (point) 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (forward-char -2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (looking-at "'"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (defun ada-adjust-case (&optional force-identifier)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 "Adjust the case of the word before the just-typed character,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 according to ada-case-keyword and ada-case-identifier
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 If FORCE-IDENTIFIER is non-nil then also adjust keyword as
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 identifier." ; (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (forward-char -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (if (and (> (point) 1) (not (or (ada-in-string-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (ada-in-comment-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (ada-after-char-p))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (if (eq (char-syntax (char-after (1- (point)))) ?w)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (not force-identifier) ; (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 (ada-after-keyword-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (funcall ada-case-keyword -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (funcall ada-case-identifier -1))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (forward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (defun ada-adjust-case-interactive (arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (let ((lastk last-command-char))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 (cond ((or (eq lastk ?\n)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (eq lastk ?\r))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 ;; horrible kludge
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (insert " ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 (ada-adjust-case)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 ;; horrible dekludge
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (delete-backward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 ;; some special keys and their bindings
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 ((eq lastk ?\n)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (funcall ada-lfd-binding))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 ((eq lastk ?\r)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (funcall ada-ret-binding))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 ((eq lastk ?\C-i) (ada-tab))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 ((self-insert-command (prefix-numeric-value arg))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 ;; if there is a keyword in front of the underscore
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 ;; then it should be part of an identifier (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (if (eq lastk ?_)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (ada-adjust-case t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (ada-adjust-case))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (defun ada-activate-keys-for-case ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 ;; save original keybindings to allow swapping ret/lfd
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 ;; when casing is activated
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 ;; the 'or ...' is there to be sure that the value will not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 ;; be changed again when ada-mode is called more than once (MH)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 (or ada-ret-binding
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (setq ada-ret-binding (key-binding "\C-M")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (or ada-lfd-binding
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (setq ada-lfd-binding (key-binding "\C-j")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 ;; call case modifying function after certain keys.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (mapcar (function (lambda(key) (define-key
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 ada-mode-map
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (char-to-string key)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 'ada-adjust-case-interactive)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 '( ?` ?~ ?! ?@ ?# ?$ ?% ?^ ?& ?* ?( ?) ?- ?= ?+ ?[ ?{ ?] ?}
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 ?_ ?\\ ?| ?\; ?: ?' ?\" ?< ?, ?. ?> ?? ?/ ?\n 32 ?\r )))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 ;; deleted ?\t from above list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 ;; added by MH
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (defun ada-loose-case-word (&optional arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 "Capitalizes the first and the letters following _
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 ARG is ignored, it's there to fit the standard casing functions' style."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (let ((pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (first t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (skip-chars-backward "a-zA-Z0-9_")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 (while (or first
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (search-forward "_" pos t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (and first
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (setq first nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 (insert-char (upcase (following-char)) 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (delete-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 (goto-char pos)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 ;; added by MH
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 (defun ada-adjust-case-region (from to)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 "Adjusts the case of all identifiers and keywords in the region.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 ATTENTION: This function might take very long for big regions !"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (interactive "*r")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 (let ((begin nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 (keywordp nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 (reldiff nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 (goto-char to)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 ;; loop: look for all identifiers and keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 (while (re-search-backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 from
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 ;; print status message
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 (setq reldiff (- (point) from))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 (message (format "adjusting case ... %5d characters left"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 (- (point) from)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 ;; do nothing if it is a string or comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 (ada-in-string-or-comment-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 ;; get the identifier or keyword
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 (setq begin (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 (setq keywordp (looking-at (concat ada-keywords "[^_]")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 (skip-chars-forward "a-zA-Z0-9_")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 ;; casing according to user-option
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 (if keywordp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 (funcall ada-case-keyword -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 (funcall ada-case-identifier -1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 (goto-char begin))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (message "adjusting case ... done"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 ;; added by MH
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (defun ada-adjust-case-buffer ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 "Adjusts the case of all identifiers and keywords in the whole buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 ATTENTION: This function might take very long for big buffers !"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 (ada-adjust-case-region (point-min) (point-max)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867 ;;;------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868 ;;; Format Parameter Lists ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 ;;;------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 (defun ada-format-paramlist ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 "Re-formats a parameter-list.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 ATTENTION: 1) Comments inside the list are killed !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 2) If the syntax is not correct (especially, if there are
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 semicolons missing), it can get totally confused !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 In such a case, use 'undo', correct the syntax and try again."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (let ((begin nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 (end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 (delend nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 (paramlist nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 ;; ATTENTION: modify sntax-table temporary !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (modify-syntax-entry ?_ "w")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 ;; check if really inside parameter list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 (or (ada-in-paramlist-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 (error "not in parameter list"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 ;; find start of current parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 "procedure\\|function\\|body\\|package\\|task\\|entry\\|accept"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 "\\)\\>") t nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 (ada-search-ignore-string-comment "(" nil nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 (backward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (setq begin (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 ;; find end of parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 (forward-sexp 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 (setq delend (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (delete-char -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 ;; find end of last parameter-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 (setq end (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 ;; build a list of all elements of the parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (setq paramlist (ada-scan-paramlist (1+ begin) end))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 ;; delete the original parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (delete-region begin (1- delend))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 ;; insert the new parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 (ada-insert-paramlist paramlist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 ;; restore syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 (modify-syntax-entry ?_ "_")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 (defun ada-scan-paramlist (begin end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 ;; Scans a parameter-list between BEGIN and END and returns a list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 ;; of its contents.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 ;; The list has the following format:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 ;; Name of Param in? out? accept? Name of Type Default-Exp or nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 ;; ( ('Name_Param_1' t nil t Type_Param_1 ':= expression')
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 ;; ('Name_Param_2' nil nil t Type_Param_2 nil) )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 (let ((paramlist (list))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (param (list))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (notend t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 (apos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 (epos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 (semipos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 (match-cons nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 ;; loop until end of last parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 (while notend
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963 ;; find first character of parameter-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 (setq apos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969 ;; find last character of parameter-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 (if (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 (ada-search-ignore-string-comment "[ \t\n]*;" nil end t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 (setq epos (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 (setq semipos (cdr match-cons)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 (setq epos end))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 ;; read name(s) of parameter(s)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981 (goto-char apos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 (looking-at "\\([a-zA-Z0-9_, \t\n]*[a-zA-Z0-9_]\\)[ \t\n]*:[^=]")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 (setq param (list (buffer-substring (match-beginning 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 (match-end 1))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 (ada-search-ignore-string-comment ":" nil epos t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 ;; look for 'in'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 (setq apos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 (setq param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 (append param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 (consp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (ada-search-ignore-string-comment "\\<in\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 epos
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 t)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 ;; look for 'out'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 (goto-char apos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 (setq param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 (append param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (consp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (ada-search-ignore-string-comment "\\<out\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 epos
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 t)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 ;; look for 'accept'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (goto-char apos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 (setq param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (append param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 (consp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 (ada-search-ignore-string-comment "\\<accept\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 epos
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 t)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 ;; skip 'in'/'out'/'accept'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 (goto-char apos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 (while (looking-at "\\<\\(in\\|out\\|accept\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 (ada-goto-next-non-ws))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 ;; read type of parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 (looking-at "\\<[a-zA-Z0-9_\\.]+\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 (setq param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 (append param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 (buffer-substring (match-beginning 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 (match-end 0)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 ;; read default-expression, if there is one
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 (goto-char (setq apos (match-end 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 (setq param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 (append param
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 (if (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 (ada-search-ignore-string-comment ":="
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 epos
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 (buffer-substring (car match-cons)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 epos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 ;; add this parameter-declaration to the list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 (setq paramlist (append paramlist (list param)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 ;; check if it was the last parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (if (eq epos end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 (setq notend nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 (goto-char semipos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 ) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (reverse paramlist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 (defun ada-insert-paramlist (paramlist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 ;; Inserts a formatted PARAMLIST in the buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 ;; See doc of ada-scan-paramlist for the format.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 (let ((i (length paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 (parlen 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (typlen 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 (temp 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 (inp nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 (outp nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (acceptp nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 (column nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 (orgpoint 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 (firstcol nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 ;; loop until last parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 (while (not (zerop i))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 (setq i (1- i))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 ;; get max length of parameter-name
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (setq parlen
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (if (<= parlen (setq temp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 (length (nth 0 (nth i paramlist)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 temp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 parlen))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 ;; get max length of type-name
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 (setq typlen
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 (if (<= typlen (setq temp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 (length (nth 4 (nth i paramlist)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 temp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 typlen))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 ;; is there any 'in' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 (setq inp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 (or inp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 (nth 1 (nth i paramlist))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 ;; is there any 'out' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (setq outp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 (or outp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 (nth 2 (nth i paramlist))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 ;; is there any 'accept' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 (setq acceptp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 (or acceptp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 (nth 3 (nth i paramlist))))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 ;; does paramlist already start on a separate line ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 (re-search-backward "^.\\|[^ \t]" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 (looking-at "^."))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 ;; yes => re-indent it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 (ada-indent-current)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 ;; no => insert newline and indent it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (ada-indent-current)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 (newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 (delete-horizontal-space)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 (setq orgpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 (setq column (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 (funcall (ada-indent-function) orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155 (indent-to column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 (insert "(")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 (setq firstcol (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 (setq i (length paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 ;; loop until last parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 (while (not (zerop i))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 (setq i (1- i))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 (setq column firstcol)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 ;; insert parameter-name, space and colon
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 (insert (nth 0 (nth i paramlist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 (indent-to (+ column parlen 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 (insert ": ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 (setq column (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 ;; insert 'in' or space
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (if (nth 1 (nth i paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 (insert "in ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (or inp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 acceptp)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (not (nth 3 (nth i paramlist))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 (insert " ")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 ;; insert 'out' or space
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 (if (nth 2 (nth i paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 (insert "out ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (or outp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 acceptp)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 (not (nth 3 (nth i paramlist))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (insert " ")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 ;; insert 'accept'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 (if (nth 3 (nth i paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 (insert "accept "))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 (setq column (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 ;; insert type-name and, if necessary, space and default-expression
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 (insert (nth 4 (nth i paramlist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 (if (nth 5 (nth i paramlist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 (indent-to (+ column typlen 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 (insert (nth 5 (nth i paramlist)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 ;; check if it was the last parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (if (not (zerop i))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 ;; no => insert ';' and newline and indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 (insert ";")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (indent-to firstcol))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 ;; yes
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (insert ")"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 ) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 ;; if anything follows, except semicolon:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 ;; put it in a new line and indent it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (if (not (looking-at "[ \t]*[;\n]"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 (ada-indent-newline-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 ;;;----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 ;;; Move To Matching Start/End ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 ;;;----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (defun ada-move-to-start ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 "Moves point to the matching start of the current end ... around point."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (let ((pos (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 ;; ATTENTION: modify sntax-table temporary !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 (modify-syntax-entry ?_ "w")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (message "searching for block start ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 ;; do nothing if in string or comment or not on 'end ...;'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 ;; or if an error occurs during processing
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 (ada-in-string-or-comment-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 (and (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 (or (looking-at "[ \t]*\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 (backward-word 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 (or (looking-at "[ \t]*\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266 (backward-word 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 (or (looking-at "[ \t]*\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 (error "not on end ...;")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 (ada-goto-matching-start 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1270 (setq pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 ;; on 'begin' => go on, according to user option
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275 ada-move-to-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 (looking-at "\\<begin\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 (ada-goto-matching-decl-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 (setq pos (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 ) ; end of save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 ;; now really move to the found position
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 (goto-char pos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (message "searching for block start ... done")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 ;; restore syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 (modify-syntax-entry ?_ "_")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 (defun ada-move-to-end ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 "Moves point to the matching end of the current block around point.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 Moves to 'begin' if in a declarative part."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 (let ((pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 (decstart nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 (packdecl nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 ;; ATTENTION: modify sntax-table temporary !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 (modify-syntax-entry ?_ "w")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 (message "searching for block end ...")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 ;; directly on 'begin'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 (looking-at "\\<begin\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (ada-goto-matching-end 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 ;; on first line of defun declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 (and (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (looking-at "\\<function\\>\\|\\<procedure\\>" )))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 (ada-search-ignore-string-comment "\\<begin\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 ;; on first line of task declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (and (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 (looking-at "\\<task\\>" )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (ada-search-ignore-string-comment "[^ \n\t]")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (not (backward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (looking-at "\\<body\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (ada-search-ignore-string-comment "\\<begin\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 ;; accept block start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 (and (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 (looking-at "\\<accept\\>" )))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 (ada-goto-matching-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 ;; package start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 (and (ada-goto-matching-decl-start t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 (looking-at "\\<package\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (ada-goto-matching-end 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 ;; inside a 'begin' ... 'end' block
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (ada-goto-matching-decl-start t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (ada-search-ignore-string-comment "\\<begin\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 ;; (hopefully ;-) everything else
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 (ada-goto-matching-end 1)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345 (setq pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 ) ; end of save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 ;; now really move to the found position
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 (goto-char pos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 (message "searching for block end ... done")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 ;; restore syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 (modify-syntax-entry ?_ "_")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 ;;;-----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 ;;; Functions For Indentation ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 ;;;-----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 ;; ---- main functions for indentation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (defun ada-indent-region (beg end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 "Indents the region using ada-indent-current on each line."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (interactive "*r")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (goto-char beg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 ;; catch errors while indenting
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (condition-case err
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (while (< (point) end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 (message (format "indenting ... %4d lines left"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 (count-lines (point) end)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 (ada-indent-current)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 (forward-line 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 ;; show line number where the error occured
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 (error
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (error (format "line %d: %s"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 (1+ (count-lines (point-min) (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 err) nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381 (message "indenting ... done"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 (defun ada-indent-newline-indent ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 "Indents the current line, inserts a newline and then indents the new line."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 (interactive "*")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1387 (let ((column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1388 (orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 (ada-indent-current)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 (newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 (delete-horizontal-space)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 (setq orgpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 ;; ATTENTION: modify syntax-table temporary !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1398 (modify-syntax-entry ?_ "w")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 (setq column (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401 (funcall (ada-indent-function) orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 ;; restore syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 (modify-syntax-entry ?_ "_")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408 (indent-to column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 ;; The following is needed to ensure that indentation will still be
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411 ;; correct if something follows behind point when typing LFD
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 ;; For example: Imagine point to be there (*) when LFD is typed:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 ;; while cond loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 ;; null; *end loop;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 ;; Result without the following statement would be:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 ;; while cond loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417 ;; null;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418 ;; *end loop;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 ;; You would then have to type TAB to correct it.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 ;; If that doesn't bother you, you can comment out the following
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 ;; statement to speed up indentation a LITTLE bit.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423 (if (not (looking-at "[ \t]*$"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 (ada-indent-current))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (defun ada-indent-current ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 "Indents current line as Ada code.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 This works by two steps:
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 1) It moves point to the end of the previous code-line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432 Then it calls the function to calculate the indentation for the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 following line as if a newline would be inserted there.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1434 The calculated column # is saved and the old position of point
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 is restored.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 2) Then another function is called to calculate the indentation for
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 the current line, based on the previously calculated column #."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 ;; ATTENTION: modify sntax-table temporary !
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 (modify-syntax-entry ?_ "w")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1445
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446 (let ((line-end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447 (orgpoint (point-marker))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 (cur-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (prev-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450 (prevline t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1451
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1453 ;; first step
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (if (ada-goto-prev-nonblank-line t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 ;; we are not in the first accessible line in the buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 (setq line-end (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 (setq prev-indent (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (funcall (ada-indent-function) line-end))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 (setq prevline nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 (if prevline
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 ;; we are not in the first accessible line in the buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 ;; second step
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (setq cur-indent (ada-get-current-indent prev-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (delete-horizontal-space)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (indent-to cur-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 ;; restore position of point
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 (goto-char orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 (if (< (current-column) (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 (back-to-indentation)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489 ;; restore syntax-table
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491 (modify-syntax-entry ?_ "_"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494 (defun ada-get-current-indent (prev-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 ;; Returns the column # to indent the current line to.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496 ;; PREV-INDENT is the indentation resulting from the previous lines.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 (let ((column nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 (pos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 (match-cons nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 ;; in open parenthesis, but not in parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1505 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1506 ada-indent-to-open-paren
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 (not (ada-in-paramlist-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 (setq column (ada-in-open-paren-p)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 ;; check if we have something like this (Table_Component_Type =>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 ;; Source_File_Record,)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 (if (and (ada-search-ignore-string-comment "[^ \t]" t nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513 (looking-at "\n")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 (ada-search-ignore-string-comment "[^ \t\n]" t nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 (looking-at ">"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (setq column (+ ada-broken-indent column))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 ;; end
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1522 ((looking-at "\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (ada-goto-matching-start 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1527 ;; found 'loop' => skip back to 'while' or 'for'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1528 ;; if 'loop' is not on a separate line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1529 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1531 (looking-at "\\<loop\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534 (not (looking-at "\\<loop\\>"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1535 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 ada-loop-start-re t nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (not (looking-at "\\<loop\\>"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 (goto-char (car match-cons))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 ;; exception
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 ((looking-at "\\<exception\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (ada-goto-matching-start 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 ;; when
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 ((looking-at "\\<when\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 (ada-goto-matching-start 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (+ (current-indentation) ada-when-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 ;; else
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1561 ((looking-at "\\<else\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1562 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 (looking-at "\\<or\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1565 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 (ada-goto-matching-start 1 nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1568 (current-indentation))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1570 ;; elsif
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1571 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1572 ((looking-at "\\<elsif\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1573 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1574 (ada-goto-matching-start 1 nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1575 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1576 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1577 ;; then
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1578 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 ((looking-at "\\<then\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1580 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1582 (looking-at "\\<and\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1583 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1584 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1585 (ada-search-ignore-string-comment "\\<elsif\\>\\|\\<if\\>" t nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586 (+ (current-indentation) ada-stmt-end-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1588 ;; loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1590 ((looking-at "\\<loop\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 (setq pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1593 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1594 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1595 (if (looking-at "\\<loop\\>\\|\\<if\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1596 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 (if (not (looking-at ada-loop-start-re))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599 (ada-search-ignore-string-comment ada-loop-start-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600 nil pos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1601 (if (looking-at "\\<loop\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1602 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1603 (+ (current-indentation) ada-stmt-end-indent))))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1605 ;; begin
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1606 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1607 ((looking-at "\\<begin\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1608 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1609 (if (ada-goto-matching-decl-start t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610 (current-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 (message "no matching declaration start")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 prev-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 ;; is
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1616 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 ((looking-at "\\<is\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 ada-indent-is-separate
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 (ada-goto-next-non-ws (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624 (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 (looking-at "\\<abstract\\>\\|\\<separate\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1629 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1630 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1631 (+ (current-indentation) ada-stmt-end-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1632 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1633 ;; record
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 ((looking-at "\\<record\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1638 "\\<\\(type\\|use\\)\\>" t nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639 (if (looking-at "\\<use\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1640 (ada-search-ignore-string-comment "\\<for\\>" t nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1641 (+ (current-indentation) ada-indent-record-rel-type)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1642 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1643 ;; or as statement-start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1645 ((ada-looking-at-semi-or)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1646 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1647 (ada-goto-matching-start 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 ;; private as statement-start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 ((ada-looking-at-semi-private)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1653 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 (ada-goto-matching-decl-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1655 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1656 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1657 ;; new/abstract/separate
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1658 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1659 ((looking-at "\\<\\(new\\|abstract\\|separate\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1660 (- prev-indent ada-indent (- ada-broken-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1661 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1662 ;; return
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1663 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1664 ((looking-at "\\<return\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 (forward-sexp -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1667 (if (and (looking-at "(")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1668 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1669 (backward-sexp 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1670 (looking-at "\\<function\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1671 (1+ (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1672 prev-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1673 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1674 ;; do
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1675 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676 ((looking-at "\\<do\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1678 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679 (+ (current-indentation) ada-stmt-end-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681 ;; package/function/procedure
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1683 ((and (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1684 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1687 (looking-at "\\<\\(package\\|function\\|procedure\\)\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1688 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1689 ;; look for 'generic'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1690 (if (and (ada-goto-matching-decl-start t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1691 (looking-at "generic"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1692 (current-column)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1693 prev-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1695 ;; label
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1696 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1697 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*:[^=]")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1698 (if (ada-in-decl-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1699 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1700 (+ prev-indent ada-label-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1701 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1702 ;; identifier and other noindent-statements
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1703 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704 ((looking-at "\\<[a-zA-Z0-9_]+[ \t\n]*")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1705 prev-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1706 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1707 ;; beginning of a parameter list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1708 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1709 ((looking-at "(")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1710 prev-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1711 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1712 ;; end of a parameter list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1713 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1714 ((looking-at ")")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1715 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1716 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1717 (backward-sexp 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1718 (current-column)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1719 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1720 ;; comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1721 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1722 ((looking-at "--")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1723 (if ada-indent-comment-as-code
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1724 prev-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727 ;; unknown syntax - maybe this should signal an error ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730 prev-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1731
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1732
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1733 (defun ada-indent-function (&optional nomove)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1734 ;; Returns the function to calculate the indentation for the current
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1735 ;; line according to the previous statement, ignoring the contents
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 ;; of the current line after point. Moves point to the beginning of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1737 ;; the current statement, if NOMOVE is nil.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 (let ((orgpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 (func nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 (stmt-start nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 ;; inside a parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 (if (ada-in-paramlist-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 (setq func 'ada-get-indent-paramlist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 ;; move to beginning of current statement
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 (if (not nomove)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 (setq stmt-start (ada-goto-stmt-start)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1753 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754 ;; no beginning found => don't change indentation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1756 (if (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 (eq orgpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 (not nomove))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1759 (setq func 'ada-get-indent-nochange)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764 ada-indent-to-open-paren
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 (ada-in-open-paren-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1766 (setq func 'ada-get-indent-open-paren))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1767 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1768 ((looking-at "\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1769 (setq func 'ada-get-indent-end))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1770 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1771 ((looking-at ada-loop-start-re)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1772 (setq func 'ada-get-indent-loop))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1773 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1774 ((looking-at ada-subprog-start-re)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1775 (setq func 'ada-get-indent-subprog))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1776 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1777 ((looking-at "\\<package\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1778 (setq func 'ada-get-indent-subprog)) ; maybe it needs a
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1779 ; special function
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1780 ; sometimes ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1781 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 ((looking-at ada-block-start-re)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1783 (setq func 'ada-get-indent-block-start))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 ((looking-at "\\<type\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 (setq func 'ada-get-indent-type))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 ((looking-at "\\<if\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 (setq func 'ada-get-indent-if))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 ((looking-at "\\<elsif\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 (setq func 'ada-get-indent-if)) ; maybe it needs a special
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 ; function sometimes ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 ((looking-at "\\<case\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 (setq func 'ada-get-indent-case))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 ((looking-at "\\<when\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 (setq func 'ada-get-indent-when))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1800 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1801 ((looking-at "--")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1802 (setq func 'ada-get-indent-comment))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1803 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1804 ((looking-at "[a-zA-Z0-9_]+[ \t\n]*:[^=]")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1805 (setq func 'ada-get-indent-label))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1806 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1807 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1808 (setq func 'ada-get-indent-noindent))))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1809
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1810 func))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1811
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1812
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1813 ;; ---- functions to return indentation for special cases
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1814
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1815 (defun ada-get-indent-open-paren (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1816 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1817 ;; Assumes point to be behind an open paranthesis not yet closed.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1818 (ada-in-open-paren-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1819
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1820
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1821 (defun ada-get-indent-nochange (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1822 ;; Returns the indentation (column #) of the current line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1823 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1824 (forward-line -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1825 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1826
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1827
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1828 (defun ada-get-indent-paramlist (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1829 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1830 ;; Assumes point to be inside a parameter-list.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1831 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1832 (ada-search-ignore-string-comment "[^ \t\n]" t nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1833 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1834 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1835 ;; in front of the first parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1836 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1837 ((looking-at "(")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1838 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1839 (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1840 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1841 ;; in front of another parameter
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1842 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1843 ((looking-at ";")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1844 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1845 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1846 (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1847 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1848 ;; inside a parameter declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1850 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 (goto-char (cdr (ada-search-ignore-string-comment "(\\|;" t nil t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1853 (+ (current-column) ada-broken-indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1854
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1855
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1856 (defun ada-get-indent-end (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1857 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1858 ;; Assumes point to be at the beginning of an end-statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1859 ;; Therefore it has to find the corresponding start. This can be a little
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1860 ;; slow, if it has to search through big files with many nested blocks.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1861 ;; Signals an error if the corresponding block-start doesn't match.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1862 (let ((defun-name nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1863 (indent nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1864 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1865 ;; is the line already terminated by ';' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1866 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1867 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1868 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1869 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1870 ;; yes, look what's following 'end'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1871 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1872 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1873 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1874 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1875 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1876 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1877 ;; loop/select/if/case/record/select
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1878 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1879 ((looking-at "\\<\\(loop\\|select\\|if\\|case\\|record\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1880 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1881 (ada-check-matching-start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1882 (buffer-substring (match-beginning 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1883 (match-end 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1884 (if (looking-at "\\<\\(loop\\|record\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1885 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1886 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1887 (ada-goto-stmt-start)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1888 ;; a label ? => skip it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1889 (if (looking-at "[a-zA-Z0-9_]+[ \n\t]+:")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1890 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1891 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1892 (ada-goto-next-non-ws)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1893 ;; really looking-at the right thing ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1894 (or (looking-at (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1895 "loop\\|select\\|if\\|case\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1896 "record\\|while\\|type\\)\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1897 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1898 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1899 (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1900 "loop\\|select\\|if\\|case\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1901 "record\\|while\\|type\\)\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1902 (backward-word 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1903 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1904 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1905 ;; a named block end
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1906 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1907 ((looking-at "[a-zA-Z0-9_]+")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1908 (setq defun-name (buffer-substring (match-beginning 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1909 (match-end 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1910 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1911 (ada-goto-matching-start 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1912 (ada-check-defun-name defun-name)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1913 (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1914 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1915 ;; a block-end without name
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1916 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1917 ((looking-at ";")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1918 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1919 (ada-goto-matching-start 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1920 (if (looking-at "\\<begin\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1921 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1922 (setq indent (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1923 (if (ada-goto-matching-decl-start t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1924 (current-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1925 indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1926 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1927 ;; anything else - should maybe signal an error ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1928 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1929 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1930 (+ (current-indentation) ada-broken-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1931
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1932 (+ (current-indentation) ada-broken-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1933
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1934
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1935 (defun ada-get-indent-case (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1936 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1937 ;; Assumes point to be at the beginning of an case-statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1938 (let ((cur-indent (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1939 (match-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1940 (opos (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1941 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1942 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1943 ;; case..is..when..=>
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1944 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1945 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1946 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1947 "[ \t\n]+=>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1948 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1949 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1950 (if (not (ada-search-ignore-string-comment "\\<when\\>" t opos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1951 (error "missing 'when' between 'case' and '=>'"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1952 (+ (current-indentation) ada-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1953 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1954 ;; case..is..when
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1955 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1956 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1957 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1958 "\\<when\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1959 (goto-char (cdr match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1960 (+ (current-indentation) ada-broken-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1961 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1962 ;; case..is
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1963 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1964 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1965 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1966 "\\<is\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1967 (+ (current-indentation) ada-when-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1968 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1969 ;; incomplete case
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1970 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1971 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1972 (+ (current-indentation) ada-broken-indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1973
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1974
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1975 (defun ada-get-indent-when (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1976 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1977 ;; Assumes point to be at the beginning of an when-statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1978 (let ((cur-indent (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1979 (if (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1980 "[ \t\n]+=>" nil orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1981 (+ cur-indent ada-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1982 (+ cur-indent ada-broken-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1983
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1984
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1985 (defun ada-get-indent-if (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1986 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1987 ;; Assumes point to be at the beginning of an if-statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1988 (let ((cur-indent (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1989 (match-cons nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1990 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1991 ;; if..then ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1992 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1993 (if (ada-search-but-not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1994 "\\<then\\>" "\\<and\\>[ \t\n]+\\<then\\>" nil orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1995
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1996 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1997 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1998 ;; 'then' first in separate line ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1999 ;; => indent according to 'then'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2000 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2001 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2002 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2003 (looking-at "\\<then\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2004 (setq cur-indent (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2005 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2006 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2007 ;; something follows 'then' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2008 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2009 (if (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2010 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2011 "[^ \t\n]" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2012 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2013 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2014 (+ ada-indent
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2015 (- cur-indent (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2016 (funcall (ada-indent-function t) orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2017
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2018 (+ cur-indent ada-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2019
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2020 (+ cur-indent ada-broken-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2021
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2022
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2023 (defun ada-get-indent-block-start (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2024 ;; Returns the indentation (column #) for the new line after
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2025 ;; ORGPOINT. Assumes point to be at the beginning of a block start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2026 ;; keyword.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2027 (let ((cur-indent (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2028 (pos nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2029 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2030 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2031 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2032 (setq pos (car (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2033 "[^ \t\n]" nil orgpoint))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2034 (goto-char pos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2035 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2036 (funcall (ada-indent-function t) orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2037 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2038 ;; nothing follows the block-start
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2039 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2040 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2041 (+ (current-indentation) ada-indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2042
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2043
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2044 (defun ada-get-indent-subprog (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2045 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2046 ;; Assumes point to be at the beginning of a subprog-/package-declaration.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2047 (let ((match-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2048 (cur-indent (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2049 (foundis nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2050 (addind 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2051 (fstart (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2052 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2053 ;; is there an 'is' in front of point ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2054 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2055 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2056 (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2057 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2058 "\\<is\\>\\|\\<do\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2059 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2060 ;; yes, then skip to its end
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2061 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2062 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2063 (setq foundis t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2064 (goto-char (cdr match-cons)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2065 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2066 ;; no, then goto next non-ws, if there is one in front of point
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2067 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2068 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2069 (if (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2070 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2071 (goto-char orgpoint))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2072
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2073 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2074 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2075 ;; nothing follows 'is'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2076 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2077 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2078 foundis
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2079 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2080 (not (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2081 "[^ \t\n]" nil orgpoint t))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2082 (+ cur-indent ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2083 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2084 ;; is abstract/separate/new ...
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2085 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2086 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2087 foundis
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2088 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2089 (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2090 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2091 "\\<\\(separate\\|new\\|abstract\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2092 nil orgpoint))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2093 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2094 (ada-search-ignore-string-comment (concat ada-subprog-start-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2095 "\\|\\<package\\>") t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2096 (ada-get-indent-noindent orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2097 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2098 ;; something follows 'is'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2099 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2100 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2101 foundis
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2102 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2103 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2104 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2105 (funcall (ada-indent-function t) orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2106 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2107 ;; no 'is' but ';'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2108 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2109 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2110 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2111 cur-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2112 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2113 ;; no 'is' or ';'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2114 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2115 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2116 (+ cur-indent ada-broken-indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2117
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2118
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2119 (defun ada-get-indent-noindent (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2120 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2121 ;; Assumes point to be at the beginning of a 'noindent statement'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2122 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2123 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2124 (current-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2125 (+ (current-indentation) ada-broken-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2126
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2127
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2128 (defun ada-get-indent-label (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2129 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2130 ;; Assumes point to be at the beginning of a label or variable declaration.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2131 ;; Checks the context to decide if it's a label or a variable declaration.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2132 ;; This check might be a bit slow.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2133 (let ((match-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2134 (cur-indent (current-indentation)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2135 (goto-char (cdr (ada-search-ignore-string-comment ":")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2136 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2137 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2138 ;; loop label
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2139 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2140 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2141 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2142 ada-loop-start-re nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2143 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2144 (ada-get-indent-loop orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2145 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2146 ;; declare label
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2147 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2148 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2149 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2150 "\\<declare\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2151 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2152 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2153 (+ (current-indentation) ada-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2154 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2155 ;; complete statement following colon
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2156 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2157 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2158 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2159 (if (ada-in-decl-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2160 cur-indent ; variable-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2161 (- cur-indent ada-label-indent))) ; label
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2162 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2163 ;; broken statement
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2164 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2165 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2166 (ada-search-ignore-string-comment "[^ \t\n]" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2167 (if (ada-in-decl-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2168 (+ cur-indent ada-broken-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2169 (+ cur-indent ada-broken-indent (- ada-label-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2170 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2171 ;; nothing follows colon
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2172 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2173 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2174 (if (ada-in-decl-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2175 (+ cur-indent ada-broken-indent) ; variable-declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2176 (- cur-indent ada-label-indent)))))) ; label
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2177
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2178
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2179 (defun ada-get-indent-loop (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2180 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2181 ;; Assumes point to be at the beginning of a loop statement
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2182 ;; or (unfortunately) also a for ... use statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2183 (let ((match-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2184 (pos (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2185 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2186
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2187 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2188 ;; statement complete
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2189 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2190 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2191 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2192 (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2193 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2194 ;; simple loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2195 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2196 ((looking-at "loop\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2197 (ada-get-indent-block-start orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2198
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2199 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2200 ;; 'for'- loop (or also a for ... use statement)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2201 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2202 ((looking-at "for\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2203 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2204 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2205 ;; for ... use
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2206 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2207 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2208 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2209 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2210 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2211 (not (backward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2212 (not (zerop (skip-chars-forward "_a-zA-Z0-9'")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2213 (ada-search-ignore-string-comment "[^ /n/t]" nil orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2214 (not (backward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2215 (looking-at "\\<use\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2216 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2217 ;; check if there is a 'record' before point
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2218 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2219 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2220 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2221 "\\<record\\>" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2222 t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2223 (if match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2224 (goto-char (car match-cons)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2225 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2226 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2227 ;; for..loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2228 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2229 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2230 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2231 "\\<loop\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2232 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2233 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2234 ;; indent according to 'loop', if it's first in the line;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2235 ;; otherwise to 'for'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2236 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2237 (if (not (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2238 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2239 (looking-at "\\<loop\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2240 (goto-char pos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2241 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2242 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2243 ;; for-statement is broken
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2244 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2245 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2246 (+ (current-indentation) ada-broken-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2247
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2248 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2249 ;; 'while'-loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2250 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2251 ((looking-at "while\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2252 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2253 ;; while..loop ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2254 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2255 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2256 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2257 "\\<loop\\>" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2258
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2259 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2260 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2261 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2262 ;; indent according to 'loop', if it's first in the line;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2263 ;; otherwise to 'while'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2264 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2265 (if (not (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2266 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2267 (looking-at "\\<loop\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2268 (goto-char pos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2269 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2270
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2271 (+ (current-indentation) ada-broken-indent))))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2272
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2273
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2274 (defun ada-get-indent-type (orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2275 ;; Returns the indentation (column #) for the new line after ORGPOINT.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2276 ;; Assumes point to be at the beginning of a type statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2277 (let ((match-dat nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2278 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2279 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2280 ;; complete record declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2281 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2282 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2283 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2284 (setq match-dat (ada-search-ignore-string-comment "\\<end\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2285 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2286 orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2287 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2288 (looking-at "\\<record\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2289 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2290 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2291 (looking-at ";")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2292 (goto-char (car match-dat))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2293 (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2294 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2295 ;; record type
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2296 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2297 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2298 (setq match-dat (ada-search-ignore-string-comment "\\<record\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2299 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2300 orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2301 (goto-char (car match-dat))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2302 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2303 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2304 ;; complete type declaration
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2305 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2306 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2307 (ada-search-ignore-string-comment ";" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2308 (current-indentation))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2309 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2310 ;; type ... is
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2311 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2312 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2313 (ada-search-ignore-string-comment "\\<is\\>" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2314 (+ (current-indentation) ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2315 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2316 ;; broken statement
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2317 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2318 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2319 (+ (current-indentation) ada-broken-indent)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2320
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2321
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2322 ;;; ---- support-functions for indentation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2323
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2324 ;;; ---- searching and matching
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2325
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2326 (defun ada-goto-stmt-start (&optional limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2327 ;; Moves point to the beginning of the statement that point is in or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2328 ;; after. Returns the new position of point. Beginnings are found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2329 ;; by searching for 'ada-end-stmt-re' and then moving to the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2330 ;; following non-ws that is not a comment. LIMIT is actually not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2331 ;; used by the indentation functions.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2332 (let ((match-dat nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2333 (orgpoint (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2334
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2335 (setq match-dat (ada-search-prev-end-stmt limit))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2336 (if match-dat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2337 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2338 ;; found a previous end-statement => check if anything follows
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2339 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2340 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2341 (if (not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2342 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2343 (goto-char (cdr match-dat))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2344 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2345 "[^ \t\n]" nil orgpoint)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2346 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2347 ;; nothing follows => it's the end-statement directly in
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2348 ;; front of point => search again
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2349 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2350 (setq match-dat (ada-search-prev-end-stmt limit)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2351 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2352 ;; if found the correct end-stetement => goto next non-ws
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2353 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2354 (if match-dat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2355 (goto-char (cdr match-dat)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2356 (ada-goto-next-non-ws))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2357
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2358 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2359 ;; no previous end-statement => we are at the beginning of the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2360 ;; accessible part of the buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2361 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2362 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2363 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2364 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2365 ;; skip to the very first statement, if there is one
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2366 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2367 (if (setq match-dat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2368 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2369 "[^ \t\n]" nil orgpoint))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2370 (goto-char (car match-dat))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2371 (goto-char orgpoint))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2372
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2373
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2374 (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2375
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2376
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2377 (defun ada-search-prev-end-stmt (&optional limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2378 ;; Moves point to previous end-statement. Returns a cons cell whose
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2379 ;; car is the beginning and whose cdr the end of the match.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2380 ;; End-statements are defined by 'ada-end-stmt-re'. Checks for
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2381 ;; certain keywords if they follow 'end', which means they are no
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2382 ;; end-statement there.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2383 (let ((match-dat nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2384 (pos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2385 (found nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2386 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2387 ;; search until found or beginning-of-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2388 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2389 (while
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2390 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2391 (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2392 (setq match-dat (ada-search-ignore-string-comment ada-end-stmt-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2393 t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2394 limit)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2395
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2396 (goto-char (car match-dat))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2397
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2398 (if (not (ada-in-open-paren-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2399 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2400 ;; check if there is an 'end' in front of the match
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2401 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2402 (if (not (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2403 (looking-at "\\<\\(record\\|loop\\|select\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2404 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2405 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2406 (looking-at "\\<end\\>"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2407 (setq found t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2408
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2409 (backward-word 1)))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2410
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2411 (if found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2412 match-dat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2413 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2414
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2415
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2416 (defun ada-goto-next-non-ws (&optional limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2417 ;; Skips whitespaces, newlines and comments to next non-ws
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2418 ;; character. Signals an error if there is no more such character
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2419 ;; and limit is nil.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2420 (let ((match-cons nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2421 (setq match-cons (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2422 "[^ \t\n]" nil limit t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2423 (if match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2424 (goto-char (car match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2425 (if (not limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2426 (error "no more non-ws")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2427 nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2428
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2429
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2430 (defun ada-goto-stmt-end (&optional limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2431 ;; Moves point to the end of the statement that point is in or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2432 ;; before. Returns the new position of point or nil if not found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2433 (if (ada-search-ignore-string-comment ada-end-stmt-re nil limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2434 (point)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2435 nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2436
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2437
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2438 (defun ada-goto-previous-word ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2439 ;; Moves point to the beginning of the previous word of ada-code.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2440 ;; Returns the new position of point or nil if not found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2441 (let ((match-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2442 (orgpoint (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2443 (if (setq match-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2444 (ada-search-ignore-string-comment "[^ \t\n]" t nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2445 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2446 ;; move to the beginning of the word found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2447 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2448 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2449 (goto-char (cdr match-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2450 (skip-chars-backward "_a-zA-Z0-9")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2451 (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2452 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2453 ;; if not found, restore old position of point
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2454 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2455 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2456 (goto-char orgpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2457 'nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2458
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2459
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2460 (defun ada-check-matching-start (keyword)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2461 ;; Signals an error if matching block start is not KEYWORD.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2462 ;; Moves point to the matching block start.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2463 (ada-goto-matching-start 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2464 (if (not (looking-at (concat "\\<" keyword "\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2465 (error (concat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2466 "matching start is not '"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2467 keyword "'"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2468
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2469
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2470 (defun ada-check-defun-name (defun-name)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2471 ;; Checks if the name of the matching defun really is DEFUN-NAME.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2472 ;; Assumes point to be already positioned by 'ada-goto-matching-start'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2473 ;; Moves point to the beginning of the declaration.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2474
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2475 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2476 ;; 'accept' or 'package' ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2477 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2478 (if (not (looking-at "\\<\\(accept\\|package\\|task\\)\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2479 (ada-goto-matching-decl-start))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2480 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2481 ;; 'begin' of 'procedure'/'function'/'task' or 'declare'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2482 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2483 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2484 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2485 ;; a named 'declare'-block ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2486 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2487 (if (looking-at "\\<declare\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2488 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2489 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2490 ;; no, => 'procedure'/'function'/'task'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2491 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2492 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2493 (forward-word 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2494 (backward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2495 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2496 ;; skip 'body' or 'type'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2497 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2498 (if (looking-at "\\<\\(body\\|type\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2499 (forward-word 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2500 (forward-sexp 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2501 (backward-sexp 1)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2502 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2503 ;; should be looking-at the correct name
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2504 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2505 (if (not (looking-at (concat "\\<" defun-name "\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2506 (error
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2507 (concat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2508 "matching defun has different name: "
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2509 (buffer-substring
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2510 (point)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2511 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2512 (forward-sexp 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2513 (point))))))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2514
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2515
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2516 (defun ada-goto-matching-decl-start (&optional noerror nogeneric)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2517 ;; Moves point to the matching declaration start of the current 'begin'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2518 ;; If NOERROR is non-nil, it only returns nil if no match was found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2519 (let ((nest-count 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2520 (pos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2521 (first t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2522 (flag nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2523 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2524 ;; search backward for interesting keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2525 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2526 (while (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2527 (not (zerop nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2528 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2529 (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2530 "is\\|separate\\|end\\|declare\\|new\\|begin\\|generic"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2531 "\\)\\>") t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2532 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2533 ;; calculate nest-depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2534 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2535 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2536 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2537 ((looking-at "end")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2538 (ada-goto-matching-start 1 noerror)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2539 (if (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2540 (looking-at "begin"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2541 (setq nest-count (1+ nest-count))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2542 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2543 ((looking-at "declare\\|generic")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2544 (setq nest-count (1- nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2545 (setq first nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2546 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2547 ((looking-at "is")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2548 ;; check if it is only a type definition
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2549 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2550 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2551 (skip-chars-backward "a-zA-Z0-9_.'")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2552 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2553 (backward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2554 (looking-at ")"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2555 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2556 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2557 (backward-sexp 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2558 (skip-chars-backward "a-zA-Z0-9_.'")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2559 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2560 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2561 (looking-at "\\<type\\>")) ; end of save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2562 (goto-char (match-beginning 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2563 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2564 (setq nest-count (1- nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2565 (setq first nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2566
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2567 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2568 ((looking-at "new")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2569 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2570 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2571 (looking-at "is"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2572 (goto-char (match-beginning 0))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2573 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2574 ((and first
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2575 (looking-at "begin"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2576 (setq nest-count 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2577 (setq flag t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2578 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2579 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2580 (setq nest-count (1+ nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2581 (setq first nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2582
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2583 ) ;; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2584
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2585 ;; check if declaration-start is really found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2586 (if (not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2587 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2588 (zerop nest-count)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2589 (not flag)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2590 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2591 (if (looking-at "is")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2592 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2593 "\\<\\(procedure\\|function\\|task\\|package\\)\\>" t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2594 (looking-at "declare\\|generic")))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2595 (if noerror nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2596 (error "no matching procedure/function/task/declare/package"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2597 t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2598
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2599
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2600 (defun ada-goto-matching-start (&optional nest-level noerror gotothen)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2601 ;; Moves point to the beginning of a block-start. Which block
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2602 ;; depends on the value of NEST-LEVEL, which defaults to zero. If
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2603 ;; NOERROR is non-nil, it only returns nil if no matching start was
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2604 ;; found. If GOTOTHEN is non-nil, point moves to the 'then'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2605 ;; following 'if'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2606 (let ((nest-count (if nest-level nest-level 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2607 (found nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2608 (pos nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2609
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2610 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2611 ;; search backward for interesting keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2612 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2613 (while (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2614 (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2615 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2616 (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2617 "end\\|loop\\|select\\|begin\\|case\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2618 "if\\|task\\|package\\|record\\|do\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2619 t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2620
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2621 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2622 ;; calculate nest-depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2623 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2624 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2625 ;; found block end => increase nest depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2626 ((looking-at "end")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2627 (setq nest-count (1+ nest-count)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2628 ;; found loop/select/record/case/if => check if it starts or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2629 ;; ends a block
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2630 ((looking-at "loop\\|select\\|record\\|case\\|if")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2631 (setq pos (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2632 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2633 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2634 ;; check if keyword follows 'end'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2635 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2636 (ada-goto-previous-word)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2637 (if (looking-at "\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2638 ;; it ends a block => increase nest depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2639 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2640 (setq nest-count (1+ nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2641 (setq pos (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2642 ;; it starts a block => decrease nest depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2643 (setq nest-count (1- nest-count))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2644 (goto-char pos))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2645 ;; found package start => check if it really is a block
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2646 ((looking-at "package")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2647 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2648 (ada-search-ignore-string-comment "\\<is\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2649 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2650 ;; ignore it if it is only a declaration with 'new'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2651 (if (not (looking-at "\\<new\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2652 (setq nest-count (1- nest-count)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2653 ;; found task start => check if it has a body
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2654 ((looking-at "task")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2655 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2656 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2657 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2658 ;; ignore it if it has no body
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2659 (if (not (looking-at "\\<body\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2660 (setq nest-count (1- nest-count)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2661 ;; all the other block starts
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2662 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2663 (setq nest-count (1- nest-count)))) ; end of 'cond'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2664
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2665 ;; match is found, if nest-depth is zero
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2666 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2667 (setq found (zerop nest-count))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2668
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2669 (if found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2670 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2671 ;; match found => is there anything else to do ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2672 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2673 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2674 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2675 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2676 ;; found 'if' => skip to 'then', if it's on a separate line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2677 ;; and GOTOTHEN is non-nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2678 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2679 ((and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2680 gotothen
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2681 (looking-at "if")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2682 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2683 (ada-search-ignore-string-comment "\\<then\\>" nil nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2684 (back-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2685 (looking-at "\\<then\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2686 (goto-char (match-beginning 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2687 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2688 ;; found 'do' => skip back to 'accept'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2689 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2690 ((looking-at "do")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2691 (if (not (ada-search-ignore-string-comment "\\<accept\\>" t nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2692 (error "missing 'accept' in front of 'do'"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2693 (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2694
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2695 (if noerror
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2696 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2697 (error "no matching start")))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2698
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2699
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2700 (defun ada-goto-matching-end (&optional nest-level noerror)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2701 ;; Moves point to the end of a block. Which block depends on the
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2702 ;; value of NEST-LEVEL, which defaults to zero. If NOERROR is
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2703 ;; non-nil, it only returns nil if found no matching start.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2704 (let ((nest-count (if nest-level nest-level 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2705 (found nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2706
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2707 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2708 ;; search forward for interesting keywords
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2709 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2710 (while (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2711 (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2712 (ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2713 (concat "\\<\\(end\\|loop\\|select\\|begin\\|case\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2714 "if\\|task\\|package\\|record\\|do\\)\\>")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2715
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2716 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2717 ;; calculate nest-depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2718 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2719 (backward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2720 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2721 ;; found block end => decrease nest depth
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2722 ((looking-at "\\<end\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2723 (setq nest-count (1- nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2724 ;; skip the following keyword
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2725 (if (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2726 (skip-chars-forward "end")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2727 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2728 (looking-at "\\<\\(loop\\|select\\|record\\|case\\|if\\)\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2729 (forward-word 1)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2730 ;; found package start => check if it really starts a block
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2731 ((looking-at "\\<package\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2732 (ada-search-ignore-string-comment "\\<is\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2733 (ada-goto-next-non-ws)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2734 ;; ignore and skip it if it is only a 'new' package
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2735 (if (not (looking-at "\\<new\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2736 (setq nest-count (1+ nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2737 (skip-chars-forward "new")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2738 ;; all the other block starts
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2739 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2740 (setq nest-count (1+ nest-count))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2741 (forward-word 1))) ; end of 'cond'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2742
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2743 ;; match is found, if nest-depth is zero
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2744 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2745 (setq found (zerop nest-count))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2746
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2747 (if (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2748 (if noerror
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2749 nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2750 (error "no matching end"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2751 t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2752
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2753
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2754 (defun ada-forward-sexp-ignore-comment ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2755 ;; Skips one sexp forward, ignoring comments.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2756 (while (looking-at "[ \t\n]*--")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2757 (skip-chars-forward "[ \t\n]")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2758 (end-of-line))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2759 (forward-sexp 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2760
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2761
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2762 (defun ada-search-ignore-string-comment
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2763 (search-re &optional backward limit paramlists)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2764 ;; Regexp-Search for SEARCH-RE, ignoring comments, strings and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2765 ;; parameter lists, if PARAMLISTS is nil. Returns a cons cell of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2766 ;; begin and end of match data or nil, if not found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2767 (let ((found nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2768 (begin nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2769 (end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2770 (pos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2771 (search-func
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2772 (if backward 're-search-backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2773 're-search-forward)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2774
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2775 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2776 ;; search until found or end-of-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2777 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2778 (while (and (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2779 (funcall search-func search-re limit 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2780 (setq begin (match-beginning 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2781 (setq end (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2782
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2783 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2784 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2785 ;; found in comment => skip it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2786 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2787 ((ada-in-comment-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2788 (if backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2789 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2790 (re-search-backward "--" nil 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2791 (goto-char (match-beginning 0)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2792 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2793 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2794 (beginning-of-line))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2795 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2796 ;; found in string => skip it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2797 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2798 ((ada-in-string-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2799 (if backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2800 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2801 (re-search-backward "\"\\|#" nil 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2802 (goto-char (match-beginning 0))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2803 (re-search-forward "\"\\|#" nil 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2804 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2805 ;; found character constant => ignore it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2806 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2807 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2808 (setq pos (- (point) (if backward 1 2)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2809 (and (char-after pos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2810 (= (char-after pos) ?')
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2811 (= (char-after (+ pos 2)) ?')))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2812 ())
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2813 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2814 ;; found a parameter-list but should ignore it => skip it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2815 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2816 ((and (not paramlists)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2817 (ada-in-paramlist-p))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2818 (if backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2819 (ada-search-ignore-string-comment "(" t nil t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2820 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2821 ;; directly in front of a comment => skip it, if searching forward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2822 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2823 ((save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2824 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2825 (looking-at "--"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2826 (if (not backward)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2827 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2828 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2829 (beginning-of-line))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2830 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2831 ;; found what we were looking for
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2832 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2833 (t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2834 (setq found t)))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2835
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2836 (if found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2837 (cons begin end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2838 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2839
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2840
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2841 (defun ada-search-but-not (search-re not-search-re &optional backward limit)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2842 ;; Searches SEARCH-RE, ignoring parts of NOT-SEARCH-RE, strings,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2843 ;; comments and parameter-lists.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2844 (let ((begin nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2845 (end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2846 (begin-not nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2847 (begin-end nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2848 (end-not nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2849 (ret-cons nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2850 (found nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2851
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2852 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2853 ;; search until found or end-of-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2854 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2855 (while (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2856 (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2857 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2858 (setq ret-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2859 (ada-search-ignore-string-comment search-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2860 backward limit))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2861 (if (consp ret-cons)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2862 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2863 (setq begin (car ret-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2864 (setq end (cdr ret-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2865 t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2866 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2867
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2868 (if (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2869 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2870 ;; if no NO-SEARCH-RE was found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2871 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2872 (not
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2873 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2874 (setq ret-cons
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2875 (ada-search-ignore-string-comment not-search-re
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2876 backward nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2877 (if (consp ret-cons)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2878 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2879 (setq begin-not (car ret-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2880 (setq end-not (cdr ret-cons))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2881 t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2882 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2883 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2884 ;; or this NO-SEARCH-RE is not a part of the SEARCH-RE
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2885 ;; found before.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2886 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2887 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2888 (<= end-not begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2889 (>= begin-not end)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2890
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2891 (setq found t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2892
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2893 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2894 ;; not found the correct match => skip this match
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2895 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2896 (goto-char (if backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2897 begin
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2898 end)))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2899
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2900 (if found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2901 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2902 (goto-char begin)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2903 (cons begin end))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2904 nil)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2905
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2906
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2907 (defun ada-goto-prev-nonblank-line ( &optional ignore-comment)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2908 ;; Moves point to previous non-blank line,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2909 ;; ignoring comments if IGNORE-COMMENT is non-nil.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2910 ;; It returns t if a matching line was found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2911 (let ((notfound t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2912 (newpoint nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2913
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2914 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2915 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2916 ;; backward one line, if there is one
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2917 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2918 (if (zerop (forward-line -1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2919 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2920 ;; there is some kind of previous line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2921 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2922 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2923 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2924 (setq newpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2925
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2926 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2927 ;; search until found or beginning-of-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2928 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2929 (while (and (setq notfound
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2930 (or (looking-at "[ \t]*$")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2931 (and (looking-at "[ \t]*--")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2932 ignore-comment)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2933 (not (in-limit-line-p)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2934 (forward-line -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2935 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2936 (setq newpoint (point))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2937
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2938 )) ; end of if
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2939
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2940 ) ; end of save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2941
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2942 (if notfound nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2943 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2944 (goto-char newpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2945 t))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2946
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2947
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2948 (defun ada-goto-next-nonblank-line ( &optional ignore-comment)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2949 ;; Moves point to next non-blank line,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2950 ;; ignoring comments if IGNORE-COMMENT is non-nil.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2951 ;; It returns t if a matching line was found.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2952 (let ((notfound t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2953 (newpoint nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2954
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2955 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2956 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2957 ;; forward one line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2958 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2959 (if (zerop (forward-line 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2960 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2961 ;; there is some kind of previous line
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2962 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2963 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2964 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2965 (setq newpoint (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2966
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2967 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2968 ;; search until found or end-of-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2969 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2970 (while (and (setq notfound
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2971 (or (looking-at "[ \t]*$")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2972 (and (looking-at "[ \t]*--")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2973 ignore-comment)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2974 (not (in-limit-line-p)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2975 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2976 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2977 (setq newpoint (point))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2978
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2979 )) ; end of if
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2980
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2981 ) ; end of save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2982
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2983 (if notfound nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2984 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2985 (goto-char newpoint)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2986 t))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2987
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2988
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2989 ;; ---- boolean functions for indentation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2990
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2991 (defun ada-in-decl-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2992 ;; Returns t if point is inside a declarative part.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2993 ;; Assumes point to be at the end of a statement.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2994 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2995 (ada-in-paramlist-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2996 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2997 (ada-goto-matching-decl-start t))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2998
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2999
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3000 (defun ada-looking-at-semi-or ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3001 ;; Returns t if looking-at an 'or' following a semicolon.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3002 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3003 (and (looking-at "\\<or\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3004 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3005 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3006 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3007 (looking-at "\\<or\\>")))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3008
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3009
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3010 (defun ada-looking-at-semi-private ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3011 ;; Returns t if looking-at an 'private' following a semicolon.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3012 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3013 (and (looking-at "\\<private\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3014 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3015 (forward-word 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3016 (ada-goto-stmt-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3017 (looking-at "\\<private\\>")))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3018
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3019
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3020 (defun in-limit-line-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3021 ;; Returns t if point is in first or last accessible line.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3022 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3023 (>= 1 (count-lines (point-min) (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3024 (>= 1 (count-lines (point) (point-max)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3025
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3026
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3027 (defun ada-in-comment-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3028 ;; Returns t if inside a comment.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3029 (save-excursion (and (re-search-backward "\\(--\\|\n\\)" nil 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3030 (looking-at "-"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3031
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3032
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3033 (defun ada-in-string-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3034 ;; Returns t if point is inside a string
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3035 ;; (Taken from pascal-mode.el, modified by MH).
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3036 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3037 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3038 (nth 3 (parse-partial-sexp
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3039 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3040 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3041 (point)) (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3042 ;; check if 'string quote' is only a character constant
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3043 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3044 (re-search-backward "\"\\|#" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3045 (not (= (char-after (1- (point))) ?'))))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3046
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3047
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3048 (defun ada-in-string-or-comment-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3049 ;; Returns t if point is inside a string or a comment.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3050 (or (ada-in-comment-p)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3051 (ada-in-string-p)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3052
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3053
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3054 (defun ada-in-paramlist-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3055 ;; Returns t if point is inside a parameter-list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3056 ;; following 'function'/'procedure'/'package'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3057 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3058 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3059 (re-search-backward "(\\|)" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3060 ;; inside parentheses ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3061 (looking-at "(")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3062 (backward-word 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3063 ;; right keyword before paranthesis ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3064 (looking-at (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3065 "procedure\\|function\\|body\\|package\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3066 "task\\|entry\\|accept\\)\\>"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3067 (re-search-forward ")\\|:" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3068 ;; at least one ':' inside the parentheses ?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3069 (not (backward-char 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3070 (looking-at ":"))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3071
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3072
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3073 ;; not really a boolean function ...
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3074 (defun ada-in-open-paren-p ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3075 ;; If point is somewhere behind an open parenthesis not yet closed,
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3076 ;; it returns the column # of the first non-ws behind this open
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3077 ;; parenthesis, otherwise nil."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3078 (let ((nest-count 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3079 (limit nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3080 (found nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3081 (pos nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3082 (col nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3083 (counter ada-search-paren-line-count-limit))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3084
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3085 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3086 ;; get search-limit
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3087 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3088 (if ada-search-paren-line-count-limit
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3089 (setq limit
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3090 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3091 (while (not (zerop counter))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3092 (ada-goto-prev-nonblank-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3093 (setq counter (1- counter)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3094 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3095 (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3096
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3097 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3098
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3099 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3100 ;; loop until found or limit
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3101 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3102 (while (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3103 (not found)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3104 (ada-search-ignore-string-comment "(\\|)" t limit t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3105 (setq nest-count
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3106 (if (looking-at ")")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3107 (1+ nest-count)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3108 (1- nest-count)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3109 (setq found (zerop nest-count))) ; end of loop
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3110
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3111 (if found
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3112 ;; if found => return column of first non-ws after the parenthesis
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3113 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3114 (forward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3115 (if (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3116 (re-search-forward "[^ \t]" nil 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3117 (backward-char 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3118 (and
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3119 (not (looking-at "\n"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3120 (setq col (current-column))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3121 col
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3122 (current-column)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3123 nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3124
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3125
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3126 ;;;-----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3127 ;;; Simple Completion Functions ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3128 ;;;-----------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3129
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3130 ;; These are my first steps in Emacs-Lisp ... :-) They can be replaced
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3131 ;; by functions based on the output of the Gnatf Tool that comes with
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3132 ;; the GNAT Ada compiler. See the file ada-xref.el (MH) But you might
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3133 ;; use these functions if you don't use GNAT
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3134
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3135 (defun ada-use-last-with ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3136 "Inserts the package name of the last 'with' statement after use."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3137 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3138 (let ((pakname nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3139 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3140 (forward-word -1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3141 (if (looking-at "use")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3142 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3143 ;; find last 'with'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3144 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3145 (progn (re-search-backward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3146 "\\(\\<with\\s-+\\)\\([a-zA-Z0-9_.]+\\)\\(\\s-*;\\)")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3147 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3148 ;; get the name of the package
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3149 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3150 (setq pakname (concat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3151 (buffer-substring (match-beginning 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3152 (match-end 2))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3153 ";")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3154 (setq pakname "")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3155 (insert pakname)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3156
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3157
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3158 (defun ada-complete-symbol (symboldef position symalist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3159 ;; Tries to complete a symbol in the buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3160 ;; SYMBOLDEF is the regexp to find the definition of the desired symbol.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3161 ;; POSITION is the position of the subexpression in SYMBOLDEF to match
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3162 ;; the symbol itself.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3163 ;; SYMALIST is an alist with possibly predefined completions."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3164 (let ((sofar nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3165 (completed nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3166 (insertpos nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3167 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3168 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3169 ;; get the part of the symbol already typed
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3170 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3171 (re-search-backward "\\([^a-zA-Z0-9_\\.]\\)\\([a-zA-Z0-9_\\.]+\\)")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3172 (setq sofar (buffer-substring (match-beginning 2)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3173 (match-end 2)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3174 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3175 ;; delete it
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3176 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3177 (delete-region (setq insertpos (match-beginning 2))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3178 (match-end 2))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3179 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3180 ;; find all possible completions by searching for definitions of
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3181 ;; this kind of symbol
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3182 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3183 (while (re-search-backward symboldef nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3184 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3185 ;; build an alist of these possible completions
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3186 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3187 (setq symalist (cons (cons (buffer-substring (match-beginning position)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3188 (match-end position))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3189 nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3190 symalist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3191
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3192 (or
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3193 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3194 ;; symbol gets completed as far as possible
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3195 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3196 (stringp (setq completed (try-completion sofar symalist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3197 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3198 ;; or is already complete
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3199 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3200 (setq completed sofar)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3201 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3202 ;; insert the completed symbol
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3203 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3204 (goto-char insertpos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3205 (insert completed)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3206
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3207
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3208 (defun ada-complete-use ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3209 "Tries to complete the package name in an 'use' statement in the buffer.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3210 Searches through former 'with' statements for possible completions."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3211 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3212 (ada-complete-symbol
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3213 "\\(\\<with\\s-+\\)\\([a-zA-Z0-9_.]+\\)\\(\\s-*;\\)" 2 nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3214 (insert ";"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3215
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3216
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3217 (defun ada-complete-procedure ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3218 "Tries to complete a procedure/function name in the buffer."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3219 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3220 (ada-complete-symbol ada-procedure-start-regexp 2 nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3221
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3222
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3223 (defun ada-complete-variable ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3224 "Tries to complete a variable name in the buffer."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3225 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3226 (ada-complete-symbol
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3227 "\\([^a-zA-Z0-9_]\\)\\([a-zA-Z0-9_]+\\)[ \t\n]+\\(:\\)" 2 nil))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3228
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3229
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3230 (defun ada-complete-type ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3231 "Tries to complete a type name in the buffer."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3232 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3233 (ada-complete-symbol "\\(type\\)[ \t\n]+\\([a-zA-Z0-9_\\.]+\\)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3234 2
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3235 '(("Integer" nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3236 ("Long_Integer" nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3237 ("Natural" nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3238 ("Positive" nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3239 ("Short_Integer" nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3240
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3241
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3242 ;;;----------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3243 ;;; Behaviour Of TAB Key ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3244 ;;;----------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3245
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3246 (defun ada-tab ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3247 "Do indenting or tabbing according to `ada-tab-policy'."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3248 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3249 (cond ((eq ada-tab-policy 'indent-and-tab) (error "not implemented"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3250 ;; ada-indent-and-tab
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3251 ((eq ada-tab-policy 'indent-rigidly) (ada-tab-hard))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3252 ((eq ada-tab-policy 'indent-auto) (ada-indent-current))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3253 ((eq ada-tab-policy 'gei) (ada-tab-gei))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3254 ((eq ada-tab-policy 'indent-af) (af-indent-line)) ; GEB
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3255 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3256 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3257
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3258
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3259 (defun ada-untab (arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3260 "Delete leading indenting according to `ada-tab-policy'."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3261 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3262 (cond ((eq ada-tab-policy 'indent-rigidly) (ada-untab-hard))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3263 ((eq ada-tab-policy 'indent-af) (backward-delete-char-untabify ; GEB
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3264 (prefix-numeric-value arg) ; GEB
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3265 arg)) ; GEB
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3266 ((eq ada-tab-policy 'indent-auto) (error "not implemented"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3267 ((eq ada-tab-policy 'always-tab) (error "not implemented"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3268 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3269
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3270
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3271 (defun ada-indent-current-function ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3272 "ada-mode version of the indent-line-function."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3273 (interactive "*")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3274 (let ((starting-point (point-marker)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3275 (ada-beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3276 (ada-tab)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3277 (if (< (point) starting-point)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3278 (goto-char starting-point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3279 (set-marker starting-point nil)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3280 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3281
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3282
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3283
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3284
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3285 (defun ada-tab-hard ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3286 "Indent current line to next tab stop."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3287 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3288 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3289 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3290 (insert-char ? ada-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3291 (if (save-excursion (= (point) (progn (beginning-of-line) (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3292 (forward-char ada-indent)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3293
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3294
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3295 (defun ada-untab-hard ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3296 "indent current line to previous tab stop."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3297 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3298 (let ((bol (save-excursion (progn (beginning-of-line) (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3299 (eol (save-excursion (progn (end-of-line) (point)))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3300 (indent-rigidly bol eol (- 0 ada-indent))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3301
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3302
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3303 (defun ada-tabsize (s)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3304 "changes spacing used for indentation. Reads spacing from minibuffer."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3305 (interactive "nnew indentation spacing: ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3306 (setq ada-indent s))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3307
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3308
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3309 ;;;---------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3310 ;;; Miscellaneous ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3311 ;;;---------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3312
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3313 (defun ada-remove-trailing-spaces ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3314 ;; remove all trailing spaces at the end of lines.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3315 "remove trailing spaces in the whole buffer."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3316 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3317 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3318 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3319 (while (re-search-forward "[ \t]+$" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3320 (replace-match "" nil nil))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3321
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3322
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3323 (defun ada-untabify-buffer ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3324 ;; change all tabs to spaces
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3325 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3326 (untabify (point-min) (point-max))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3327
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3328
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3329 (defun ada-uncomment-region (beg end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3330 "delete comment-start at the beginning of a line in the region."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3331 (interactive "r")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3332 (comment-region beg end -1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3333
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3334
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3335 ;; define a function to support find-file.el if loaded
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3336 (defun ada-ff-other-window ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3337 "Find other file in other window using ff-find-other-file."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3338 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3339 (and (fboundp 'ff-find-other-file)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3340 (ff-find-other-file t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3341
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3342
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3343 ;;;-------------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3344 ;;; Moving To Procedures/Packages ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3345 ;;;-------------------------------;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3346
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3347 (defun ada-next-procedure ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3348 "Moves point to next procedure."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3349 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3350 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3351 (if (re-search-forward ada-procedure-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3352 (goto-char (match-beginning 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3353 (error "No more functions/procedures/tasks")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3354
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3355 (defun ada-previous-procedure ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3356 "Moves point to previous procedure."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3357 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3358 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3359 (if (re-search-backward ada-procedure-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3360 (goto-char (match-beginning 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3361 (error "No more functions/procedures/tasks")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3362
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3363 (defun ada-next-package ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3364 "Moves point to next package."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3365 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3366 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3367 (if (re-search-forward ada-package-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3368 (goto-char (match-beginning 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3369 (error "No more packages")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3370
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3371 (defun ada-previous-package ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3372 "Moves point to previous package."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3373 (interactive)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3374 (beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3375 (if (re-search-backward ada-package-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3376 (goto-char (match-beginning 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3377 (error "No more packages")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3378
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3379
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3380 ;;;-----------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3381 ;;; define keymap for Ada
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3382 ;;;-----------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3383
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3384 (if (not ada-mode-map)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3385 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3386 (setq ada-mode-map (make-sparse-keymap))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3387
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3388 ;; Indentation and Formatting
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3389 (define-key ada-mode-map "\C-j" 'ada-indent-newline-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3390 (define-key ada-mode-map "\t" 'ada-tab)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3391 (define-key ada-mode-map "\C-c\C-l" 'ada-indent-region)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3392 ;; How do I write this for working with Lucid Emacs?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3393 (define-key ada-mode-map [S-tab] 'ada-untab)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3394 (define-key ada-mode-map "\C-c\C-f" 'ada-format-paramlist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3395 (define-key ada-mode-map "\C-c\C-p" 'ada-call-pretty-printer)
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3396 ;;; We don't want to make meta-characters case-specific.
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3397 ;;; (define-key ada-mode-map "\M-Q" 'ada-fill-comment-paragraph-justify)
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3398 (define-key ada-mode-map "\M-\C-q" 'ada-fill-comment-paragraph-postfix)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3399
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3400 ;; Movement
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3401 ;;; It isn't good to redefine these. What should be done instead? -- rms.
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3402 ;;; (define-key ada-mode-map "\M-e" 'ada-next-procedure)
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3403 ;;; (define-key ada-mode-map "\M-a" 'ada-previous-procedure)
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3404 (define-key ada-mode-map "\M-\C-e" 'ada-next-package)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3405 (define-key ada-mode-map "\M-\C-a" 'ada-previous-package)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3406 (define-key ada-mode-map "\C-c\C-a" 'ada-move-to-start)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3407 (define-key ada-mode-map "\C-c\C-e" 'ada-move-to-end)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3408
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3409 ;; Compilation
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3410 (define-key ada-mode-map "\C-c\C-c" 'compile)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3411
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3412 ;; Casing
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3413 (define-key ada-mode-map "\C-c\C-r" 'ada-adjust-case-region)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3414 (define-key ada-mode-map "\C-c\C-b" 'ada-adjust-case-buffer)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3415
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3416 (define-key ada-mode-map "\177" 'backward-delete-char-untabify)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3417
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3418 ;; Use predefined function of emacs19 for comments (RE)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3419 (define-key ada-mode-map "\C-c;" 'comment-region)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3420 (define-key ada-mode-map "\C-c:" 'ada-uncomment-region)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3421
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3422 ;; Change basic functionality
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3423 (mapcar (lambda (pair)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3424 (substitute-key-definition (car pair) (cdr pair)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3425 ada-mode-map global-map))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3426 '((beginning-of-line . ada-beginning-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3427 (end-of-line . ada-end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3428 (forward-to-indentation . ada-forward-to-indentation)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3429 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3430 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3431
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3432
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3433 ;;;-------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3434 ;;; define menu 'Ada'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3435 ;;;-------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3436
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3437 (defun ada-add-ada-menu ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3438 "Adds the menu 'Ada' to the menu-bar in Ada Mode."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3439 (easy-menu-define t ada-mode-map t
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3440 '("Ada"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3441 ["next package" ada-next-package t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3442 ["previous package" ada-previous-package t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3443 ["next procedure" ada-next-procedure t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3444 ["previous procedure" ada-previous-procedure t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3445 ["goto start" ada-move-to-start t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3446 ["goto end" ada-move-to-end t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3447 ["------------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3448 ["indent current line (TAB)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3449 ada-indent-current-function t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3450 ["indent lines in region" ada-indent-region t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3451 ["format parameter list" ada-format-paramlist t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3452 ["pretty print buffer" ada-call-pretty-printer t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3453 ["------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3454 ["fill comment paragraph"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3455 ada-fill-comment-paragraph t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3456 ["justify comment paragraph"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3457 ada-fill-comment-paragraph-justify t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3458 ["postfix comment paragraph"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3459 ada-fill-comment-paragraph-postfix t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3460 ["------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3461 ["adjust case region" ada-adjust-case-region t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3462 ["adjust case buffer" ada-adjust-case-buffer t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3463 ["----------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3464 ["comment region" comment-region t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3465 ["uncomment region" ada-uncomment-region t]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3466 ["----------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3467 ["compile" compile (fboundp 'compile)]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3468 ["next error" next-error (fboundp 'next-error)]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3469 ["---------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3470 ["Index" imenu (fboundp 'imenu)]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3471 ["--------------" nil nil]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3472 ["other file other window" ada-ff-other-window
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3473 (fboundp 'ff-find-other-file)]
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3474 ["other file" ff-find-other-file
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3475 (fboundp 'ff-find-other-file)])))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3476
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3477
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3478 ;;;-------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3479 ;;; Define Some Support Functions
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3480 ;;;-------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3481
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3482 (defun ada-beginning-of-line (&optional arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3483 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3484 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3485 ((eq ada-tab-policy 'indent-af) (af-beginning-of-line arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3486 (t (beginning-of-line arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3487 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3488
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3489 (defun ada-end-of-line (&optional arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3490 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3491 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3492 ((eq ada-tab-policy 'indent-af) (af-end-of-line arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3493 (t (end-of-line arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3494 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3495
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3496 (defun ada-current-column ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3497 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3498 ((eq ada-tab-policy 'indent-af) (af-current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3499 (t (current-column))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3500 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3501
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3502 (defun ada-forward-to-indentation (&optional arg)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3503 (interactive "P")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3504 (cond
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3505 ((eq ada-tab-policy 'indent-af) (af-forward-to-indentation arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3506 (t (forward-to-indentation arg))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3507 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3508
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3509 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3510 ;;; support for find-file
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3511 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3512
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3513 (defvar ada-krunch-args "8"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3514 "*Argument of gnatk8, a string containing the max number of characters.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3515 Set to a big number, if you dont use crunched filenames.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3516
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3517 (defun ada-make-filename-from-adaname (adaname)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3518 "determine the filename of a package/procedure from its own Ada name."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3519 ;; this is done simply by calling gkrunch, when we work with GNAT. It
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3520 ;; must be a more complex function in other compiler environments.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3521 (interactive "s")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3522
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3523 ;; things that should really be done by the external process
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3524 (let (krunch-buf)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3525 (setq krunch-buf (generate-new-buffer "*gkrunch*"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3526 (save-excursion
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3527 (set-buffer krunch-buf)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3528 (insert (downcase adaname))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3529 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3530 (while (search-forward "." nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3531 (replace-match "-" nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3532 (setq adaname (buffer-substring (point-min)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3533 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3534 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3535 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3536 (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3537 ;; clean the buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3538 (delete-region (point-min) (point-max))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3539 ;; send adaname to external process "gnatk8"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3540 (call-process "gnatk8" nil krunch-buf nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3541 adaname ada-krunch-args)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3542 ;; fetch output of that process
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3543 (setq adaname (buffer-substring
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3544 (point-min)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3545 (progn
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3546 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3547 (end-of-line)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3548 (point))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3549 (kill-buffer krunch-buf)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3550 (setq adaname adaname) ;; can I avoid this statement?
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3551 )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3552
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3553 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3554 ;;; support for imenu
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3555 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3556
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3557 (defun imenu-create-ada-index (&optional regexp)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3558 "create index alist for Ada files."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3559 (let ((index-alist '())
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3560 prev-pos char)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3561 (goto-char (point-min))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3562 ;(imenu-progress-message prev-pos 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3563 ;; Search for functions/procedures
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3564 (save-match-data
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3565 (while (re-search-forward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3566 (or regexp ada-procedure-start-regexp)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3567 nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3568 ;(imenu-progress-message prev-pos)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3569 ;;(backward-up-list 1) ;; needed in Ada ????
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3570 ;; do not store forward definitions
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3571 (save-match-data
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3572 (if (not (looking-at (concat
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3573 "[ \t\n]*" ; WS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3574 "\([^)]+\)" ; parameterlist
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3575 "\\([ \n\t]+return[ \n\t]+"; potential return
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3576 "[a-zA-Z0-9_\\.]+\\)?"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3577 "[ \t]*" ; WS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3578 ";" ;; THIS is what we really look for
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3579 )))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3580 ; (push (imenu-example--name-and-position) index-alist)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3581 (setq index-alist (cons (imenu-example--name-and-position)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3582 index-alist))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3583 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3584 ;(imenu-progress-message 100)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3585 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3586 (nreverse index-alist)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3587
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3588 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3589 ;;; support for font-lock
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3590 ;;;---------------------------------------------------
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3591
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3592 ;; Strings are a real pain in Ada because both ' and " can appear in a
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3593 ;; non-string quote context (the former as an operator, the latter as
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3594 ;; a character string). We follow the least losing solution, in which
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3595 ;; only " is a string quote. Therefore a character string of the form
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3596 ;; '"' will throw fontification off on the wrong track.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3597
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3598 (defconst ada-font-lock-keywords-1
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3599 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3600 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3601 ;; Function, package (body), pragma, procedure, task (body) plus name.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3602 (list (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3603 "function\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3604 "p\\(ackage\\(\\|[ \t]+body\\)\\|r\\(agma\\|ocedure\\)\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3605 "task\\(\\|[ \t]+body\\)"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3606 "\\)\\>[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3607 '(1 font-lock-keyword-face) '(6 font-lock-function-name-face nil t)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3608 "For consideration as a value of `ada-font-lock-keywords'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3609 This does fairly subdued highlighting.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3610
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3611 (defconst ada-font-lock-keywords-2
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3612 (append ada-font-lock-keywords-1
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3613 (list
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3614 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3615 ;; Main keywords, except those treated specially below.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3616 (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3617 ; ("abort" "abs" "abstract" "accept" "access" "aliased" "all"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3618 ; "and" "array" "at" "begin" "case" "declare" "delay" "delta"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3619 ; "digits" "do" "else" "elsif" "entry" "exception" "exit" "for"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3620 ; "generic" "if" "in" "is" "limited" "loop" "mod" "not"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3621 ; "null" "or" "others" "private" "protected"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3622 ; "range" "record" "rem" "renames" "requeue" "return" "reverse"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3623 ; "select" "separate" "tagged" "task" "terminate" "then" "until"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3624 ; "while" "xor")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3625 "a\\(b\\(ort\\|s\\(\\|tract\\)\\)\\|cce\\(pt\\|ss\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3626 "l\\(iased\\|l\\)\\|nd\\|rray\\|t\\)\\|begin\\|case\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3627 "d\\(e\\(clare\\|l\\(ay\\|ta\\)\\)\\|igits\\|o\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3628 "e\\(ls\\(e\\|if\\)\\|ntry\\|x\\(ception\\|it\\)\\)\\|for\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3629 "generic\\|i[fns]\\|l\\(imited\\|oop\\)\\|mod\\|n\\(ot\\|ull\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3630 "o\\(r\\|thers\\|ut\\)\\|pr\\(ivate\\|otected\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3631 "r\\(ange\\|e\\(cord\\|m\\|names\\|queue\\|turn\\|verse\\)\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3632 "se\\(lect\\|parate\\)\\|"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3633 "t\\(a\\(gged\\|sk\\)\\|erminate\\|hen\\)\\|until\\|while\\|xor"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3634 "\\)\\>")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3635 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3636 ;; Anything following end and not already fontified is a body name.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3637 '("\\<\\(end\\)\\>[ \t]*\\(\\sw+\\)?"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3638 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3639 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3640 ;; Variable name plus optional keywords followed by a type name. Slow.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3641 ; (list (concat "\\<\\(\\sw+\\)\\>[ \t]*:?[ \t]*"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3642 ; "\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)?[ \t]*"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3643 ; "\\(\\sw+\\)?")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3644 ; '(1 font-lock-variable-name-face)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3645 ; '(2 font-lock-keyword-face nil t) '(3 font-lock-type-face nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3646 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3647 ;; Optional keywords followed by a type name.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3648 (list (concat ; ":[ \t]*"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3649 "\\<\\(access\\|constant\\|in\\|in[ \t]+out\\|out\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3650 "[ \t]*"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3651 "\\(\\sw+\\)?")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3652 '(1 font-lock-keyword-face nil t) '(2 font-lock-type-face nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3653 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3654 ;; Keywords followed by a type or function name.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3655 (list (concat "\\<\\("
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3656 "new\\|of\\|subtype\\|type"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3657 "\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*\\((\\)?")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3658 '(1 font-lock-keyword-face)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3659 '(2 (if (match-beginning 4)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3660 font-lock-function-name-face
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3661 font-lock-type-face) nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3662 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3663 ;; Keywords followed by a (comma separated list of) reference.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3664 (list (concat "\\<\\(goto\\|raise\\|use\\|when\\|with\\)\\>"
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3665 ; "[ \t]*\\(\\sw+\\(\\.\\sw*\\)*\\)?") ; RE
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3666 "[ \t]*\\([a-zA-Z0-9_\\.\\|, ]+\\)\\W")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3667 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3668 ;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3669 ;; Goto tags.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3670 '("<<\\(\\sw+\\)>>" 1 font-lock-reference-face)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3671 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3672 "For consideration as a value of `ada-font-lock-keywords'.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3673 This does a lot more highlighting.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3674
10880
7c5fe757600b Use font-lock-maximum-decoration when setting ada-font-lock-keywords
Simon Marshall <simon@gnu.org>
parents: 10707
diff changeset
3675 (defvar ada-font-lock-keywords (if font-lock-maximum-decoration
7c5fe757600b Use font-lock-maximum-decoration when setting ada-font-lock-keywords
Simon Marshall <simon@gnu.org>
parents: 10707
diff changeset
3676 ada-font-lock-keywords-2
7c5fe757600b Use font-lock-maximum-decoration when setting ada-font-lock-keywords
Simon Marshall <simon@gnu.org>
parents: 10707
diff changeset
3677 ada-font-lock-keywords-1)
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3678 "*Expressions to highlight in Ada mode.")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3679
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3680 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3681 ;;; ????
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3682 ;;;
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3683 (defun ada-gen-comment-until-proc ()
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3684 ;; comment until spec of a procedure or a function.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3685 (forward-line 1)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3686 (set-mark-command (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3687 (if (re-search-forward ada-procedure-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3688 (progn (goto-char (match-beginning 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3689 (comment-region (mark) (point)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3690 (error "No more functions/procedures")))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3691
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3692
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3693 (defun ada-gen-treat-proc nil
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3694 ;; make dummy body of a procedure/function specification.
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3695 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3696 (let ((wend (point))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3697 (wstart (progn (re-search-backward "[ ][a-zA-Z0-9_\"]+" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3698 (+ (match-beginning 0) 1)))) ; delete leading WS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3699 (copy-region-as-kill wstart wend) ; store proc name in kill-buffer
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3700
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3701
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3702 ;; if the next notWS char is '(' ==> parameterlist follows
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3703 ;; if the next notWS char is ';' ==> no paramterlist
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3704 ;; if the next notWS char is 'r' ==> paramterless function, search ';'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3706 ;; goto end of regex before last (= end of procname)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3707 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3708 ;; look for next non WS
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3709 (backward-char)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3710 (re-search-forward "[ ]*.")
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3711 (if (char-equal (char-after (match-end 0)) ?\;)
10705
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3712 (delete-char 1) ;; delete the ';'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3713 ;; else
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3714 ;; find ');' or 'return <id> ;'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3715 (re-search-forward
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3716 "\\()[ \t]*;\\)\\|\\(return[ \t]+[a-zA-Z0-9_]+[ \t]*;\\)" nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3717 (goto-char (match-end 0))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3718 (delete-backward-char 1) ;; delete the ';'
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3719 )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3720
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3721 (insert " is")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3722 ;; if it is a function, we should generate a return variable and a
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3723 ;; return statement. Sth. like "Result : <return-type>;" and a
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3724 ;; "return Result;".
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3725 (ada-indent-newline-indent)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3726 (insert "begin -- ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3727 (yank)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3728 (newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3729 (insert "null;")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3730 (newline)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3731 (insert "end ")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3732 (yank)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3733 (insert ";")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3734 (ada-indent-newline-indent))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3735
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3736
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3737 (defun ada-gen-make-bodyfile (spec-filename)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3738 "Create a new buffer containing the correspondig Ada body
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3739 to the current specs."
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3740 (interactive "b")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3741 ;;; (let* (
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3742 ;;; (file-name (ada-body-filename spec-filename))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3743 ;;; (buf (get-buffer-create file-name)))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3744 ;;; (switch-to-buffer buf)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3745 ;;; (ada-mode)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3746 (ff-find-other-file t t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3747 ;;; (if (= (buffer-size) 0)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3748 ;;; (make-header)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3749 ;;; ;; make nothing, autoinsert.el had put something in already
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3750 ;;; )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3751 (end-of-buffer)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3752 (let ((hlen (count-lines (point-min) (point-max))))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3753 (insert-buffer spec-filename)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3754 ;; hlen lines have already been inserted automatically
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3755 )
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3756
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3757 (if (re-search-forward ada-package-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3758 (progn (goto-char (match-end 1))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3759 (insert " body"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3760 (error "No package"))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3761 ; (comment-until-proc)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3762 ; does not work correctly
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3763 ; must be done by hand
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3764
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3765 (while (re-search-forward ada-procedure-start-regexp nil t)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3766 (ada-gen-treat-proc))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3767
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3768 ; don't overwrite an eventually
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3769 ; existing file
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3770 ; (if (file-exists-p file-name)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3771 ; (error "File with this name already exists!")
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3772 ; (write-file file-name))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3773 ))
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3774
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3775 ;;; provide ourself
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3776
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3777 (provide 'ada-mode)
3d356714b662 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3778
10707
4a2ea4f52ea0 Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 10705
diff changeset
3779 ;;; ada-mode.el ends here