Search code examples
code-formattingstm32cubeide

Possible to manually trigger automatic source code formatting in STM32CubeIDE?


I use STM32CubeIDE version 1.6.1, and have noticed that CubeMX outputs formatted code (e.g. indented with 2 spaces). I would like to reapply this source code formatting manually (that is, manually trigger the source code formatting on selected files).

I have found this post: https://www.openstm32.org/forumthread6435 , which mentions:

go the preferences dialog and select C/C++ > Code Style > Formatter
click on “Edit...” change the tab size field. close the preferences

Then, select all the project you want to apply it, click right and select “Source > Format”

So, I'm not 100% sure the above quote refers to STM32CubeIDE, however, the first part is still there, in Window/Preferences I can get to this:

STM32CubeIDE Windows/Preferences

However, I cannot see how to trigger this source code formatting manually, on selected files. For instance, https://dvteclipse.com/documentation/e/Format_Multiple_Files.html for Eclipse (that STM32CubeIDE is built upon), mentions that by right-clicking source files, one can call the command "Format Source Files"; however, when I click my main.c in the STM32CubeIDE Project Explorer, I cannot see anything like that:

STM32CubeIDE right-click

So, is there a way to manually trigger automatic source code formatting on selected (single or multiple) source code files in STM32CubeIDE?


Solution

  • Got it, finally - when you right-click the Core node, or any of its children, in Project Explorer in STM32CubeIDE, you get a "Source >" entry in the right-click context menu, which has only one child, "Format":

    stm32cubeide_format_source