Skip to content
Patrick Scheibe edited this page May 7, 2018 · 3 revisions

Beside simply typing (* this is a comment *), the plugin gives you many additional features to work with comments. First of all, you should never manually type (, *, *, and ) to create a comment. Learn to use Ctrl+/ or Ctrl+Shift+/ to create a new empty comment where the cursor is already in the middle. The difference between the two shortcuts is subtle but important

  • The first shortcut will create a new comment in an empty line. On a line that contains already code or if you have selected a portion of code, this shortcut will comment out the line/selection.
  • The second short, however, will create an empty comment even, when you are in the middle of a line that contains code. This is helpful if you want to add a comment to a function parameter or directly after an expression.

When you are inside a longer comment and need several lines, there are two forms. The first form consists of several lines with several separate comments like in the header of a package file

(* Mathematica Package  *)
(* Created by Mathematica Plugin for IntelliJ IDEA, see http://wlplugin.halirutan.de/ *)

(* :Title: IGraph/M   *)
(* :Context: IGraphM` *)
(* :Author: szhorvat  *)
(* :Date: 2015-08-28  *)

When you are inside a comment, you can always press Ctrl+Shift+Enter and you will get a new empty comment in the next line with the cursor inside it.

Completion inside comments

Basic function and word completion works inside comments. If you have an empty comment (**) with the cursor in the middle and you press Ctrl+Space, then the plugin will provide you with completion for (1) sectioning comments like (* ::Subsection *) and (2) tag comments like (* :Author: *).

Sectioning comments must always consist of two lines like this

(* ::Section:: *)
(* This is the section title *)

Otherwise they won't be recognized by Mathematica itself.

Folding sections

Using sectioning comments to document and divide your code into structural parts has two advantages. First, users that view your package in the Mathematica front-end will see the blocks as separated cells with title-text. More important, however, if you use sectioning comments consistently, you can fold the contents inside IDEA.

The plugin will respect the hierarchy which means folding a section will close all code between its start and the next section including all sub-sections that are in between. In essences you can easily create a foldable outline of your package. IDEA will present a closed section with its title like this

section

The small + sign on the left side indicates that this portion can be expandend.