Macro Functions

A macro function is declared in a format that looks like a C function. White space is ignored, and function and variable names are not case sensitive. A macro function begins with either the macro or function keyword, followed by the name of the function. Here is a most basic function:

macro HelloWorld()

{

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

}

Macro functions can have parameters and can call other macros. You can return a value from a macro by using "return n" where n is the return value. For example:

function add2(n)

{

   return n + 2

}

User-Level Macros vs Functions

There are three flavors of macro functions:

For example, this function becomes a user-level command, and it can be assigned to a keystroke:

macro SaveCurrentFileNow ()

{

   perform_save()

}

You can use Options > Key Assignments to locate the SaveCurrentFileNow command and assign a keystroke to it.

However this function can only be called from another macro function, because it is declared with the func­tion keyword:

function perform_save ()

{

   var hbuf

 

   hbuf = GetCurrentBuf()

   if (hbuf != nil)

       SaveBuf(hbuf)

}