Computers: Universe: Editor Macros

In our discussion of the editor, we drew certain parallels between the editor command language and the UniVerse command system. Both had a HELP command you could use to consult an on-line user manual. Both allowed you to enter .L to list a history of previously used commands, and various other commands like .X, .R and .C to manipulate and re-execute them. One feature of the UniVerse command language wasn't compared: the way in which you could add commands to the UniVerse command language by adding records to the VOC file. Can you add commands to the editor's command language?

Well, sort of. Every command in the UniVerse command language is defined by a record in the VOC file: change those records, and you change the language. The commands in the editor command language are all 'hard-coded' into the editor: you can't change them. Neither can you just add a new command called (say) DOSOMETHING.

However, you can do something similar. Begin by starting the editor:

ED VOC FLUFFY
4 lines long.

----:

The number of lines reported will depend on the state in which you left the FLUFFY record at the end of the last section: but its not important. However long the record is, display it using the P command:

----: P
0001: PA
0002: DISPLAY You have just typed the command 'FLUFFY'.
0003: DISPLAY This command is not terribly useful.
0004: DISPLAY It just displays this message.
Bottom at line 4.
----:

Now enter the .L command to list your command stack:

----: .L

01 P

0004: DISPLAY It just displays this message.
Bottom at line 4.
----:

From this you can see that you have a single command in you command stack: the P command.

You can save this command, giving it a name of your own choosing so that you can use it again. To do this, use the .S command:

----: .S1 MYCOMMAND
Creating file "&ED&" as Type 1.
Creating file "D_&ED&" as Type 3, Modulo 1, Separation 2.
Added "@ID", the default record for RetrieVe, to "D_&ED&".
Saved "MYCOMMAND" in "&ED&".

(If someone has used the .S command from the editor before in your directory, the &ED& file will already exist and you will not see the messages describing its creation.)

The &ED& file is the closest equivalent the editor command language has to a VOC file. Each record in &ED& creates not a new command in the editor command language, but rather what is termed a macro. The idea, though, is similar.

To execute your new macro, use the .X command: but instead of specifying a line number from the command stack to reexecute, specify the name of your macro:

----: .X MYCOMMAND
0001: PA
0002: DISPLAY You have just typed the command 'FLUFFY'.
0003: DISPLAY This command is not terribly useful.
0004: DISPLAY It just displays this message.
Bottom at line 4.

***** End of prestored command execution.
0004: DISPLAY It just displays this message.
Bottom at line 4.
----:

So far, all I have demonstrated is a handy way to take a one letter command (P) and abbreviate it to 12 letters (.X MYCOMMAND): less than breathtaking. However, the principle applies, of course, to macros of any length: you can string together as many of these commands as you wish, and execute them with a single command. For instance, if your development team uses a standard header at the beginning of each UniVerse Basic program, you can create a macro to insert the template lines and call it TEMPLATE or somesuch.

Ok, ok, I can tell you're still not impressed. To get a bit more impressive, create the following macro. Create the following record in the &ED& file with the editor:

ED &ED& BASIC.RUN
New record.

----: I
0001= E
0002= SAVE
0003= XEQ BASIC @FILE @ID
0004= XEQ RUN @FILE @ID
0005=
(Press ENTER)
Bottom at line 5.
----: FILE

What's happening here? Well, the first line of each macro, like the first line of each VOC record, indicates the type of record it is: fairly pointless in practice, as all editor macros have an E on this line.

The second line is the ordinary SAVE command: so when the macro executes, it will save the record currently being edited.

The third line is the clever bit. It uses XEQ to invoke the UniVerse BASIC command. This is the command which compiles programs. It takes two parameters, the filename containing the program to be compiled, and the key of the program record.

In these places, the macro passes @FILE and @ID. These are special values that are specially designed for use with XEQ commands from the editor. @FILE is automatically replaced with the name of the file which ED is currently editing, and @ID with the key of the record. So if you are editing MYPROGRAM in BP, the command actually executed by XEQ here is BASIC BP MYPROGRAM - the program you have just SAVEd. Clever, huh? The next line then runs the program for you in the same way.

When the macro finishes, you are returned to the editor, where you can continue working on your program. In this way, you can edit, compile, run, edit, compile, run... all without ever leaving the editor!

The UniVerse documentation on editor macros is a little odd, for two reasons:

1. All their examples show macro commands being created using .S - as I showed in my first example: but for most macros, it's much each just to edit &ED&, and I'm not sure why the manual doesn't explain this.

2. They explain two 'special' editor commands, LOOP and PAUSE, which they clearly feel are particularly useful in editor macros. They are both weird in syntax and implementation, and I don't fancy explaining either here. Their names sort of suggest their purposes, so if you're keen to look, go for it.