Content Assist
Content Assistance displays in a pop-up window when you place the mouse cursor in a full or partial IDL routine name and press Ctrl-Space. The Content Assist window displays a list of routine and variable names that begin with the characters in the selected string.
Highlighting an item from the Content Assist window displays the syntax for that routine. Selecting the item inserts it at the cursor location. In addition:
- If the cursor is positioned at the end of a routine name, the list begins with the names of keywords to that routine.
- If the cursor is positioned after an equals sign, the list contains the names of variables in IDL’s current execution scope, followed by functions.
- If the cursor is positioned at the dot after the name of a structure variable, the list contains the names of the structure tags associated with that structure.
- If the cursor is positioned on a blank line, the list contains the names of all variables, routines, and code templates defined in the current workspace.
Commenting Code
The semicolon (;) is the comment character in IDL. When IDL encounters the semicolon, it ignores the remainder of the line. It is good programming practice to fully document programs with comments. Comments in IDL do not slow down code execution or add noticeable size to IDL files.
A comment can exist on a line by itself, or can follow another IDL statement, as shown below:
COUNT = 5
Toggle Comments
To toggle comments on or off, select a line or block of lines in the IDL Editor, right-click and select Toggle Comments from the menu. You can also use the Ctrl+; keyboard shortcut.
IDL also provides a way to create documentation from your code comments using IDLdoc. See Using IDLdoc to Generate Documentation for more information.
Manipulating Lines
You can easily move lines up or down, copy lines, or insert lines. Select a line or block of lines and do the following:
- Move lines up or down—Alt+Arrow Up and Alt+Arrow Down
- Copy lines to the line above or below the current line—Ctrl+Alt+Arrow Up or Ctrl+Alt+Arrow Down
- Insert a new line above or below the current line—Ctrl+Shift+Enter or Shift+Enter
Syntax coloring
The Syntax Coloring feature in IDL is the text chromacoding that makes your code easier to read and scan for particular elements. See the following example from the U.S. Census demo program:
Templates
Templates provide a convenient method to insert a pre-defined block of text into a program.
The following table describes the template options on the Preferences > IDL > Templates preferences page:
Option |
Description |
Template List |
This list displays the templates currently loaded in the IDL Workbench.
When you select a template in the list, the template contents are displayed in the Preview box.
If the value in the Auto Insert column is “on”, the template is automatically inserted if there is an exact content assist match.
|
New/Edit |
Creates a new template, or edits a template selected from the list.
Refer to Creating or Modifying a Template for more information.
|
Remove |
Removes a selected template from the list. |
Restore Removed |
Restores all the current templates removed from the list. |
Revert to Default |
If you altered a template, this option restores the original version of the selected template. |
Import |
Imports an external .xml file containing IDL Workbench templates. A template file can be created using the Export button. |
Export |
Exports one or more selected templates into an external .xml file. These files can later be reimported with the Import button. |
Preview |
The Preview box shows the contents of a selected template. |
Restore Defaults |
Restores the Templates page to its initial configuration. |
Apply |
Applies all the current preference changes made to the Templates page. |
Creating or Modifying a Template
In addition to using preexisting templates, you can create your own code templates and modify them later.
To create a new template or modify an existing template:
- On the Preferences > IDL > Templates page, click New or select a template from the Template list and click Edit. The New Template or Edit Template dialog appears.
- Enter a template name in the Name box, or modify the existing name.
-
Select Automatically insert to ensure that templates that exactly match a content assist request are automatically inserted into the editor.
Note: The Automatically insert option is only useful for templates that do not include a line or word selection.
- Enter a description of the template in the Description box.
-
Enter or modify the template text in the Pattern box.
You can insert variables into your template, which allow you to customize a template upon insertion. Variable names follow the form:
${variable_name}
Once a template is inserted in the editor, the variable sections of the template are active, and the variable text can be changed.
- Click Insert Variable to insert a predefined variable into the template. Refer to Predefined Variables for a description of the predefined template variables.
- Click OK.
If you changed the name of the existing template, you are presented with the option of either renaming the template, or creating another template with the new name.
Predefined Variables
The following table describes the predefined variables available when constructing a template.
Predefined Variable |
Description |
cursor |
The cursor position after editing template variables. This is the spot in the template for adding additional code after the template is inserted into the editor. |
date |
The current date value. |
dollar |
The dollar character ( ‘$’ ).
Normally, the ‘$’ character is the beginning character of a user-defined variable. This variable is used when you need to insert a ‘$’ character into your code, but do not want it to be interpreted as a user-defined variable.
|
line_selection |
The lines selected in the editor before the template is inserted. |
time |
The current time. |
user |
The current process user name. |
word_selection |
The word selected in the editor before the template is inserted. |
year |
The current year. |
Inserting a Template into an Editor
If a template contains a word selection or a line selection variable, you must select the appropriate text prior to inserting the template. Selecting text prior to invoking the content assist menu also means that you must explicitly choose the template from the list (automatic template insertion is not an option).
To insert a template into your code that does not include a line or word selection:
- Type the name (or part of a name) of a template in the editor.
-
Press Ctrl-Space to display the list of content assist items.
If the template was configured to automatically insert itself, and if the name of the template does not match any other content assist item, the template is inserted automatically into the editor.
- Select a template from the list to display the template’s content.
- Double-click a template in the list (or press Enter) to insert the template into the editor.
- If the template contains user-defined variables, the keyboard focus is on the first variable. Edit the variable value, and press Tab to highlight the next variable (if one exists).
- After the last variable, if the template contains a ${cursor} variable, pressing Tab places the keyboard focus at the ${cursor} position. Enter additional code at this position.
To insert a template into your code that includes a line or word selection:
- In the editor, select the desired text.
- Press Ctrl-Space to display the list of content assist items.
- Select a template from the list to display the template’s content.
- Double-click a template in the list (or press Enter) to insert the template into the editor.
- If the template contains user-defined variables, the keyboard focus is on the first variable. Edit the variable value, and press Tab to highlight the next variable (if one exists).
- After the last variable, if the template contains a ${cursor} variable, pressing Tab places the keyboard focus at the ${cursor} position. Enter additional code at this position.
Inserting a Template into the Command Line
You can insert a template that consists of a single line into the command line as well as into an editor.
For example, suppose you want to select a data file with the extension .dat from a specific directory quite often. You could define a one-line template similar to the following, giving it a short name like df:
${file}=DIALOG_PICKFILE(PATH='C:\Sensor\Data', FILTER='*.dat')
Then to select a data file, type df at the command line and press Ctrl-Space. Assuming no other template begins with the characters df, the template is inserted into the Command Line with the initial file highlighted, allowing you to quickly change the variable name. Pressing Return brings up the file selection dialog in the specified directory, with the file list filtered for .dat files.
Using Source Control Tools in IDL
IDL gives you the ability to use source control directly from the Workbench. The source control tools that come with IDL include:
- CVS
- Git
- Perforce
- Subversion
The IDL Workbench is developed in the Eclipse Interface Development Environment, and the source control tools are Eclipse plugins. Use the following links to find information about how to set up your environment to use the plugins for each source control application: