LPCXpresso - templates - code formatter

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCXpresso - templates - code formatter

817 Views
andreasklockner
Contributor II

At the moment I have problems with code templates in conjunction with the formatter.

- I have edited an own profile for the formatter (Preferences->C/C++->Code Style->Formatter)

- I have configured the code templates (Preferences->C/C++->Editor->Templates) to "use code formatter"

     ("use code formatter" check box is active.  Thus I expect LPCXpresso to 'ignore' the format of the

     existing templates and use the Code Style, which I have edited in the formatter. )

So I think, LPCXpresso will format my code in the same way,

if I use "auto-complete" (CTRL+Space) or if I use the formatter

for existing code.

But these two methods lead to different code formatting:

Exampe for "switch" statement:

Using auto-complete (typing "sw" and pressing CTRL+Space) results in:

(this is NOT the result I want to have)

switch (key)

{

    case value:

   

    break;

    default:

    break;

}

Using the formatter afterwards (mark the code + SHIFT+CTRL+F) results in:

(this is the result I want to have)

switch (key)

{

case value:

   

    break;

default:

    break;

}

It seems, that the auto-complete function catches some rules, but

not ALL rules from the formatter...?

Or am I missing something?

------------------------------------------------------------

PS:

I'm using:

- Win7

- LPCxpresso v7.9.2

The template for "switch" is defined like this (Preferences->C/C++->Editor->Templates):

switch (${key}) {

    case ${value}:

        ${cursor}

        break;

    default:

        break;

}

Labels (2)
0 Kudos
1 Reply

474 Views
lpcxpresso_supp
NXP Employee
NXP Employee

You need to tweak the Indent options related to 'switch', 'case' and 'break' in the Indentation tab of the active profile in your  Code Style - Formatter.

To get what you what I think that you probably need 'switch' unticked and 'case' and 'break' ticked. You might also want to look at the tab settings here vs what you are putting into your template.

The other thing to try is leaving the "use code formatter" check box unticked, and seeing if that helps.

Aside - the Code Templates and Formatter are standard Eclipse/CDT - there is nothing LPCXpresso IDE specific about them. So if you are still having issues, it might be worth doing an internet search.

Regards,

LPCXpresso Support

0 Kudos