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