6.1.5. Managing Comments

The Ada language-sensitive editor makes it easy to convert existing text to comments, to convert comments back to non-comment text, and to format comments so that they adhere to margin constraints. Toggling Comments

The current non-comment source code selection will be converted to comments by pressing control+- (control dash). Similarly, comment lines are converted back to regular code by the same key sequence. Alternatively, the transformation can be achieved by invoking the “Toggle Comment” command available under the Ada menubar entry and the editor’s Ada contextual menu. using the contextual menu invoked by right-clicking in the source file and selecting Toggle Comment.

The following figure illustrates a selection of non-comment code about to be converted into comments:

Commenting Lines Before

After invoking the command the selected lines are commented, as the following figure shows.

Commenting Lines After Reformatting Comments

Comment lines as well as lines of arbitrary text within an Ada source file can be adjusted so that none of the text flows past the Eclipse “print margin” boundary. Comment lines remain as comments after this reformatting; non-comment lines remain non-comments.

The action can be applied to individual lines or to a selection of lines within an Ada source file. If no selection is active when the command is invoked, only the line containing the cursor will be reformatted.

The command is invoked by simultaneously pressing the Alt+Shift+| keys, or by invoking the “Refill Selection to Margin” command available under the Ada menubar entry and the editor’s Ada contextual menu.

If the Eclipse print margin margin is not enabled no reformatting will occur. You can tell if the margin is set by the appearance of a colored vertical line in the editor immediately after the column corresponding to the margin. Use the General/Editors/Text Editors preference page and look for the “Show print margin” check-box. On that page you also specify the column for the margin and can control the color of the resulting line.

The figures below illustrate the application of the editor action. In the first figure, a block of comments that goes past the print margin is selected. The margin is indicated by the vertical gray line to the right inside the editor box.

before refilling the block to the right margin

The command is then invoked and the text is refilled so that none of the text goes past the print margin:

after refilling the block to the right margin