Creating and using code templates

A code template is text that is automatically inserted into the body of new code element definitions. Code templates are extremely useful for enforcing or simplifying programming standards in a team or organization. You can specify uniform error handling, logging, or tracing code, and the LotusScript editor automatically inserts it each time you create a new code element, saving time and preventing accidentally ignoring the standard or making mistakes in its implementation.

About this task

The code elements supported include design elements (script libraries, agents, and so on), subs, functions, property gets and sets, classes, and types. When you create a new code element (either by creating a design element, or by typing in a definition for it), the code element is inserted into the body of the definition. In the case of design elements, the code template is inserted when the design element is created, and appears after any automatically included "Option" statements. If you type a function definition in the editor, the code template is inserted into the body of the definition. For example, if you type a function definition like Function IsPrime (X As Integer) As Boolean and press Enter, the LotusScript Editor autocompletes the line to the following:
<multiline comment templates are inserted here> 
Function IsPrime (X As Integer) As Boolean 
<multiline code templates are inserted here> 
End Function
To view the current code templates, click File > Preferences, expand Domino Designer and LotusScript Editor and click Code Templates. You can then do the following:

Procedure

  • Click any element in the Code element listbox to see its template in the Code template field.
  • Enable code templates. By default, code templates are disabled and every code template is set to a blank newline. To enable code templates, check Automatically include template in new code elements.
  • Create a code template:
    1. Click any element in the Code element listbox, then enter your template in the Code template field.
      Your LotusScript code is automatically modified to use the correct upper- and lower-case letters as you type. Note that content assist, syntax checking, and hover help are not available in the field.
    2. Pressing Ctrl+Up or Ctrl+Down in the template editor moves you to the previous or next template.
    3. When you are finished editing your template, click Apply or OK to save your changes.