Syntax Expansion is a feature designed to minimize keystrokes, increasing your code editing efficiency. When you type certain keywords and then press the spacebar, Syntax Expansion inserts a default template that is specifically designed for this statement. For example, if you are using the C language and type "for", press Space and the following text expansion is inserted, with the cursor location between the parentheses:
for() {
}Syntax Expansion triggers Dynamic Surround for block-oriented statements. This allows you to expand and collapse the newly inserted block to include more/less code. Additionally, for C, C#, C++, J#, Java, and Slick-CŪ, after the statement is expanded, you can use the next_hotspot command (Ctrl+[) to jump the cursor to the next part of the statement. In the case of the for loop above, Ctrl+[ would move the cursor from the group in parentheses to the code block.
The structures loop, if, and switch or case are also expanded. You do not have to type the entire keyword for Syntax Expansion to occur. If there is more than one keyword that matches what you type, a list of possible keyword matches is displayed. To get the C template displayed above, type "f" followed by pressing Space.
To override the insertion of braces immediately for one line if, for, or while statements, type a semicolon immediately after the keyword. For example:
if; => if ( <cursor here> ) <next hotspot>;
To override non-insertion of braces immediately for if, for, while, foreach, with, lock, fixed, and switch statements, type an open brace immediately after the keyword. For example:
if{ => if ( <cursor here> ) { <next hotspot> }If the default behavior of Syntax Expansion does not match your coding style, for most languages, it can be customized. From the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select [Language] Formatting Options. See Language-Specific Formatting Options for more information.
For further customization, for most languages, you can override the default keyword expansion by defining an alias for that keyword. See Language-Specific Aliases for more information.
To access Syntax Expansion settings, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Indent.
To turn Syntax Expansion on or off, select or clear the option Syntax expansion. To change the minimum expandable keyword length, enter the value by using the Minimum expandable keyword length spin box.
To set options such as brace style, from the main menu, use the [Language] Formatting Options screen.
SlickEditŪ Core can display Syntax Expansion choices for the word prefix under the cursor. To turn this option on/off, select the Auto-Complete language-specific options screen and select/clear the Syntax expansion option. See Completions for more information.
Syntax Expansion templates are essentially language-specific aliases that have been pre-defined. You can modify these templates by replacing them with your own.
For example, to add a comment to the end of C for, while, if, and switch statements:
From the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Aliases.
Click New and then type for as the alias name.
Type the following lines in the text box to the right of the alias name:
for (%\c;;) {
} /* for */The %\c escape sequence above specifies the cursor placement after expansion is performed.
Repeat Steps 2 and 3 for the while, if, and switch keywords.
Click OK to save new aliases.
The above steps replace the default Syntax Expansion templates for these keywords. The C brace style options will not affect defined aliases.
For more information on working with aliases, using the Alias options page, or using alias escape sequences, see Language-Specific Aliases.
To add syntax expansion and indenting for other languages, complete the following steps:
Use the prg.e macro as a template. This file is located in the macros subdirectory of your installation directory. Make a copy of it and give it another name.
Change the #define constants EXTENSION and MODE_NAME near the top of the file to reflect the new extension and mode name respectively. Do not use any spaces in these constants.
Change the name of the first five characters of the _command functions dbase_mode, dbase_enter, and dbase_space to use the value given to the MODE_NAME constant in Step 2.
Modify the prg_expand_enter function to provide the Enter key the desired support.
Modify the prg_expand_space function to provide the spacebar key the desired support. If you can rely on language-specific aliases, follow the comment in this function.
Use the load command Macro → Load Module to load new macro modules.
Steps 4 and 5 require a good understanding of the Slick-CŪ language and what this specific macro is doing. See the Slick-CŪ Macro Programming Guide for more information.