Next: Hungry WS Deletion, Previous: Electric Keys, Up: Commands

### 4.7 Auto-newline Insertion

When you have Auto-newline minor mode enabled (see Minor Modes), CC Mode inserts newlines for you automatically (in certain syntactic contexts) when you type a left or right brace, a colon, a semicolon, or a comma. Sometimes a newline appears before the character you type, sometimes after it, sometimes both.

Auto-newline only triggers when the following conditions hold:

- Auto-newline minor mode is enabled, as evidenced by the indicator ‘`a`’ after the mode name on the modeline (e.g. ‘`C/a`’ or ‘`C/la`’).
- The character was typed at the end of a line, or with only whitespace after it, and possibly a ‘`\`’ escaping the newline.
- The character is not on its own line already. (This applies only to insertion of a newline before the character.)
- The character was not typed inside of a literal 1.
- No numeric argument was supplied to the command (i.e. it was typed as normal, with no `C-u` prefix).

You can configure the precise circumstances in which newlines get inserted (see see Custom Auto-newlines). Typically, the style system (see Styles) will have set this up for you, so you probably won't have to bother.

Sometimes CC Mode inserts an auto-newline where you don't want one, such as after a ‘`}`’ when you're about to type a ‘`;`’. Hungry deletion can help here (see Hungry WS Deletion), or you can activate an appropriate clean-up, which will remove the excess whitespace after you've typed the ‘`;`’. See Clean-ups for a full description. See also Electric Keys for a summary of clean-ups listed by key.

#### Footnotes

[1] A literal is defined as any comment, string, or preprocessor macro definition. These constructs are also known as syntactic whitespace since they are usually ignored when scanning C code.