2009-01-31 Carsten Dominik <carsten.dominik@gmail.com>
[bpt/emacs.git] / doc / misc / ada-mode.texi
CommitLineData
4009494e 1\input texinfo @c -*-texinfo-*-
db78a8cb 2@setfilename ../../info/ada-mode
4009494e
GM
3@settitle Ada Mode
4
5@copying
6Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004,
71dd9983 72005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4009494e
GM
8
9@quotation
10Permission is granted to copy, distribute and/or modify this document
6a2c4aec 11under the terms of the GNU Free Documentation License, Version 1.3 or
7b2d06e1
GM
12any later version published by the Free Software Foundation; with no
13Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
14and with the Back-Cover Texts as in (a) below. A copy of the license
15is included in the section entitled ``GNU Free Documentation License''.
4009494e 16
6f093307
GM
17(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
18modify this GNU manual. Buying copies from the FSF supports it in
19developing GNU and promoting software freedom.''
4009494e
GM
20@end quotation
21@end copying
22
23@dircategory Emacs
24@direntry
25* Ada mode: (ada-mode). Emacs mode for editing and compiling Ada code.
26@end direntry
27
28@titlepage
29@sp 10
30@title{Ada Mode}
31@sp 2
32@subtitle An Emacs major mode for programming in Ada
d5875b25 33@subtitle Ada Mode Version 4.00
4009494e
GM
34@sp 2
35@page
36@vskip 0pt plus 1filll
37@insertcopying
38@end titlepage
39
40@c fixme; title page doesn't show up in ada-mode.info; why bother with
41@c it?
42
43@node Top, Overview, (dir), (dir)
44
45@menu
46* Overview::
47* Installation:: Installing Ada mode on your system
48* Customization:: Setting up Ada mode to your taste
49* Compiling Executing:: Working with your application within Emacs
50* Project files:: Describing the organization of your project
51* Compiling Examples:: A small tutorial
52* Moving Through Ada Code:: Moving easily through Ada sources
53* Identifier completion:: Finishing words automatically
54* Automatic Smart Indentation:: Indenting your code automatically as you type
55* Formatting Parameter Lists:: Formatting subprograms' parameter lists
56 automatically
57* Automatic Casing:: Adjusting the case of words automatically
58* Statement Templates:: Inserting code templates
59* Comment Handling:: Reformatting comments easily
d5875b25 60* GNU Free Documentation License:: The license for this documentation.
4009494e
GM
61* Index::
62@end menu
63
64
65@node Overview, Installation, Top, Top
66@chapter Overview
67
68The Emacs mode for programming in Ada helps the user in understanding
69existing code and facilitates writing new code.
70
71When the Gnu Ada compiler GNAT is used, the cross-reference
72information output by the compiler is used to provide powerful code
73navigation (jump to definition, find all uses, etc).
74
75When you open a file with a file extension of @file{.ads} or
76@file{.adb}, Emacs will automatically load and activate Ada mode.
77
78Ada mode works without any customization, if you are using the GNAT
79compiler (@url{https://libre2.adacore.com/}) and the GNAT default
80naming convention.
81
82You must customize a few things if you are using a different compiler
83or file naming convention; @xref{Other compiler}, @xref{Non-standard
84file names}.
85
86In addition, you may want to customize the indentation,
87capitalization, and other things; @xref{Other customization}.
88
89Finally, for large Ada projects, you will want to set up an Emacs
90Ada mode project file for each project; @xref{Project files}. Note
91that these are different from the GNAT project files used by gnatmake
92and other GNAT commands.
93
94See the Emacs info manual, section 'Running Debuggers Under Emacs',
95for general information on debugging.
96
97@node Installation, Customization, Overview, Top
98@chapter Installation
99
100Ada mode is part of the standard Emacs distribution; if you use that,
101no files need to be installed.
102
103Ada mode is also available as a separate distribution, from the Emacs
104Ada mode website
105@uref{http://stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html}. The
106separate distribution may be more recent.
107
108For installing the separate distribution, see the @file{README} file
109in the distribution.
110
111To see what version of Ada mode you have installed, do @key{M-x
112ada-mode-version}.
113
114The following files are provided with the Ada mode distribution:
115
116@itemize @bullet
117
118@item
119@file{ada-mode.el}: The main file for Ada mode, providing indentation,
120formatting of parameter lists, moving through code, comment handling
121and automatic casing.
122
123@item
124@file{ada-prj.el}: GUI editing of Ada mode project files, using Emacs
125widgets.
126
127@item
128@file{ada-stmt.el}: Ada statement templates.
129
130@item
131@file{ada-xref.el}: GNAT cross-references, completion of identifiers,
132and compilation. Also provides project files (which are not
133GNAT-specific).
134
135@end itemize
136
137@node Customization, Compiling Executing, Installation, Top
138@chapter Customizing Ada mode
139
140Here we assume you are familiar with setting variables in Emacs,
141either thru 'customize' or in elisp (in your @file{.emacs} file). For
142a basic introduction to customize, elisp, and Emacs in general, see
143the tutorial in
144@iftex
145@cite{The GNU Emacs Manual}.
146@end iftex
147@ifhtml
148@cite{The GNU Emacs Manual}.
149@end ifhtml
150@ifinfo
151@ref{Top, , The GNU Emacs Manual, emacs, The GNU Emacs Manual}.
152@end ifinfo
153
154These global Emacs settings are strongly recommended (put them in your
155.emacs):
156
157@example
158(global-font-lock-mode t)
159(transient-mark-mode t)
160@end example
161
162@samp{(global-font-lock-mode t)} turns on syntax
163highlighting for all buffers (it is off by default because it may be
164too slow for some machines).
165
166@samp{(transient-mark-mode t)} highlights selected text.
167
168See the Emacs help for each of these variables for more information.
169
170@menu
171* Non-standard file names::
172* Other compiler::
173* Other customization::
174@end menu
175
176@node Non-standard file names, Other compiler, Customization, Customization
177@section Non-standard file names
178
179By default, Ada mode is configured to use the GNAT file naming
180convention, where file names are a simple modification of the Ada
181names, and the extension for specs and bodies are
182@samp{.ads} and @samp{.adb}, respectively.
183
184Ada mode uses the file extentions to allow moving from a package body
185to the corresponding spec and back.
186
187Ada mode supports a list of alternative file extensions for specs and bodies.
188
189For instance, if your spec and bodies files are called
190@file{@var{unit}_s.ada} and @file{@var{unit}_b.ada}, respectively, you
191can add the following to your @file{.emacs} file:
192
193@example
194(ada-add-extensions "_s.ada" "_b.ada")
195@end example
196
197You can define additional extensions:
198
199@example
200(ada-add-extensions ".ads" "_b.ada")
201(ada-add-extensions ".ads" ".body")
202@end example
203
204This means that whenever Ada mode looks for the body for a file
205whose extension is @file{.ads}, it will take the first available file
206that ends with either @file{.adb}, @file{_b.ada} or
207@file{.body}.
208
209Simililarly, if Ada mode is looking for a spec, it will look for
210@file{.ads} or @file{_s.ada}.
211
212If the filename is not derived from the Ada name following the GNAT
213convention, things are a little more complicated. You then need to
214rewrite the function @code{ada-make-filename-from-adaname}. Doing that
215is beyond the scope of this manual; see the current definitions in
216@file{ada-mode.el} and @file{ada-xref.el} for examples.
217
218@node Other compiler, Other customization, Non-standard file names, Customization
219@section Other compiler
220
221By default, Ada mode is configured to use the Gnu Ada compiler GNAT.
222
223To use a different Ada compiler, you must specify the command lines
224used to run that compiler, either in lisp variables or in Emacs
225Ada mode project files. See @ref{Project file variables} for the list
226of project variables, and the corresponding lisp variables.
227
228@node Other customization, , Other compiler, Customization
229@section Other customization
230
231All user-settable Ada mode variables can be set via the menu
232@samp{Ada | Customize}. Click on the @samp{Help} button there for help
233on using customize.
234
235To modify a specific variable, you can directly call the function
236@code{customize-variable}; just type @kbd{M-x customize-variable
237@key{RET} @var{variable-name} @key{RET}}).
238
239Alternately, you can specify variable settings in the Emacs
240configuration file, @file{.emacs}. This file is coded in Emacs lisp,
241and the syntax to set a variable is the following:
242@example
243(setq variable-name value)
244@end example
245
246@node Compiling Executing, Project files, Customization, Top
247@chapter Compiling Executing
248
249Ada projects can be compiled, linked, and executed using commands on
250the Ada menu. All of these commands can be customized via a project
251file (@pxref{Project files}), but the defaults are sufficient for using
252the GNAT compiler for simple projects (single files, or several files
253in a single directory).
254
255Even when no project file is used, the GUI project editor (menu
256@key{Ada | Project | Edit}) shows the settings of the various project
257file variables referenced here.
258
259@menu
260* Compile commands::
261* Compiler errors::
262@end menu
263
264@node Compile commands, Compiler errors, Compiling Executing, Compiling Executing
265@section Compile commands
266
267Here are the commands for building and using an Ada project, as
268listed in the Ada menu.
269
270In multi-file projects, there must be one file that is the main
d5875b25 271program. That is given by the @code{main} project file variable;
4009494e
GM
272it defaults to the current file if not yet set, but is also set by the
273``set main and build'' command.
274
275@table @code
276
277@item Check file
278Compiles the current file in syntax check mode, by running
279@code{check_cmd} defined in the current project file. This typically
280runs faster than full compile mode, speeding up finding and fixing
281compilation errors.
282
d5875b25 283This sets @code{main} only if it has not been set yet.
4009494e
GM
284
285@item Compile file
286Compiles the current file, by running @code{comp_cmd} from the current
287project file.
288
d5875b25 289This does not set @code{main}.
4009494e
GM
290
291@item Set main and Build
d5875b25 292Sets @code{main} to the current file, then executes the Build
4009494e
GM
293command.
294
295@item Show main
d5875b25 296Display @code{main} in the message buffer.
4009494e
GM
297
298@item Build
d5875b25
JB
299Compiles all obsolete units of the current @code{main}, and links
300@code{main}, by running @code{make_cmd} from the current project.
4009494e 301
d5875b25 302This sets @code{main} only if it has not been set yet.
4009494e
GM
303
304@item Run
305Executes the main program in a shell, displayed in a separate Emacs
306buffer. This runs @code{run_cmd} from the current project. The
307execution buffer allows for interactive input/output.
308
309To modify the run command, in particular to provide or change the
310command line arguments, type @key{C-u} before invoking the command.
311
312This command is not available for a cross-compilation toolchain.
313
314@end table
315It is important when using these commands to understand how
d5875b25 316@code{main} is used and changed.
4009494e
GM
317
318Build runs 'gnatmake' on the main unit. During a typical edit/compile
319session, this is the only command you need to invoke, which is why it
320is bound to @key{C-c C-c}. It will compile all files needed by the
321main unit, and display compilation errors in any of them.
322
323Note that Build can be invoked from any Ada buffer; typically you will
324be fixing errors in files other than the main, but you don't have to
325switch back to the main to invoke the compiler again.
326
327Novices and students typically work on single-file Ada projects. In
328this case, @key{C-c C-m} will normally be the only command needed; it
329will build the current file, rather than the last-built main.
330
d5875b25 331There are three ways to change @code{main}:
4009494e
GM
332
333@enumerate
334@item
d5875b25 335Invoke @key{Ada | Set main and Build}, which sets @code{main} to
4009494e
GM
336the current file.
337
338@item
d5875b25 339Invoke @key{Ada | Project | Edit}, edit @code{main} and
4009494e
GM
340@code{main}, and click @key{[save]}
341
342@item
d5875b25 343Invoke @key{Ada | Project | Load}, and load a project file that specifies @code{main}
4009494e
GM
344
345@end enumerate
346
347@node Compiler errors, , Compile commands, Compiling Executing
348@section Compiler errors
349
350The @code{Check file}, @code{Compile file}, and @code{Build} commands
351all place compilation errors in a separate buffer named
352@code{*compilation*}.
353
354Each line in this buffer will become active: you can simply click on
355it with the middle button of the mouse, or move point to it and press
356@key{RET}. Emacs will then display the relevant source file and put
357point on the line and column where the error was found.
358
359You can also press the @kbd{C-x `} key (@code{next-error}), and Emacs
360will jump to the first error. If you press that key again, it will
361move you to the second error, and so on.
362
363Some error messages might also include references to other files. These
364references are also clickable in the same way, or put point after the
365line number and press @key{RET}.
366
367@node Project files, Compiling Examples, Compiling Executing, Top
368@chapter Project files
369
370An Emacs Ada mode project file specifies what directories hold sources
371for your project, and allows you to customize the compilation commands
372and other things on a per-project basis.
373
374Note that Ada mode project files @samp{*.adp} are different than GNAT
d5875b25
JB
375compiler project files @samp{*.gpr}. However, Emacs Ada mode can use a
376GNAT project project file to specify the project directories. If no
377other customization is needed, a GNAT project file can be used without
378an Emacs Ada mode project file.
4009494e
GM
379
380@menu
381* Project File Overview::
382* GUI Editor::
383* Project file variables::
384@end menu
385
386@node Project File Overview, GUI Editor, Project files, Project files
387@section Project File Overview
388
389Project files have a simple syntax; they may be edited directly. Each
390line specifies a project variable name and its value, separated by ``='':
391@example
392src_dir=/Projects/my_project/src_1
393src_dir=/Projects/my_project/src_2
394@end example
395
396Some variables (like @code{src_dir}) are lists; multiple occurances
397are concatenated.
398
399There must be no space between the variable name and ``='', and no
400trailing spaces.
401
402Alternately, a GUI editor for project files is available (@pxref{GUI
403Editor}). It uses Emacs widgets, similar to Emacs customize.
404
405The GUI editor also provides a convenient way to view current project
406settings, if they have been modified using menu commands rather than
407by editing the project file.
408
409After the first Ada mode build command is invoked, there is always a
410current project file, given by the lisp variable
411@code{ada-prj-default-project-file}. Currently, the only way to show
412the current project file is to invoke the GUI editor.
413
414To find the project file the first time, Ada mode uses the following
415search algorithm:
416
417@itemize @bullet
418@item
419If @code{ada-prj-default-project-file} is set, use that.
420
421@item
422Otherwise, search for a file in the current directory with
423the same base name as the Ada file, but extension given by
424@code{ada-prj-file-extension} (default @code{".adp"}).
425
426@item
427If not found, search for @file{*.adp} in the current directory; if
428several are found, prompt the user to select one.
429
430@item
431If none are found, use @file{default.adp} in the current directory (even
432if it does not exist).
433
434@end itemize
435
436This algorithm always sets @code{ada-prj-default-project-file}, even
437when the file does not actually exist.
438
439To change the project file before or after the first one is found,
440invoke @key{Ada | Project | Load ...}.
441
d5875b25 442Or, in lisp, evaluate @code{(ada-set-default-project-file "/path/file.adp")}.
4009494e
GM
443This sets @code{ada-prj-default-project-file}, and reads the project file.
444
d5875b25
JB
445You can also specify a GNAT project file to @key{Ada | Project | Load
446...} or @code{ada-set-default-project-file}. Emacs Ada mode checks the
447file extension; if it is @code{.gpr}, the file is treated as a GNAT
448project file. Any other extension is treated as an Emacs Ada mode
449project file.
450
4009494e
GM
451@node GUI Editor, Project file variables, Project File Overview, Project files
452@section GUI Editor
453
454The project file editor is invoked with the menu @samp{Ada | Projects
455| Edit}.
456
457Once in the buffer for editing the project file, you can save your
458modification using the @samp{[save]} button at the bottom of the
459buffer, or the @kbd{C-x C-s} binding. To cancel your modifications,
460kill the buffer or click on the @samp{[cancel]} button.
461
462@node Project file variables, , GUI Editor, Project files
463@section Project file variables
464
465The following variables can be defined in a project file; some can
466also be defined in lisp variables.
467
468To set a project variable that is a list, specify each element of the
469list on a separate line in the project file.
470
471Any project variable can be referenced in other project variables,
472using a shell-like notation. For instance, if the variable
473@code{comp_cmd} contains @code{$@{comp_opt@}}, the value of the
474@code{comp_opt} variable will be substituted when @code{comp_cmd} is
475used.
476
d5875b25
JB
477In addition, process environment variables can be referenced using the
478same syntax, or the normal @code{$var} syntax.
479
4009494e
GM
480Most project variables have defaults that can be changed by setting
481lisp variables; the table below identifies the lisp variable for each
482project variable. Lisp variables corresponding to project variables
483that are lists are lisp lists.
484
d5875b25
JB
485In general, project variables are evaluated when referenced in
486Emacs Ada mode commands. Relative file paths are expanded to
487absolute relative to @code{$@{build_dir@}}.
488
4009494e
GM
489Here is the list of variables. In the default values, the current
490directory @code{"."} is the project file directory.
491
4009494e 492@table @asis
d5875b25 493@c defined in ada-default-prj-properties; alphabetical order
4009494e 494
d5875b25
JB
495@item @code{ada_project_path_sep} [default: @code{":" or ";"}]
496Path separator for @code{ADA_PROJECT_PATH}. It defaults to the correct
497value for a native implementation of GNAT for the current operating
498system. The user must override this when using Windows native GNAT
499with Cygwin Emacs, and perhaps in other cases.
4009494e 500
d5875b25 501Lisp variable: @code{ada-prj-ada-project-path-sep}.
4009494e 502
d5875b25
JB
503@item @code{ada_project_path} [default: @code{""}]
504A list of directories to search for GNAT project files.
505
506If set, the @code{ADA_PROJECT_PATH} process environment variable is
507set to this value in the Emacs process when the Emacs Ada mode project
508is selected via menu @samp{Ada | Project | Load}.
509
510For @code{ada_project_path}, relative file paths are expanded to
511absolute when the Emacs Ada project file is read, rather than when the
512project file is selected.
513
514For example if the project file is in the directory
515@file{/home/myproject}, the environment variable @code{GDS_ROOT} is
516set to @code{/home/shared}, and the project file contains:
517@example
518ada_project_path_sep=:
519ada_project_path=$GDS_ROOT/makerules
520ada_project_path=../opentoken
521@end example
522the environment variable @code{ADA_PROJECT_PATH} will be set to
523@code{"/home/shared/makerules:/home/opentoken/"}.
524
525The default value is not the current value of this environment
526variable, because that will typically have been set by another
527project, and will therefore be incorrect for this project.
528
529If you have the environment variable set correctly for all of your
530projects, you do not need to set this project variable.
531
532@item @code{bind_opt} [default: @code{""}]
533Holds user binder options; used in the default build commands.
534
535Lisp variable: @code{ada-prj-default-bind-opt}.
536
537@item @code{build_dir} [default: @code{"."}]
538The compile commands will be issued in this directory.
4009494e
GM
539
540@item @code{casing} [default: @code{("~/.emacs_case_exceptions")}
541List of files containing casing exceptions. See the help on
542@code{ada-case-exception-file} for more info.
543@c FIXME: section on case exceptions
544
545Lisp variable: @code{ada-case-exception-file}.
546
d5875b25
JB
547@item @code{check_cmd} [default: @code{"$@{cross_prefix@}gnatmake -u -c -gnatc $@{gnatmake_opt@} $@{full_current@} -cargs $@{comp_opt@}"}]
548Command used to syntax check a single file.
549The name of the file is substituted for @code{full_current}.
550
551Lisp variable: @code{ada-prj-default-check-cmd}
552
553@item @code{comp_cmd} [default: @code{"$@{cross_prefix@}gnatmake -u -c $@{gnatmake_opt@} $@{full_current@} -cargs $@{comp_opt@}"}]
554Command used to compile a single file.
555The name of the file is substituted for @code{full_current}.
556
557Lisp variable: @code{ada-prj-default-comp-cmd}.
558
4009494e
GM
559@item @code{comp_opt} [default: @code{"-gnatq -gnatQ"}]
560Holds user compiler options; used in the default compile commands. The
561default value tells gnatmake to generate library files for
562cross-referencing even when there are errors.
563
564If source code for the project is in multiple directories, the
565appropriate compiler options must be added here. @ref{Set source
566search path} for examples of this. Alternately, GNAT project files may
567be used; @ref{Use GNAT project file}.
568
569Lisp variable: @code{ada-prj-default-comp-opt}.
570
d5875b25
JB
571@item @code{cross_prefix} [default: @code{""}]
572Name of target machine in a cross-compilation environment. Used in
573default compile and build commands.
4009494e 574
d5875b25
JB
575@item @code{debug_cmd} [default: @code{"$@{cross_prefix@}gdb $@{main@}"}]
576Command used to debug the application
4009494e 577
d5875b25 578Lisp variable: @code{ada-prj-default-debugger}.
4009494e 579
d5875b25
JB
580@item @code{debug_post_cmd} [default: @code{""}]
581Command executed after @code{debug_cmd}.
4009494e 582
d5875b25
JB
583@item @code{debug_pre_cmd} [default: @code{"cd $@{build_dir@}"}]
584Command executed before @code{debug_cmd}.
4009494e
GM
585
586@item @code{gnatfind_opt} [default: @code{"-rf"}]
587Holds user gnatfind options; used in the default find commands.
588
589Lisp variable: @code{ada-prj-gnatfind-switches}.
590
d5875b25
JB
591@item @code{gnatmake_opt} [default: @code{"-g"}]
592Holds user gnatmake options; used in the default build commands.
4009494e 593
d5875b25 594Lisp variable: @code{ada-prj-default-gnatmake-opt}.
4009494e 595
d5875b25
JB
596@item @code{gpr_file} [default: @code{""}]
597Specify GNAT project file.
4009494e 598
d5875b25
JB
599If set, the source and object directories specified in the GNAT
600project file are appended to @code{src_dir} and @code{obj_dir}. This
601allows specifying Ada source directories with a GNAT project file, and
602other source directories with the Emacs project file.
4009494e 603
d5875b25
JB
604In addition, @code{-P@{gpr_file@}} is added to the project variable
605@code{gnatmake_opt} whenever it is referenced. With the default
606project variables, this passes the project file to all gnatmake
607commands.
4009494e 608
d5875b25 609Lisp variable: @code{ada-prj-default-gpr-file}.
4009494e 610
d5875b25 611@c FIXME: add gnatstub-opts
4009494e 612
d5875b25
JB
613@item @code{link_opt} [default: @code{""}]
614Holds user linker options; used in the default build commands.
615
616Lisp variable: @code{ada-prj-default-link-opt}.
4009494e 617
d5875b25
JB
618@item @code{main} [default: current file]
619Specifies the name of the executable file for the project; used in the
620default build commands.
621
622@item @code{make_cmd} [default: @code{"$@{cross_prefix@}gnatmake -o $@{main@} $@{main@} $@{gnatmake_opt@} -cargs $@{comp_opt@} -bargs $@{bind_opt@} -largs $@{link_opt@}"}]
4009494e
GM
623Command used to build the application.
624
625Lisp variable: @code{ada-prj-default-make-cmd}.
626
d5875b25
JB
627@item @code{obj_dir} [default: @code{"."}]
628A list of directories to search for library files. Ada mode searches
629this list for the @samp{.ali} files generated by GNAT that contain
630cross-reference information.
4009494e 631
d5875b25
JB
632The compiler commands must place the @samp{.ali} files in one of these
633directories; the default commands do that.
4009494e 634
d5875b25
JB
635@item @code{remote_machine} [default: @code{""}]
636Name of the machine to log into before issuing the compile and build
637commands. If this variable is empty, the command will be run on the
638local machine.
4009494e 639
d5875b25
JB
640@item @code{run_cmd} [default: @code{"./$@{main@}"}]
641Command used to run the application.
4009494e 642
d5875b25
JB
643@item @code{src_dir} [default: @code{"."}]
644A list of directories to search for source files, both for compile
645commands and source navigation.
4009494e
GM
646
647@end table
648
649@node Compiling Examples, Moving Through Ada Code, Project files, Top
650@chapter Compiling Examples
651
652We present several small projects, and walk thru the process of
653compiling, linking, and running them.
654
655The first example illustrates more Ada mode features than the others;
656you should work thru that example before doing the others.
657
658All of these examples assume you are using GNAT.
659
660The source for these examples is available on the Emacs Ada mode
661website mentioned in @xref{Installation}.
662
663@menu
664* No project files:: Just menus
665* Set compiler options:: A basic Ada mode project file
666* Set source search path:: Source in multiple directories
667* Use GNAT project file::
d5875b25 668* Use multiple GNAT project files::
4009494e
GM
669@end menu
670
671@node No project files, Set compiler options, Compiling Examples, Compiling Examples
672@section No project files
673This example uses no project files.
674
675First, create a directory @file{Example_1}, containing:
676
677@file{hello.adb}:
678
679@example
680with Ada.Text_IO;
681procedure Hello
682is begin
683 Put_Line("Hello from hello.adb");
684end Hello;
685@end example
686
687Yes, this is missing ``use Ada.Text_IO;'' - we want to demonstrate
688compiler error handling.
689
690@file{hello_2.adb}:
691
692@example
693with Hello_Pkg;
694procedure Hello_2
695is begin
696 Hello_Pkg.Say_Hello;
697end Hello_2;
698@end example
699
d5875b25
JB
700This file has no errors.
701
4009494e
GM
702@file{hello_pkg.ads}:
703
704@example
705package Hello_Pkg is
706 procedure Say_Hello;
707end Hello_Pkg;
708@end example
709
d5875b25
JB
710This file has no errors.
711
4009494e
GM
712@file{hello_pkg.adb}:
713
714@example
715with Ada.Text_IO;
716package Hello_Pkg is
717 procedure Say_Hello
718 is begin
719 Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
720 end Say_Hello;
721end Hello_Pkg;
722@end example
723
724Yes, this is missing the keyword @code{body}; another compiler error
725example.
726
727In buffer @file{hello.adb}, invoke @key{Ada | Check file}. You should
728get a @code{*compilation*} buffer containing something like (the
729directory paths will be different):
730
731@example
732cd c:/Examples/Example_1/
733gnatmake -u -c -gnatc -g c:/Examples/Example_1/hello.adb -cargs -gnatq -gnatQ
734gcc -c -Ic:/Examples/Example_1/ -gnatc -g -gnatq -gnatQ -I- c:/Examples/Example_1/hello.adb
735hello.adb:4:04: "Put_Line" is not visible
736hello.adb:4:04: non-visible declaration at a-textio.ads:264
737hello.adb:4:04: non-visible declaration at a-textio.ads:260
738gnatmake: "c:/Examples/Example_1/hello.adb" compilation error
739@end example
740
741If you have enabled font-lock, the lines with actual errors (starting
742with @file{hello.adb}) are highlighted, with the file name in red.
743
744Now type @key{C-x `} (on a PC keyboard, @key{`} is next to @key{1}).
745Or you can click the middle mouse button on the first error line. The
746compilation buffer scrolls to put the first error on the top line, and
747point is put at the place of the error in the @file{hello.adb} buffer.
748
749To fix the error, change the line to be
750
751@example
752 Ada.Text_IO.Put_Line ("hello from hello.adb"):
753@end example
754
d5875b25 755Now invoke @key{Ada | Show main}; this displays @file{Ada mode main: hello}.
4009494e
GM
756
757Now (in buffer @file{hello.adb}), invoke @key{Ada | Build}. You are
758prompted to save the file (if you haven't already). Then the
759compilation buffer is displayed again, containing:
760
761@example
762cd c:/Examples/Example_1/
763gnatmake -o hello hello -g -cargs -gnatq -gnatQ -bargs -largs
764gcc -c -g -gnatq -gnatQ hello.adb
765gnatbind -x hello.ali
766gnatlink hello.ali -o hello.exe -g
767@end example
768
769The compilation has succeeded without errors; @file{hello.exe} now
770exists in the same directory as @file{hello.adb}.
771
772Now invoke @key{Ada | Run}. A @file{*run*} buffer is displayed,
773containing
774
775@example
776Hello from hello.adb
777
778Process run finished
779@end example
780
781That completes the first part of this example.
782
783Now we will compile a multi-file project. Open the file
784@file{hello_2.adb}, and invoke @key{Ada | Set main and Build}. This
785finds an error in @file{hello_pkg.adb}:
786
787@example
788cd c:/Examples/Example_1/
789gnatmake -o hello_2 hello_2 -g -cargs -gnatq -gnatQ -bargs -largs
790gcc -c -g -gnatq -gnatQ hello_pkg.adb
791hello_pkg.adb:2:08: keyword "body" expected here [see file name]
792gnatmake: "hello_pkg.adb" compilation error
793@end example
794
795This demonstrates that gnatmake finds the files needed by the main
796program. However, it cannot find files in a different directory,
797unless you use an Emacs Ada mode project file to specify the other directories;
798@xref{Set source search path}, or a GNAT project file; @ref{Use GNAT
799project file}.
800
d5875b25 801Invoke @key{Ada | Show main}; this displays @file{Ada mode main: hello_2}.
4009494e
GM
802
803Move to the error with @key{C-x `}, and fix the error by adding @code{body}:
804
805@example
806package body Hello_Pkg is
807@end example
808
809Now, while still in @file{hello_pkg.adb}, invoke @key{Ada | Build}.
810gnatmake successfully builds @file{hello_2}. This demonstrates that
811Emacs has remembered the main file, in the project variable
d5875b25 812@code{main}, and used it for the Build command.
4009494e
GM
813
814Finally, again while in @file{hello_pkg.adb}, invoke @key{Ada | Run}.
815The @code{*run*} buffer displays @code{Hello from hello_pkg.adb}.
816
817One final point. If you switch back to buffer @file{hello.adb}, and
818invoke @key{Ada | Run}, @file{hello_2.exe} will be run. That is
d5875b25 819because @code{main} is still set to @code{hello_2}, as you can
4009494e
GM
820see when you invoke @key{Ada | Project | Edit}.
821
d5875b25 822There are three ways to change @code{main}:
4009494e
GM
823
824@enumerate
825@item
d5875b25 826Invoke @key{Ada | Set main and Build}, which sets @code{main} to
4009494e
GM
827the current file.
828
829@item
71dd9983 830Invoke @key{Ada | Project | Edit}, edit @code{main}, and click @key{[save]}
4009494e
GM
831
832@item
d5875b25 833Invoke @key{Ada | Project | Load}, and load a project file that specifies @code{main}
4009494e
GM
834
835@end enumerate
836
837@node Set compiler options, Set source search path, No project files, Compiling Examples
838@section Set compiler options
839
840This example illustrates using an Emacs Ada mode project file to set a
841compiler option.
842
843If you have files from @file{Example_1} open in Emacs, you should
844close them so you don't get confused. Use menu @key{File | Close
845(current buffer)}.
846
847In directory @file{Example_2}, create these files:
848
849@file{hello.adb}:
850
851@example
852with Ada.Text_IO;
853procedure Hello
854is begin
855 Put_Line("Hello from hello.adb");
856end Hello;
857@end example
858
859This is the same as @file{hello.adb} from @file{Example_1}. It has two
860errors; missing ``use Ada.Text_IO;'', and no space between
861@code{Put_Line} and its argument list.
862
863@file{hello.adp}:
864
865@example
866comp_opt=-gnatyt
867@end example
868
869This tells the GNAT compiler to check for token spacing; in
870particular, there must be a space preceding a parenthesis.
871
872In buffer @file{hello.adb}, invoke @key{Ada | Project | Load...}, and
873select @file{Example_2/hello.adp}.
874
875Then, again in buffer @file{hello.adb}, invoke @key{Ada | Set main and
876Build}. You should get a @code{*compilation*} buffer containing
877something like (the directory paths will be different):
878
879@example
880cd c:/Examples/Example_2/
881gnatmake -o hello hello -g -cargs -gnatyt -bargs -largs
882gcc -c -g -gnatyt hello.adb
883hello.adb:4:04: "Put_Line" is not visible
884hello.adb:4:04: non-visible declaration at a-textio.ads:264
885hello.adb:4:04: non-visible declaration at a-textio.ads:260
886hello.adb:4:12: (style) space required
887gnatmake: "hello.adb" compilation error
888@end example
889
890Compare this to the compiler output in @ref{No project files}; the
891gnatmake option @code{-cargs -gnatq -gnatQ} has been replaced by
892@code{-cargs -gnaty}, and an additional error is reported in
893@file{hello.adb} on line 4. This shows that @file{hello.adp} is being
894used to set the compiler options.
895
896Fixing the error, linking and running the code proceed as in @ref{No
897project files}.
898
899@node Set source search path, Use GNAT project file, Set compiler options, Compiling Examples
900@section Set source search path
901
902In this example, we show how to deal with files in more than one
d5875b25
JB
903directory. We start with the same code as in @ref{No project files};
904create those files (with the errors present)
4009494e
GM
905
906Create the directory @file{Example_3}, containing:
907
908@file{hello_pkg.ads}:
909
910@example
911package Hello_Pkg is
912 procedure Say_Hello;
913end Hello_Pkg;
914@end example
915
916@file{hello_pkg.adb}:
917
918@example
919with Ada.Text_IO;
920package Hello_Pkg is
921 procedure Say_Hello
922 is begin
923 Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
924 end Say_Hello;
925end Hello_Pkg;
926@end example
927
928These are the same files from example 1; @file{hello_pkg.adb} has an
929error on line 2.
930
931In addition, create a directory @file{Example_3/Other}, containing these files:
932
933@file{Other/hello_3.adb}:
934
935@example
936with Hello_Pkg;
937with Ada.Text_IO; use Ada.Text_IO;
938procedure Hello_3
939is begin
940 Hello_Pkg.Say_Hello;
941 Put_Line ("From hello_3");
942end Hello_3;
943@end example
944
945There are no errors in this file.
946
947@file{Other/other.adp}:
948
949@example
950src_dir=..
951comp_opt=-I..
952@end example
953
954Note that there must be no trailing spaces.
955
956In buffer @file{hello_3.adb}, invoke @key{Ada | Project | Load...}, and
957select @file{Example_3/Other/other.adp}.
958
959Then, again in @file{hello_3.adb}, invoke @key{Ada | Set main and
960Build}. You should get a @code{*compilation*} buffer containing
961something like (the directory paths will be different):
962
963@example
964cd c:/Examples/Example_3/Other/
965gnatmake -o hello_3 hello_3 -g -cargs -I.. -bargs -largs
966gcc -c -g -I.. hello_3.adb
967gcc -c -I./ -g -I.. -I- C:\Examples\Example_3\hello_pkg.adb
968hello_pkg.adb:2:08: keyword "body" expected here [see file name]
969gnatmake: "C:\Examples\Example_3\hello_pkg.adb" compilation error
970@end example
971
972Compare the @code{-cargs} option to the compiler output in @ref{Set
973compiler options}; this shows that @file{other.adp} is being used to
974set the compiler options.
975
976Move to the error with @key{C-x `}. Ada mode searches the list of
977directories given by @code{src_dir} for the file mentioned in the
978compiler error message.
979
980Fixing the error, linking and running the code proceed as in @ref{No
981project files}.
982
d5875b25 983@node Use GNAT project file, Use multiple GNAT project files, Set source search path, Compiling Examples
4009494e
GM
984@section Use GNAT project file
985
d5875b25
JB
986In this example, we show how to use a GNAT project file, with no Ada
987mode project file.
4009494e
GM
988
989Create the directory @file{Example_4}, containing:
990
991@file{hello_pkg.ads}:
992
993@example
994package Hello_Pkg is
995 procedure Say_Hello;
996end Hello_Pkg;
997@end example
998
999@file{hello_pkg.adb}:
1000
1001@example
1002with Ada.Text_IO;
1003package Hello_Pkg is
1004 procedure Say_Hello
1005 is begin
1006 Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
1007 end Say_Hello;
1008end Hello_Pkg;
1009@end example
1010
1011These are the same files from example 1; @file{hello_pkg.adb} has an
1012error on line 2.
1013
1014In addition, create a directory @file{Example_4/Gnat_Project},
1015containing these files:
1016
d5875b25 1017@file{Gnat_Project/hello_4.adb}:
4009494e
GM
1018
1019@example
1020with Hello_Pkg;
1021with Ada.Text_IO; use Ada.Text_IO;
1022procedure Hello_4
1023is begin
1024 Hello_Pkg.Say_Hello;
1025 Put_Line ("From hello_4");
1026end Hello_4;
1027@end example
1028
1029There are no errors in this file.
1030
4009494e
GM
1031@file{Gnat_Project/hello_4.gpr}:
1032
1033@example
1034Project Hello_4 is
1035 for Source_Dirs use (".", "..");
1036end Hello_4;
1037@end example
1038
1039In buffer @file{hello_4.adb}, invoke @key{Ada | Project | Load...}, and
d5875b25 1040select @file{Example_4/Gnat_Project/hello_4.gpr}.
4009494e
GM
1041
1042Then, again in @file{hello_4.adb}, invoke @key{Ada | Set main and
1043Build}. You should get a @code{*compilation*} buffer containing
1044something like (the directory paths will be different):
1045
1046@example
1047cd c:/Examples/Example_4/Gnat_Project/
1048gnatmake -o hello_4 hello_4 -Phello_4.gpr -cargs -gnatq -gnatQ -bargs -largs
1049gcc -c -g -gnatyt -gnatq -gnatQ -I- -gnatA c:\Examples\Example_4\Gnat_Project\hello_4.adb
1050gcc -c -g -gnatyt -gnatq -gnatQ -I- -gnatA c:\Examples\Example_4\hello_pkg.adb
1051hello_pkg.adb:2:08: keyword "body" expected here [see file name]
1052gnatmake: "c:\examples\example_4\hello_pkg.adb" compilation error
1053@end example
1054
1055Compare the @code{gcc} options to the compiler output in @ref{Set
1056compiler options}; this shows that @file{hello_4.gpr} is being used to
1057set the compiler options.
1058
1059Fixing the error, linking and running the code proceed as in @ref{No
1060project files}.
1061
d5875b25
JB
1062@node Use multiple GNAT project files, , Use GNAT project file, Compiling Examples
1063@section Use multiple GNAT project files
1064
1065In this example, we show how to use multiple GNAT project files,
1066specifying the GNAT project search path in an Ada mode project file.
1067
1068Create the directory @file{Example_4} as specified in @ref{Use GNAT
1069project file}.
1070
1071Create the directory @file{Example_5}, containing:
1072
1073@file{hello_5.adb}:
1074
1075@example
1076with Hello_Pkg;
1077with Ada.Text_IO; use Ada.Text_IO;
1078procedure Hello_5
1079is begin
1080 Hello_Pkg.Say_Hello;
1081 Put_Line ("From hello_5");
1082end Hello_5;
1083@end example
1084
1085There are no errors in this file.
1086
1087@file{hello_5.adp}:
1088
1089@example
1090ada_project_path=../Example_4/Gnat_Project
1091gpr_file=hello_5.gpr
1092@end example
1093
1094@file{hello_5.gpr}:
1095
1096@example
1097with "hello_4";
1098Project Hello_5 is
1099 for Source_Dirs use (".");
1100 package Compiler is
1101 for Default_Switches ("Ada") use ("-g", "-gnatyt");
1102 end Compiler;
1103end Hello_5;
1104@end example
1105
1106In buffer @file{hello_5.adb}, invoke @key{Ada | Project | Load...}, and
1107select @file{Example_5/hello_5.adp}.
1108
1109Then, again in @file{hello_5.adb}, invoke @key{Ada | Set main and
1110Build}. You should get a @code{*compilation*} buffer containing
1111something like (the directory paths will be different):
1112
1113@example
1114cd c:/Examples/Example_5/
1115gnatmake -o hello_5 hello_5 -Phello_5.gpr -g -cargs -gnatq -gnatQ -bargs -largs
1116gcc -c -g -gnatyt -g -gnatq -gnatQ -I- -gnatA c:\Examples\Example_5\hello_5.adb
1117gcc -c -g -gnatyt -g -gnatq -gnatQ -I- -gnatA c:\Examples\Example_4\hello_pkg.adb
1118hello_pkg.adb:2:08: keyword "body" expected here [see file name]
1119gnatmake: "c:\examples\example_4\hello_pkg.adb" compilation error
1120@end example
1121
1122Now type @key{C-x `}. @file{Example_4/hello_pkg.adb} is shown,
1123demonstrating that @file{hello_5.gpr} and @file{hello_4.gpr} are being
1124used to set the compilation search path.
1125
4009494e
GM
1126@node Moving Through Ada Code, Identifier completion, Compiling Examples, Top
1127@chapter Moving Through Ada Code
4009494e
GM
1128
1129There are several easy to use commands to navigate through Ada code. All
1130these functions are available through the Ada menu, and you can also
1131use the following key bindings or the command names. Some of these
1132menu entries are available only if the GNAT compiler is used, since
1133the implementation relies on the GNAT cross-referencing information.
1134
1135@table @kbd
1136@item M-C-e
1137@findex ada-next-procedure
1138Move to the next function/procedure/task, which ever comes next
1139(@code{ada-next-procedure}).
1140@item M-C-a
1141@findex ada-previous-procedure
1142Move to previous function/procedure/task
1143(@code{ada-previous-procedure}).
1144@item M-x ada-next-package
1145@findex ada-next-package
1146Move to next package.
1147@item M-x ada-previous-package
1148@findex ada-previous-package
1149Move to previous package.
1150@item C-c C-a
1151@findex ada-move-to-start
1152Move to matching start of @code{end} (@code{ada-move-to-start}). If
1153point is at the end of a subprogram, this command jumps to the
1154corresponding @code{begin} if the user option
1155@code{ada-move-to-declaration} is @code{nil} (default), otherwise it jumps to
1156the subprogram declaration.
1157@item C-c C-e
1158@findex ada-move-to-end
1159Move point to end of current block (@code{ada-move-to-end}).
1160@item C-c o
1161Switch between corresponding spec and body file
1162(@code{ff-find-other-file}). If point is in a subprogram, position
1163point on the corresponding declaration or body in the other file.
1164@item C-c c-d
1165@findex ada-goto-declaration
1166Move from any reference to its declaration, for from a declaration to
1167its body (for procedures, tasks, private and incomplete types).
1168@item C-c C-r
1169@findex ada-find-references
1170Runs the @file{gnatfind} command to search for all references to the
1171identifier surrounding point (@code{ada-find-references}). Use
1172@kbd{C-x `} (@code{next-error}) to visit each reference (as for
1173compilation errors).
1174@end table
1175
1176If the @code{ada-xref-create-ali} variable is non-@code{nil}, Emacs
1177will try to run GNAT for you whenever cross-reference information is
1178needed, and is older than the current source file.
1179
1180@node Identifier completion, Automatic Smart Indentation, Moving Through Ada Code, Top
1181@chapter Identifier completion
1182
1183Emacs and Ada mode provide two general ways for the completion of
1184identifiers. This is an easy way to type faster: you just have to type
1185the first few letters of an identifiers, and then loop through all the
1186possible completions.
1187
1188The first method is general for Emacs. It works by parsing all open
1189files for possible completions.
1190
1191For instance, if the words @samp{my_identifier}, @samp{my_subprogram}
1192are the only words starting with @samp{my} in any of the opened files,
1193then you will have this scenario:
1194
1195@example
1196You type: my@key{M-/}
1197Emacs inserts: @samp{my_identifier}
1198If you press @key{M-/} once again, Emacs replaces @samp{my_identifier} with
1199@samp{my_subprogram}.
1200Pressing @key{M-/} once more will bring you back to @samp{my_identifier}.
1201@end example
1202
1203This is a very fast way to do completion, and the casing of words will
1204also be respected.
1205
1206The second method (@key{C-TAB}) is specific to Ada mode and the GNAT
1207compiler. Emacs will search the cross-information for possible
1208completions.
1209
1210The main advantage is that this completion is more accurate: only
1211existing identifier will be suggested.
1212
1213On the other hand, this completion is a little bit slower and requires
1214that you have compiled your file at least once since you created that
1215identifier.
1216
1217@table @kbd
1218@item C-@key{TAB}
1219@findex ada-complete-identifier
1220Complete current identifier using cross-reference information.
1221@item M-/
1222Complete identifier using buffer information (not Ada-specific).
1223@end table
1224
1225@node Automatic Smart Indentation, Formatting Parameter Lists, Identifier completion, Top
1226@chapter Automatic Smart Indentation
1227
1228Ada mode comes with a full set of rules for automatic indentation. You
1229can also configure the indentation, via the following variables:
1230
1231@table @asis
1232@item @code{ada-broken-indent} (default value: 2)
1233Number of columns to indent the continuation of a broken line.
1234
1235@item @code{ada-indent} (default value: 3)
1236Number of columns for default indentation.
1237
1238@item @code{ada-indent-record-rel-type} (default value: 3)
1239Indentation for @code{record} relative to @code{type} or @code{use}.
1240
1241@item @code{ada-indent-return} (default value: 0)
1242Indentation for @code{return} relative to @code{function} (if
1243@code{ada-indent-return} is greater than 0), or the open parenthesis
1244(if @code{ada-indent-return} is negative or 0). Note that in the second
1245case, when there is no open parenthesis, the indentation is done
1246relative to @code{function} with the value of @code{ada-broken-indent}.
1247
1248@item @code{ada-label-indent} (default value: -4)
1249Number of columns to indent a label.
1250
1251@item @code{ada-stmt-end-indent} (default value: 0)
1252Number of columns to indent a statement @code{end} keyword on a separate line.
1253
1254@item @code{ada-when-indent} (default value: 3)
1255Indentation for @code{when} relative to @code{exception} or @code{case}.
1256
1257@item @code{ada-indent-is-separate} (default value: t)
1258Non-@code{nil} means indent @code{is separate} or @code{is abstract} if on a single line.
1259
1260@item @code{ada-indent-to-open-paren} (default value: t)
1261Non-@code{nil} means indent according to the innermost open parenthesis.
1262
1263@item @code{ada-indent-after-return} (default value: t)
1264Non-@code{nil} means that the current line will also be re-indented
1265before inserting a newline, when you press @key{RET}.
1266@end table
1267
1268Most of the time, the indentation will be automatic, i.e when you
1269press @key{RET}, the cursor will move to the correct column on the
1270next line.
1271
1272You can also indent single lines, or the current region, with @key{TAB}.
1273
1274Another mode of indentation exists that helps you to set up your
1275indentation scheme. If you press @kbd{C-c @key{TAB}}, Ada mode will do
1276the following:
1277
1278@itemize @bullet
1279@item
1280Reindent the current line, as @key{TAB} would do.
1281@item
1282Temporarily move the cursor to a reference line, i.e., the line that
1283was used to calculate the current indentation.
1284@item
1285Display in the message window the name of the variable that provided
1286the offset for the indentation.
1287@end itemize
1288
1289The exact indentation of the current line is the same as the one for the
1290reference line, plus an offset given by the variable.
1291
1292@table @kbd
1293@item @key{TAB}
1294Indent the current line or the current region.
1295@item C-M-\
1296Indent lines in the current region.
1297@item C-c @key{TAB}
1298Indent the current line and display the name of the variable used for
1299indentation.
1300@end table
1301
1302@node Formatting Parameter Lists, Automatic Casing, Automatic Smart Indentation, Top
1303@chapter Formatting Parameter Lists
1304
1305@table @kbd
1306@item C-c C-f
1307@findex ada-format-paramlist
1308Format the parameter list (@code{ada-format-paramlist}).
1309@end table
1310
1311This aligns the declarations on the colon (@samp{:}) separating
1312argument names and argument types, and aligns the @code{in},
1313@code{out} and @code{in out} keywords.
1314
1315@node Automatic Casing, Statement Templates, Formatting Parameter Lists, Top
1316@chapter Automatic Casing
1317
1318Casing of identifiers, attributes and keywords is automatically
1319performed while typing when the variable @code{ada-auto-case} is set.
1320Every time you press a word separator, the previous word is
1321automatically cased.
1322
1323You can customize the automatic casing differently for keywords,
1324attributes and identifiers. The relevant variables are the following:
1325@code{ada-case-keyword}, @code{ada-case-attribute} and
1326@code{ada-case-identifier}.
1327
1328All these variables can have one of the following values:
1329
1330@table @code
1331@item downcase-word
1332The word will be lowercase. For instance @code{My_vARIable} is
1333converted to @code{my_variable}.
1334
1335@item upcase-word
1336The word will be uppercase. For instance @code{My_vARIable} is
1337converted to @code{MY_VARIABLE}.
1338
1339@item ada-capitalize-word
1340The first letter and each letter following an underscore (@samp{_})
1341are uppercase, others are lowercase. For instance @code{My_vARIable}
1342is converted to @code{My_Variable}.
1343
1344@item ada-loose-case-word
1345Characters after an underscore @samp{_} character are uppercase,
1346others are not modified. For instance @code{My_vARIable} is converted
1347to @code{My_VARIable}.
1348@end table
1349
1350Ada mode allows you to define exceptions to these rules, in a file
1351specified by the variable variable @code{ada-case-exception-file}
1352(default @file{~/.emacs_case_exceptions}). Each line in this file
1353specifies the casing of one word or word fragment. Comments may be
1354included, separated from the word by a space.
1355
1356If the word starts with an asterisk (@key{*}), it defines the casing
1357af a word fragemnt (or ``substring''); part of a word between two
1358underscores or word boundary.
1359
1360For example:
1361
1362@example
1363DOD Department of Defense
1364*IO
1365GNAT The GNAT compiler from Ada Core Technologies
1366@end example
1367
1368The word fragment @code{*IO} applies to any word containing ``_io'';
1369@code{Text_IO}, @code{Hardware_IO}, etc.
1370
1371@findex ada-create-case-exception
1372There are two ways to add new items to this file: you can simply edit
1373it as you would edit any text file. Or you can position point on the
1374word you want to add, and select menu @samp{Ada | Edit | Create Case
1375Exception}, or press @kbd{C-c C-y} (@code{ada-create-case-exception}).
1376The word will automatically be added to the current list of exceptions
1377and to the file.
1378
1379To define a word fragment case exception, select the word fragment,
1380then select menu @samp{Ada | Edit | Create Case Exception Substring}.
1381
1382It is sometimes useful to have multiple exception files around (for
1383instance, one could be the standard Ada acronyms, the second some
1384company specific exceptions, and the last one some project specific
1385exceptions). If you set up the variable @code{ada-case-exception-file}
1386as a list of files, each of them will be parsed and used in your emacs
1387session. However, when you save a new exception through the menu, as
1388described above, the new exception will be added to the first file in
1389the list.
1390
1391@table @kbd
1392@item C-c C-b
1393@findex ada-adjust-case-buffer
1394Adjust case in the whole buffer (@code{ada-adjust-case-buffer}).
1395@item C-c C-y
1396Create a new entry in the exception dictionary, with the word under
1397the cursor (@code{ada-create-case-exception})
1398@item C-c C-t
1399@findex ada-case-read-exceptions
1400Rereads the exception dictionary from the file
1401@code{ada-case-exception-file} (@code{ada-case-read-exceptions}).
1402@end table
1403
1404@node Statement Templates, Comment Handling, Automatic Casing, Top
1405@chapter Statement Templates
1406
1407Templates are defined for most Ada statements, using the Emacs
1408``skeleton'' package. They can be inserted in the buffer using the
1409following commands:
1410
1411@table @kbd
1412@item C-c t b
1413@findex ada-exception-block
1414exception Block (@code{ada-exception-block}).
1415@item C-c t c
1416@findex ada-case
1417case (@code{ada-case}).
1418@item C-c t d
1419@findex ada-declare-block
1420declare Block (@code{ada-declare-block}).
1421@item C-c t e
1422@findex ada-else
1423else (@code{ada-else}).
1424@item C-c t f
1425@findex ada-for-loop
1426for Loop (@code{ada-for-loop}).
1427@item C-c t h
1428@findex ada-header
1429Header (@code{ada-header}).
1430@item C-c t i
1431@findex ada-if
1432if (@code{ada-if}).
1433@item C-c t k
1434@findex ada-package-body
1435package Body (@code{ada-package-body}).
1436@item C-c t l
1437@findex ada-loop
1438loop (@code{ada-loop}).
1439@item C-c p
1440@findex ada-subprogram-body
1441subprogram body (@code{ada-subprogram-body}).
1442@item C-c t t
1443@findex ada-task-body
1444task Body (@code{ada-task-body}).
1445@item C-c t w
1446@findex ada-while
1447while Loop (@code{ada-while}).
1448@item C-c t u
1449@findex ada-use
1450use (@code{ada-use}).
1451@item C-c t x
1452@findex ada-exit
1453exit (@code{ada-exit}).
1454@item C-c t C-a
1455@findex ada-array
1456array (@code{ada-array}).
1457@item C-c t C-e
1458@findex ada-elsif
1459elsif (@code{ada-elsif}).
1460@item C-c t C-f
1461@findex ada-function-spec
1462function Spec (@code{ada-function-spec}).
1463@item C-c t C-k
1464@findex ada-package-spec
1465package Spec (@code{ada-package-spec}).
1466@item C-c t C-p
1467@findex ada-procedure-spec
1468procedure Spec (@code{ada-package-spec}.
1469@item C-c t C-r
1470@findex ada-record
1471record (@code{ada-record}).
1472@item C-c t C-s
1473@findex ada-subtype
1474subtype (@code{ada-subtype}).
1475@item C-c t C-t
1476@findex ada-task-spec
1477task Spec (@code{ada-task-spec}).
1478@item C-c t C-u
1479@findex ada-with
1480with (@code{ada-with}).
1481@item C-c t C-v
1482@findex ada-private
1483private (@code{ada-private}).
1484@item C-c t C-w
1485@findex ada-when
1486when (@code{ada-when}).
1487@item C-c t C-x
1488@findex ada-exception
1489exception (@code{ada-exception}).
1490@item C-c t C-y
1491@findex ada-type
1492type (@code{ada-type}).
1493@end table
1494
1495@node Comment Handling, GNU Free Documentation License, Statement Templates, Top
1496@chapter Comment Handling
1497
1498By default, comment lines get indented like Ada code. There are a few
1499additional functions to handle comments:
1500
1501@table @kbd
1502@item M-;
1503Start a comment in default column.
1504@item M-j
1505Continue comment on next line.
1506@item C-c ;
1507Comment the selected region (add -- at the beginning of lines).
1508@item C-c :
1509Uncomment the selected region
1510@item M-q
1511autofill the current comment.
1512@end table
1513
1514@node GNU Free Documentation License, Index, Comment Handling, Top
1515@appendix GNU Free Documentation License
1516@include doclicense.texi
1517
1518@node Index, , GNU Free Documentation License, Top
1519@unnumbered Index
1520
1521@printindex fn
1522
1523@contents
1524@bye
1525
1526@ignore
1527 arch-tag: 68cf0d8a-55cc-4190-a28d-4984fa56ed1e
1528@end ignore