GNU Info

Info Node: (indent.info)Indentation

(indent.info)Indentation


Next: Breaking long lines Prev: Declarations Up: Indent Program
Enter node , (file) or (file)node

Indentation
===========

   One issue in the formatting of code is how far each line should be
indented from the left margin.  When the beginning of a statement such
as `if' or `for' is encountered, the indentation level is increased by
the value specified by the `-i' option.  For example, use `-i8' to
specify an eight character indentation for each level.  When a
statement is broken across two lines, the second line is indented by a
number of additional spaces specified by the `-ci' option.  `-ci'
defaults to 0.  However, if the `-lp' option is specified, and a line
has a left parenthesis which is not closed on that line, then
continuation lines will be lined up to start at the character position
just after the left parenthesis.  This processing also applies to `['
and applies to `{' when it occurs in initialization lists.  For
example, a piece of continued code might look like this with `-nlp
-ci3' in effect:

       p1 = first_procedure (second_procedure (p2, p3),
          third_procedure (p4, p5));

With `-lp' in effect the code looks somewhat clearer:

       p1 = first_procedure (second_procedure (p2, p3),
                             third_procedure (p4, p5));

   When a statement is broken in between two or more paren pairs (...),
each extra pair causes the indentation level extra indentation:

     if ((((i < 2 &&
             k > 0) || p == 0) &&
         q == 1) ||
       n = 0)

The option `-ipN' can be used to set the extra offset per paren.  For
instance, `-ip0' would format the above as:

     if ((((i < 2 &&
       k > 0) || p == 0) &&
       q == 1) ||
       n = 0)

`indent' assumes that tabs are placed at regular intervals of both
input and output character streams.  These intervals are by default 8
columns wide, but (as of version 1.2) may be changed by the `-ts'
option.  Tabs are treated as the equivalent number of spaces.

   The indentation of type declarations in old-style function
definitions is controlled by the `-ip' parameter.  This is a numeric
parameter specifying how many spaces to indent type declarations.  For
example, the default `-ip5' makes definitions look like this:

     char *
     create_world (x, y, scale)
          int x;
          int y;
          float scale;
     {
       . . .
     }

   For compatibility with other versions of indent, the option `-nip'
is provided, which is equivalent to `-ip0'.

   ANSI C allows white space to be placed on preprocessor command lines
between the character `#' and the command name.  By default, `indent'
removes this space, but specifying the `-lps' option directs `indent'
to leave this space unmodified.


automatically generated by info2www version 1.2.2.9