cancel
Showing results for 
Search instead for 
Did you mean: 

I want to change source formatting of if statements from the top example to the bottom example shown. I want the brackets to align with the if, i.e. same column..

inotec
Associate III

if (SW1Pressed_F && (!SW1ActionTaken_F))

{

   DesiredSpeed = 10;

    DesiredDirection = LEFT;

   }

if (SW1Pressed_F && (!SW1ActionTaken_F))

{

   DesiredSpeed = 10;

    DesiredDirection = LEFT;

   }

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

Formatting the source code can either be done by the editor, or many GUIs already contain it. The STM32CubeIDE, for example, is able to apply such formatting as an Eclipse variant with so-called profiles. Some profiles are already predefined, but you can also modify them and save or export them under your preferred name.

By the way, exporting a profile is very useful because you can import the exported profile into new installations with just a few clicks.

How to reach the Formatter:

  • Windows > Preferences > C/C++ > Code Style > Formatter

or a little shorter:

  • Windows > Preferences > [type filter text] --> formatt

Modify an existing profile:

  • within the Formatter via New > [new profile name] + select the profile to be used as a template
  • Adjusting the 65 million parameters (after that it is clear why Export is extremely useful)
  • Export
  • save with OK

Export:

  • within the Formatter via Edit > Export

Perhaps my Kernighan&Richie-derived Quick'n'Dirty profile (attached) will be of interest to you and could serve as a template.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

10 REPLIES 10
inotec
Associate III

Note that the forum messed up my columns in the example, but my statement is correct.

inotec
Associate III

Trying again...

if (SW1Pressed_F && (!SW1ActionTaken_F))

{

DesiredSpeed = 10;

DesiredDirection = LEFT;

}

if (SW1Pressed_F && (!SW1ActionTaken_F))

{

DesiredSpeed = 10;

DesiredDirection = LEFT;

}

inotec
Associate III

Nope, screwed it up again

You can a) Edit your posts see V icon in upper right corner of posting, b) use the code posting tool </> icon, or c) post a picture or bitmap mountain/sub icon

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
LauraCx
ST Employee

Hello,

Something like this?

if (SW1Pressed_F && (!SW1ActionTaken_F))
 
{
 
	DesiredSpeed = 10;
 
	DesiredDirection = LEFT;
 
}

Yes, but without the lines before the brackets:
if (SW1Pressed_F && (!SW1ActionTaken_F)) { DesiredSpeed = 10; DesiredDirection = LEFT; }
1. if (SW1Pressed_F && (!SW1ActionTaken_F))
2. {
3.
4. DesiredSpeed = 10;
5.
6. DesiredDirection = LEFT;
7. }

Aren't there tools like Uncrustify that can apply any kind of formatting template you want?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Peter BENSCH
ST Employee

Formatting the source code can either be done by the editor, or many GUIs already contain it. The STM32CubeIDE, for example, is able to apply such formatting as an Eclipse variant with so-called profiles. Some profiles are already predefined, but you can also modify them and save or export them under your preferred name.

By the way, exporting a profile is very useful because you can import the exported profile into new installations with just a few clicks.

How to reach the Formatter:

  • Windows > Preferences > C/C++ > Code Style > Formatter

or a little shorter:

  • Windows > Preferences > [type filter text] --> formatt

Modify an existing profile:

  • within the Formatter via New > [new profile name] + select the profile to be used as a template
  • Adjusting the 65 million parameters (after that it is clear why Export is extremely useful)
  • Export
  • save with OK

Export:

  • within the Formatter via Edit > Export

Perhaps my Kernighan&Richie-derived Quick'n'Dirty profile (attached) will be of interest to you and could serve as a template.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Thank you for the response. Very helpful.