cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE Indentation and Generate Code

hardrock
Associate III

Whenever I generate code, the indentation is always 2 characters.


Even though the indentation is set to 4 characters in the settings,
it continues to be generated as 2 characters except for the user code.

Formatter > Indentation

Tab Policy : Spaces Only
Indentation Size : 4
Tab Size : 4

 

I always repeat the below actions after generating the code.

main.c > Select All (Ctrl+A) > Correct Indentation (Ctrl+I)

 

I always use 4 characters indentation in my S/W design.
but it is quite inconvenient.
and I would like to ask if there is any room for improvement this.

10 REPLIES 10
AScha.3
Chief III

Hi,

what you set in (right click in text area )-> preferences ? 

I have :

AScha3_0-1714380488889.png

and in text editors ->

AScha3_1-1714380552465.png

--> makes 4 char indentation ->

AScha3_2-1714380683349.png

 

If you feel a post has answered your question, please click "Accept as Solution".
hardrock
Associate III

Thank you for your reply.

I still have the problem.

The code is always generated 2 characters indentation except user code.

Formatter.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

Text Editor.jpg

 

 

 

 

 

 

 

 

 

 

main.jpg

Andrew Neil
Evangelist III

So, just to be clear, you're saying that the editor observes your settings for what you type, but the CubeMX generator does not observe them for the code it auto-generated?

To understand you : you want the HAL lib changed to another style , than it is, or 

the code generator generate a different code style in the "not-for-user" generated code areas ?

+

When you write your program - in "user code area" - its doing, as you want /set it ?

If you feel a post has answered your question, please click "Accept as Solution".
hardrock
Associate III

Thank you for your reply.

 

The CubeIDE generator creates that "user code" is 4-chars indentation based on settings,

but "non-user code" is 2-chars indentation automatically.


The indentation is mixed between 2 or 4 chars in one file, it makes difficult to see.


I want that both "user code" and "non-user code" are generated together

with N-chars indentation according to user's settings.

 


@hardrock wrote:

The CubeIDE generator creates that "user code" is 4-chars indentation based on settings,


Not sure what you mean by that?

CubeIDE/MX doesn't generate any User Code; it's called "User Code" because it's created by the User - you!

CubeIDE/MX puts comments to indicate where you can safely enter your "User Code" - but it doesn't generate any of that code.

 

 

I understand what you are saying.


The "user code" (my code) can be adjusted the indentation according to my settings.


But how to adjust the indentation of "non-user code".
The indentation of "non-user code" is always 2 chars as default.

 

As @AScha.3 said, it would need to be a lot more than just the indent step:

https://community.st.com/t5/stm32cubemx-mcus/cubemx-generates-code-with-spaces-but-cubeide-uses-tabs/td-p/167681

Probably best is to put it through a code formatter - aka "beautifier" or "prettifier" - configured to your particular tastes...

And/or keep your code out of the auto-generated files - so you don't have to look at it! 

Pavel A.
Evangelist III

Since the Cube thing is integrated into CubeIDE, the code generation should get the formatting options from Eclipse. This looks reasonable.