Skip to main content
hardrock
Associate II
April 29, 2024
Question

STM32CubeIDE Indentation and Generate Code

  • April 29, 2024
  • 10 replies
  • 8457 views

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.

This topic has been closed for replies.

10 replies

AScha.3
Super User
April 29, 2024

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 on " Best Answer ".
hardrock
hardrockAuthor
Associate II
April 29, 2024

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

AScha.3
Super User
April 29, 2024

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 on " Best Answer ".
Andrew Neil
Super User
April 29, 2024

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?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
hardrock
hardrockAuthor
Associate II
April 29, 2024

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.

 

Andrew Neil
Super User
April 29, 2024

@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.

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
hardrock
hardrockAuthor
Associate II
April 29, 2024

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.

 

Pavel A.
April 29, 2024

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

 

Mikk Leini
Senior
June 6, 2024

I am also hoping to see the solution to this feature request, but since there's confusion in the follow-up replies, I would like to specify that IMHO only the user-modifiable project files should have user-configurable indentation style and it should be all across the file - even outside user editable sections. Such files are under Core folder and different Middlewares "glue code" folders. Library files, like HAL, CMSIS, Middleware, can keep their original style.

If generator gets the indentation style from Eclipse code style settings then that's perfect, but if there are indentation character and indentation space count configuration option in CubeMX window (e.g. Project manager -> Code generator), then that's fine also.

This is obviously not a showstopper feature, but for developers who appreciate aesthetics it causes itchy feeling and for developers who occasionally use automatic code formatting, it can create unwanted code differences since white spaces change back and forth.