Adaptive Formatting

Many development teams set standards for code formatting styles. These standards often vary from project to project or between languages. In this environment, you can lose valuable time in having to change configurations, set/unset options, or run beautifiers from file to file just so you can meet the team's requirements.

Adaptive Formatting addresses these situations by scanning a file for the formatting styles in use, and automatically matching those settings for the current editing session. This provides seamless integration of new code with existing code, making it easier to read, not only for you but for the next person who needs to edit the file.

Adaptive Formatting recognizes indentation and tab style settings, parentheses padding, and begin/end style settings. It also recognizes case settings, such as keyword casing for case-insensitive languages, and tag, attribute, and value casing for HTML-based languages.

Feature Notifications are used when Adaptive Formatting identifies formatting that conflicts with your settings. With Feature Notifications, you can control whether you get a dialog, a pop-up message, or no notice at all. By default, Adaptive Formatting is set to display a pop-up message. You can change the notification level by selecting Window → SlickEdit Preferences → Application Options → Notfications.

Enabling/Disabling Adaptive Formatting

Adaptive Formatting is disabled by default. You can toggle it on and off on a language-specific basis, and you can also enable/disable each of the individual formatting settings on a language-specific basis as well. To access these options, from the main menu, select Window → SlickEdit Preferences → Languages → Application Languages → [Language] → Adaptive Formatting. As an example, the C/C++ Adaptive Formatting options are shown below.

The specific Adaptive Formatting settings available for that language are shown on the options screen. Select or clear the Use Adaptive Formatting check box to enable or disable the feature. When Adaptive Formatting is enabled, use the subsequent check boxes to select the settings for which SlickEdit® Core should scan.

You can also toggle Adaptive Formatting on and off for a language by using the menu item Format → Adaptive Formatting (or the adaptive_format_toggle command). This turns the feature on and off for the current language without affecting the individual style settings.

The individual formatting style settings are located on various screens in the language-specific section of the Options dialog. A label, linked to the Adaptive Formatting options screen, appears next to each setting to indicate if Adaptive Formatting is on or off for that setting. Adaptive Formatting does not change the value set in these options; rather, it overrides the value on a document-by-document basis. For example, notice how Adaptive Formatting is enabled for settings on the C/C++ Indent options screen:

The values specified by Adaptive Formatting will be used instead of the values shown on the options screen. Click on the Adaptive Formatting hyperlinks to jump to the Adaptive Formatting options screen for that language.

Recognized Settings

The table below shows each option recognized by Adaptive Formatting, the path to the option in SlickEdit® Core, and a description, along with a link for more information. Because these options are language-specific, the option paths are relative to the language-specific portion of the Options dialog: click Window → SlickEdit Preferences → Languages, expand your language category and then select your language.

Formatting Option

Path to Option in SlickEdit Core

Description

Syntax indent

Indent (Language-Specific Indent Options)

When enabled, the Enter key indents according to the language syntax, and you can specify the amount to indent for each level. See Syntax Indent for information.

Tabs

Indent (Language-Specific Indent Options)

Specifies tab stops, which can be in increments of a specific value or at specific column positions. See Indenting with Tabs for information.

Indent with tabs

Indent (Language-Specific Indent Options)

Determines whether the Tab key, Enter key, and paragraph reformat commands indent with spaces or tabs. See Indenting with Tabs for information.

Begin/End style

Formatting Options (Language-Specific Formatting Options)

The is the brace style used for Syntax Expansion and smart indenting. See the section for your language in the Language-Specific Editing chapter. For example, C/C++ Formatting Options.

Indent CASE from SWITCH and Indent constant from case

Formatting Options (Language-Specific Formatting Options)

Specifies Syntax Expansion indentation. See the section for your language in the Language-Specific Editing chapter. For example, C/C++ Formatting Options.

No space before parenthesis

Formatting Options (Language-Specific Formatting Options)

When enabled, no space is placed between keywords (such as if, for, or while) and the open paren when Syntax Expansion occurs. See the section for your language in the Language-Specific Editing chapter. For example, C/C++ Formatting Options.

Insert padding between parenthesis

Formatting Options (Language-Specific Formatting Options)

