1

I'm using Eclipse 4.29.0 CDT (STM32CubeIDE) to write C code and have a curious behavior with the auto formatting feature. Arrays with numbers or short element names are formatted as expected (first one) arrays with long initializer names (second one) not. Especially the single element in the beginning of the line is distracting.

#define WHY_AUTOFORMAT_PUT_THIS_HERE 3  //remove this line to change autoformat behavior

  uint8_t my_defines_array[] = { NUM1, NUM1, NUM1, NUM3, NUM1, NUM1, NUM3, NUM1, NUM3, NUM1, NUM3, NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM8, NUM8, NUM5,
                                 NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3 };

  uint8_t my_long_names_array[] = { NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3,
  WHY_AUTOFORMAT_PUT_THIS_HERE,
                                    NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3 };

My used settings:
Line Wrapping - Expressions - Initializer list:

  • Line wrapping only when necessary
  • No force split
  • Indent on column

Is there a special setting that I'm missing to avoid long names be wrongly formatted?

EDIT: My minimal example didn't work, but now the behavior is more questionable. The formatting of WHY_AUTOFORMAT_PUT_THIS_HERE changes depending if it is defined or not.
This issue is that the formatting is wrong when it is defined, not the other way around.

Settings:Line Wrapping settings

6
  • What is the question? Ig you not happy go to the preferences and set up formatter for your liking Commented Oct 22, 2024 at 8:58
  • OK, it looks like I wasn't clear enough: Is somebody aware of a setting to avoid long initialisier names be wrongly formatted? Commented Oct 22, 2024 at 10:58
  • 1
    Just a thought to explore: I use clang-format for formatting. (I do not use clang itself). But with clang-format I got a lot of formatting options (so I can do exactly what I like) and independence from text editors.
    – White Owl
    Commented Oct 22, 2024 at 12:28
  • 1
    I cannot reproduce the indentation from your example. I duggest to explain in your question what settings exactly you use. Maybe show screenshots.
    – Bodo
    Commented Oct 22, 2024 at 17:27
  • @Bodo: Thank you for the hint. I made the example too minimal and updated it now. It makes a difference in formatting whether the define is done or not. Commented Oct 23, 2024 at 8:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.