5 Macros and Keys


Macros allow you to add new functionality to Phedit. Each macro has a name and consists of a list of calls to primitives and/or other macros. You may bind a key to the macro such that when the user presses the key the macro is then run. You may also make it so that when the user chooses a menu item your macro is then run.

5.1 Sample Macros

The following is a macro that causes the File Selector window to appear in order to prompt the user for a file to open. Once the user has openned a file using that File Selector window then the current search pattern is searched for in that file and if found then the line that the pattern is found on is displayed.
OpenAndSearch()
{
    OpenFilePrompt();
    SearchNext();
}
Some things to note about the above macro: Now let's look at another macro.
GetFileGoodbye()
{
    OpenAndSearch();
    InsertString( "Goodbye" );
}
There are two things to note about the above macro:

Macro Name Rules

The macro name is limited to a maximum of 40 characters. For backward compatability with QWEdit almost any character except a space is acceptable but for new macros restrict yourself to just alphabetic characters, numbers and the underscore (_).

Macro Formatting Rules

Note that the spacing around the various components of a macro is not important. The GetFileGoodbye macro could have been formatted as shown below and it would still have been the same macro (though it is much harder to read).
GetFileGoodbye ( ){
OpenAndSearch ( ) ; InsertString ("Goodbye") ; }

5.2 Macro Files

Each macro file begins with some header information that tells Phedit that it is a macro file and what version of macro file format it is. As Phedit evolves so to will the macro language. The format version number will help Phedit be backward compatible with less capable macro languages.

An example header follows:

[PheditMacros]
Format=0.2
Macros are stored in two different files:

The .phedit.mac File

This file contains the macros that you create. See the section that talks about the start up search order for where this file is looked for when Phedit starts up.

A sample .phedit.mac file follows:

[PheditMacros]
Format=0.2

GetFileGoodbye()
{
    OpenAndSearch();
    InsertString( "Goodbye" );
}

OpenAndSearch()
{
    OpenFilePrompt();
    SearchNext();
}

The .phedit.key File

This file contains a special macro that binds the various keys to your macros. You typically let Phedit create this file but you may want to add things to it yourself. See the section that talks about the start up search order for where this file is looked for when Phedit starts up.

A sample .phedit.key file follows:

[PheditMacros]
Format=0.2

BindKeys()
{
    AddKeyBinding( "Ctrl+O", "OpenAndSearch()" );
    AddKeyBinding( "Ctrl+G", "GetFileGoodbye()" );
}

5.3 How to Create Macros

Macros can be created in two ways: For details on recording macros see the Start Macro and End Macro sections. The section on saving macros and keys may also be of some interest.

To create a macro file directly you simply create your own or open existing .phedit.mac and .phedit.key files and edit them. Read the sections above about the formats of these files.

5.4 Keyboard Shortcut Format

In order to bind keys to macros you must know what is acceptable for use as a keyboard shortcut.

Phedit is not sensitive about case with regards to keyboard shortcuts. Ctrl+F1 or ctrl+f1 are the same thing as far as Phedit is concerned. The keyboard shortcut can be:

When combining Alt, Shift or Ctrl with another key then you can specify the key combination with a + (plus sign) between them, with no space between them or with a - (minus sign) between them. Phedit accepts either format. The following are all the same as far as Phedit is concerned: