Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Eclipse Formatter to not destroy commented out code?

A lot of my co-workers enjoy leaving behind commented out code, how to make Eclipse Formatter to not destroy formatting of that code(now it makes a big blob or block of it).

P.S. I know I can somehow configure the formatter to just ignore that code, I done it once, but I cant remember how.

like image 467
IAdapter Avatar asked Jan 05 '11 16:01

IAdapter


3 Answers

In the Eclipse Formatter Settings (Preferences/Java/Code Style/Formatter) in the tab Comments UNCHECK the checkbox "Enable Block Comment Formatting" and "Enable Line Comment Formatting" These should be disabled anyway.

like image 176
Peter Kofler Avatar answered Nov 15 '22 15:11

Peter Kofler


One option in 3.6 would be to tell Eclipse not to format these blocks, using /* @formatter:off */

Another option that I use a lot when working in other people's code is to select the lines I'm working on before invoking the formatter - that way I only format the areas I've actually changed, and leave the rest untouched (to get more readable diffs etc.).

like image 40
Fabian Steeg Avatar answered Nov 15 '22 16:11

Fabian Steeg


For Eclipse 3.7.1, there's a new configuration page (Off/On Tags) in the code format profiles. Make sure you've enabled them. You can also specify the exact comment off and comment on tags.

like image 40
Ross Judson Avatar answered Nov 15 '22 17:11

Ross Judson