user855
user855

Reputation: 19918

Change eclipse formatting to indent only 4 spaces on newline after opening parenthesis

Is there a way to configure such a thing in eclipse java?

Upvotes: 0

Views: 293

Answers (2)

Mike
Mike

Reputation: 41

I don't think this is possible. I've been looking for this for a while (but for C). I want the code to look like this for wrapped lines:

/*
 * Parameters
 */
class Example {
    void foo(int arg1, int arg2,
        int arg3, int arg4,
        int arg5, int arg6) {
    }
};

However, Eclipse only allows you to specify the number of tabs to use, not whether to use tabs or spaces. The place I've been looking is in the Preferences under C/C++ > Code Style > Formatter > Edit Format button.

Update: This is doable, but the settings are a pain and it won't appear quite correctly on the screen. It will write the file properly however. Here we go:

  • Click the "Edit" button in the preferences area mentioned above (replace "C/C++" with your language of choice)
  • In the "Indentation" section,
    • Set "Tab Policy" to "Mixed"
    • Check the box for "Use tabs only for leading indentations"
    • Set "Indentation size" and "Tab size" both to 4
  • In the "Line Wrapping" section:
    • Set "Default indentation for wrapped lines" to 1

Word of warning: I have no idea how this might affect other indentation settings elsewhere in the Code Formatter preferences.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691735

I think what you're looking for is Window - Preferences - Java - Code Style - Formatter - Edit... - Line Wrapping - Default indentation for wrapped lines.

Upvotes: 1

Related Questions