Commenting

SlickEdit® Core makes commenting your code easy. You can comment out selected text, or type the start characters for a new doc comment and have the doc comment skeleton automatically expanded. SlickEdit Core also makes your comments easier to read by automatically wrapping them as you type. Existing comments can be "reflowed" to match current comment wrap settings.

Commenting Blocks and Lines

Existing text in your code can be commented out (or uncommented) as follows:

  • To comment out a selected code block, from the main menu, click Format → Comment Block (or use the box command). This comments out the entire selection as a single block comment by surrounding the block with comment characters you have specified in your comment settings.

  • To comment out selected lines, from the main menu, click Format → Comment Lines (or use the comment command). Each line in the selection is commented out as a single line comment. If there is no selection, the current line is commented out. If using a block selection where there are partially selected lines, comment characters are placed at the beginning and end of the selection. If using a character selection where there are partially selected lines, comment characters are placed based on your settings. The comment characters that are placed to the left and right of the text are also specified in your comment settings.

  • To uncomment lines in a selection, from the main menu, click Format → Uncomment Lines (or use the comment_erase command). Surrounding line comment characters are removed from the line. If there is no active selection, the current line will be uncommented. Uncomment Line only works for well-formed comments, which means that every line in the selection is commented and that the comment characters occur in the same column.

Whether you are creating a comment block or a comment line, if the selected text already contains comments, another set of comment characters is added. SlickEdit® Core attempts to preserve the indentation level of the code and any existing comments when adding or removing comment characters.

Comment Block and Line Settings

To specify the characters and other settings used for comment blocks and lines, from the main menu, click Format → Comment Setup (or use the comment_setup command). The Options dialog opens to the language-specific Comments screen for the current language. You can also open this screen by clicking Window → SlickEdit Preferences → Languages → [Language Category] → [Language] → Comments.

The Comment block group box provides eight fields to specify the characters used in your commenting style. If you want to apply a comment with no additional decoration, fill in the upper-left and lower-right fields with the characters to begin and end a block comment. To draw a box around the comment, fill in additional characters in the other fields. For example, you might put an asterisk in each of the other fields to draw a box of asterisks around the block comment.

The Comment line group box contains fields for you to specify the characters to be inserted at left and right sides of a line comment.

For code examples and descriptions of the other available options, see Language-Specific Comment Options.

Doc Comments

Doc comments are specially formatted comments that are processed by tools that extract and present the information in a formatted manner. Doc comments follow a predefined structure, based on the programming language and the tool processing the comments.

SlickEdit® Core supports the most common doc comment formats (Javadoc, XMLdoc, and Doxygen). When you type the start characters for one of these comment formats and press Enter on a line directly above a function, class, or variable, SlickEdit Core can automatically insert a skeleton doc comment for that style.

Note

In C#, you do not need to press Enter, as the skeleton comment is inserted after you type the third slash.

To activate and configure automatic completion of doc comment skeletons, complete the following steps:

  1. From the main menu, click Format → Comment Setup (or use the comment_setup command). The Options dialog is displayed, open to the Comments option screen for the current language. You can also open this screen by clicking Window → SlickEdit Preferences → Languages → [Language Category] → [Language] → Comments.

  2. In the Doc comments box, check the option Automatically expand doc comments.

  3. Click the Edit expansion button to configure the start characters and comment templates for the doc comment style you plan to use for the selected language. For comments formatted in Javadoc, select /**. For XMLdoc, select ///. For Doxygen, select /*! or //!.

  4. Optionally, click the Edit expansion button to view or edit the doc comment template that is inserted when you type the selected start characters. See Modifying Doc Comment Templates for more information.

  5. Click OK on the Options dialog.

Tip

If you modify a function signature, you can update the associated doc comment by running the update_doc_comment command from the SlickEdit Core command line.

Doc Comment Examples

Javadoc Format

To use the Javadoc commenting format for the selected language, select the start characters /** and use style @param. Check Insert leading *. Using the following code sample:

/**[CURSOR_HERE]*/
int setDimensions(int length, int width, int height) {
  ...
}

Pressing Enter at the "cursor here" location results in the following automatic completion:

/**
 * [CURSOR_HERE]
 *
 * @param length
 * @param width
 * @param height
 *
 * @return int
*/
int setDimensions(int length, int width, int height) {
  ...
}
XMLdoc Format

To use the XMLdoc comment format, select the start characters /// and the <param> style. Using the following code sample:

///[CURSOR_HERE]
int setDimensions(int length, int width, int height) {
  ...
}

Pressing Enter at the "cursor here" location results in the following automatic completion:

/// <summary>
/// [CURSOR_HERE]
/// </summary>
/// <param name="length"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns>int</returns>
int setDimensions(int length, int width, int height) {
  ...
}
Doxygen Format

To use a Doxygen comment format, select the start characters /*! or //! (based on your preference) and the \param style. Using the following code sample:

/*![CURSOR_HERE]*/
int setDimensions(int length, int width, int height) {
  ...
}

Pressing Enter at the "cursor here" location results in the following automatic completion:

/*! 
 * [CURSOR_HERE]
 * 
 * \param length
 * \param width
 * \param height
 * 
 * \return int
 */
int setDimensions(int length, int width, int height) {
  ...
}

Modifying Doc Comment Templates

To modify a doc comment template, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, and click the Edit expansion button. The Doc Comment Editor dialog for the selected language opens. Click on the start characters for style of comments you want to use to view and edit the associated comment template.

The box on the left contains a list of doc comment start characters. The edit window on the right contains the expansion for the selected start characters. See Alias Escape Sequences for a list of special escape characters you can use inside doc comment templates, for example, to insert local function param names, types, and return types. See Doc Comment Examples for an example of each comment style.

Tip

You cannot add or delete doc comment templates using the Doc Comment Editor. You can, however, add a new doc comment expansion as a regular language-specific alias. See Creating a Language-Specific Alias for more information. All of the doc comment escape sequences will work as long as you expand the alias on a blank line above a function or class declaration.

String Editing

When the cursor is inside of a string, if you press Enter to split the line, SlickEdit® Core can automatically align the string with the original string as well as insert the closing and opening quotes and, if necessary, operators. To set this option, click Format → Comment Setup (comment_setup command). The Options dialog is displayed open to the Comments screen. Select the option Split strings on Enter.

Comment Wrapping

Comments can be set to automatically wrap to the next line as you type. This feature is available for C, C++, C#, Java, and Slick-C® files.

To activate comment wrapping, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Comment Wrap. Select the option Enable comment wrap, then select the type of comments you want wrapped (block comments, line comments, and/or doc comments).

The Comment Wrap screen also provides options to control how comments are wrapped. There are three types of width settings:

  • Fixed - Comments will be formatted to a specified width.

  • Automatic - Comments will be formatted according to the width of existing comments.

  • Fixed right margin - Lines will break before a specified number of columns has been reached.

For more details on comment wrapping configuration, see Language-Specific Comment Wrap Options.

Reflowing Comments

After configuring comment wrap settings, you can use the Reflow Comment dialog to reflow block comments, paragraphs, or a selection of the current file. To display this dialog, click Format → Reflow Comment. .