aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann1999-10-07 14:46:58 +0000
committerGerd Moellmann1999-10-07 14:46:58 +0000
commit00ce37149123aaf09333fc2b104bf1cdb7f5d742 (patch)
tree42ca489a771be1ab651b0ee707522768d2bc795e
parent92d91a2cab4335d48cf9c11062b2410672c549e4 (diff)
downloademacs-00ce37149123aaf09333fc2b104bf1cdb7f5d742.tar.gz
emacs-00ce37149123aaf09333fc2b104bf1cdb7f5d742.zip
New file.
-rw-r--r--man/ada-mode.texi1183
1 files changed, 1183 insertions, 0 deletions
diff --git a/man/ada-mode.texi b/man/ada-mode.texi
new file mode 100644
index 00000000000..f937921f28c
--- /dev/null
+++ b/man/ada-mode.texi
@@ -0,0 +1,1183 @@
1\input texinfo @c -*-texinfo-*-
2@setfilename ada-mode.info
3@settitle Ada Mode
4
5@ifinfo
6This file documents Ada mode.
7
8Permission is granted to make and distribute verbatim copies of this
9manual provided the copyright notice and this permission notice are
10preserved on all copies.
11
12@ignore
13Permission is granted to process this file through TeX and print the
14results, provided the printed document carries copying permission notice
15identical to this one except for the removal of this paragraph (this
16paragraph not being relevant to the printed manual).
17
18@end ignore
19Permission is granted to copy and distribute modified versions of this
20manual under the conditions for verbatim copying, provided that the
21entire resulting derived work is distributed under the terms of a
22permission notice identical to this one.
23
24Permission is granted to copy and distribute translations of this manual
25into another language, under same conditions as for modified versions.
26@end ifinfo
27
28@titlepage
29@sp 10
30@title{Ada Mode}
31@sp 2
32@subtitle An Emacs major mode for programming Ada 95 with GNAT
33@subtitle July 1998 for Ada Mode Version 3.0
34@sp 2
35
36@comment This is for the copyright page.
37@page
38@vskip 0pt plus 1filll
39
40Permission is granted to make and distribute verbatim copies of
41this manual provided the copyright notice and this permission notice
42are preserved on all copies.
43
44@ignore
45Permission is granted to process this file through TeX and print the
46results, provided the printed document carries copying permission
47notice identical to this one except for the removal of this paragraph
48(this paragraph not being relevant to the printed manual).
49
50@end ignore
51Permission is granted to copy and distribute modified versions of this
52manual under the conditions for verbatim copying, provided that the entire
53resulting derived work is distributed under the terms of a permission
54notice identical to this one.
55
56Permission is granted to copy and distribute translations of this manual
57into another language, under the same conditions as for modified versions.
58
59@end titlepage
60
61@node Top, Overview, (dir), (dir)
62
63@menu
64* Overview::
65* Installation:: Installing the Ada mode on your system
66* Customization:: Setting up the Ada mode to your taste
67* Project files:: Describing the organization of your project
68* Syntax highlighting:: Using specific colors and fonts to highlight
69 the structure of your files
70* Moving Through Ada Code:: Moving easily through Ada sources
71* Identifier completion:: Finishing words automatically
72* Index Menu of Subprograms:: A menu of all the types and subprograms
73 defined in your application
74* File Browser:: Easy access to your files
75* Automatic Smart Indentation:: Indenting your code automatically as you type
76* Formatting Parameter Lists:: Formating subprograms parameter lists
77 automatically
78* Automatic Casing:: Adjusting the case of words automatically
79* Statement Templates:: Inserting code templates
80* Comment Handling:: Reformatting comments easily
81* Compiling Executing:: Working with your application within Emacs
82* Debugging:: Debugging your application
83* Using non-standard file names:: Configuring Emacs for special file names
84* Working Remotely:: Working on a different machine
85@end menu
86
87
88@c -----------------------------------------------------------------------
89@node Overview, Installation, Top, Top
90@chapter Overview
91@c -----------------------------------------------------------------------
92
93The Emacs mode for programming in Ada 95 with GNAT helps the user in
94understanding existing code and facilitates writing new code. It
95furthermore provides some utility functions for easier integration of
96standard Emacs features when programming in Ada.
97
98@section General features:
99
100@itemize @bullet
101@item full Integrated Development Environment :
102@itemize @bullet
103@item support of 'project files' for the configuration (directories,
104compilation options,...)
105@item compiling and stepping through error messages.
106@item running and debugging your applications within Emacs.
107@end itemize
108@item easy to use for beginners by pull-down menus,
109@item user configurable by many user-option variables.
110@end itemize
111
112@section Ada mode features that help understanding code:
113
114@itemize @bullet
115@item functions for easy and quick stepping through Ada code,
116@item getting cross reference information for identifiers (e.g. find the
117defining place by a keystroke),
118@item displaying an index menu of types and subprograms and move point to
119the chosen one,
120@item automatic color highlighting of the various entities in Ada code.
121@end itemize
122
123@section Emacs support for writing Ada code:
124
125@itemize @bullet
126@item switching between spec and body files with eventually
127auto-generation of body files,
128@item automatic formating of subprograms parameter lists.
129@item automatic smart indentation according to Ada syntax,
130@item automatic completion of identifiers,
131@item automatic casing of identifiers, keywords, and attributes,
132@item insertion of statement templates,
133@item filling comment paragraphs like filling normal text,
134@end itemize
135
136@c -----------------------------------------------------------------------
137@node Installation, Customization, Overview, Top
138@chapter Installation
139@c -----------------------------------------------------------------------
140
141If you got the Ada mode as a separate distribution, you should have a
142look at the @file{README} file. It explains the basic steps necessary
143for a good installation of the emacs Ada mode.
144
145Installing the Ada mode is basically just a matter of copying a few
146files into the Emacs library directories. Every time you open a file
147with a file extension of @file{.ads} or @file{.adb}, Emacs will
148automatically load and activate the Ada mode.
149
150See the section @xref{Using non-standard file names} if your files do
151not use these extensions and if you want Emacs to automatically start the
152Ada mode every time you edit an Ada file.
153
154See also the Emacs documentation @xref{(emacs)} for general usage
155variables that you might want to set.
156
157@c ---------------------------------------------------------------------
158@section Required files
159@c ---------------------------------------------------------------------
160
161This Ada mode works best with Emacs 20.3 or higher (the easy editing
162features for the project files won't work with any older version), but
163most of the commands should work with older versions too. Please try to
164install the most recent version of Emacs on your system before
165installing the Ada mode.
166
167Although part of the Ada mode is compiler independent, the most advanced
168features are specific to the Gnat compiler @url{http://www.gnat.com}.
169
170The following files are provided with the Ada mode distribution:
171
172@itemize @bullet
173
174@item @file{ada-mode.el}: The main file for the Ada mode.
175This is the only file which does not require Gnat. It contains the
176functions for indentation, formatting of parameter lists, stepping
177through code, comment handling and automatic casing. Emacs versions
17820.2 and higher already contain Ada mode version 2.27, which is an older
179version of this file and should be replaced. Loading @file{ada-mode.el}
180from the current distribution supersedes the standard installation.
181
182@item @file{ada-stmt.el}: Contains the statement templates feature.
183
184@item @file{ada-xref.el}: This file provides the main support for Gnat.
185This is where the functions for cross-references, completion of
186identifiers, support for project files and compilation of your
187application are defined.
188
189@item @file{ada-prj.el}: The functions to use for easy-edition of the
190project files. This file is the only one which really requires Emacs at
191least 20.2. It uses the new widget features from Emacs.
192
193@end itemize
194
195@c --------------------------------------------------------------------
196@node Customization, Project files, Installation, Top
197@chapter Customizing the Ada mode
198@c ---------------------------------------------------------------------
199
200The ada-mode is fully customizable. Everything, from the file names to
201the automatic indentation and the automatic casing can be adapted to
202your own needs.
203
204There are two different kinds of variables that control this
205customization, both are easy to modify.
206
207The first set of variables are standard Emacs variables. Of course, some
208are defined only for the Ada mode, whereas others have a more general
209meaning in Emacs. Please see the Emacs documentation for more
210information on the latest. In this documentation, we will detail all the
211variables that are specific to the Ada mode, and a few others. The names
212will be given, as in @code{ada-case-identifier}.
213
214Emacs provides an easy way to modify them, through a special mode called
215customization. To access this mode, select the menu
216@kbd{Ada->Customize}. This will open a new buffer with some fields that
217you can edit. For instance, you will get something like:
218@example
219Put below the compiler switches.
220comp_opt= _____________________________________
221@end example
222The first line gives a brief description of the variable. The second
223line is the name of the variable and the field where you can give a
224value for this variable. Simply type what you want in the field.
225
226When you are finished modifying the variables, you can simply click on
227the @b{Save for future sessions} button at the top of the buffer (click
228with the middle mouse button). This will save the values in your
229@file{.emacs} file, so that next time you start Emacs they will have the
230same values.
231
232To modify a specific variable, you can directly call the function
233@code{customize-variable} from Emacs (just type @key{M-x
234customize-variable RET} and then type the variable name.
235
236Some users might prefer to modify the variables directly in their
237configuration file, @file{.emacs}. This file is coded in Emacs lisp, and
238the syntax to set a variable is the following:
239@example
240(setq variable-name value)
241@end example
242
243The second set of variables for customization are set through the use of
244project files. These variables are specific to a given project, whereas
245the first set was more general. For more information, please
246@xref{Project files}.
247
248@c ---------------------------------------------------------------------
249@node Project files, Syntax highlighting, Customization, Top
250@chapter Project files
251@c ---------------------------------------------------------------------
252
253@c ---------------------------------------------------------------------
254@section General overview
255@c ---------------------------------------------------------------------
256
257Emacs provides a full Integrated Development Environment for GNAT and
258Ada programmers. That is to say, editing, compiling, executing and
259debugging can be performed within Emacs in a convenient and natural way.
260
261To take full advantage of this features, it is possible to create a file
262in the main directory of your application, with a '.adp' extension.
263This file contain all needed information dealing with the way your
264application is organized between directories, the commands to compile,
265run and debug it etc. Creating this file is not mandatory and convenient
266defaults are automatically provided for simple setups. It only becomes
267necessary when those above mentioned defaults need customizing.
268
269A simple way to edit this file is provided for Emacs 20.2 or newer, with
270the following functions, that you can access also through the Ada
271menu. It is also possible to edit the project file as a regular text
272file.
273
274Once in the buffer for editing the project file, you can save your
275modification using the '[OK]' button at the bottom of the buffer, or
276simply use the usual @kbd{C-x C-s} binding. To cancel your
277modifications, simply kill the buffer or click on the '[CANCEL]' button
278at the button.
279
280Each buffer using Ada mode will be associated with one project file when
281there is one available, so that Emacs can easily navigate through
282related source files for instance.
283
284The exact algorithm to determine which project file should be used is
285described in the next section, but you can force the project file you
286want to use by setting one or two variables in your @file{.emacs} file.
287
288@itemize @bullet
289@item To set up a default project file to use for any directory, anywhere
290on your system, set the variable @code{ada-prj-default-project-file} to
291the name of that file.
292@example
293 (set 'ada-prj-default-project-file "/dir1/dir2/file")
294@end example
295
296@item For a finer controlled, you can set a per-directory project file.
297This is done through the variable @code{ada-xref-default-prj-file}.
298@example
299 (set 'ada-xref-default-prj-file
300 '(("/dir1/dir2" . "/dir3/file1")
301 ("/dir4/dir5" . "/dir6/file2")))
302@end example
303Note: This has a higher priority than the first variable, so the first
304choice is to use this variable settings, and otherwise
305@code{ada-prj-default-project-file}.
306@end itemize
307
308
309@table @kbd
310@item C-c u ada-customize menu: Ada->Project->New/Edit
311Create or edit the project file for the current buffer.
312@item C-c c ada-change-prj
313Change the project file associated with the current Ada buffer.
314@item C-c d
315Change the default project file for the current directory. Every new
316file opened from this directory will be associated with that file by
317default.
318@item ada-set-default-project-file menu: Ada->Project->Set Default
319Set the default project file to use for *any* Ada file opened anywhere
320on your system. This sets this file only for the current Emacs session.
321@end table
322
323@c ---------------------------------------------------------------------
324@section Project file variables
325@c ---------------------------------------------------------------------
326
327The following variables can be defined in a project file. They all have
328a default value, so that small projects do not need to create a project
329file.
330
331Some variables below can be referenced in other variables, using a
332shell-like notation. For instance, if the variable @code{comp_cmd}
333contains a sequence like @code{$@{comp_opt@}}, the value of that variable
334will be substituted.
335
336Here is the list of variables:
337
338@table @code
339@item src_dir [default: "./"]
340This is a list of directories where the Ada mode will look for source
341files. These directories are used mainly in two cases, both as a switch
342for the compiler and for the cross-references.
343
344@item obj_dir [default: "./"]
345This is a list of directories where to look for object and library
346files. The library files are the .ali files generated by Gnat and that
347contain cross-reference informations.
348
349@item comp_opt [default: ""]
350Creates a variable which can be referred to subsequently by using the
351@code{$@{comp_opt@}} notation. This is intended to store the default
352switches given to `gnatmake' and `gcc'.
353
354@item bind_opt=SWITCHES [default: ""]
355Creates a variable which can be referred to subsequently by using the
356@code{$@{bind_opt@}} notation. This is intended to store the default
357switches given to `gnatbind'.
358
359@item link_opt=SWITCHES [default: ""]
360Creates a variable which can be referred to subsequently by using the
361@code{$@{link_opt@}} notation. This is intended to store the default
362switches given to `gnatlink'.
363
364@item main=EXECUTABLE [default: ""]
365Specifies the name of the executable for the application. This variable
366can be referred to in the following lines by using the @code{$@{main@}}
367notation.
368
369@item cross_prefix=PREFIX [default: ""]
370This variable should be set if you are working in a cross-compilation
371environment. This is the prefix used in front of the gnatmake commands.
372
373@item remote_machine=MACHINE [default: ""]
374This is the name of the machine to log into before issuing the
375compilation command. If this variable is empty, the command will be run
376on the local machine. This will not work on Windows NT machines, since
377the Ada mode will simply precede the compilation command with a 'rsh'
378command, unknown on Windows.
379
380@item comp_cmd=COMMAND [default: "$@{cross_prefix@}gcc -c -I$@{src_dir@} -g -gnatq"]
381Specifies the command used to compile a single file in the application.
382The name of the file will be added at the end of this command.
383
384@item make_cmd=COMMAND [default: "$@{cross_prefix@}gnatmake $@{main@} -aI$@{src_dir@} -aO$@{obj_dir@} -g -gnatq -cargs $@{comp_opt@} -bargs $@{bind_opt@} -largs $@{link_opt@}"]'
385Specifies the command used to recompile the whole application.
386
387@item run_cmd=COMMAND [default: "$@{main@}"]
388Specifies the command used to run the application.
389
390@item debug_cmd=COMMAND [default: "$@{cross_prefix@}gdb $@{main@}"]
391Specifies the command used to debug the application
392
393@end table
394
395@c ---------------------------------------------------------------------
396@section Detailed algorithm
397@c ---------------------------------------------------------------------
398
399This section gives more details on the project file setup and is only of
400interest for advanced users.
401
402Usually, an Ada file is part of a larger application, whose sources and
403objects can be spread over multiple directories. The first time emacs is
404asked to compile, run or debug an application, or when a cross reference
405function is used (goto declaration for instance), the following steps
406are taken:
407
408@itemize @bullet
409@item find the appropriate project file, open and parse it.
410All the fields read in the project file are then stored by emacs
411locally. Finding the project file requires a few steps:
412
413@itemize @minus
414@item if a file from the same directory was already associated with
415a project file, use the same one. This is the variable
416@code{ada-xref-default-prj-file} described above.
417@item if the variable @code{ada-prj-default-project-file} is set,
418use the project file specified in this variable.
419@item if there is a project file whose name is the same as the source file
420 except for the suffix, use this one.
421@item if there's only one project file in the source directory, use
422that one.
423@item if there are more than one project file in the source directory,
424ask the user.
425@item if there are no project files in the source directory use standard
426default values.
427@end itemize
428
429The first project file that is selected in a given directory becomes the
430default project file for this directory and is used implicitly for other
431sources unless specified otherwise by the user.
432
433@item look for the corresponding .ali file in the @code{obj_dir} defined
434in the project file. If this file can not be found, emacs proposes to
435compile the source using the @code{comp_cmd} defined in the project file
436in order to create the ali file.
437
438@item when cross referencing is requested, the .ali file is parsed to
439determine the file and line of the identifier definition. It is
440possible for the .ali file to be older than the source file, in which
441case it will be recompiled if the variable @code{ada-xref-create-ali} is
442set, otherwise the reference is searched in the obsolete ali file with
443possible inaccurate results.
444
445@item look for the file containing the declaration using the source
446path @code{src_dir} defined in the project file. Put the cursor at the
447correct position and display this new cursor.
448@end itemize
449
450@c -----------------------------------------------------------------------
451@node Syntax highlighting, Moving Through Ada Code, Project files, Top
452@chapter Syntax highlighting
453@c -----------------------------------------------------------------------
454
455The Ada mode is made to help you understand the structure of your source
456files. Some people like having colors or different fonts depending on
457the context: commands should be displayed differently than keywords,
458which should also be different from strings, ...
459
460Emacs is able to display in a different way the following syntactic
461entities:
462
463@itemize @bullet
464@item keywords
465@item commands
466@item strings
467@item gnatprep statements (preprocessor)
468@item types (under certain conditions)
469@item other words
470@end itemize
471
472This is not the default behavior for Emacs. You have to explicitly
473activate it. This requires that you add a new line in your @file{.emacs}
474file (if this file does not exist, just create it).
475
476@example
477 (global-font-lock-mode t)
478@end example
479
480But the default colors might not be the ones you like. Fortunately,
481there is a very easy way to change them. Just select the menu
482@kbd{Help->Customize->Specific Face...} and press @kbd{Return}. This
483will display a buffer will all the "faces" (the colors) that Emacs knows
484about. You can change any of them.
485
486
487@c -----------------------------------------------------------------------
488@node Moving Through Ada Code, Identifier completion, Syntax highlighting, Top
489@chapter Moving Through Ada Code
490@c -----------------------------------------------------------------------
491
492There are several easy to use commands to stroll through Ada code. All
493these functions are available through the Ada menu, and you can also use
494the following key bindings or the command names:
495
496@table @kbd
497@item M-C-e ada-next-procedure
498Move to the next function/procedure/task, which ever comes next.
499@item M-C-a ada-previous-procedure
500Move to previous function/procedure/task.
501@item ada-next-package
502Move to next package.
503@item ada-prev-package
504Move to previous package.
505@item C-c C-a ada-move-to-start
506Move to matching start of @code{end}. If point is at the end of a
507subprogram, this command jumps to the corresponding @code{begin} if the
508user option @code{ada-move-to-declaration} is @code{nil} (default), it
509jumps to the subprogram declaration otherwise.
510@item C-c C-e ada-move-to-end
511Move point to end of current block.
512@item C-c o ff-find-other-file
513Switch between corresponding spec and body file. If the cursor is on a
514subprogram, switch between declaration and body.
515@item C-c c-d
516Move from any reference to its declaration and switch between
517declaration and body (for procedures, tasks, private and incomplete
518types).
519@item C-c C-r ada-find-references
520runs the @file{gnatfind} command to search for all references to the
521entity pointed by the cursor. Use 'next-error' function, or C-x `, to
522visit each reference (as for compilation errors).
523@end table
524
525These functions use the information in the output of the Gnat Ada
526compiler. However, if your application was compiled with the
527@code{-gnatx} switch, these functions will not work, since no extra
528information is generated by GNAT. See GNAT documentation for further
529information.
530
531Emacs will try to run Gnat for you whenever the cross-reference
532informations are older than your source file (provided the
533@code{ada-xref-create-ali} variable is non nil). Gnat then produces a
534file with the same name as the current Ada file but with the extension
535changed to @code{.ali}. This files are normally used by the binder, but
536they will also contain additional cross-referencing information.
537
538@c -----------------------------------------------------------------------
539@node Identifier completion, Index Menu of Subprograms, Moving Through Ada Code, Top
540@chapter Identifier completion
541@c -----------------------------------------------------------------------
542
543@c -----------------------------------------------------------------------
544@section Overview
545@c -----------------------------------------------------------------------
546
547Emacs and the Ada mode provide two general ways for the completion of
548identifiers. This is an easy way to type faster: you just have to type
549the first few letters of an identifiers, and then loop through all the
550possible completions.
551
552The first method is general for Emacs. It will work both with Ada
553buffers, but also in C buffers, Java buffers, ... The idea is to parse
554all the opened buffers for possible completions.
555
556For instance, if the following words are present in any of the opened
557files: my_identifier, my_subprogam, then you will have this scenario:
558@example
559You type: my@key{M-/}
560Emacs will display: my_identifier
561If you press @key{M-/} once again, Emacs will replace my_identifier with
562my_subprogram.
563Pressing @key{M-/} once more will bring you back to my_identifier.
564@end example
565
566This is a very fast way to do completion, and the casing of words will
567also be respected.
568
569The second method is specific to Ada buffer, and even to users of the
570Gnat compiler. Emacs will search the cross-information found in the .ali
571files generated by Gnat for possible completions.
572
573The main advantage is that this completion is more accurate: only
574existing identifier will be suggested, you don't need to have a file
575opened that already contains this identifiers,...
576
577On the other hand, this completion is a little bit slower and requires
578that you have compiled your file at least once since you created that
579identifier.
580
581@c -----------------------------------------------------------------------
582@section Summary of commands
583@c -----------------------------------------------------------------------
584
585@table @kbd
586@item C-TAB ada-complete-identifier
587complete accurately current identifier using information in .ali file
588@item M-/
589complete identifier using buffer information (not ada specific)
590@end table
591
592@c -----------------------------------------------------------------------
593@node Index Menu of Subprograms, File Browser, Identifier completion, Top
594@chapter Index Menu of Subprograms
595@c -----------------------------------------------------------------------
596
597You can display a choice menu with all procedure/function/task
598declarations in the file and choose an item by mouse click to get to its
599declaration. This function is accessible through the 'Ada' menu when
600editing a Ada file, or simply through the following key binding :
601
602@table @kbd
603@item C-S-mouse-3
604display index menu
605@end table
606
607@c -----------------------------------------------------------------------
608@node File Browser, Automatic Smart Indentation, Index Menu of Subprograms, Top
609@chapter File Browser
610@c -----------------------------------------------------------------------
611
612Emacs provides a special mode, called @code{speedbar}. When this mode is
613activated, a new frame is displayed, with a file browser. The files from
614the current directory are displayed, and you can click on them as you
615would with any file browser. The following commands are then available.
616
617You can click on a directory name or file name to open it. The editor
618will automatically select the best possible mode for this file,
619including of course the ada-mode for files written in Ada
620
621If you click on the [+] symbol near a file name, all the symbols (types,
622variables and subprograms) defined in that file will be displayed, and
623you can directly click on them to open the right file at the right
624place.
625
626You can activate this mode by typing @key{M-x speedbar} in the editor.
627This will open a new frame. A better way might be to assicate the
628following key binding
629
630@example
631(global-set-key [f7] 'speedbar-get-focus)
632@end example
633
634Every time you press @key{f7}, the mouse will automatically move to the
635speedbar frame (which will be created if it does not exist).
636
637@c -----------------------------------------------------------------------
638@node Automatic Smart Indentation, Formatting Parameter Lists, File Browser, Top
639@chapter Automatic Smart Indentation
640@c -----------------------------------------------------------------------
641
642The Ada mode comes with a full set of rules for automatic indentation.
643You can of course configure the indentation as you want, by setting the
644value of a few variables.
645
646As always, the preferred way to modify variables is to use the
647@code{Ada->Customize} menu (don't forget to save your changes!). This
648will also show you some example of code where this variable is used, and
649hopefully make things clearer.
650
651The relevant variables are the following:
652
653@table @code
654@item ada-broken-indent (default value: 2)
655Number of columns to indent the continuation of a broken line
656
657@item ada-indent (default value: 3)
658Width of the default indentation
659
660@item ada-indent-record-rel-type (default value: 3)
661Indentation for 'record' relative to 'type' or 'use'
662
663@item ada-indent-return (default value: 0)
664Indentation for 'return' relative to 'function' (if ada-indent-return
665is greater than 0), or the open parenthesis (if ada-indent-return is
666negative or null). Note that in the second case, when there is no
667open parenthesis, the indentation is done relative to 'function' with
668the value of ada-broken-indent.
669
670@item ada-label-indent (default value: -4)
671Number of columns to indent a label
672
673@item ada-stmt-end-indent (default value: 0)
674Number of columns to indent a statement 'end' keyword on a separate line
675
676@item ada-when-indent (default value: 3)
677Indentation for 'when' relative to 'exception' or 'case'
678
679@item ada-indent-is-separate (default value: t)
680Non-nil means indent 'is separate' or 'is abstract' if on a single line
681
682@item ada-indent-to-open-paren (default value: t)
683Non-nil means indent according to the innermost open parenthesis
684
685@item ada-indent-after-return (default value: t)
686Non-nil means that the current line will also be re-indented before
687inserting a newline, when you press @kbd{Return}.
688
689@end table
690
691Most of the time, the indentation will be automatic, i.e when you will
692press @kbd{Return}, the cursor will move to the correct column on the
693next line.
694
695However, you might want or need sometimes to re-indent the current line
696or a set of lines. For this, you can simply go to that line, or select
697the lines, and then press @kbd{TAB}. This will automatically re-indent
698the lines.
699
700Another mode of indentation exists that helps you to set up your
701indentation scheme. If you press @kbd{C-c TAB}, the ada-mode will do the
702following:
703@itemize @bullet
704@item Reindent the current line, as @kbd{TAB} would do
705@item Temporarily move the cursor to a reference line, i.e the line that
706 was used to calculate the current indentation
707@item Display at the bottom of the window the name of the variable that
708 provided the offset for the indentation
709@end itemize
710
711The exact indentation of the current line is the same as the one for the
712reference line, plus an offset given by the variable.
713
714Once you know the name of the variable, you can either modify it through
715the usual @key{Ada->Customize} menu, or by typing @key{M-x
716customize-variable RET} in the Emacs window, and then give the name of
717the variable.
718
719@table @kbd
720@item TAB
721indent the current line or the current region.
722@item M-C-\
723indent lines in the current selected block.
724@item C-c TAB
725indent the current line and prints the name of the variable used for
726indentation.
727@end table
728
729
730
731@c -----------------------------------------------------------------------
732@node Formatting Parameter Lists, Automatic Casing, Automatic Smart Indentation, Top
733@chapter Formatting Parameter Lists
734@c -----------------------------------------------------------------------
735
736To help you correctly align fields in a subprogram parameter list, Emacs
737provides one function that will do most of the work for you. This
738function will align the declarations on the colon (':') separating
739argument names and argument types, plus align the 'in', 'out' and 'in
740out' keywords if required.
741
742@table @kbd
743@item C-c C-f ada-format-paramlist
744Format the parameter list.
745@end table
746
747@c -----------------------------------------------------------------------
748@node Automatic Casing, Statement Templates, Formatting Parameter Lists, Top
749@chapter Automatic Casing
750@c -----------------------------------------------------------------------
751
752Casing of identifiers, attributes and keywords is automatically
753performed while typing when the variable @code{ada-auto-case} is set.
754Every time you press a word separator, the previous word is
755automatically cased.
756
757You can customize the automatic casing differently for keywords,
758attributes and identifiers. The relevant variables are the following:
759@code{ada-case-keyword}, @code{ada-case-attribute} and
760@code{ada-case-identifier}.
761
762All these variables can have one of the following values:
763
764@table @kbd
765@item downcase-word
766The previous word will simply be in all lower cases. For instance
767@code{My_vARIable} is converted to @code{my_variable}.
768
769@item upcase-word
770The previous word will be fully converted to upper cases. For instance
771@code{My_vARIable} is converted to @code{MY_VARIABLE}.
772
773@item ada-capitalize-word
774All letters, except the first one of the word and every letter after the
775'_' character are lower cased. Other letters are upper cased. For
776instance @code{My_vARIable} is converted to @code{My_Variable}.
777
778@item ada-loose-case-word
779No letters is modified in the previous word, except the ones after the
780'_' character that are upper cased. For instance @code{My_vARIable} is
781converted to @code{My_VARIable}.
782@end table
783
784These functions, although they will work in most cases, will not be
785accurate sometimes. The Ada mode allows you to define some exceptions,
786that will always be cased the same way.
787
788The idea is to create a dictionary of exceptions, and store it in a
789file. This file should contain one identifier per line, with the casing
790you want to force. The default name for this file is
791@file{~/.emacs_case_exceptions}. You can of course change this name,
792through the variable @code{ada-case-exception-file}.
793
794Note that each line in this file must start with the key word whose
795casing you want to specify. The rest of the line can be used for
796comments (explaining for instance what an abbreviation means, as
797recommended in the Ada 95 Quality and Style, paragrpah 3.1.4). Thus, a
798good example for this file could be:
799
800@example
801DOD Department of Defense
802Text_IO
803GNAT The GNAT compiler from Ada Core Technologies
804@end example
805
806When working on project involving multiple programmers, we recommend
807that every member of the team sets this variable to the same value,
808which should point to a system-wide file that each of them can
809write. That way, you will ensure that the casing is consistent
810throughout your application(s).
811
812There are two ways to add new items to this file: you can simply edit it
813as you would edit any text file, and add or suppress entries in this
814file. Remember that you should put one entity per line. The other,
815easier way, is to position the cursor over the word you want to add, in
816an Ada buffer. This word should have the casing you want. Then simply
817select the menu @kbd{Ada->Edit->Create Case Exception}, or the key
818@kbd{C-c C-y}. The word will automatically be added to the current list
819of exceptions and to the file.
820
821It is sometimes useful to have multiple exception files around (for
822instance, one could be the standard Ada acronyms, the second some
823company specific exceptions, and the last one some project specific
824exceptions). If you set up the variable @code{ada-case-exception-file}
825as a list of files, each of them will be parsed and used in your emacs
826session.
827
828However, when you save a new exception through the menu, as described
829above, the new exception will be added to the first file in the list
830only. You can not automatically add an exception to one of the other
831files, although you can of course edit the files by hand at any time.
832
833Automatic casing can be performed on port or whole buffer using:
834@table @kbd
835@item C-c C-b
836Adjust case in the whole buffer.
837@item C-c C-y
838Create a new entry in the exception dictionary, with the word under
839the cursor
840@item C-c C-t
841Rereads the exception dictionary from the file
842@code{ada-case-exception-file}.
843@end table
844
845@c -----------------------------------------------------------------------
846@node Statement Templates, Comment Handling, Automatic Casing, Top
847@chapter Statement Templates
848@c -----------------------------------------------------------------------
849
850NOTE: This features are not available on VMS for Emacs 19.28. The
851functions used here do not exist on Emacs 19.28.
852
853Templates exist for most Ada statements. They can be inserted in the
854buffer using the following commands:
855
856@table @kbd
857@item C-c t b
858exception Block
859@item C-c t c
860case.
861@item C-c t d
862declare Block.
863@item C-c t e
864else.
865@item C-c t f
866for Loop.
867@item C-c t h
868Header.
869@item C-c t i
870if.
871@item C-c t k
872package Body.
873@item C-c t l
874loop.
875@item C-c t t
876task Body.
877@item C-c t w
878while Loop.
879@item C-c t u
880use.
881@item C-c t x
882exit.
883@item C-c t C-a
884array.
885@item C-c t C-e
886elsif.
887@item C-c t C-f
888function Spec.
889@item C-c t C-k
890package Spec.
891@item C-c t C-p
892procedure Spec.
893@item C-c t C-r
894record.
895@item C-c t C-s
896subtype.
897@item C-c t C-t
898task Spec.
899@item C-c t C-u
900with.
901@item C-c t C-v
902private.
903@item C-c t C-w
904when.
905@item C-c t C-x
906exception.
907@item C-c t C-y
908type.
909@end table
910
911@c -----------------------------------------------------------------------
912@node Comment Handling, Compiling Executing, Statement Templates, Top
913@chapter Comment Handling
914@c -----------------------------------------------------------------------
915
916By default, comment lines get indented like Ada code. There are a few
917additional functions to handle comments:
918
919
920@table @kbd
921@item M-;
922Start a comment in default column.
923@item M-j
924Continue comment on next line.
925@item C-c ; comment-region
926Comment the selected region (add -- at the beginning of lines).
927@item C-c :
928Uncomment the selected region
929@item M-q
930autofill the current comment.
931@end table
932
933@c -----------------------------------------------------------------------
934@node Compiling Executing, Debugging, Comment Handling, Top
935@chapter Compiling Executing
936@c -----------------------------------------------------------------------
937
938Ada mode provides a much complete environment for compiling, debugging
939and running an application within Emacs.
940
941All the commands used by Emacs to manipulate your application can be
942customized in the project file. Some default values are provided, but
943these will likely not be good enough for a big or even medium-sized
944project. See the section on the project file for an explanation on how
945to set up the commands to use.
946
947One of the variables you can set in your project file,
948@code{cross_prefix}, indicates whether you are using a cross-compilation
949environment, and if yes for which target. The default command used for
950compilation will add this @code{cross_prefix} in front of the name:
951@code{gcc} will become @code{cross_prefix}-@code{gcc}, @code{gnatmake}
952will become @code{cross_prefix}-@code{gnatmake}, ...
953
954This will also modify the way your application is run and debugged,
955although this is not implemented at the moment.
956
957Here are the commands for building and using an Ada application
958
959@itemize @bullet
960
961@item Compiling the current source
962This command is issued when issuing the @code{compile} command from the
963Ada menu. It compiles unconditionally the current source using the
964@code{comp_cmd} variable of the project file. Compilation options can be
965customized with the variable @code{comp_opt} of the project file.
966
967Emacs will display a new buffer that contains the result of the
968compilation. Each line associated with an error will become active: you
969can simply click on it with the middle button of the mouse, or move the
970cursor on it and press @kbd{Return}. Emacs will then display the
971relevant source file and put the cursor on the line and column the error
972was found at.
973
974You can also simply press the @kbd{C-x `} key and Emacs will jump to the
975first error. If you press that key again, it will move you to the second
976error, and so on.
977
978Some error messages might also include references to some files. These
979references are also clickable in the same way.
980
981
982@item (Re)building the whole application
983This command is issued when you select the @code{build} command from the
984Ada menu. It compiles all obsolete units of the current application
985using the @code{make_cmd} variable of the project file. Compilation
986options can be customized with the variable @code{comp_opt} of the
987project file, binder options with @code{bind_opt} and linker options
988with @code{link_opt}. The main unit of the application may be specified
989with @code{main}.
990
991The compilation buffer is also active in the same way it was for the above
992command.
993
994@item Running the application
995This command is issued when you select the @code{run} command from the
996Ada menu. It executes the current application in an emacs
997buffer. Arguments can be passed through before executing. The execution
998buffer allows for interactive input/output.
999
1000This command is not yet available in a cross-compilation
1001toolchain. Emacs would first need to log on the target before running
1002the application. This will be implemented in a future release of Gnat.
1003
1004@end itemize
1005
1006@c ---------------------------------------------------------------------
1007@node Debugging, Using non-standard file names, Compiling Executing, Top
1008@chapter Debugging your application
1009@c ---------------------------------------------------------------------
1010
1011You can set up in the project file a command to use to debug your
1012application. Emacs is compatible with a lot of debuggers, and provide an
1013easy interface to them.
1014
1015This selection will focus on the gdb debugger, and two of the graphical
1016interfaces that exist for it.
1017
1018In all cases, the main window in Emacs will be split in two: in the
1019upper buffer, the source code will appear, whereas the debugger
1020input/output window is displayed at the bottom. You can enter the
1021debugger commands as usual in the command window. Every time a new
1022source file is selected by the debugger (for instance as a result of a
1023@code{frame} command), the appropriate source file is displayed in the
1024upper buffer.
1025
1026The source window is interactive: you can click on an identifier with the
1027right mouse button, and print its value in the debugger window. You can
1028also set a breakpoint simply by right-clicking on a line.
1029
1030You can easily use Emacs as the source window when you are using a
1031graphical interface for the debugger. The interesting thing is that,
1032whereas you still have the graphical nifties, you can also you the
1033cross-references features that the ada-mode provides to look at the
1034definition for the identifiers,...
1035
1036Here is how you can set up gdbtk and ddd for use with Emacs (These are
1037the commands you should setup in the project file):
1038
1039@itemize @bullet
1040@item gdbtk
1041should be used with the switch --emacs_gdbtk. It provides a nice
1042backtrace window, as well as a tasks window. You can click interactively
1043on both of them, and Emacs will display the source file on the correct
1044line.
1045
1046@item ddd (Data Display Debugger)
1047should be used with the switches --tty and -fullname. Whenever you
1048print a variable from Emacs, it will be displayed graphically in the
1049data window.
1050
1051@end itemize
1052
1053
1054@c ---------------------------------------------------------------------
1055@node Using non-standard file names, Working Remotely, Debugging, Top
1056@chapter Using non-standard file names
1057@c ---------------------------------------------------------------------
1058
1059By default, Emacs is configured to use the GNAT style file names, where
1060file names are the package names, and the extension for spec and bodies
1061are respectively .ads and .adb.
1062
1063If you want to use other types of file names, you will need to modify
1064your .emacs configuration file.
1065
1066Adding new possible extensions is easy. Since the ada-mode needs to know
1067how to go from the body to the spec (and back), you always have to
1068specify both. A function is provided with the ada-mode to add new
1069extensions.
1070
1071For instance, if your files are called <unit>_s.ada and <unit>_b.ada
1072respectively for spec and bodies, you need to add the following to your
1073@file{.emacs} :
1074
1075@example
1076(ada-add-extensions "_s.ada" "_b.ada")
1077@end example
1078
1079Note that it is possible to redefine the extension, even if they already
1080exist, as in:
1081
1082@example
1083(ada-add-extensions ".ads" "_b.ada")
1084(ada-add-extensions ".ads" ".body")
1085@end example
1086
1087This simply means that whenever the ada-mode will look for the body for
1088a file whose extension is @file{.ads}, it will take the first available
1089file that ends with either @file{.adb} (standard), @file{_b.ada} or
1090@file{.body}.
1091
1092If the filename is not the unit name, then things are a little more
1093complicated. You then need to rewrite the function
1094ada-make-filename-from-adaname (see the file @file{ada-mode.el} for an
1095example).
1096
1097@c ---------------------------------------------------------------------
1098@node Working Remotely, ,Using non-standard file names, Top
1099@chapter Working Remotely
1100@c ---------------------------------------------------------------------
1101
1102When you work on project that involve a lot of programmers, it is
1103generally the case that you will edit the files on your own machine, but
1104you want to compile, run and debug your application in another buffer.
1105
1106Fortunately, here too Emacs provides a very convenient way to do this.
1107
1108@c ---------------------------------------------------------------------
1109@section Remote editing
1110@c ---------------------------------------------------------------------
1111
1112First of all, the files do not need to be on your machine. Emacs can
1113edit any remote file, by doing transparent FTP sessions between your
1114machine and the remote machine that stores your files. This is a special
1115Emacs mode, called @code{ange-ftp}. To use it, you just have to use a
1116slightly different syntax when you open a file.
1117
1118@example
1119For instance, if you want to open the file /work/foo.adb on the machine
1120aleph.gnu.org, where you log in as qwe, you would simply do this:
1121
1122@key{C-x C-f} /qwe@@aleph.gnu.org:/work/foo.adb @key{Return}
1123
1124i.e put your name, the name of the machine and the name of the file.
1125@end example
1126
1127The first time, Emacs will ask you for a password that it will remember
1128until you close the current Emacs. Even if the ftp session times out,
1129you won't need to reenter your password.
1130
1131Every time you save the file, Emacs will upload it to the remote machine
1132transparently. No file is modified on the local machine.
1133
1134@c ---------------------------------------------------------------------
1135@section Remote compiling
1136@c ---------------------------------------------------------------------
1137
1138If the machine you want to compile on is not the one your Emacs is
1139running on, you can set the variable @code{remote_machine} in the
1140project file for your application.
1141
1142This will force Emacs to issue a rsh command for the compilation,
1143instead of running it on the local machine. Unfortunately, this won't
1144work on Windows workstations, since this protocol is not supported.
1145
1146@example
1147If your @code{remote_machine} is aleph.gnu.org and the standard
1148compilation command is @code{cd /work/ && gnatmake foo}, then Emacs will
1149actually issue the command @code{rsh aleph.gnu.org 'cd /work/ &&
1150gnatmake foo'}.
1151@end example
1152
1153The advantage of using the @code{remote_machine} variable is that it is
1154easier to change that machine without having to modify the compilation
1155command.
1156
1157Note that if you need to set up some environment variables before the
1158compilation, you need to insert a call to the appropriate initialization
1159script in the compilation command, for instance:
1160
1161@example
1162build_cmd= initialization_script ; cd /work/ && gnatmake foo
1163@end example
1164
1165@c ---------------------------------------------------------------------
1166@section Remote running and debugging
1167@c ---------------------------------------------------------------------
1168
1169This feature is not completely implemented yet.
1170
1171However, most of the time, you will be able to run your application
1172remotely simply by replacing it with a 'rsh' call on Unix.
1173
1174@example
1175For instance, if your command was '$@{main@}', you could replace it with
1176'rsh aleph.gnu.org $@{main@}'.
1177@end example
1178
1179However, this would not fully work for instance on vxworks, where rsh
1180is not supported.
1181
1182@contents
1183@bye