MPLAB® X IDE Formatting Tab

Last modified by Microchip on 2023/11/09 09:11

Formatting Tab

The Formatting tab in the Editor category controls the editor's automatic code formatting feature. Formatting rules such as the placement of braces, line alignment and spacing can all be specified here. These settings will determine how code is formatted when using features like code templates and the Format command under the Source menu.

Table of Contents

the formatting window


Language: All Languages

shows formatting options when all languages are selected

Language

When set to All Languages…

Category

Tabs and Indents

Properties

​These settings for All Languages are overridden by default in the language-specific settings. Changing these values will have no effect unless you uncheck Override Global Options in the language-specific settings (C, C++ and C/C++ Header).

Property

Possible Values

Expand Tabs to Spaces

Yes/No

Number of Spaces per Indent

Number of Spaces

Tab Size

Number of Spaces

Right Margin

This property determines where the vertical red line is displayed in the editor, indicating what should be the maximum length of a line, specified as the number of characters. This is useful if you want to ensure your code can be printed in the width of a single page or if you are concerned about lines running too long, requiring scrolling to the right to view their ends.

The setting is only a visual cue and does not enforce the right margin, so you can continue typing lines as long as you wish.

If you want to eliminate the red line altogether, set the right margin to 0.

Example

The example box provides live, visual feedback as you change properties on the left side of the window. The sample code is displayed, reflecting the settings you specified.


Language: C, C++ and C/C++ Header

Shows the formatting options when c code is selected for the language

Language

When set to C, C++, or C/C++ Header you will be presented with an identical set of properties as shown below. Each set of properties are independent of one another, making it possible for C to have completely different settings from C++.

Category

The Category box acts as a filter for the Properties grid below. Each section in the Properties grid has a grey heading that corresponds to one of the categories in this list.

Override Global Options

Allow properties for this language's settings to override properties in the All Languages settings (enabled by default).

Style

This drop-down box lets you choose from a list of style presets for the selected language. Clicking on the Manage button will let you add, modify, delete, or create your own custom style preset.

Properties

In this section, you are presented with a list of all the formatting choices that programmers love to argue with each other about. These properties will be applied to a selected file whenever you select from the main menu Source ► Format. They will also be applied to individual blocks of code, added in via the Code Templates mechanism.

Property

Possible Values

Indents

Indent Size

Number of Spaces

Expand Tabs to Spaces

Yes/No

Tab Size

Number of Spaces

Statement Continuation Indent

Number of Spaces

Constructor Continuation Initializer List

Number of Spaces

Preprocessor Directives Indent

None
Code
Preprocessor

# at Start Line

Yes/No

Indent Namespaces

Yes/No

Indent Case Statements in Switch

Yes/No

Absolute Label Indentation

Yes/No

Indent Visibility

None
Half Indent

Keep Extra Spaces

Yes/No

Braces Placement

Namespace Declaration

Same Line
New Line
New Line Half Indented

Class Declaration

Same Line
New Line
New Line Half Indented

Function Declaration

Same Line
New Line
New Line Half Indented

Ignore Empty Function Body

Yes/No

"switch" Statement

Same Line
New Line
New Line Half Indented

Other

Same Line
New Line
New Line Half Indented

Multiline Alignment

Function Parameters

Yes/No

Function Call Arguments

Yes/No

Array Initializer

Yes/No

"for" Statement

Yes/No

"if" Statement

Yes/No

"while" Statement

Yes/No

Other Parenthesis

Yes/No

New Line

Function Name

Yes/No

"catch"

Yes/No

"else"

Yes/No

"while"

Yes/No

Spaces Before Keywords

"catch"

Yes/No

"else"

Yes/No

"while"

Yes/No

Spaces Before Parentheses

Function Declaration

Yes/No

Function Call

Yes/No

"catch"

Yes/No

"for"

Yes/No

"if"

Yes/No

"switch"

Yes/No

"while"

Yes/No

Other Keywords

Yes/No

Spaces Around Operators

Assignment Operators

Yes/No

Binary Operators

Yes/No

Ternary Operators

Yes/No

Unary Operators

Yes/No

Spaces Before Left Braces

Class Declaration

Yes/No

Function Declaration

Yes/No

Array Initializer

Yes/No

"catch"

Yes/No

"do"

Yes/No

"else"

Yes/No

"for"

Yes/No

"if"

Yes/No

"switch"

Yes/No

"try"

Yes/No

"while"

Yes/No

Spaces Within Parentheses

Function Declaration

Yes/No

Function Call

Yes/No

Braces

Yes/No

Parentheses

Yes/No

"catch"

Yes/No

"for"

Yes/No

"if"

Yes/No

"switch"

Yes/No

Type Cast

Yes/No

"while"

Yes/No

Other Spaces

Before Comma

Yes/No

After Comma

Yes/No

Before Semicolon

Yes/No

After Semicolon

Yes/No

Before Colon

Yes/No

After Colon

Yes/No

After Type Cast

Yes/No

Blank Lines

Before Class

Number of Lines

After Class Header

Number of Lines

Before Function

Number of Lines

Other

Add leading star in comment

Yes/No

Example

The example box provides live, visual feedback as you change properties on the left side of the window. The sample code is displayed, reflecting the settings you specified.