19

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?

viam0Zah
  • 25,949
  • 8
  • 77
  • 100
Brian Duff
  • 406
  • 3
  • 12

2 Answers2

37

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 (c-show-syntactic-information) 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 (c-set-offset) 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 . +)))

updogliu
  • 6,066
  • 7
  • 37
  • 50
Chris Jones
  • 4,815
  • 6
  • 34
  • 28
3

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
  • 31
  • 1
  • Note that when putting this in the actual file, you override any customizations other users may have in their .emacs settings when viewing your file. If at all possible, move these things to your configuration file. – Thorbjørn Ravn Andersen Dec 06 '11 at 22:45