When enabled, a space is placed after the open parenthesis and before the close parenthesis, providing padding for the enclosed text. See the section for your language in the Language-Specific Editing chapter. For example, C/C++ Formatting Options.

Keyword case

Formatting Options (Language-Specific Formatting Options)

Specifies the case of keywords used by Syntax Expansion. See the section for your language in the Language-Specific Editing chapter. For example, Ada Formatting Options.

Case for inserted tags

Formatting Options (Language-Specific Formatting Options)

Specifies the case for tags that are automatically inserted. See HTML Formatting Options for more information.

Case for inserted attributes

Formatting Options (Language-Specific Formatting Options)

Specifies the case for tag attributes that are automatically inserted. See HTML Formatting Options for more information.

Case for inserted single word values

Formatting Options (Language-Specific Formatting Options)

Specifies the case of word values that are automatically inserted inside a tag. See HTML Formatting Options for more information.

Case for hex values

Formatting Options (Language-Specific Formatting Options)

Specifies the case for hex values that are automatically inserted inside a tag. See HTML Formatting Options for more information.

Scanning for Styles in Use

Adaptive Formatting has two modes of scanning: automatic, which is the default behavior, and manual, which lets you run a scan at any time to determine a file's formatting styles in order to quickly save them as the default settings.

When you open a file for editing, Adaptive Formatting initially scans for the indent-related settings that are in effect (Syntax indent, Indent with tabs, and Tabs), starting at the beginning of the file. Thereafter, Adaptive Formatting scans as you type to determine brace settings, parentheses padding, and other formatting styles. If Adaptive Formatting determines that the file is using a different formatting style than the current language-specific setting, a dialog is displayed that shows the settings in effect. You can then choose to use the settings or use the settings set for the language. Once the formatting style is determined, the options for those styles are used as long as the buffer is open for editing.

For example, when you type a keyword such as if in a C/C++ file that uses formatting styles different from the current settings, the C/C++ Adaptive Formatting Results dialog is displayed (depending on your settings for Adaptive Formatting under Feature Notifications).

On this dialog, the selected settings are used only for the current buffer. You can access the Adaptive Formatting options screen to enable/disable Adaptive Formatting for this language by clicking the hyperlink to Configure or disable Adaptive Formatting.

If you always want to accept the Adaptive Formatting results, select Don't show me this again to suppress the dialog from appearing in the future.

A similar dialog is shown when you run Adaptive Formatting manually. This mode lets you run Adaptive Formatting on the entire file at once, in order to quickly save the settings as the defaults for that language. To run a manual scan, use the adaptive_format_stats command. The Adaptive Formatting Results dialog for that language is displayed, showing all of the recognized style settings that are in use in the current file.

This dialog lets you enable/disable the settings just for the current buffer, or select Use these settings for all files of this language to quickly set these values as the default.

Confidence Level and Statistics

Both Adaptive Formatting Results dialogs show a confidence level and provide a link to a statistics screen. The Confidence Level is a statistical percentage, based on the frequency of use of that style in the file, that indicates the editor's confidence in this being a "correct" setting. To be considered the "correct" setting, the option must meet a confidence level of 66%. SlickEdit® Core ignores setting results with a confidence level of less than 66% and they do not appear on the results dialogs. For these options, the current language settings are used.

For example, if the dialog shows Indent with tabs enabled and a Confidence Level of 85%, this means that out of all of the examined instances of this style in the file, 85% of them were indented with tabs, and 15% were indented with spaces.

Click the Statistics button, and the Adaptive Formatting Statistics dialog shows each style that was found and the total number of times it occurred in the examined instances. Each individual setting is categorized in the tree according to type. Click on the plus/minus bitmaps to expand/collapse the tree categories.

Rescanning

Certain events require the file to be rescanned in case any formatting changes have occurred. These events include beautification, auto-reload, and version control update. After one of these processes, Adaptive Formatting is placed again in automatic mode, just as when you first opened the file, scanning the entire file once for indent-type settings, then as you type for all of the other settings.

You can also rescan a file manually with the adaptive_format_update command. This clears the Adaptive Formatting results from memory, then scans the entire file for all Adaptive Formatting settings available for that language. This is useful if you want to create a new file and use different settings for it than what you currently have configured.