views:

596

answers:

1

Right now the standard emacs indentation works like the following:


switch (cond) {
case 0: {
  command;
}
  break;
}

I want the break; to line up with case.

Also, is there a list of the c-set-offset commands somewhere?

+14  A: 

The biggest help (I've found) in customizing indentation is figuring out what cc-mode uses to indent the current line. That's what C-c C-o aka M-x c-set-offset can do - it'll allow you to customize the offset for a syntactic element, and it shows you what element was used for the current line!

Here's how you can customize it. Move your cursor to the break; line.

C-c C-o RET 0 RET

At which point, your code will be indented like:

switch (cond) {
case 0: {
  command;
}
break;
}

For documentation on the offsets, check out the docstring for the variable 'c-offsets-alist

C-h v c-offsets-alist RET

Similarly, you can add this to your .emacs:

(setq c-offsets-alist '((statement-case-intro . 0)))

The documentation for customizing indention is here and is worth reading. There are tons of ways to do it, so reading the manual is worth the time (if you want non-default indentation). And here's a pointer to all the syntactic symbols used in cc-mode.

Trey Jackson
I don't know if this answer was useful for the OP, but it damn sure was for me. I've been annoyed by emacs's insisting on indenting the opening curly-brace on blocks for years. Thanks!
T.E.D.
Awesome, worked perfectly. I have been using emacs for a couple of years but only recently started customizing it. So the emacs-lisp is all foreign to me. Thanks for the doc.
John Bellone