Multiple-Line Macros

This topic demonstrates how caret control codes are used to define macros whose output spans multiple lines. The for macro is an example.

The for macro expands into a simple for loop including braces.

The definition in the macros.txt file is:

for
for {(};;{)} {{}{ENTER 2}{}}{UP 2}{END}{LEFT 5}

As in the cn macro, the parentheses and braces are quoted.

The control code {LEFT 5} at the end of the macro means move the caret left five characters, and other control codes are introduced.

{ENTER 2} means press the Enter key twice, and leave a blank line between the two braces.

{UP 2} is similar to {LEFT 2}, press the up arrow key twice.

{END} press the End key to move the caret to the end of the current line.

Therefore, the overall effect of the macro is seen by reading it from left to right, imagining the special keys being pressed where the caret control codes are located.

The macro expands with the caret between the opening parenthesis and the first semicolon; that is, where the loop index variable is initialized.

for (;;) {
}