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