11.3.1 Brace and Parenthesis Line-Up Functions

The line-up functions here calculate the indentation for braces, parentheses and statements within brace blocks.

Function: c-lineup-close-paren

Line up the closing paren under its corresponding open paren if the open paren is followed by code. If the open paren ends its line, no indentation is added. E.g.:

main (int,
      char **
     )                <- c-lineup-close-paren

and

main (
    int, char **
)                     <- c-lineup-close-paren

As a special case, if a brace block is opened at the same line as the open parenthesis of the argument list, the indentation is c-basic-offset instead of the open paren column. See c-lineup-arglist for further discussion of this “DWIM” measure.

Works with:  All *-close symbols.

Function: c-lineup-arglist-close-under-paren

Set your arglist-close syntactic symbol to this line-up function so that parentheses that close argument lists will line up under the parenthesis that opened the argument list. It can also be used with arglist-cont and arglist-cont-nonempty to line up all lines inside a parenthesis under the open paren.

As a special case, if a brace block is opened at the same line as the open parenthesis of the argument list, the indentation is c-basic-offset only. See c-lineup-arglist for further discussion of this “DWIM” measure.

Works with:  Almost all symbols, but are typically most useful on arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty.

Function: c-indent-one-line-block

Indent a one line block c-basic-offset extra. E.g.:

if (n > 0)
    {m+=n; n=0;}      <- c-indent-one-line-block
<--> c-basic-offset

and

if (n > 0)
{                     <- c-indent-one-line-block
    m+=n; n=0;
}

The block may be surrounded by any kind of parenthesis characters. nil is returned if the line doesn’t start with a one line block, which makes the function usable in list expressions.

Works with:  Almost all syntactic symbols, but most useful on the -open symbols.

Function: c-indent-multi-line-block

Indent a multiline block c-basic-offset extra. E.g.:

int *foo[] = {
    NULL,
    {17},             <- c-indent-multi-line-block

and

int *foo[] = {
    NULL,
        {             <- c-indent-multi-line-block
        17
        },
    <--> c-basic-offset

The block may be surrounded by any kind of parenthesis characters. nil is returned if the line doesn’t start with a multiline block, which makes the function usable in list expressions.

Works with:  Almost all syntactic symbols, but most useful on the -open symbols.

Function: c-lineup-runin-statements

Line up statements for coding standards which place the first statement in a block on the same line as the block opening brace47. E.g.:

int main()
{ puts ("Hello!");
  return 0;           <- c-lineup-runin-statements
}

If there is no statement after the opening brace to align with, nil is returned. This makes the function usable in list expressions.

Works with:  The statement syntactic symbol.

Function: c-lineup-inexpr-block

This can be used with the in-expression block symbols to indent the whole block to the column where the construct is started. E.g., for Java anonymous classes, this lines up the class under the ‘new’ keyword, and in Pike it lines up the lambda function body under the ‘lambda’ keyword. Returns nil if the block isn’t part of such a construct.

Works with:  inlambda, inexpr-statement, inexpr-class.

Function: c-lineup-after-whitesmith-blocks

Compensate for Whitesmith style indentation of blocks. Due to the way CC Mode calculates anchor positions for normal lines inside blocks, this function is necessary for those lines to get correct Whitesmith style indentation. Consider the following examples:

int foo()
    {
    a;
    x;                 <- c-lineup-after-whitesmith-blocks
int foo()
    {
        {
        a;
        }
    x;                 <- c-lineup-after-whitesmith-blocks

The fact that the line with x is preceded by a Whitesmith style indented block in the latter case and not the first should not affect its indentation. But since CC Mode in cases like this uses the indentation of the preceding statement as anchor position, the x would in the second case be indented too much if the offset for statement was set simply to zero.

This lineup function corrects for this situation by detecting if the anchor position is at an open paren character. In that case, it instead indents relative to the surrounding block just like c-lineup-whitesmith-in-block.

Works with:  brace-list-entry, brace-entry-open, statement, arglist-cont.

Function: c-lineup-whitesmith-in-block

Line up lines inside a block in Whitesmith style. It’s done in a way that works both when the opening brace hangs and when it doesn’t. E.g.:

something
    {
    foo;              <- c-lineup-whitesmith-in-block
    }

and

something {
    foo;              <- c-lineup-whitesmith-in-block
    }
<--> c-basic-offset

In the first case the indentation is kept unchanged, in the second c-basic-offset is added.

Works with:  defun-close, defun-block-intro, inline-close, block-close, brace-list-close, brace-list-intro, statement-block-intro, arglist-intro, arglist-cont-nonempty, arglist-close, and all in* symbols, e.g., inclass and inextern-lang.


Footnotes

(47)

Run-in style doesn’t really work too well. You might need to write your own custom line-up functions to better support this style.