Creating Wildfilew aware macros


Most of Vedit macros can be called from Wildfilew.vdm. However, making your macros wildfile aware gives you more possibilities. Here is some technical information about Wildfilew.vdm.

Register usage

Numeric registers

Wildfilew.vdm uses numeric registers #41 to #97. Wildfilew pushes these register in stack before calling user macro. These registers can be used by user macro, but their values are not retainet on successive calls of user macro.

Registers #0 to #39 are not used by Wildfilew. These registers can be used by user macro to pass information between successive calls.

Some registers have special meaning and can be used in user macro:
#60 - contains number of files to be processed.
#61 - buffer that contains search.tmp (for listing output)
#98 - flags for passing information between Wildfilew and user macro (see below).
#99 - when Wildfilew is running, contains value 0x57495C44 ("WILD")
Register #98 contains several flags for passing information between Wildfilew and user macro. (Flags are represented here as mask values):
Wildfile sets:
0x00 = First call to user macro (Wildfile resets #98 at the beginning)
0x02 = Last file being processed
User macro sets:
0x01 = First call done (set by user macro if needed)
0x02 = Stop processing more files
0x04 = Do not show end dialog
0x08 = Do not close current file
0x10 = Search.tmp was used, do not close it.

For more information of the special registers, see below.

Text registers

User macro should only use free text registers in range 10 to 99 (use Reg_Free to check for free text registers). Any text registers used must be emptied at the end.

Passing information between Wildfilew.vdm and user macro

Usually, the macro should be made such way that it can be called either directly or from Wildfilew.vdm. This may require different operation in case macro is called from Wildfile (and thus multiple files are being processed). In addition, Wildfilew allows controlling some functions of Wildfilew from user macro.

Check if macro was called from Wildfilew

If numerig register #99 has value 0x57495C44 ("WILD"), the macro was called from Wildfile. You can check this e.g. with the following command:

if (#99==0x57495C44) {
   // Wildfile is running
}

Check if first or last call to user macro

If the user macro collects information from multiple files, it is necessary to do some initializations on the first call and store or display results on the last call. You can check if this is the firs call or last call by checking value of numreg #98. Example:

if (#98 == 0) {
    // first call, do initializations etc.
    #98 = 1   // initializations have been done
}

if (#98 == 2) {
    // last call, display results etc.
}

Examples

Some of the supplied macros can be used as an example of how to create Wildfile aware macros.

Count2.vdm is a simple example. You enter a search string in a dialog box and the macro then counts how many times the string occurs in the file. The result is displayed on status line. If you call the macro directly, it counts the strings in current file only. If you call the macro from Wildfile, the strings are counted in all the specified files. The dialog box is only displayed once in the beginning.

C_paren.vdm is a more complex example of Wildfile aware macro is. It checks that all the parentheses in C file(s) are balanced. Just like count2.vdm, it can be called either directly or from Wildfile.


Related topics:

Macro dialog
Wildfile - Multi file processing