]> code.delx.au - gnu-emacs-elpa/blob - packages/ada-mode/ada-mode.texi
remove bogus execute priv
[gnu-emacs-elpa] / packages / ada-mode / ada-mode.texi
1 \input texinfo @c -*-texinfo-*-
2 @setfilename ../../info/ada-mode
3 @settitle Ada Mode
4
5 @copying
6 Copyright @copyright{} 1999 - 2014 Free Software Foundation, Inc.
7
8 @quotation
9 Permission is granted to copy, distribute and/or modify this document
10 under the terms of the GNU Free Documentation License, Version 1.3 or
11 any later version published by the Free Software Foundation; with no
12 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
13 and with the Back-Cover Texts as in (a) below. A copy of the license
14 is included in the section entitled ``GNU Free Documentation License''.
15
16 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
17 modify this GNU manual. Buying copies from the FSF supports it in
18 developing GNU and promoting software freedom.''
19 @end quotation
20 @end copying
21
22 @dircategory Emacs editing modes
23 @direntry
24 * Ada mode: (ada-mode). Emacs mode for editing and navigating Ada code.
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
32 @subtitle Ada Mode Version 5.1.5
33 @sp 2
34 @page
35 @vskip 0pt plus 1filll
36 @insertcopying
37 @end titlepage
38
39 @contents
40
41 @node Top, Overview, (dir), (dir)
42
43 @ifnottex
44 @insertcopying
45 @end ifnottex
46
47 @menu
48 * Overview::
49 * Installation:: Installing Ada mode on your system
50 * Customization:: Setting up Ada mode to your taste
51 * Compiling Executing:: Working with your application within Emacs
52 * Project files:: Describing the organization of your project
53 * Moving Through Ada Code:: Moving easily through Ada sources
54 * Identifier completion:: Finishing words automatically
55 * Indentation:: Indenting your code automatically as you type
56 * Statement skeletons:: Some code is written for you
57 * Aligning code:: Making it pretty
58 * Automatic casing:: Adjusting the case of words automatically
59 * Comment Handling:: Reformatting comments easily
60 * Key summary::
61 * Developer overview::
62 * GNU Free Documentation License::
63 * Index::
64 @end menu
65
66 @node Overview, Installation, Top, Top
67 @chapter Overview
68
69 The Emacs mode for programming in Ada helps the user in reading
70 existing code and facilitates developing new code.
71
72 Cross-reference information output by the compiler is used to provide
73 powerful code navigation (jump to definition, find all uses, etc).
74
75 When you open a file with a file extension of @file{.ads} or
76 @file{.adb}, Emacs will automatically load and activate Ada
77 mode.
78
79 Ada mode works without any customization, if you are using the GNAT
80 compiler (@url{https://libre2.adacore.com/}) and the GNAT default
81 naming convention.
82
83 You must customize a few things if you are using a different file
84 naming convention or compiler; @xref{Non-standard file names},
85 @xref{Other compiler}.
86
87 In addition, you may want to customize the indentation,
88 capitalization, and other things; @xref{Other customization}.
89
90 Finally, for large Ada projects, you will want to set up an Emacs Ada
91 mode project file for each project; @xref{Project files}. Note that
92 these are different from the GNAT project files used by the GNAT
93 tools.
94
95 @xref{Debuggers,,Debuggers,emacs,Emacs User Guide}, for general
96 information on debugging.
97
98 @node Installation, Customization, Overview, Top
99 @chapter Installation
100
101 Ada mode requires Emacs 24.2 or greater; it also requires the Emacs
102 lisp sources (not just the compiled binaries).
103
104 Ada mode is distributed in the Gnu ELPA package archive; it can be
105 installed via @code{M-x list-packages} (@pxref{Packages,,,emacs,Emacs
106 User Guide}). You must first enable packages in your @file{~/.emacs},
107 @emph{after} customizing @code{Info-default-directory-list} (if you do
108 that):
109
110 @example
111 (package-initialize)
112 @end example
113
114 Ada mode is also available as a separate distribution, from the Emacs
115 Ada mode website
116 @uref{http://stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html}.
117
118 For installing the separate distribution, see the @file{README} file
119 in the distribution.
120
121 To see what version of Ada mode you have installed, invoke @kbd{M-x
122 ada-mode-version}.
123
124 @menu
125 * gnatinspect::
126 * Upgrading::
127 @end menu
128
129 @node gnatinspect, Upgrading, Installation, Installation
130 @section gnatinspect
131 Ada mode has experimental support for the new AdaCore cross reference
132 tool @code{gnatinspect}, which supports Ada, C, C++, and any other
133 language for which gcc provices the @code{-fdump-xref}.
134
135 @code{gnatinspect} is distributed as part of @code{gnatcoll}. Ada mode
136 requires the very latest version, in @code{gnatcoll 1.7w} distributed
137 with GNAT GPL 2014.
138
139 To build @code{gnatinspect}, assuming GNAT GPL 2014 is installed in
140 @file{/usr/gnat-gpl-2014}, and @file{/usr/gnat-gpl-2014/bin} is in
141 PATH:
142
143 @example
144 tar xf ~/Downloads/gnatcoll-1.7x-src.tgz
145 cd gnatcoll-1.7w-src
146 ./configure --prefix=/usr/gnat-gpl-2014
147 make Gnatcoll_Build=Debug
148 sudo make Gnatcoll_Build=Debug install
149 @end example
150
151 To build an sqlite3 executable that is compatible with the database
152 created by gnatinspect:
153
154 @example
155 cd gnatcoll-1.7w-src/src/sqlite/amalgamation/
156 gcc -O2 -o sqlite3 shell.c sqlite3.c -ldl -lpthread
157 @end example
158
159 @node Upgrading, , gnatinspect, Installation
160 @section Upgrading from previous versions
161
162 See the file NEWS for more details; here we summarize only important
163 user interface changes.
164
165 @table @samp
166 @item from 5.0.1
167 Nothing to do.
168
169 @item from 4.01
170 There are many user interface and API changes between 4.01 and 5.0.1;
171 we only document those that may be hard to diagnose here.
172
173 @code{prog-mode-hook} is no longer run by @code{ada-mode};
174 @code{ada-mode} is no longer derived from @code{prog-mode}. Use
175 @code{ada-mode-hook} instead.
176
177
178 @end table
179
180 @node Customization, Compiling Executing, Installation, Top
181 @chapter Customizing Ada mode
182
183 Here we assume you are familiar with setting variables in Emacs,
184 either thru 'customize' or in elisp (in your @file{.emacs} file). For
185 a basic introduction to customize, elisp, and Emacs in general, see
186 the tutorial (@kbd{C-h t}).
187
188 @menu
189 * Non-standard file names::
190 * Other compiler::
191 * Other cross-reference::
192 * Other customization::
193 @end menu
194
195 @node Non-standard file names, Other compiler, Customization, Customization
196 @section Non-standard file names
197
198 By default, Ada mode is configured to use the GNAT file naming
199 convention, where file names are a simple modification of the Ada
200 names, and the extension for specs and bodies are
201 @samp{.ads} and @samp{.adb}, respectively.
202
203 Emacs uses the file extension to enable Ada mode; Ada mode uses the
204 file extentions to allow moving from a package body to the
205 corresponding spec and back.
206
207 Emacs and Ada mode support ways to use alternative file extensions for
208 specs and bodies. Note that you must also tell the compiler about
209 these extensions; doing that is beyond the scope of this manual.
210
211 For instance, if your spec and bodies files are called
212 @file{@var{unit}_s.ada} and @file{@var{unit}_b.ada}, respectively, you
213 can add the following to your @file{.emacs} file:
214
215 @example
216 ;; Tell Ada mode about spec and body extensions
217 (ada-add-extensions "_s.ada" "_b.ada")
218
219 ;; Tell Emacs to use Ada mode for those extensions
220 (add-to-list 'auto-mode-alist '("\\.ada\\'" . ada-mode))
221 @end example
222
223 You can define additional extensions:
224
225 @example
226 (ada-add-extensions ".ads" "_b.ada")
227 (ada-add-extensions ".ads" ".body")
228 @end example
229
230 This means that whenever Ada mode looks for the body for a file
231 whose extension is @file{.ads}, it will take the first available file
232 that ends with either @file{.adb}, @file{_b.ada} or
233 @file{.body}.
234
235 Simililarly, if Ada mode is looking for a spec, it will look for
236 @file{.ads} or @file{_s.ada}.
237
238 If the filename excluding the extension is not derived from the Ada
239 name following the GNAT convention, you need to provide an alternate
240 function for @code{ada-file-name-from-ada-name}. Doing that is beyond
241 the scope of this manual; see the current definitions in
242 @file{ada-mode.el} and @file{ada-gnat-xref.el} for examples.
243
244 @node Other compiler, Other cross-reference, Non-standard file names, Customization
245 @section Other compiler
246 The project variable @code{ada_compiler} (default elisp variable
247 @code{ada-compiler}) is used to index several variables that point to
248 the compiler-specific functions for corresponding Ada mode operations.
249
250 To use a compiler other than GNAT, you must write Emacs lisp code that
251 provides the interface to the compiler, and set @code{ada-compiler} and
252 the indirection variables.
253
254 See @file{ada-gnat-compile.el} for an example.
255
256 @node Other cross-reference, Other customization, Other compiler, Customization
257 @section Other cross-reference
258 The project variable @code{ada_xref} (default elisp variable
259 @code{ada-xref-tool}) is used to index several variables that point to
260 the cross-reference-tool-specific functions for corresponding Ada mode
261 operations.
262
263 To use a cross reference tool other than gnatxref, you must write
264 Emacs lisp code that provides the interface to the compiler, and set
265 @code{ada-xref-tool} and the indirection variables. This has already
266 been done for @code{gnatinspect}; set @code{ada-xref-tool} to
267 @code{'gnat_inspect}.
268
269 See @file{ada-gnat-xref.el} and @file{gnat-inspect.el} for examples.
270
271 @node Other customization, , Other cross-reference, Customization
272 @section Other customization
273
274 All user-settable Ada mode variables can be set via the menu
275 @samp{Ada | Customize}. Click on the @samp{Help} button there for help
276 on using customize.
277
278 To modify a specific variable, you can directly call the function
279 @code{customize-variable}; just type @kbd{M-x customize-variable
280 @key{RET} @var{variable-name} @key{RET}}).
281
282 Alternately, you can specify variable settings in the Emacs
283 configuration file, @file{~/.emacs}. This file is coded in Emacs lisp,
284 and the syntax to set a variable is the following:
285 @example
286 (setq variable-name value)
287 @end example
288
289 Some general Emacs settings that are useful for Ada files:
290 @table @code
291 @item delete-trailing-whitespace
292 Deletes space, tab at end of line and blank lines at end of buffer.
293 @item untabify
294 Deletes tab characters that have crept into the file.
295 @item indent-tabs-mode
296 Don't insert tab characters when indenting.
297 @item copyright-update
298 Updates the copyright date in the file header comment, to the current
299 year.
300 @item electric-pair-mode
301 Insert a matching right paren when you type a left paren.
302 @item hippie-expand
303 Bind @code{hippie-expand} to a key; it expands the word before point, using
304 words from current buffer, other buffers, file names, etc; see
305 @code{hippie-expand-try-functions-list}. You can also add
306 @code{ada-skel-hippie-try} to that list. Note that @code{ada-expand},
307 which defaults to @code{ada-skel-expand}, is bound to @key{C-c C-e}
308 (@pxref{Statement skeletons}).
309 @item imenu
310 @item which-func
311 @end table
312
313 The above can all be set by the following code in your
314 @file{~/.emacs}. Note that some are functions are added to
315 @code{before-save-hook}; they run just before a buffer is written to
316 disk. Also, the order is important; ada-mode does not set up the
317 Ada-specific features of imenu and which-func unless they are loaded
318 first.
319
320 @example
321 (setq-default indent-tabs-mode nil)
322 (electric-pair-mode 1)
323 (require 'imenu)
324 (require 'which-func)
325 (require 'ada-mode)
326 (add-to-list 'hippie-expand-try-functions-list 'ada-skel-hippie-try)
327 (define-key ada-mode-map "\C-e" 'hippie-expand)
328 (add-hook 'ada-mode-hook
329 (lambda ()
330 (add-hook 'before-save-hook 'delete-trailing-whitespace nil t)
331 (add-hook 'before-save-hook 'copyright-update nil t)
332 (add-hook 'before-save-hook
333 (lambda () (untabify (point-min) (point-max)))
334 nil t)))
335 @end example
336
337 @node Compiling Executing, Project files, Customization, Top
338 @chapter Compiling Executing
339
340 Ada projects can be compiled, linked, and executed using commands on
341 the Ada menu. All of these commands can be customized via a project
342 file (@pxref{Project files}), but the defaults are sufficient for using
343 the GNAT compiler for simple projects (single files, or several files
344 in a single directory).
345
346 For complex projects, you will want to use @code{make} or some other
347 build tool; in that case, you will need an Emacs Ada mode project file
348 to tell Emacs about the project directory tree and other settings.
349
350 @menu
351 * Compile commands::
352 * Compiling Examples::
353 * Compiler errors::
354 @end menu
355
356 @node Compile commands, Compiling Examples, Compiling Executing, Compiling Executing
357 @section Compile commands
358
359 Here are the commands for building an Ada project and running the main
360 program.
361
362 In multi-file projects, there must be one file that is the main
363 program. That is given by the @code{main} project file variable;
364 it defaults to the current file if not yet set, but is also set by the
365 ``set main and build'' command.
366 @c IMPROVEME: get main from gpr via gnatinspect? not in gnatcoll 1.6w
367
368 @table @code
369
370 @item Check file
371 Compiles the current file in syntax check mode, by running
372 @code{check_cmd} defined in the current project file. This typically
373 runs faster than full compile mode, speeding up finding and fixing
374 compilation errors.
375
376 This sets @code{main} only if it has not been set yet.
377
378 @item Compile file
379 Compiles the current file, by running @code{comp_cmd} from the current
380 project file.
381
382 This does not set @code{main}.
383
384 @item Set main and Build
385 Sets @code{main} to the current file, then executes the Build
386 command.
387
388 @item Show main
389 Display @code{main} in the message buffer.
390
391 @item Build
392 Compiles all obsolete units of the current @code{main}, and links
393 @code{main}, by running @code{make_cmd} from the current project.
394
395 This sets @code{main} only if it has not been set yet.
396
397 @item Run
398 Executes the main program in a shell, displayed in a separate Emacs
399 buffer. This runs @code{run_cmd} from the current project. The
400 execution buffer allows for interactive input/output.
401
402 To modify the run command, in particular to provide or change the
403 command line arguments, type @kbd{C-u} before invoking the command.
404
405 This command is not available for a cross-compilation toolchain.
406
407 @end table
408 It is important when using these commands to understand how
409 @code{main} is used and changed.
410
411 Build runs 'gnatmake' on the main unit. During a typical edit/compile
412 session, this is the only command you need to invoke, which is why it
413 is bound to @kbd{C-c C-c}. It will compile all files needed by the
414 main unit, and display compilation errors in any of them.
415
416 Note that Build can be invoked from any Ada buffer; typically you will
417 be fixing errors in files other than the main, but you don't have to
418 switch back to the main to invoke the compiler again.
419
420 Novices and students typically work on single-file Ada projects. In
421 this case, @kbd{C-c C-m} will normally be the only command needed; it
422 will build the current file, rather than the last-built main.
423
424 There are three ways to change @code{main}:
425
426 @enumerate
427 @item
428 Invoke @samp{Ada | Set main and Build}, which sets @code{main} to
429 the current file.
430
431 @item
432 Invoke @samp{Ada | Project | Edit}, edit @code{main} and
433 @code{main}, and click @samp{[save]}
434
435 @item
436 Invoke @samp{Ada | Project | Load}, and load a project file that specifies @code{main}
437
438 @end enumerate
439
440 @node Compiling Examples, Compiler errors, Compile commands, Compiling Executing
441 @section Compiling Examples
442
443 We present several small projects, and walk thru the process of
444 compiling, linking, and running them.
445
446 The first example illustrates more Ada mode features than the others;
447 you should work thru that example before doing the others.
448
449 All of these examples assume you are using GNAT.
450
451 The source for these examples is available on the Emacs Ada mode
452 website mentioned in @xref{Installation}.
453
454 @menu
455 * No project files:: Just menus
456 * Set compiler options:: A basic Ada mode project file
457 * Set source search path:: Source in multiple directories
458 * Use GNAT project file::
459 * Use multiple GNAT project files::
460 * Use a Makefile::
461 @end menu
462
463 @node No project files, Set compiler options, Compiling Examples, Compiling Examples
464 @subsection No project files
465 This example uses no project files.
466
467 First, create a directory @file{Example_1}, containing:
468
469 @file{hello.adb}:
470
471 @example
472 with Ada.Text_IO;
473 procedure Hello
474 is begin
475 Put_Line("Hello from hello.adb");
476 end Hello;
477 @end example
478
479 Yes, this is missing ``use Ada.Text_IO;'' - we want to demonstrate
480 compiler error handling.
481
482 @file{hello_2.adb} has no errors:
483
484 @example
485 with Hello_Pkg;
486 procedure Hello_2
487 is begin
488 Hello_Pkg.Say_Hello;
489 end Hello_2;
490 @end example
491
492 @file{hello_pkg.ads} has no errors:
493
494 @example
495 package Hello_Pkg is
496 procedure Say_Hello;
497 end Hello_Pkg;
498 @end example
499
500 @file{hello_pkg.adb}:
501
502 @example
503 with Ada.Text_IO;
504 package Hello_Pkg is
505 procedure Say_Hello
506 is begin
507 Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
508 end Say_Hello;
509 end Hello_Pkg;
510 @end example
511
512 Yes, this is missing the keyword @code{body}; another compiler error
513 example. However, note that the indentation engine parser accepts this
514 code with no errors, making it easier to indent slightly illegal Ada
515 code.
516
517 In buffer @file{hello.adb}, invoke the menu entry @samp{Ada | Build |
518 Check syntax}. You should get a @code{*compilation*} buffer containing
519 something like (the directory paths will be different):
520
521 @example
522 -*- mode: compilation; default-directory: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/" -*-
523 Compilation started at Fri Oct 18 04:23:54
524
525 gnatmake -u -c -gnatc c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/hello.adb -cargs
526 gcc -c -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/ -gnatc -I- c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/hello.adb
527 hello.adb:4:04: "Put_Line" is not visible
528 hello.adb:4:04: non-visible declaration at a-textio.ads:263
529 hello.adb:4:04: non-visible declaration at a-textio.ads:259
530 gnatmake: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/hello.adb" compilation error
531
532 Compilation exited abnormally with code 4 at Fri Oct 18 04:23:54
533 @end example
534
535 The lines with actual errors (starting with @file{hello.adb}) are
536 highlighted, with the file name in red.
537
538 Now invoke @samp{Ada | Build | Next compilation error}. Or you can
539 click the middle mouse button on the first error line, or use the key
540 binding shown on the menu. The compilation buffer scrolls to put the
541 first error on the top line, and point is put at the place of the
542 error in the @file{hello.adb} buffer.
543
544 To fix the error, invoke @samp{Ada | Build | Fix compilation error};
545 this adds ``Ada.Text_Io.'' to the line:
546
547 @example
548 Ada.Text_Io.Put_Line ("hello from hello.adb");
549 @end example
550
551 Now invoke @samp{Ada | Build | Show main}; this displays @samp{Ada mode main: hello}.
552
553 Now (in buffer @file{hello.adb}), invoke @samp{Ada | Build | Build}. You are
554 prompted to save the file (if you haven't already). Then the
555 compilation buffer is displayed again, containing:
556
557 @example
558 -*- mode: compilation; default-directory: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/" -*-
559 Compilation started at Fri Oct 18 20:39:33
560
561 gnatmake -o hello hello -cargs -bargs -largs
562 gcc -c hello.adb
563 gnatbind -x hello.ali
564 gnatlink hello.ali -o hello.exe
565
566 Compilation finished at Fri Oct 18 20:39:34
567 @end example
568
569 The compilation has succeeded without errors; @file{hello.exe} now
570 exists in the same directory as @file{hello.adb}.
571
572 Now invoke @samp{Ada | Build | Run}. The @file{*compilation*} buffer
573 is displayed, containing
574
575 @example
576 -*- mode: compilation; default-directory: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_1/" -*-
577 Compilation started at Fri Oct 18 20:41:53
578
579 ./hello
580 Hello from hello.adb
581
582 Compilation finished at Fri Oct 18 20:41:53
583 @end example
584
585 That completes the first part of this example.
586
587 Now we will compile a multi-file project. Open the file
588 @file{hello_2.adb}, invoke @samp{Ada | Build | Set main and
589 Build}. This finds an error in @file{hello_pkg.adb}:
590
591 @example
592 hello_pkg.adb:2:08: keyword "body" expected here [see file name]
593 @end example
594
595 This demonstrates that gnatmake finds the files needed by the main
596 program. However, it cannot find files in a different directory,
597 unless you use an Emacs Ada mode project file or a GNAT project file
598 to specify the other directories; @xref{Set source search path},
599 @ref{Use GNAT project file}.
600
601 Invoke @samp{Ada | Build | Show main}; this displays @file{Ada mode
602 main: hello_2}.
603
604 Move to the error with @kbd{C-x `}, and fix the error by adding @code{body}:
605
606 @example
607 package body Hello_Pkg is
608 @end example
609
610 Now, while still in @file{hello_pkg.adb}, invoke @samp{Ada | Build |
611 Build}. gnatmake successfully builds @file{hello_2}. This
612 demonstrates that Emacs has remembered the main file, in the project
613 variable @code{main}, and used it for the Build command.
614
615 Finally, again while in @file{hello_pkg.adb}, invoke @samp{Ada | Build
616 | Run}. The @code{*compilation*} buffer displays @code{Hello from
617 hello_pkg.adb}.
618
619 One final point. If you switch back to buffer @file{hello.adb}, and
620 invoke @samp{Ada | Build | Run}, @file{hello_2.exe} will be run. That
621 is because @code{main} is still set to @code{hello_2}, as you can see
622 when you invoke @samp{Ada | Build | Show main}.
623
624 There are two ways to change @code{main}:
625
626 @enumerate
627 @item
628 Invoke @samp{Ada | Build | Set main and Build}, which sets @code{main} to
629 the current file.
630
631 @item
632 Invoke @samp{Ada | Build | Set Project ...}, and select a project file that
633 specifies @code{main}.
634
635 @end enumerate
636
637 @node Set compiler options, Set source search path, No project files, Compiling Examples
638 @subsection Set compiler options
639
640 This example illustrates using an Emacs Ada mode project file to set a
641 compiler option.
642
643 If you have files from @file{Example_1} open in Emacs, you should
644 close them so you don't get confused. Use menu @samp{File | Close
645 (current buffer)}.
646
647 In directory @file{Example_2}, create these files:
648
649 @file{hello.adb}:
650
651 @example
652 with Ada.Text_IO;
653 procedure Hello
654 is begin
655 Put_Line("Hello from hello.adb");
656 end Hello;
657 @end example
658
659 This is the same as @file{hello.adb} from @file{Example_1}. It has two
660 errors; missing ``use Ada.Text_IO;'', and no space between
661 @code{Put_Line} and its argument list.
662
663 @file{hello.adp}:
664
665 @example
666 comp_opt=-gnatyt
667 @end example
668
669 This tells the GNAT compiler to check for token spacing; in
670 particular, there must be a space preceding a parenthesis.
671
672 In buffer @file{hello.adb}, invoke @samp{Ada | Build | Set main and
673 Build}. This finds the project file @file{hello.adp}, uses it to set
674 the compiler options, and builds the project. You should get a
675 @code{*compilation*} buffer containing something like (the directory
676 paths will be different):
677
678 @example
679 cd c:/Examples/Example_2/
680 gnatmake -o hello hello -g -cargs -gnatyt -bargs -largs
681 gcc -c -g -gnatyt hello.adb
682 hello.adb:4:04: "Put_Line" is not visible
683 hello.adb:4:04: non-visible declaration at a-textio.ads:264
684 hello.adb:4:04: non-visible declaration at a-textio.ads:260
685 hello.adb:4:12: (style) space required
686 gnatmake: "hello.adb" compilation error
687 @end example
688
689 Compare this to the compiler output in @ref{No project files}; the
690 gnatmake option @code{-cargs} has been replaced by @code{-cargs
691 -gnaty}, and an additional error is reported in @file{hello.adb} on
692 line 4. This shows that @file{hello.adp} is being used to set the
693 compiler options.
694
695 Fixing the error, linking and running the code proceed as in @ref{No
696 project files}.
697
698 @node Set source search path, Use GNAT project file, Set compiler options, Compiling Examples
699 @subsection Set source search path
700
701 In this example, we show how to deal with files in more than one
702 directory, using an Emacs Ada mode project file to set the search
703 path.
704
705 Create the directory @file{Example_3}, containing:
706
707 @file{hello_pkg.ads}:
708
709 @example
710 package Hello_Pkg is
711 procedure Say_Hello;
712 end Hello_Pkg;
713 @end example
714
715 @file{hello_pkg.adb}:
716
717 @example
718 with Ada.Text_IO;
719 package 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;
724 end Hello_Pkg;
725 @end example
726
727 These are the same files from example 1; @file{hello_pkg.adb} has an
728 error on line 2.
729
730 In addition, create a directory @file{Example_3/Other}, containing these files:
731
732 @file{Other/hello_3.adb}:
733
734 @example
735 with Hello_Pkg;
736 with Ada.Text_IO; use Ada.Text_IO;
737 procedure Hello_3
738 is begin
739 Hello_Pkg.Say_Hello;
740 Put_Line ("From hello_3");
741 end Hello_3;
742 @end example
743
744 There are no errors in this file.
745
746 @file{Other/other.adp}:
747
748 @example
749 src_dir=..
750 @end example
751
752 Note that there must be no trailing spaces.
753
754 In buffer @file{hello_3.adb}, invoke @samp{Ada | Project files | Find and
755 set project...}, and select @file{Example_3/Other/other.adp}. This
756 tells Emacs Ada mode to stop using the project file from
757 @file{Example_2}, and use the one for @file{Example_3}. Also note that
758 since this project file is not named @file{hello_3.adp}, it would not
759 be found by default.
760
761 Then, again in @file{hello_3.adb}, invoke @samp{Ada | Set main and
762 Build}. You should get a @code{*compilation*} buffer containing
763 something like (the directory paths will be different):
764
765 @example
766 cd c:/Examples/Example_3/Other/
767 gnatmake -o hello_3 hello_3 -g -cargs -I.. -bargs -largs
768 gcc -c -g -I.. hello_3.adb
769 gcc -c -I./ -g -I.. -I- C:\Examples\Example_3\hello_pkg.adb
770 hello_pkg.adb:2:08: keyword "body" expected here [see file name]
771 gnatmake: "C:\Examples\Example_3\hello_pkg.adb" compilation error
772 @end example
773
774 Compare the @code{-cargs} option to the compiler output in @ref{Set
775 compiler options}; this shows that @file{other.adp} is being used to
776 set the compiler options.
777
778 Move to the error with @kbd{C-x `}. Ada mode searches the list of
779 directories given by @code{src_dir} for the file mentioned in the
780 compiler error message.
781
782 Fixing the error, linking and running the code proceed as in @ref{No
783 project files}.
784
785 @node Use GNAT project file, Use multiple GNAT project files, Set source search path, Compiling Examples
786 @subsection Use GNAT project file
787
788 In this example, we show how to use a GNAT project file, with no Ada
789 mode project file.
790
791 Create the directory @file{Example_4}, containing:
792
793 @file{hello_pkg.ads}:
794
795 @example
796 package Hello_Pkg is
797 procedure Say_Hello;
798 end Hello_Pkg;
799 @end example
800
801 @file{hello_pkg.adb}:
802
803 @example
804 with Ada.Text_IO;
805 package Hello_Pkg is
806 procedure Say_Hello
807 is begin
808 Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
809 end Say_Hello;
810 end Hello_Pkg;
811 @end example
812
813 These are the same files from example 1; @file{hello_pkg.adb} has an
814 error on line 2.
815
816 In addition, create a directory @file{Example_4/Gnat_Project},
817 containing these files:
818
819 @file{Gnat_Project/hello_4.adb}:
820
821 @example
822 with Hello_Pkg;
823 with Ada.Text_IO; use Ada.Text_IO;
824 procedure Hello_4
825 is begin
826 Hello_Pkg.Say_Hello;
827 Put_Line ("From hello_4");
828 end Hello_4;
829 @end example
830
831 There are no errors in this file.
832
833 @file{Gnat_Project/hello_4.gpr}:
834
835 @example
836 project Hello_4 is
837 for Source_Dirs use (".", "..");
838 end Hello_4;
839 @end example
840
841 In buffer @file{hello_4.adb}, invoke @samp{Ada | Project | Load...}, and
842 select @file{Example_4/Gnat_Project/hello_4.gpr}.
843
844 Then, again in @file{hello_4.adb}, invoke @samp{Ada | Set main and
845 Build}. You should get a @code{*compilation*} buffer containing
846 something like (the directory paths will be different):
847
848 @example
849 -*- mode: compilation; default-directory: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project/" -*-
850 Compilation started at Mon Oct 21 11:28:31
851
852 gnatmake -Pc:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project/hello_4.gpr -o hello_4 hello_4 -cargs -I. -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4 -Ic:/Apps/GNAT-7.1.2/lib/gcc/i686-pc-mingw32/4.7.3/adainclude -bargs -largs
853 gcc -c -I. -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4 -Ic:/Apps/GNAT-7.1.2/lib/gcc/i686-pc-mingw32/4.7.3/adainclude -I- -gnatA C:\Projects\org.emacs.ada-mode.stephe-1\test\Example_4\hello_pkg.adb
854 hello_pkg.adb:2:08: keyword "body" expected here [see file name]
855 gnatmake: "C:\Projects\org.emacs.ada-mode.stephe-1\test\Example_4\hello_pkg.adb" compilation error
856
857 Compilation exited abnormally with code 4 at Mon Oct 21 11:28:31
858 @end example
859
860 Compare the @code{gcc} options to the compiler output in @ref{Set
861 compiler options}; this shows that @file{hello_4.gpr} is being used to
862 set the compiler options.
863
864 Fixing the error, linking and running the code proceed as in @ref{No
865 project files}.
866
867 @node Use multiple GNAT project files, Use a Makefile, Use GNAT project file, Compiling Examples
868 @subsection Use multiple GNAT project files
869
870 In this example, we show how to use multiple GNAT project files,
871 specifying the GNAT project search path in an Ada mode project file.
872
873 Create the directory @file{Example_4} as specified in @ref{Use GNAT
874 project file}.
875
876 Create the directory @file{Example_5}, containing:
877
878 @file{hello_5.adb}:
879
880 @example
881 with Hello_Pkg;
882 with Ada.Text_IO; use Ada.Text_IO;
883 procedure Hello_5
884 is begin
885 Hello_Pkg.Say_Hello;
886 Put_Line ("From hello_5");
887 end Hello_5;
888 @end example
889
890 There are no errors in this file.
891
892 @file{hello_5.adp}:
893
894 @example
895 ada_project_path=../Example_4/Gnat_Project
896 gpr_file=hello_5.gpr
897 @end example
898
899 @file{hello_5.gpr}:
900
901 @example
902 with "hello_4";
903 project Hello_5 is
904 for Source_Dirs use (".");
905 package Compiler is
906 for Default_Switches ("Ada") use ("-g", "-gnatyt");
907 end Compiler;
908 end Hello_5;
909 @end example
910
911 In buffer @file{hello_5.adb}, invoke @samp{Ada | Project | Find and
912 select project...}, and select @file{Example_5/hello_5.adp}. This
913 would also be found by default if no previous project file had been
914 selected.
915
916 Then, again in @file{hello_5.adb}, invoke @samp{Ada | Build | Set main
917 and Build}. You should get a @code{*compilation*} buffer containing
918 something like (the directory paths will be different):
919
920 @example
921 -*- mode: compilation; default-directory: "c:/Projects/org.emacs.ada-mode.stephe-1/test/Example_5/" -*-
922 Compilation started at Mon Oct 21 11:32:05
923
924 gnatmake -Pc:/Projects/org.emacs.ada-mode.stephe-1/test/Example_5/hello_5.gpr -o hello_5 hello_5 -cargs -I. -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_5 -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4 -Ic:/Apps/GNAT-7.1.2/lib/gcc/i686-pc-mingw32/4.7.3/adainclude -bargs -largs
925 gcc -c -I. -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_5 -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4/Gnat_Project -Ic:/Projects/org.emacs.ada-mode.stephe-1/test/Example_4 -Ic:/Apps/GNAT-7.1.2/lib/gcc/i686-pc-mingw32/4.7.3/adainclude -I- -gnatA C:\Projects\org.emacs.ada-mode.stephe-1\test\Example_4\hello_pkg.adb
926 hello_pkg.adb:2:08: keyword "body" expected here [see file name]
927 gnatmake: "C:\Projects\org.emacs.ada-mode.stephe-1\test\Example_4\hello_pkg.adb" compilation error
928
929 Compilation exited abnormally with code 4 at Mon Oct 21 11:32:05
930 @end example
931
932 Now type @kbd{C-x `}. @file{Example_4/hello_pkg.adb} is shown,
933 demonstrating that @file{hello_5.gpr} and @file{hello_4.gpr} are being
934 used to set the compilation search path.
935
936 @node Use a Makefile, , Use multiple GNAT project files, Compiling Examples
937 @subsection Use a Makefile
938
939 In this example, we show how to use a Makefile to build an Ada project
940 with GNAT, run the result, and clean the build directories.
941
942 Create the directories @file{Example_4, Example_5} as specified in @ref{Use GNAT
943 project file}, @ref{Use multiple GNAT project files}.
944
945 In @file{Example_5}, add the file:
946
947 @file{Makefile}:
948
949 @example
950 # build and run hello_5 project
951
952 all : build run
953
954 .PHONY : force
955
956 build : force
957 gprbuild -Phello_5.gpr hello_5
958
959 run :
960 ./hello_5
961
962 clean :
963 gnatclean -r -Phello_5
964
965 export GPR_PROJECT_PATH = ../Example_4/Gnat_Project
966
967 # Local Variables:
968 # eval:(ada-parse-prj-file "hello_5.adp")
969 # eval:(ada-select-prj-file "hello_5.adp")
970 # End:
971 @end example
972
973 Close and re-open @file{Makefile}; the @samp{Local Variables} section
974 sets the project file to @file{hello_5.adp} when the @file{Makefile}
975 is opened. You can also use @key{C-x C-e} to execute the select line
976 after the @file{Makefile} is opened, to change the project file back
977 to @file{hello_5.adp}.
978
979 In @file{Makefile}, invoke @samp{Tools | Compile...}, and accept the
980 default make command. This runs the @samp{all} target, which builds
981 @file{hello_5} and runs it.
982
983 @node Compiler errors, , Compiling Examples, Compiling Executing
984 @section Compiler errors
985
986 The @code{Check syntax} and @code{Build} commands, or running
987 @code{make}, place compilation errors in a separate buffer named
988 @code{*compilation*}.
989
990 Each line in this buffer will become active: you can simply click on
991 it with the middle button of the mouse, or move point to it and press
992 @key{RET}. Emacs will then display the relevant source file and put
993 point on the line and column where the error was found.
994
995 You can also press the @kbd{C-x `} key (@code{next-error}), and Emacs
996 will jump to the first error. If you press that key again, it will
997 move you to the second error, and so on.
998
999 Some error messages also include references to other files. These
1000 references are accessed via @kbd{C-c `}.
1001
1002 @node Project files, Moving Through Ada Code, Compiling Executing, Top
1003 @chapter Project files
1004
1005 An Emacs Ada mode project file specifies what directories hold sources
1006 for your project, and allows you to customize the compilation commands
1007 and other things on a per-project basis.
1008
1009 The default file extension for Ada mode project files is @file{*.adp}
1010 or @file{*.prj}. You can use a different extension by adding it to
1011 @code{ada-prj-file-extensions}, and a different syntax by adding a
1012 parser function to @code{ada-prj-parser-alist}.
1013
1014 Note that Ada mode project files @file{*.adp} are different than GNAT
1015 compiler project files @samp{*.gpr}. However, Emacs Ada mode can use a
1016 GNAT project file to specify the project directories. If no
1017 other customization is needed, a GNAT project file can be used without
1018 an Emacs Ada mode project file.
1019
1020 If no Emacs Ada mode project file is specified, some Ada mode
1021 functions are not available.
1022
1023 @menu
1024 * Project file overview::
1025 * Project file variables::
1026 @end menu
1027
1028 @node Project file overview, Project file variables, Project files, Project files
1029 @section Project file overview
1030
1031 Project files have a simple syntax; they may be edited directly. Each
1032 line specifies a project variable name and its value, separated by
1033 ``='' (spaces not allowed):
1034 @example
1035 src_dir=/Projects/my_project/src_1
1036 src_dir=/Projects/my_project/src_2
1037 @end example
1038
1039 Any line that does not have an ``='' is a comment.
1040
1041 Some variables (like @code{src_dir}) are lists; multiple occurrences
1042 are concatenated.
1043
1044 There must be no space between the variable name and ``='', and no
1045 trailing spaces.
1046
1047 The current project file is given by the lisp variable
1048 @code{ada-prj-default-project-file}, and shown by the menu command
1049 @key{Ada | Project Files | Show project}.
1050
1051 To set the project file, use the menu command @samp{Ada | Set Project
1052 ...}, or the elisp functions @code{ada-parse-prj-file,
1053 ada-select-prj-file}. The latter can be added to a Makefile:
1054
1055 @example
1056 # Local Variables:
1057 # eval: (ada-parse-prj-file "ada-mode.prj")
1058 # eval: (ada-select-prj-file ada-mode.prj")
1059 # End:
1060 @end example
1061
1062 You specify either a GNAT project file or an Emacs Ada mode project
1063 file; if the file extension is @code{.gpr}, the file is treated as a
1064 GNAT project file. Extensions given by @code{ada-prj-file-extensions}
1065 (default @file{.adp, .prj}) are treated as an Emacs Ada mode
1066 project file.
1067
1068 After a project file is parsed, you can make it current again with
1069 just @code{ada-select-prj-file}, or by selecting it from the menu.
1070
1071 @node Project file variables, , Project file overview, Project files
1072 @section Project file variables
1073
1074 To set a project variable that is a list, specify each element of the
1075 list on a separate line in the project file.
1076
1077 Process environment variables can be referenced using the
1078 normal @code{$var} syntax.
1079
1080 Most project variables have defaults that can be changed by setting
1081 elisp variables; the table below identifies the elisp variable for each
1082 project variable. Elisp variables corresponding to project variables
1083 that are lists are elisp lists.
1084
1085 In general, project variables are evaluated when referenced in Emacs
1086 Ada mode commands. Relative file paths are expanded relative to the
1087 directory containing the project file.
1088
1089 Ada mode defines some project variables; others are defined by the
1090 compiler.
1091
1092 Here is the list of variables valid for all compilers. In the default
1093 values, the current directory @code{"."} is the directory containing
1094 the project file.
1095
1096 @table @asis
1097 @c These are the names that appear in the .adp file, which are the
1098 @c same as the symbols used with ada-prj-get
1099 @c
1100 @c defined in ada-mode.el ada-prj-parse-file-1; alphabetical order
1101 @c defaults defined in ada-mode.el ada-prj-default
1102
1103 @item @code{ada_compiler} [default: @code{ada-compiler, gnat}]
1104 Ada compiler for this project. It must occur in the project file
1105 before any compiler-specific project variable.
1106
1107 @item @code{auto_case} [default: @code{ada-auto-case, t}]
1108 Non-nil means automatically change case of preceding word while typing.
1109
1110 @item @code{case_identifier} [default: @code{ada-case-identifier, ada-mixed-case}]
1111 Function to call to adjust the case of an Ada identifier.
1112
1113 @item @code{case_keyword} [default: @code{ada-case-keyword, downcase-word}]
1114 Function to call to adjust the case of an Ada keyword.
1115
1116 @item @code{case_strict} [default: @code{ada-case-strict, t}]
1117 If non-nil, @code{ada-mixed-case} forces @code{Mixed_Case} for identifiers.
1118 Otherwise, @code{ada-mixed-case} allows @code{UPPERCASE} for identifiers.
1119
1120 @item @code{casing} [default: @code{ada-case-exception-file, nil}]
1121 List of files containing casing exceptions. @xref{Automatic casing}.
1122
1123 @item @code{el_file} [default: ]
1124 The value is a file name, which is loaded as an elisp file when the
1125 project file is parsed or selected. This allows setting Ada mode indentation
1126 variables, and any arbitrary elisp code used to customize the project.
1127
1128 @item @code{path_sep} [default: @code{path-separator}]
1129 Separator character used in compiler search paths.
1130
1131 @item @code{src_dir} [default: @code{"."}]
1132 A list of directories to search for source files.
1133
1134 @item @code{xref_tool} [default: @code{ada-xref-tool, gnat-xref}]
1135 Cross reference tool for this project.
1136
1137 @end table
1138
1139 The following variables are valid with the GNAT compiler:
1140
1141 @table @asis
1142 @c defined in ada-gnat.el ada-gnat-prj-parse-emacs-file; alphabetical order
1143 @item @code{ada_project_path} [default: @code{""}]
1144 @c ada-prj-get 'prj_dir, 'proc_env
1145 A list of directories to search for GNAT project files.
1146
1147 If set, the @code{GPR_PROJECT_PATH} process environment variable is
1148 set to this value in the child process that runs GNAT tools. If not
1149 set, @code{GPR_PROJECT_PATH} in the child process is inherited from
1150 the Emacs process.
1151
1152 If you have the @code{GPR_PROJECT_PATH} or @code{ADA_PROJECT_PATH}
1153 environment variable set in the Emacs process correctly for all of
1154 your projects, you do not need to set this project variable.
1155
1156 The project search path can also be set in GNAT aggregate
1157 projects. However, the gnat tools do not make that path available to
1158 Emacs, so you must duplicate it in an Emacs Ada project file.
1159
1160 @item @code{gpr_file} [default: @code{""}]
1161 The GNAT project file.
1162
1163 If set, the source and project directories specified in the GNAT
1164 project file are appended to @code{src_dir} and
1165 @code{ada_project_path}. This allows specifying Ada source directories
1166 with a GNAT project file, and other source directories with the Emacs
1167 project file.
1168
1169 @item @code{gpr_project_path} [default: @code{""}]
1170 Same as @code{ada_project_path}.
1171
1172 @end table
1173
1174 @node Moving Through Ada Code, Identifier completion, Project files, Top
1175 @chapter Moving Through Ada Code
1176
1177 There are several commands to navigate through Ada code. All
1178 these functions are available through the Ada menu and keybindings.
1179
1180 Some of these commands rely on cross reference facilities provided by
1181 the compiler; the standard Emacs Ada mode only supports the GNAT
1182 compiler, but others can be added (@pxref{Other cross-reference}).
1183
1184 @table @kbd
1185 @item C-c C-d
1186 @findex ada-goto-declaration
1187 Move from any use of an identifier to its declaration, for from a declaration to
1188 its body (if there is one).
1189
1190 @item C-c M-d
1191 @findex ada-goto-declaration-parent
1192 Move from a child type declaration to the parent type declaration;
1193 display a list of references if there is more than one parent.
1194
1195 @item C-c C-n
1196 @findex ada-next-statement-keyword
1197 Move to the next keyword in the current statement.
1198
1199 For example, if point is on @samp{if}, move to @samp{then}.
1200
1201 @item C-c C-p
1202 @findex ada-prev-statement-keyword
1203 Move to the previous keyword in the current statement.
1204
1205 For example, if point is on @samp{then}, move to @samp{if}.
1206
1207 @item C-c C-o
1208 @findex ada-find-other-file
1209 Switch between corresponding spec and body. There are several special
1210 cases:
1211
1212 @itemize @bullet
1213 @item
1214 If the region is active, it is assumed to contain an Ada package
1215 name; position point on the corresponding package declaration.
1216
1217 @item
1218 If point is in the start line of a top level child package
1219 declaration (but not package body), or a child subprogram spec or
1220 body, position point on the corresponding parent package
1221 declaration.
1222
1223 @item
1224 If point is in the start line of a top level separate body,
1225 position point on the corresponding separate stub declaration.
1226
1227 @item
1228 If point is in a subprogram declaration or body, position point on the
1229 corresponding body or declaration in the other file.
1230
1231 @item
1232 If point is on a @code{with} clause, position point on the
1233 corresponding declaration.
1234
1235 @end itemize
1236
1237 @item C-c C-r
1238 @findex ada-show-references
1239 Show all references to the identifier surrounding point. Use
1240 @kbd{C-x `} (@code{next-error}) to visit each reference (as for
1241 compilation errors).
1242
1243 @item C-c C-x
1244 @findex ada-show-overriding
1245 Show all declarations that override the primitive procedure at
1246 point. Use @kbd{C-x `} (@code{next-error}) to visit each reference (as
1247 for compilation errors).
1248
1249 @item C-c M-x
1250 @findex ada-show-overridden
1251 Show the declaration that the declaration at point overrides.
1252
1253 @item C-u SPACE
1254 Jump back to the previous location.
1255
1256 @item Ada | Misc | Refresh cross reference cache
1257 Cross reference information is loaded from the compiler output when
1258 the first cross reference command is issued. If the code is recompiled
1259 after that, the cross reference information is reloaded by invoking
1260 this menu command.
1261
1262 @end table
1263
1264 @node Identifier completion, Indentation, Moving Through Ada Code, Top
1265 @chapter Identifier completion
1266
1267 Emacs provides a general way of completing identifiers: @kbd{M-/}
1268 (bound to @code{dabbrev-expand}). This is an easy way to type faster:
1269 you just have to type the first few letters of an identifier, and then
1270 loop through all the possible completions.
1271
1272 @kbd{M-/} works by parsing all open Ada files for possible
1273 completions.
1274
1275 For instance, if the words @samp{my_identifier} and @samp{my_subprogram}
1276 are the only words starting with @samp{my} in any of the open Ada files,
1277 then you will have this scenario:
1278
1279 @example
1280 You type: my@kbd{M-/}
1281 Emacs inserts: @samp{my_identifier}
1282 If you press @kbd{M-/} once again, Emacs replaces @samp{my_identifier} with
1283 @samp{my_subprogram}.
1284 Pressing @kbd{M-/} once more will bring you back to @samp{my_identifier}.
1285 @end example
1286
1287 This is a very fast way to do completion, and the casing of words will
1288 also be respected.
1289
1290 @node Indentation, Statement skeletons, Identifier completion, Top
1291 @chapter Indentation
1292
1293 Ada mode comes with a full set of rules for automatic indentation. You
1294 can also configure the indentation, via the following variables:
1295
1296 @table @asis
1297 @item @code{ada-indent} (default value: 3)
1298 Number of columns for default indentation.
1299
1300 @item @code{ada-indent-broken} (default value: 2)
1301 Number of columns to indent the continuation of a broken line.
1302
1303 @item @code{ada-indent-comment-col-0} (default value: nil)
1304 If non-nil, comments currently starting in column 0 are left in column
1305 0. Otherwise, they are indented with previous comments or code.
1306
1307 @item @code{ada-indent-label} (default value: -3)
1308 Number of columns to indent a label.
1309
1310 @item @code{ada-indent-record-rel-type} (default value: 3)
1311 Indentation for @code{record} relative to @code{type} or @code{use}.
1312
1313 @item @code{ada-indent-renames} (default value: 2)
1314 Indentation for @code{renames} relative to the matching subprogram keyword.
1315
1316 If the subprogram has parameters then if @code{ada-indent-renames} is
1317 zero or less the indentation is abs @code{ada-indent-renames} relative
1318 to the open parenthesis; if @code{ada-indent-renames} is one or more
1319 the indentation is relative to the line containing the keyword.
1320
1321 If the subprogram has no parameters then @code{ada-indent-broken} the
1322 indentation is relative to the indentation of the line containing
1323 the keyword.
1324
1325 @item @code{ada-indent-return} (default value: 0)
1326 Indentation for @code{return} relative to the matching
1327 @code{function}.
1328
1329 If the function has parameters, then if @code{ada-indent-return} is
1330 zero or less the indentation is abs @code{ada-indent-return} relative
1331 to the open parenthesis; if @code{ada-indent-return} is one or more,
1332 indentation is relative to line containing @code{function}.
1333
1334 If the function has no parameters, @code{ada-indent-broken} is used
1335 relative to line containing @code{function}.
1336
1337 @item @code{ada-indent-use} (default value: ada-indent-broken)
1338 Indentation for the lines in a @code{use} statement.
1339
1340 @item @code{ada-indent-when} (default value: 3)
1341 Indentation for @code{when} relative to @code{exception}, @code{case},
1342 or @code{or} in @code{select}.
1343
1344 @item @code{ada-indent-with} (default value: ada-indent-broken)
1345 Indentation for the lines in a @code{with} context clause.
1346
1347 @end table
1348
1349 The indentation variables are buffer local; the global value may be
1350 overridden in an elisp file invoked by an @code{el_file} Emacs Ada
1351 mode project file statement, or in a file local variable section.
1352
1353 The following keys indent portions of the text:
1354 @table @kbd
1355
1356 @item RET
1357 Insert and indent a new line.
1358
1359 @item TAB
1360 Indent the current line, or the current region.
1361
1362 @item C-c TAB
1363 Indent the current statement or declaration.
1364
1365 @end table
1366
1367 The indentation algorithm relies on a grammar parser to identify the
1368 syntactic role for keywords and other words in the code. If the code
1369 is accepted by the parser, the indentation is done according to the
1370 rules in the indentation engine.
1371
1372 If the code is not accepted (because it is partially complete during
1373 editing), the indentation engine falls back to the trivial algorithm
1374 of indenting each new line the same as the previous line. Once enough
1375 new text has been entered to make the code acceptable to the parser,
1376 the statement or declaration is properly indented.
1377
1378 For example, if you are entering this code:
1379
1380 @example
1381 if A then
1382 B;
1383 end if;
1384 @end example
1385
1386 when you type @kbd{RET B}, @code{B} is indented to the same column as
1387 @code{if}, because the parser does not find @code{end if;}. Then when
1388 you type the final @code{;} followed by @key{TAB}, all three lines are
1389 indented, putting @code{B} where it belongs.
1390
1391 To be more user friendly, the parser accepts a superset of the Ada
1392 grammer. For example, the parser accepts this code for an @code{if}
1393 statement:
1394
1395 @example
1396 if then
1397 end if;
1398 @end example
1399
1400 In general, any sequence of statements, and many expressions, may be
1401 omitted.
1402
1403 One way to easily insert empty statements like this is using
1404 @ref{Statement skeletons}.
1405
1406 In rare cases, the parser gets confused; it can be reset by invoking
1407 menu @key{Ada | Misc | Reset parser}. Please report such cases as a
1408 bug.
1409
1410 @node Statement skeletons, Aligning code, Indentation, Top
1411 @chapter Statement skeletons
1412
1413 @kbd{C-c C-e} expands the previous one or two words into a statment
1414 skeleton. For example, @kbd{i f C-c C-e} expands to:
1415
1416 @example
1417 if then
1418 elsif then
1419 else
1420 end if;
1421 @end example
1422
1423 All skeleton expansions are accepted by the indentation parser, so
1424 this is a convenient way to insert statements with correct
1425 indentation.
1426
1427 For named statements (packages, loops, etc), the name is taken from
1428 the word before point, and the name of the statement from the word
1429 before that.
1430
1431 Some expansions prompt for more information, such as
1432 whether a spec or body is desired. For example, @kbd{package A_Package
1433 C-c C-e} first prompts for ``body'' or ``spec''. If ``spec'' is
1434 selected, the following code is inserted:
1435
1436 @example
1437 package A_Package is
1438 private
1439 end A_Package;
1440 @end example
1441
1442 Named blocks work similarly: @kbd{declare A_Block C-c C-e} expands
1443 (without prompting) to:
1444
1445 @example
1446 A_Block:
1447 declare
1448 begin
1449 exception
1450 end A_Block;
1451 @end example
1452
1453 Note that the order of the keyword @code{declare} and the name
1454 @code{A_Block} are reversed in the expansion; this may take some
1455 getting used to. Alternately, if no name is present in the buffer, you
1456 are prompted for a name: @kbd{declare C-c C-e} first prompts for a
1457 name, then expands to the above.
1458
1459 The variable @code{ada-skel-initial-string} defines what to insert in
1460 a newly created empty buffer. It defaults to @code{@{header@}}, which
1461 is a placeholder defined by @code{ada-skel-header}, which inserts a
1462 typical header with a copyright license (choice of GPL or
1463 restricted). Users will typically want to override the definition of
1464 @code{ada-skel-initial-string} and/or @code{ada-skel-header}, or
1465 provide more choices of copyright license.
1466
1467 @node Aligning code, Automatic casing, Statement skeletons, Top
1468 @chapter Aligning code
1469
1470 Aligning code adds space in each line so that similar parts of
1471 successive lines are aligned vertically. For example, a sequence of
1472 declarations:
1473
1474 @example
1475 A : Integer;
1476 Another : Float := 1.0;
1477 More : Integer := 2;
1478 @end example
1479
1480 changes to this when aligned:
1481
1482 @example
1483 A : Integer;
1484 Another : Float := 1.0;
1485 More : Integer := 2;
1486 @end example
1487
1488 Alignment is invoked by @kbd{C-c C-a}, which aligns the sequence of
1489 statements surrounding point, or within the selected region.
1490
1491 Parameter lists are also aligned:
1492
1493 @example
1494 procedure Foo
1495 (A : in Integer;
1496 Another : out Float := 1.0;
1497 More : in out Integer := 2);
1498 @end example
1499
1500 is aligned to:
1501
1502 @example
1503 procedure Foo
1504 (A : in Integer;
1505 Another : out Float := 1.0;
1506 More : in out Integer := 2);
1507 @end example
1508
1509 @node Automatic casing, Comment Handling, Aligning code, Top
1510 @chapter Automatic casing
1511
1512 Casing of identifiers, attributes and keywords is automatically
1513 performed while typing when the variable @code{ada-auto-case} is
1514 non-nil (the default). Every time you type a word separator, the
1515 previous word is automatically cased.
1516
1517 You can customize the automatic casing with the following variables:
1518
1519 @table @code
1520 @item ada-case-keyword
1521 Value must be one of:
1522 @table @code
1523 @item downcase-word
1524 Ada keywords will be lowercase.
1525
1526 @item upcase-word
1527 Ada keywords will be uppercase.
1528 @end table
1529
1530 @item ada-case-strict
1531 If non-nil, all identifiers are forced to @code{Mixed_Case}; first
1532 letter, and letter following ``_'' are uppercase; rest are
1533 lowercase.
1534
1535 If nil, the mixed case characters in identifiers are forced to upper
1536 case, but the other characters are not modified. That allows typing
1537 all uppercase identifiers without defining a casing exception.
1538 @end table
1539
1540 You can define exceptions to these rules, in files specified by the
1541 variable @code{ada-case-exception-file}. Each line in a case exception
1542 file specifies the casing of one word or word fragment. If an
1543 exception is defined in multiple files, the first occurrence is used.
1544
1545 If the word starts with an asterisk (@code{*}), it defines the casing
1546 of a word fragemnt (or ``substring''); part of a word between two
1547 underscores or word boundary.
1548
1549 For example:
1550
1551 @example
1552 DOD
1553 *IO
1554 GNAT
1555 @end example
1556
1557 The word fragment @code{*IO} applies to any word containing ``_io'';
1558 @code{Text_IO}, @code{Hardware_IO}, etc.
1559
1560 @findex ada-case-create-exception
1561 There are two ways to add new items to this file: you can simply edit
1562 it as you would edit any text file. Or you can position point on the
1563 word you want to add, and select menu @samp{Ada | Casing | Create full
1564 exception} or @samp{Ada | Casing | Create partial exception}. The
1565 word will be added to the current list of exceptions and to the file.
1566
1567 It is sometimes useful to have multiple exception files. For
1568 example, one could be the standard Ada acronyms, the second some
1569 company specific exceptions, and the last one some project specific
1570 exceptions. If you set up the variable @code{ada-case-exception-file}
1571 as a list of files, each of them will be parsed and used in your emacs
1572 session. When you create a new exception, you are prompted for the
1573 file to save it in.
1574
1575 Other keys and menu entries are defined:
1576
1577 @table @kbd
1578 @item C-c C-w
1579 @findex ada-case-adjust-at-point
1580 Adjust case of the word at point. With prefix arg, adjust case even if
1581 in comment. Normally, comments are not affected by case adjust.
1582
1583 @item Ada | Casing | Adjust case region
1584 Adjust case in the active region.
1585
1586 @item Ada | Casing | Adjust case buffer
1587 Adjust case in the active buffer.
1588
1589 @end table
1590
1591 @node Comment Handling, Key summary, Automatic casing, Top
1592 @chapter Comment Handling
1593
1594 By default, comment lines get indented like Ada code. There are a few
1595 additional functions to handle comments:
1596
1597 @table @kbd
1598 @item M-;
1599 @findex comment-dwim
1600 If the region is active, comment or uncomment it.
1601
1602 If the current line is empty, start a comment.
1603
1604 Otherwise, add a comment at the end of the line, in a column given by
1605 @code{comment-column}.
1606
1607 @item M-q
1608 @findex fill-paragraph
1609 Fill the current comment paragraph.
1610 @end table
1611
1612 @node Key summary, Developer overview, Comment Handling, Top
1613 @chapter Key summary
1614 @c search for @kbd and @key. Alphabetical by key sequence
1615
1616 This table summarizes the keys described in this manual. Other keys
1617 are bound by Ada mode; see @key{C-h b} for a complete list. The
1618 Ada menu also displays keys bound to menu operations.
1619
1620 @table @kbd
1621 @item M-/
1622 @xref{Identifier completion}.
1623 Complete the word before point; repeat to cycle thru possible
1624 completions.
1625
1626 @item M-;
1627 @xref{Comment Handling}.
1628 If the region is active, comment or uncomment it.
1629
1630 @item M-q
1631 @xref{Comment Handling}.
1632 Fill the current comment paragraph.
1633
1634 @item RET
1635 @xref{Indentation}.
1636 Insert and indent a new line.
1637
1638 @item TAB
1639 @xref{Indentation}.
1640 Indent the current line, or the current region.
1641
1642 @item C-c TAB
1643 @xref{Indentation}.
1644 Indent the current statement or declaration.
1645
1646 @item C-c `
1647 @xref{Compiler errors}.
1648 Move to the location of the secondary reference in the current compilation error.
1649
1650 @item C-c C-a
1651 @xref{Aligning code}.
1652 Align code.
1653
1654 @item C-c C-c
1655 @xref{Compile commands}.
1656 Build the current main program.
1657
1658 @item C-c C-d
1659 @xref{Moving Through Ada Code}.
1660 Move from any use of an identifier to its declaration, for from a declaration to its body.
1661
1662 @item C-c M-d
1663 @xref{Moving Through Ada Code}.
1664 Move from a child type declaration to the parent type declaration.
1665
1666 @item C-c C-e
1667 @xref{Statement skeletons}.
1668 Expand previous one or two words into a statement or declaration
1669 skeleton.
1670
1671 @item C-c C-c
1672 @xref{Compile commands}.
1673 Build the current file.
1674
1675 @item C-c C-n
1676 @xref{Moving Through Ada Code}.
1677 Move to the next keyword in the current statement.
1678
1679 @item C-c C-o
1680 @xref{Moving Through Ada Code}.
1681 Switch between corresponding spec and body, or find other spec.
1682
1683 @item C-c C-p
1684 @xref{Moving Through Ada Code}.
1685 Move to the previous keyword in the current statement.
1686
1687 @item C-c C-r
1688 @xref{Moving Through Ada Code}.
1689 Show all references to the identifier surrounding point.
1690
1691 @item C-c C-w
1692 @xref{Automatic casing}.
1693 Adjust case of the word at point. With prefix arg, adjust case even if
1694 in comment.
1695
1696 @item C-c C-x
1697 @xref{Moving Through Ada Code}.
1698 Show all declarations that override the primitive procedure at
1699 point.
1700
1701 @item C-c C-y
1702 @xref{Automatic casing}.
1703 Create case exception.
1704
1705 @item C-c `
1706 @xref{Compiler errors}.
1707 Move to the location of the next secondary compilation error.
1708
1709 @item C-x `
1710 @xref{Compiler errors}.
1711 Move to the location of the next compilation error or show result.
1712
1713 @item M-q
1714 @xref{Comment Handling}.
1715 Fill the current comment paragraph.
1716
1717 @end table
1718
1719 @node Developer overview, GNU Free Documentation License, Key summary, Top
1720 @chapter Developer overview
1721 If you'd like to contribute to Ada mode, or just understand the
1722 sources, here's an overview.
1723
1724 @menu
1725 * Directory structure::
1726 * Package organization::
1727 * OpenToken::
1728 * ELPA::
1729 @end menu
1730
1731 @node Directory structure, Package organization, Developer overview, Developer overview
1732 @section Directory structure
1733 @table @file
1734 @item org.emacs.ada-mode
1735 Main source.
1736
1737 File extensions:
1738 @table @file
1739 @item *.el
1740 Elisp files; main code.
1741
1742 @item *.elc
1743 Byte-compiled elisp files, not in the distribution. Generated by the
1744 Makefile target @code{byte-compile}, or by the Emacs package installer.
1745
1746 Compiling the parse tables (@file{*-wy.el}) speeds up loading them
1747 significantly. Compiling other files speeds up parsing, but not
1748 noticeably.
1749
1750 One reason to byte-compile files is to find errors; the byte compiler
1751 reports undefined variables, wrong argument counts, etc.
1752
1753 @item *-wy.el
1754 Parse tables, generated from the corresponding grammar @file{*.wy} by
1755 the OpenToken tool @file{wisi-generate.exe}. These are in the tarball
1756 distribution and the monotone repository so users and Elisp developers
1757 don't have to install OpenToken.
1758
1759 @item *-wy.output
1760 Diagnostic output from @file{wisi-generate.exe}, useful for tracing
1761 parses while debugging a grammar issue. Not in the tarball
1762 distribution or the monotone repository.
1763
1764 @item *.wy
1765 Grammar files, specifying the language to be parsed. The syntax for
1766 these grammar files is similar to that for bison and wisent, but not
1767 the same; see the OpenToken documentation for more info.
1768
1769 The wisi parser (in @file{wisi-parse.el}) is a generalized LALR
1770 parser, so it tolerates some conflicts and ambiguities. This makes the
1771 grammars easier to write, and in particular makes it possible to let
1772 the Ada grammar closely match Annex P of the Ada Language Reference
1773 Manual (the syntax summary).
1774
1775 @item *.texi
1776 Texinfo source for the user guides.
1777
1778 @item *.html
1779 Generated user guide in HTML format.
1780
1781 @item *.info
1782 Generated user guide in Emacs info format.
1783
1784
1785 @end table
1786
1787 @item build
1788 Makefile for building the user guides, publishing to the web page or
1789 Gnu ELPA. Test drivers.
1790
1791 @item build/wisi
1792 Makefile for building and testing with the wisi-based
1793 parser. Separate from @file{build}, because there used to be a
1794 SMIE-based parser, and there might be another parser someday.
1795
1796 The emacs used to byte-compile and run tests is given by the 'make'
1797 variable EMACS_EXE, which defaults to 'emacs'; it can be overridden on
1798 the make command line or by an environment variable.
1799
1800 @item test
1801 All tests for Ada mode, gpr mode, parser.
1802
1803 Each test is run in a separate invocation of Emacs, so it is
1804 completely independent of all other tests.
1805
1806 The tests are driven by the elisp code in @file{build/*.el}.
1807
1808 In general, the Ada mode tests open the file, execute test actions,
1809 re-indent, and re-captialize the entire file. The result is diffed
1810 with the original, and must match.
1811
1812 The test actions are defined by comments with the prefix
1813 @code{--EMACSCMD:}; they are elisp forms that invoke Ada mode
1814 functions. This is used to test navigation features and other parser
1815 effects.
1816
1817 @item test/Example_*
1818 Starting files for examples in user guide.
1819
1820 @item test/gpr
1821 Tests for gpr mode.
1822
1823 @item test/subdir
1824 More tests; allows testing path search features.
1825
1826 @item test/wisi
1827 Tests of the elisp wisi grammar compiler and parser.
1828 @end table
1829
1830 @node Package organization, OpenToken, Directory structure, Developer overview
1831 @section Package organization
1832
1833 @menu
1834 * Ada mode::
1835 * gpr mode::
1836 * GNAT core::
1837 * Wisi::
1838 @end menu
1839
1840 @node Ada mode, gpr mode, Package organization, Package organization
1841 @subsection Ada mode
1842 Ada mode consists of all files with @file{ada-} prefix in the file
1843 name.
1844
1845 @table @file
1846 @item ada-mode.el
1847 The main file, implementing the keymap, menu, and top level
1848 functionality.
1849
1850 It allows for different backend implementations for compiling,
1851 cross-referencing, and indenting. The functions for each of these
1852 backends dispatch thru global variables that are set by Emacs Ada mode
1853 project files. They default to the GNAT compiler, the gnatxref cross
1854 reference tool, and the ada-wisi indentation engine.
1855
1856 @item ada-build.el
1857 Provides functions for compiling Ada files without a Makefile (or
1858 similar tool).
1859
1860 @item ada-fix-error.el
1861 Provides an interface to utilities for automatically fixing errors
1862 reported by the compiler. It dispatches to a compiler-specific
1863 backend.
1864
1865 @item ada-gnat-compile.el
1866 Implements the Ada mode compiler functions for the GNAT compiler.
1867
1868 @item ada-gnat-xref.el
1869 Implements the Ada mode cross reference functions for the GNAT compiler.
1870
1871 @item ada-grammar.*
1872 The Ada language grammar, and files generated from it by the OpenToken
1873 tool @file{wisi-generate.exe}.
1874
1875 @item ada-indent-user-options.el
1876 All user-settable options for the Ada indentation engine.
1877
1878 @item ada-mode-compat-23.4.el
1879 Defines functions used by Ada mode that are not in Emacs 23.4.
1880
1881 Emacs Ada mode is written for Emacs 24.3. Emacs version 23.4 is
1882 partially supported. Earlier versions of Emacs are not supported.
1883
1884 @item ada-mode.texi
1885 The Ada mode user guide source and compiled versions.
1886
1887 @item ada-skel.el
1888 Skeletons for expansion of Ada syntax (@pxref{Statement
1889 skeletons}). Extends the Emacs skeleton functions with ``tokens'',
1890 inspired by the lamented Else package (which was inspired by DEC LSE).
1891
1892 @item ada-wisi-opentoken.el
1893 Indentation functions useful when editing OpenToken code; an example
1894 of extending the Ada mode indentation engine for special
1895 circumstances.
1896
1897 @item ada-wisi.el
1898 Implements the Ada mode indentation functions for the wisi indentation
1899 engine backend.
1900
1901 @end table
1902
1903 @node gpr mode, GNAT core, Ada mode, Package organization
1904 @subsection gpr mode
1905
1906 gpr mode consists of all files with @file{gpr-} prefix in the file
1907 name. The functions in each file are similar to the similarly-named
1908 Ada mode files.
1909
1910 @node GNAT core, Wisi, gpr mode, Package organization
1911 @subsection GNAT core
1912 @table @file
1913
1914 @item gnat-core.el
1915 GNAT is actually a multi-language tool; it builds on top of the
1916 multi-language gcc.
1917
1918 @file{gnat-core.el} is a start at a language-agnostic interface to the
1919 GNAT tools. It was first factored out from @file{ada-gnat.el} and
1920 @file{ada-mode.el} to support the multi-language
1921 @file{gnat-inspect.el}, which is still experimental.
1922
1923 More code currently in @file{ada-mode.el} could be migrated to
1924 @file{gnat-core.el}, in particular the project file support.
1925
1926 @item gnat-inspect.el
1927 Provides an experimental interface to the experimental multi-language
1928 cross-reference tool @file{gnatinspect} from AdaCore, which will
1929 supercede @file{gnatxref}.
1930
1931 Implements the Ada mode cross-reference functions for the
1932 @file{gnatinspect} backend, and a minor mode providing similar
1933 functions for C++.
1934
1935 @end table
1936
1937 @node Wisi, , GNAT core, Package organization
1938 @subsection Wisi
1939
1940 The ``wisi'' parser. ``wisi'' used to be an acronym, but now it's just
1941 a name.
1942
1943 @table @file
1944 @item wisi.el
1945 Implements the lexer, the main parser driver,
1946 parser actions that cache parser information in text properties,
1947 utilities for indenting and navigating using the cached information,
1948 and general setup.
1949
1950 @item wisi-compile.el
1951 Implements the parse table
1952 compiler. @file{wisi-generate.exe} processes the grammar source
1953 @file{*.wy} into an elisp source representation of a parse table
1954 @file{*-wy.el}. That is compiled into an internal structure containing
1955 the state transitions and executable actions. The actions can be any
1956 elisp form; the intent is that they be calls to the action functions
1957 provided by @file{wisi.el}. @file{wisi-compile.el} uses some features
1958 provided by @code{semantic}.
1959
1960 @item wisi-parse.el
1961 Implements the generalized LALR parser.
1962 @end table
1963
1964 @node OpenToken, ELPA, Package organization, Developer overview
1965 @section OpenToken
1966 Ada mode uses the OpenToken tool @file{wisi-generate.exe} to process
1967 the grammar sources into elisp parse tables. See
1968 @uref{http://stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html} for
1969 current information about which version of OpenToken is required, and
1970 how to get it.
1971
1972 The Makefile variable @code{WISI_OPENTOKEN} gives the path to the
1973 build directory for OpenToken; you probably need to override it with
1974 an external environment variable or on the @code{make} command line.
1975
1976 @node ELPA, , OpenToken, Developer overview
1977 @section ELPA
1978 Ada mode is published via the Gnu ELPA archive. To test a new version
1979 of Ada mode, we use a local Gnu ELPA archive. That requires fetching
1980 Gnu ELPA via git:
1981
1982 @example
1983 cd /Projects
1984 git clone git://git.savannah.gnu.org/emacs/elpa.git
1985 @end example
1986
1987 If you have an Emacs Savannah developer account, you can use:
1988
1989 @example
1990 cd /Projects
1991 git clone <login>@@git.savannah.gnu.org/emacs/elpa.git
1992 @end example
1993
1994 @file{build/Makefile} contains targets for copying Ada mode source to
1995 the elpa workspace, and for building the elpa archive there.
1996
1997 @node GNU Free Documentation License, Index, Developer overview, Top
1998 @appendix GNU Free Documentation License
1999 @include doclicense.texi
2000
2001 @node Index, , GNU Free Documentation License, Top
2002 @unnumbered Index
2003
2004 @printindex fn
2005
2006 @bye