Setting template preferences

You can use the Templates preference page to define code templates that enable you to use custom code snippets.

About this task

Note: Custom code snippets (and the shortcuts that invoke them) are used in conjunction with content assist to type frequently used code constructs quickly. For example, a predefined code snippet is provided for the if else statement in the list of available templates. The shortcut that invokes this code snippet is ifelse. In the z Systems® LPEX Editor, you can typeifelse and then press Ctrl + Space to insert the entire code block for an if else statement into the source file.

To set the C/C++ Templates preferences, complete the following steps:

Procedure

  1. In the navigation pane of the Preferences window, double-click the LPEX Editor node to open the tree of available preference pages.
  2. Double-click the z Systems LPEX Editor node to open the tree of available preference pages.
  3. Double-click on the C/C++ Parser node to open the tree of available preference pages, then click Templates to open the Templates preference page.
  4. To create a new template:
    1. Click New to open the New Template dialog box.
    2. In the Name field, type a name for the new template that you want to create. For example, if you want to create a template for if else statements, type ifelse.
    3. Specify the context in which you would like your template to appear:
      • Select C/C++ to have the template appear in executable C or C++ code in your C or C++ source file.
      • Select Comment to have the template appear when editing comments in your C or C++ source file.
      • Select CICS to have the template appear when editing embedded CICS® statements in your C or C++ source file.
      • Select SQL to have the template appear when editing embedded SQL in your C or C++ source file.
    4. Select the Automatically insert checkbox to automatically insert the new template if it is the only available option at the caret position.
    5. In the Description field, type a description of the type of code snippet that you want to create a template for. For example, if else statement.
    6. In the Pattern field, type the pattern for your code template. This pattern can contain predefined and custom template variables. To insert a predefined template variable, click Insert Variable. From the list of predefined variables, double-click the variable that you want to include in your template pattern. You can also insert your own custom template variables into the template pattern. These must evaluate to the name of the variable itself. If you want to display the dollar symbol ($), it must be escaped using two dollar symbols or the ${dollar} variable.
    Tip: You can also use the Add as new template action to create a new template based on selected code, refer to Creating a new template based on selected code, to enable you to use custom code snippets.
  5. To edit an existing template:
    1. Select the template that you want to edit, and then click Edit to open the Edit Template dialog box.
    2. Modify any information that you want to change for the selected template.
    3. Click OK to save your changes and close the dialog box.
    Tip: To revert the template to the default values that existed before you edited the template, click Revert to Default.
  6. To remove an existing template, select the template the you want to remove and click Remove. The template is removed from the list of available templates.
    Tip: To restore a template that you removed from the list of available templates, click Restore Removed.
  7. To import a code template from another location, click Import to open the Browse dialog box and browse for the location of the template.
  8. To export an existing code template to another location, select the template that you want to export, and then click Export to open the Browse dialog box. Browse for the location that you want to export the template to.
    Tip: To export multiple templates to a single XML file, select the first template that you want to export, and then press Ctrl + click for each additional template that you want to export.
  9. Do one of the following actions:
    • Click Restore Defaults to discard your changes and restore the default settings for this page.
    • Click Apply to save your selections in the preference page.

Results

Note: Templates added to the C/C++ parser templates preference page will also appear for the Remote C/C++ Editor.