13.7.3. Template examples

Example 13.1 shows a template file using text from the specified file, called myfile.txt. On insertion, the text is placed above the cursor position.

Example 13.1. 

# Simple template example using text from a specified file

“TemplateName” TEMPLATE -above C:\myProjects\project1\myfile.txt
“TemplateName” END

Example 13.2 shows a template of a simple FOR loop written in C. On insertion, the text is placed below the cursor position and indented to match the line of C code that immediately precedes it.

Example 13.2. 

# Simple template example - simple FOR loop

“Simple For Loop” TEMPLATE -below -indent
for (index = 0; index < top; index++);
{
}
“Simple For Loop” END

Example 13.3 shows the use of an auto-insertion phrase. With this template, type the auto-insertion phrase WriteDevice and immediately press Ctrl+3 to display all the template text. However, press Ctrl+Shift+3 to insert only the text immediately below the ^L.

Example 13.3. 

# Simple template example
# This combines an auto insertion phrase and the use of ^L (ASCII 12)

“WriteDevice Function” TEMPLATE -auto=’WriteDevice’
EXAMPLE
/* write a message string to the LCD */
if (!WriteDevice(main_lcd, sizeof(init_msg), init_msg))
    ReportFailure(DEV_ERR, class_lcd, main_lcd);
^L
Status WriteDevice(int dev_no, int len, uint8 *buffer);
“WriteDevice Function” END

Example 13.4 shows the use of selection when inserting a template. If you are editing source code and you select a function name within a definition and insert this template, the body is expanded above the function and the function name is filled in where $selection is found.

Example 13.4. 

# Simple template example using selection

“Function Header” TEMPLATE -sel -above
/*
---------------------------------
$selection -
Notes:

---------------------------------
*/
“Function Header” END

Each example can be typed into a .tpl file or they can all be entered into a single file, for example template_examples.tpl, for access through the Insert Template dialog box.

Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0234B
Non-Confidential