Emacs: selective c-auto-newline

Posted by Yktula on Stack Overflow See other posts from Stack Overflow or by Yktula
Published on 2010-05-23T21:42:00Z Indexed on 2010/05/24 0:30 UTC
Read the original article Hit count: 710

Filed under:
|
|
|

When c-auto-newline is set to non-nil, it re-indents the current line and inserts a carriage return and then indents the new line. However. I'm using 1TBS indent-style, which means if/else statements are made like this:

if (n == 1) {
    exit(EXIT_SUCCESS);
} else {
    perror("n");
}

Also, I write do/while write loops like this:

do {
    printf("%d\n", n++);
} while (n < 64);

As such, while I do want a newline automatically inserted after every opening brace and semicolon, I don't want newlines to be automatically inserted after an if statement or do loop is concluded with a closing brace.

How can I have GNU Emacs (23.2.1, *nix) selectively insert newlines like that? Along the same lines, can I have Emacs insert an opening brace, a newline, and a closing brace on another newline, while putting the cursor in the middle of the two braces after closing parentheses following an if statement, function declaration, and the like?

© Stack Overflow or respective owner

Related posts about c

    Related posts about emacs