Source Insight provides an interpreted C-like macro language, which is useful for scripting commands, inserting 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 Assignments dialog boxes.
There is a library of built-in macro functions for accessing Source Insight objects, such as file buffers, or windows. You can call these built-in functions from your own macro functions.
Source Insight’s macro language is designed to be easy to write and require minimal housekeeping. The syntax has been kept fairly simple.
Identifier names are used to identify variables and functions.
Identifier names are not case sensitive. For example, Open and open are the same.
Identifier names must begin with a letter A to Z or a to z or an underscore (_), followed by zero or more letters, underscores and digits. Examples are isOpen, MyThing2, and open_file.
Identifier names cannot contain punctuation characters such as @ or % or dot(.).
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.
Two types of comments are supported:
A comment begins with /* and ends with */. The comment can span any number of lines.
A single line comment begins with // and extends to the end of the line.
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 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 are not required at the end of statements, but they are allowed and ignored.