How to make eclipse not auto-indent a block of code
-
15-10-2019 - |
Question
I like Eclipse's auto-indent function, but sometimes I've got some indentation I don't want it to correct, like
audioBuffer1[j] = (short) (VOLUME_REDUCER * ( inputBuffer[i]
+ ALPHA * inputBuffer[i - echo1a]
+ ALPHA * inputBuffer[i + echo1a]
- ALPHA * inputBuffer[i - echo1b]
- ALPHA * inputBuffer[i + echo1b]
));
which gets corrected to something horrible. Is there a way of making the auto-indent function skip over some bits of code, using an @annotation
or something?
Solution
You can put // at the end of the lines you don't want it to wrap.
audioBuffer1[j] = (short) (VOLUME_REDUCER * ( inputBuffer[i] //
+ ALPHA * inputBuffer[i - echo1a] //
+ ALPHA * inputBuffer[i + echo1a] //
- ALPHA * inputBuffer[i - echo1b] //
- ALPHA * inputBuffer[i + echo1b] //
));
OTHER TIPS
For disabling auto-indent, see bug 193688 and bug 319532 (not before 3.7M2).
You will be able to set the preference to the Typing page to enable/disable smart indent on New Line. If disabled, it still indents to previous line.
Note: For format in general (since Eclipse3.6 JDT)
class X {
// disable-formatter
void foo1() {}
void foo2() {}
// enable-formatter
void bar1() {}
// enable-formatter
void bar2() {}
}
The bug 27079 ("Tags for disabling/enabling code formatter") and its attached patch are addressing that particular feature (which is not exactly what you want here).
There isn't an annotation to control formatting behavior, but I find it helpful to turn off Edit -> Smart Insert Mode prior to inserting a block of code that you don't want to be messed with.