Macro Language Guide

Source Insight provides an interpreted C-like macro language, which is useful for scripting commands, insert­ing specially formatted text, and automating editing operations.

Here is an example of a macro function that shows a message box.

macro HelloWorld()

{

   msg("Hello World!")   // message box appears with "Hello World"

}

Macros are saved in a text file with a .em extension. The macro source files can be added to your project, or to any project on the Project Symbol Path, or to the Base project. Once a macro file is part of the project, the macro functions in the file become available as user-level commands in the Key Assignments or Menu Assign­ments dialog boxes.

There is a library of built-in macro functions for accessing Source Insight objects, such as file buffers, or win­dows. You can call these built-in functions from your own macro functions.

Basic Syntax Overview

Source Insight’s macro language is designed to be easy to write and require minimal housekeeping. The syn­tax has been kept fairly simple.

Identifier Names

Identifier names are used to identify variables and functions.

Indentation and White Space

White space means a tab or a space character. White space is generally ignored, except when it is used to delimit identifiers and operators. Lines are that completely blank are ignored. You can use any indentation style you like, as Source Insight ignores it.

Comments

Two types of comments are supported:

For example:

/* this is a comment */

var a

 

/* this comment

  spans

 multiple lines */

 

a = 0  // this is a comment to the end of the line

Strings

Strings must be enclosed in double-quote marks. Single quotes are not used. For example:

a = "this is a literal string"

To embed a double-quote character in a string, you must escape it with a backslash character. For example:

a = "Open the file \"test.txt\" to begin the test."

Semi-Colons at the End of Statements

Semi-colons are not required at the end of statements, but they are allowed and ignored.