DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(indent.info.gz) Indentation

Info Catalog (indent.info.gz) Declarations (indent.info.gz) Indent Program (indent.info.gz) Breaking long lines
 
 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. The option `-ppi' overrides  `-nlps'
 and  `-lps'.
 
    This option can be used to request that preprocessor conditional
 statements can be indented by to given number of spaces, for example
 with the option `-ppi 3'
 
      #if X
      #if Y
      #define Z 1
      #else
      #define Z 0
      #endif
      #endif
 becomes
      #if X
      #   if Y
      #      define Z 1
      #   else
      #      define Z 0
      #   endif
      #endif
 
Info Catalog (indent.info.gz) Declarations (indent.info.gz) Indent Program (indent.info.gz) Breaking long lines
automatically generated byinfo2html