views:

889

answers:

2

In emacs, when I type:

public void foo(String one,
    String two) {

It tabifies like this:

public void foo(String one,
                String two) {

I'd rather it didn't, and just aligned parameters like other line continuations. How can I configure it not to do this?

+12  A: 

This comes from the Info manual for Emacs CC Mode, using GNU Emacs 23.1 on Windows:

  1. Start building your Java class that's not indenting properly. In your case, exactly what you've typed above.
  2. Move your cursor to the start of the line that's not indenting properly. In your case, "String two) {".
  3. Hit C-c C-s to ask Emacs what syntax element it thinks you're looking at. In your case, it'll say something like ((arglist-cont-nonempty n m)).
  4. Use C-c C-o to tell it you want to change the indentation level for this syntactic element.
  5. It defaults to what it thinks that syntactic element is, e.g., arglist-cont-nonempty. Just hit RET if that default is correct.
  6. Now it wants to know what expression to use to calculate the offset. In your case, the default is an elisp expression. Delete that, and just use a single plus sign + instead.
  7. Test it out to make sure it's working correctly: Hit TAB a bunch on different lines, or M-x indent-region or similar.
  8. To make it permanent, add this to your .emacs file:

(setq c-offsets-alist '((arglist-cont-nonempty . +)))

Chris Jones
Thank you for not only answering my question, but enlightening me about how to solve similar things in the future. :)
Brian Duff
A: 

I like to specify the mode style in each source file's first line. Try:

// -*- mode: java; c-file-style: "stroustrup" -*-

This will give you rational tabification. You might also try "k&r".

Brian