Home > Coding Helpers > Coding Helpers – Smart Parentheses and Smart Brackets

Coding Helpers – Smart Parentheses and Smart Brackets

April 18th, 2011

Let’s talk about two similar features – the Smart Parentheses (also known as Smart Parens) and Smart Brackets. These two features allow you to easily type parens and brackets without having to close them with the corresponding closing paren or bracket, because they will be inserted automatically.

In this article the ‘paren’ means the opening or closing parenthesis ‘(‘ or ‘)’, and the bracket means the ‘[‘ (opening) and ‘]’ (closing) characters.

Once you type an opening paren (or bracket), the closing paren (or bracket) appears immediately:

CodeRush Smart Parentheses preview

CodeRush Smart Brackets preview

When the feature is performed, the text fields (an orange box) are added with the capability of a quick leaving the parens (brackets) after the Enter key is pressed. If you type something inside parens or brackets and press the Enter key to commit your change – the editor caret will move after the closing paren or bracket, allowing you to continue typing without using arrow keys to move the caret. Such behavior with the text fields will likely seem to be unexpected for the most users, but after you get accustomed to it, I’m sure you will love it.

Both of these features, apart from the automatic completion of parens (brackets), also include the following:

  • easy deletion of empty parentheses (brackets)

If you don’t need parens (e.g. mistyped it), you can press the Backspace key and both parens (or brackets) will be removed.

  • smart semi-colon when typed inside parentheses (brackets)

As an alternative to the Enter key to continue typing after the closing paren or bracket is inserted, you can type the semicolon ‘;’, if appropriate. This is useful mostly in C# and C++ languages, for code constructions which need to invoke a line terminator, e.g. method calls:

  • ignoring closing paren (or bracket) if manually typed

Note, if you have a habit of typing the closing paren or bracket immediately after an opening paren or bracket, CodeRush will put only a single closing character instead of two (one automatically added and the other one – manually typed), so you won’t end with two closing parens or brackets.

Both Smart Parentheses and Smart Brackets features are fully customizable. Their settings are available on a single options page (Editor | Auto Complete | Parens & Brackets) in the Options Dialog:

CodeRush Parens and Brackets options page

The settings are split into two groups separately for each feature. Available Smart Parens options are:

Option Name

Description

Use Smart Parentheses Toggles the availability of the Smart Parentheses feature.
Auto-complete parentheses Enables or disables parentheses auto completion (automatic insertion of the closing paren after the opening parent is typed).
Auto-complete parentheses in front of identifiers (typecasting) Enables or disables parentheses auto completion when typed in front of an identifier (e.g. for a casting in C#).
Add spaces inside parens ( | ) If this option is turned on, a space is added between parentheses after auto-complete parentheses is performed.
Use text fields Enables or disables the text fields insertion after auto-complete parentheses is performed.
Easy-delete empty parentheses Enables or disables the capability to easily delete empty parentheses with a single Backspace keystoke inside empty parentheses.
Ignore closing parenthesis typed inside empty parentheses Enables or disables the capability to ignore the manually typed closing parenthesis after auto-complete parentheses is performed.
Smart semi-colon Enables or disables the capability to type the semi-colon inside the parentheses (before the closing paren) and automatically move it to the appropriate location (after the closing paren).

The same options are available for Smart Brackets separately:

Option Name

Description

Use Smart Brackets Toggles the availability of the Smart Brackets feature.
Auto-complete brackets Enables or disables brackets auto completion (automatic insertion of the closing bracket after the opening bracket is typed).
Add spaces inside brackets [ | ] If this option is turned on, a space is added between brackets after auto-complete brackets is performed.
Use text fields Enables or disables the text fields insertion after auto-complete parentheses is performed.
Easy-delete empty brackets Enables or disables the capability to easily delete empty brackets with a single Backspace keystoke inside empty brackets.
Ignore closing bracket typed inside empty brackets Enables or disables the capability to ignore the manually typed closing bracket after auto-complete brackets is performed.
Smart semi-colon Enables or disables the capability to type the semi-colon inside the brackets (before the closing bracket) and automatically move it to the appropriate location (after the closing bracket).
—–
Products: CodeRush Pro
Versions: 10.2 and up
VS IDEs: any
Updated: Apr/18/2011
ID: C087

Similar Posts:

  1. No comments yet. Be the first and leave a comment!