0

Is there any way to stop the formatter in Eclipse from removing space in the following type of code?

uint16_t ABC        = 0x123;
uint16_t ALPHA      = 0x543;
uint8_t UNICORNSOUP = 0x80;

This ends up as:

uint16_t ABC = 0x123;
uint16_t ALPHA = 0x543;
uint8_t UNICORNSOUP = 0x80;

It leaves #define's alone but not assignments, I think the issue is in the formatter under White Space > Expressions > Assignments you can select to have space before the assignment operator and after but this either has no space or a single space, you can't select to leave as is or only insert if no space.

The other issue is it is reformatting enums from

enum FastLoggingStopCondition
{
    FAST_LOGGING_STOP_INACTIVE = 0,
    FAST_LOGGING_STOP_ACK = 1
};

to:

enum FastLoggingStopCondition
{
    FAST_LOGGING_STOP_INACTIVE=0, FAST_LOGGING_STOP_ACK=1
};

Is it possible to change this behaviour?

Alternative formatters that can be run from Eclipse or outside of Eclipse that are tailored to C could be a possibility if Eclipse can't be hammered into submission.

LogicTom
  • 93
  • 1
  • 9
  • Not sure for cdt, but for java there is *Align fields in columns*, which produce similar result as your first code snippet. – Aleksandr M Mar 30 '16 at 10:47
  • duplicate of http://stackoverflow.com/questions/16886890/how-to-disable-eclipse-cdt-code-formatter-for-a-code-block? – Silvano Brugnoni Mar 30 '16 at 11:10
  • Thanks Aleksandr, I will check that out. – LogicTom Mar 30 '16 at 21:38
  • silflow I want the formatter to format enums into that format so that they're all the same therefore leaving existing ones as is. – LogicTom Mar 30 '16 at 21:40
  • Preserving whitespace for alignment purposes in this way is not currently supported. There is an issue on file for adding this support: https://bugs.eclipse.org/bugs/show_bug.cgi?id=257323 – HighCommander4 Feb 19 '17 at 22:00

0 Answers0