Macros are composed of individual statements. Groups of two or more statements are enclosed with curly braces { }.

A statement can be one of the following:

A macro language statement element, such as an if or while statement. These statements are described later.

A call to a user-defined macro function. You define and save macro functions in a macro source file.

A call to an internal macro function, such as GetCurrentBuf. Source Insight provides many built-in functions. They are described in a later section.

An invocation of a Source Insight user command, such as Line_Up or Copy. All user-level commands in Source Insight are available to the macro language. To call a user command, use the name of the command by itself, without parameters. Parentheses are not used. If the command contains embedded spaces in the command name, you must replace the spaces with underscore (_) characters. For example, to call the “Select All” command, the statement should look like Select_All.

Function and variable names are not case sensitive.

Statement syntax is generally the same as in C or Java, except that semi-colons are not required, and are ignored. If your fingers are used to typing them, you don’t have to change your habits.

Here are a few example statements:

hbuf = OpenBuf(“file.c”) // call internal function 
SaveBufAs(hbuf, “filenew.c”) // call internal function 
Select_All // call user-level command “Select All”
Copy        // call user-level command “Copy”
Line_Up     // call user-level command “Line Up”
x = add2(n) // call user-defined macro function add2.

You can stop execution using the “stop” statement.

If you run a Source Insight command with a dialog box from a macro, the dialog box appears.

The following table summarizes the basic macro language statements.

Table 6.1: Macro Statements




Exits a while loop.

if (cond)… else

Tests a condition.


Continues a while loop at the top.

return n

Returns n from a function.


Stops executing the macro.

while (cond)

Loops while cond is true.