clang-formatstm32cubeide

Disable source formatting in stm32cube for a small part in a source file


I am trying to make the source formatter in stm32cubeide code editor to skip some parts of my code. Normally it just works fine but in some cases I want to have it differently for readability.

Take the example below, a list of unsigned char values taking 3 positions aligned to the right. (I didn't want to show all 3000 values, so I deleted many lines)

// clang-format off
const uint8_t samples[3000] = { 127, 127, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131
                              , 103, 103, 103, 102, 102, 102, 102, 101, 101, 101, 100, 100, 100, 100,  99 
                              ,  10,  10,  10,  10,  10,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9
                              };
// clang-format on

When I press ctrl-shift-F or when I change anything in the configuration, the source is reformatted and the clang-format line is disregarded. The source formatting is changed to:

// clang-format off
const uint8_t samples[3000] = {
        127, 127, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, 131, 132, 132, 132, 132, 133,
        13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 
        7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        124, 125, 125, 125, 125, 126, 126, 126, 126, 127 };
// clang-format on

Is there any way in Stm32Cube to disable formatting for only a small section of the code?
Does Cube use another command than clang-format?


Solution

  • I found it in:

    Window > Preferences > C/C++ > Code Style > Formatter > "active profile" > Edit > Off/On Tags

    set checkbox "Enable Off/On tags"
    Off tag: @formatter:off
    On tag: @formatter:on