ada-mode.texi 48 KB

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