The Ada mode comes with a full set of rules for automatic indentation. You can of course configure the indentation as you want, by setting the value of a few variables.
As always, the preferred way to modify variables is to use the
Ada->Customize
menu (don't forget to save your changes!). This
will also show you some example of code where this variable is used, and
hopefully make things clearer.
The relevant variables are the following:
ada-broken-indent (default value: 2)
ada-indent (default value: 3)
ada-indent-record-rel-type (default value: 3)
ada-indent-return (default value: 0)
ada-indent-renames (default value: 2)
ada-label-indent (default value: -4)
ada-stmt-end-indent (default value: 0)
ada-when-indent (default value: 3)
ada-indent-is-separate (default value: t)
ada-indent-to-open-paren (default value: t)
ada-indent-after-return (default value: t)
Most of the time, the indentation will be automatic, i.e when you will press Return, the cursor will move to the correct column on the next line.
However, you might want or need sometimes to re-indent the current line or a set of lines. For this, you can simply go to that line, or select the lines, and then press TAB. This will automatically re-indent the lines.
Another mode of indentation exists that helps you to set up your indentation scheme. If you press C-c TAB, the ada-mode will do the following:
The exact indentation of the current line is the same as the one for the reference line, plus an offset given by the variable.
Once you know the name of the variable, you can either modify it through the usual <Ada->Customize> menu, or by typing <M-x customize-variable RET> in the Emacs window, and then give the name of the variable.
You can also want to reformat a set of files directly from the command line, without going into interactive mode. You should then use a command like:
emacs -batch -l ada-mode -f ada-batch-reformat file1 file2 ...
This will load the files, reformat them and save them with the same name. Note the order of the arguments on the command line, which is important. The files should appear last on the command line.