Begining Macros

- Written and documented by Stephen Wiebelhaus

In this tutorial, I will create a simple set of CMacros that build on one another. I have tried to write this tutorial to explain basic concepts, so even beginning programmers can understand. First, the problem to solve: I need to remove lines from every file in a project. Removing a few lines from a few files is simple by hand, but for several thousand files, doing it by hand is not an option. CMacros save the day.


This is the start of a CMac file. Multiple CMacros may be defined in one file.

Multi-Edit code screenshot

CMacros of the same name may be referenced by which file they are contained in, for example: JavaMacros^search and CppMacros^search. Both macros have the same name, but are contained in different files and are optimized for different languages.

These are the basic include headers used with many CMacros. These make available the features of the referenced system CMacros, allowing this CMacro to build on their features and do the necessary work.

Multi-Edit code screenshot

This macro removes the first line from the current file.

Multi-Edit code screenshot

However with some simple parameter passing, it can work for any line.

Multi-Edit code screenshot

This macro makes use of the rem_line by iterating through all the files in the project, calling rem_line for each one.

Multi-Edit code screenshot

Notice the use of ttrace statements. These can be valuable in debugging your macros, and they are simple to use. Learn more about them here http://www.multieditsoftware.com/trace_facility.php


For testing purposes, I wanted to be able to easily see how many lines and which lines were being removed. Having the first lines of a file labeled with their numbers would make this easy to look for. Rather than typing in manually, the CMacro can do this quickly. This one creates a list of labels from 1 to 30.

Multi-Edit code screenshot

Using the num_line CMacro, I now do the same thing for all the files in the project.

Multi-Edit code screenshot

This CMacro now calls the prj_rem_line repeatedly.

Multi-Edit code screenshot

I set it to be called 29 times, which should remove 29 lines, leaving only the last "This is line: 30" on each of the files. After testing proved the macros were working correctly, they could be used on real projects.

Here is the complete source code of the CMacros. http://www.multieditsoftware.com/mayMacro.s


This simple set of macros probably sets off your ideas about many other repetitive things you can do with Multi-Edit everyday. For those working with websites, you may use the same navigation menu for many pages. When you want to change it, you could simply call a CMacro to search for the beginning and ending of the navigation menu, (think using begin and end comments) and replace it with a navigation menu from a single file. Also, since its bad to have a page that has links to itself, the macro could also remove the navigation link that points to the current file. There are numerous possibilities. What will you create?



(click the links below for more CMac tutorials)


1:     2:     3:     4:     5:     6:     7:     8:     9:     10:     11:     12.1:     12.2:     12.3:     12.4: