9. User Macros

This section describes in detail TrEd's support for user macros. It is devoted mainly to programmers.

As was already mentioned, TrEd is itself written in Perl and therefore it is natural that also user macros are written in Perl language. The details of the Perl language syntax are not described here. You may find them in the literature on programming in Perl as well as in manual pages of Perl language. A large volume of documentation on Perl and many specific Perl modules is collected for example by ActiveState. In this text, we concentrate on the TrEd's macro specifics.

9.1. What is a macro

A macro for TrEd is simply any Perl routine defined using the sub { ... } construct:

sub my_first_macro {
	# any Perl code may come here
}

Macros may be called from other macros in the same way as any other sub-routines in Perl, for example:

sub my_first_macro {
	my_second_macro();  # call another macro
}

In this case, macros may use the usual Perl mechanisms to pass the called macro any number of argumens.

To make the macro accessible from TrEd, two more things should be done. First, a special “directive” should be added, so that the macro appears in the User-defined menu and thus may be called interactively, second the macro must be stored in some file and TrEd must be told where to look for the file. This (and more) is discussed in the following sections.