In This Article

Indent Provider

An indent provider enables support for smart indent features when pressing ENTER.

The Indent Providers topic talks about indent providers in general and how to register them as a "feature" language service.

The XmlIndentProvider class is the default implementation of an IIndentProvider service for this language.

Feature Summary

Smart Indent

The built-in indent provider will normally use block indent (same indent level as the previous line) except when it detects that ENTER is pressed on a line that ends with a start tag. In this case, the caret is indented another level on the next line.

Block Element Handling

Also consider this scenario, where the caret is at |:

<tag>|</tag>

If the end user presses ENTER, the indent provider will make this the result:

<tag>
	|
</tag>

Note how the end tag is moved to the line below the caret and is properly indented to the same indent level of the start tag. However the caret is indented on the line in the middle of the tags.

Registering with a Syntax Language

Any object that implements IIndentProvider can be associated with a syntax language by registering it as an IIndentProvider service on the language.

The XmlSyntaxLanguage class automatically registers a XmlIndentProvider with itself when it is created, so normally indent providers never need to be set on an XML language unless a custom one is made.

This code creates a custom indent provider (defined in a make-believe CustomXmlIndentProvider class) and registers it with the syntax language that is already declared in the language variable:

language.RegisterIndentProvider(new CustomXmlIndentProvider());
Note

The SyntaxLanguageExtensions.RegisterIndentProvider method in the code snippet above is a helper extension method that gets added to ISyntaxLanguage objects when the ActiproSoftware.Text namespace is imported. See the Service Locator Architecture topic for details on registering and retrieving various service object instances, both via extension methods and generically, as there are some additional requirements for using the extension methods.

Disabling the Functionality

Since this feature is installed as a "feature" service on the language and is installed on XmlSyntaxLanguage by default, it can be disabled by uninstalling the service from the language.