Do You Know the Secrets of the Source Menu? [TrueSTUDIO Tips & Tricks for Embedded Developers]

Posted by Magnus Unemyr on Dec 2, 2016 2:55:11 PM

Many useful and convenient editor functionalities are available in the Source menu of the Atollic TrueSTUDIO IDE. Use them to improve your editing efficiency, and get more consistent and better-locking source code. If you haven't tried these features yet, now is a great time to learn some time saving tricks!

Read this blog post to learn more on these highly useful features! My previous blog post on code navigation may interest you as well.



Correct Indentation

As you edit the source code, the indentation can easily get disorganized. But there is a simple solution to this problem. Select the code block you want to beautify, and use the Source > Correct Indentation menu command (or press CTRL-I) to auto-correct the indentation of the selected source code.


Sort Lines

Sometimes you find yourself having a number of source code lines with strings or tokens you want sorted alphabetically. It can be a long array that is initialized with strings of some sort, hash tables, lookup-tables, etc.


The TrueSTUDIO editor includes a very convenient code line sorting function. Select the lines you want to sort, and use the menu command Source > Sort Lines (or press CTRL-ALT-S). The selected lines will now be sorted alphabetically.

Code Formatting

Reading the source code becomes much easier if you adhere to a consistent coding style. Select the code lines you want to beautify and use the menu command Source > Format (or press CTRL-SHIFT-F). The selected code lines are reformatted into the selected coding style.


The editor can be configured to use any of the predefined coding styles (such as K&R, BSD/Allman, Whitesmiths, etc.). You can also configure your own custom coding style, using the Code Style configuration panel.

Surround With

A common coding task is to embrace one or more code lines within curly brackets, for use with if-, while- or for- statements. To simplify this routine task, the editor have a convenient function that wraps an if/for/while etc. statement around the selected code lines.


Select the lines you want to wrap, and use the Source > Surround With (ALT-SHIFT-Z) menu command. Then select the kind of statement you want to wrap around the code lines (such as a for loop). You can even define your own templates!

Add and Remove Block Comment

A common developer task is to turn a code block into a comment, to remove it from the compilation. Instead of doing this manually, you can automate this by selecting the code block and use the menu commands Source > Add Block Comment (CTRL-SHIFT-/) or Source > Remove Block Comment (CTRL-SHIFT-\).


The editor will add or remove /* and */ tokens before and after the selected code block as necessary.

Toggle Comment

A related functionality is the Source > Toggle Comment (CTRL-7) command. But instead of wrapping the selected code line with /* and */ tokens, it adds or removes C++ style comment tokens in front of each line.


Organize Include Files

Knowing what header files to #include is always a problem, and a common source of frustration. Use the Source > Organize Includes menu command (CTRL-SHIFT-O) to solve this problem. This function automatically adds the #include statements needed!


Do you want to learn more on ARM Cortex-M development and debugging? Read this free whitepaper:

ARM Development White Paper - TrueSTUDIO


Topics: Atollic TrueSTUDIO, editing