Next: , Previous: , Up: CC Mode   [Contents][Index]

8 Customizing Auto-newlines

CC Mode determines whether to insert auto-newlines in two basically different ways, depending on the character just typed:

Braces and Colons

CC Mode first determines the syntactic context of the brace or colon (see Syntactic Symbols), then looks for a corresponding element in an alist. This element specifies where to put newlines: this is any combination of before and after the brace or colon. If no alist element is found, newlines are inserted both before and after a brace, but none are inserted around a colon. See Hanging Braces and Hanging Colons.

Semicolons and Commas

The variable c-hanging-semi&comma-criteria contains a list of functions which determine whether to insert a newline after a newly typed semicolon or comma. See Hanging Semicolons and Commas.

The names of these configuration variables contain ‘hanging’ because they let you hang the pertinent characters. A character which introduces a C construct is said to hang on the right when it appears at the end of a line after other code, being separated by a line break from the construct it introduces, like the opening brace in:

while (i < MAX) {
    total += entry[i];
    entry [i++] = 0;
}

A character hangs on the left when it appears at the start of the line after the construct it closes off, like the above closing brace.

The next chapter, “Clean-ups”, describes how to configure CC Mode to remove these automatically added newlines in certain specific circumstances. See Clean-ups.

Next: Clean-ups, Previous: Customizing Filling and Line Breaking, Up: CC Mode   [Contents][Index]