Controlled Auto-indent

Introduction

Controlled Auto-indent is an experimental Notepad++ plugin for testing possible extensions to automatic indentation.

Like Notepad++, this software is released under the GNU General Public License (either version 3 of the License, or, at your option, any later version).

This plugin was built using the NppCppMSVS framework, which is released under the GNU General Public License.

Purpose and use

This plugin implements a more customizable version of the Auto-indent feature built into Notepad++. I’ve created it to enable some discussion and evaluation of possibly useful extensions to Notepad++ itself, which hopefully will eventually render this plugin obsolete.

Controlled Auto-indent will do nothing unless you check the Enable item on its menu. This assures that you can get it out of the way quickly if it is causing problems or if you want to use only built-in Notepad++ functionality.

Before enabling this plugin, please make sure the Notepad++ setting at Settings | Preferences... | Indentation : Auto-indent is set to None.

Controlled Auto-indent does not apply indentation to multiple or rectangular selections. This differs from the Auto-indent built into Notepad++, which computes indentation based on the primary selection or the row selected last and applies that to all selections or rows.

The Settings... dialog, explained in detail below, offers various options to control automatic indentation.

Installation

To install Controlled Auto-indent, download the x86 or x64 zip file, depending on whether you're using 32-bit or 64-bit Notepad++, from the latest release. Unzip the file to a folder named ControlledAutoIndent (the name must be exactly this, or Notepad++ will not load the plugin) and copy that folder into the plugins directory where Notepad++ is installed (usually C:\Program Files (x86)\Notepad++\plugins for 32-bit versions or C:\Program Files\Notepad++\plugins for 64-bit versions).

Settings

The most basic operation of auto-indent, which is done whenever Enabled is checked in the menu, is that when you press the Enter key the indentation (white space at the beginning of a line) of the line containing the caret before you pressed Enter is replicated at the beginning of the new line created. In some cases, where information about typical indentation in the language set for the document is available, adjustments can be applied. The settings control the details of this process.

Common settings
Use tabs or spaces as needed to match the document.Indentation created by the built-in auto-indent in Notepad++ follows the setting at Settings | Preferences... | Indentation : Indent Settings : Indent using, which specifies either tabs or spaces. When this box is checked, Controlled auto-indent uses the same indentation characters as the previous line. If indentation is to be increased and the indentation in the reference line contains all tabs or all spaces, the same character is used to increase the indentation; if the reference line is not indented or contains a mixture of tabs and spaces, the Indent using setting determines the characters used for indentation.
When indenting to match a line containing only tabs and spaces, remove the tabs and spaces from the earlier line.When checked, pressing Enter on a line containing only tabs and/or spaces to the left of the caret replicates the indentation to the left of the cursor in the new line, but removes the tabs and spaces from the earlier line. This is useful if you often want to add empty lines between indented lines, but you want the added lines to be truly empty (not left with invisible tabs and/or spaces); however, it makes it difficult to add lines which contain only white space intentionally.
When splitting a line with the Enter key
Trim trailing tabs and spaces from the line before the split.When this box is checked, if you press the Enter key when the caret is within a line (any position other than the very beginning or the very end of the line) and there are blanks and/or tabs before the caret, those characters are removed when you split the line. When not checked, whitespace preceding the split point remains at the end of the line. (Note: If the caret is at the end of the line, white space is not removed; so it is still possible to add trailing white space intentionally even when this setting is checked.)
Retain tabs and spaces following the split.Normally, white space following the caret when a line is split with the Enter key is “absorbed” into the indentation on the new line. If this box is checked, white space following the caret remains after the indentation added to the new line. The caret is placed following the added indentation, before the retained white space.
When the language is Python
Increase indentation after lines that end in a colon.This is equivalent to the “Advanced” indentation for Python built in to Notepad++. When checked, if a new line is created following a line which ends with a colon (excepting white space and comments), the new line is indented a tab width more than the line with the colon.
When the language is C-like

Adjust indentation for braces.

When checked, Controlled Auto-indent increases or decreases indentation according to typical conventions when the Enter key is pressed on a line containing braces ({}).

This differs from built-in Notepad++ Advanced Auto-indent because it always occurs when you press the Enter key, not when you type the brace character. The reason for this choice is that the author believes it is possible to achieve greater accuracy and predictability by waiting until the line is complete.

Admittedly, this does not match the way IDEs like Visual Studio work; for technical reasons concerning the way Scintilla and Lexilla work, is it not practical in Notepad++ to obtain the same information an IDE would have at the time a brace is typed. Acting only on the Enter key allows more consistent and predicable behavior, and makes it possible to use information from the lexer to make decisions that otherwise require complex, error-prone attempts to parse the document.

Add an empty line when splitting between braces.When checked, if the Enter key is pressed when the character following the caret is a closing brace and the last before the caret (excluding comments and white space) is an opening brace, an additional line is added before the closing brace. This is especially useful if you have auto-completion for braces turned on.
Increase indentation for continuation of incomplete statements.In C-like languages which use a semi-colon as a statement terminator, is is customary to indent the second and subsequent lines of statements which span more that a single line. When this option is checked, Controlled Auto-indent attempts to apply this indentation automatically.

The built-in Advanced Auto-indent in Notepad++ does something similar, but only when it recognizes a compound statement (such as if or for).