I’ve been meaning to tinker around with MicroEmacs macros for some time, but never got around to it. Recently I decided to take the time to really give it a try. Of all of the text editors available for the QL, I think MicroEmacs is the most powerful. It’s macro language is the most robust of the editors. Both QED and ED have macros that can automate keystroke commands, but they don’t have any logic (IF..THEN) or structure ( WHILE ) features. MicroEmacs has looping and logic controls.
As an example, I thought that a line number macro would be nice. The following macro goes to the beginning of the file and starts putting line numbers on each line. Before it does this it queries you for a starting line number, which are are incremented in 10’s. To determine when to stop processing, I had to know when the macro had reached the end of the file. Since there is no end-of-file checking mechanism, I had to move to the end of the file and get the line number of the last line. This was then used in the while loop. If there are lots of empty lines at the bottom of the file, there macro will number them also. A check could be put in the see if the current line is empty, but this would not work if a line had only white space in it ( tabs and/or spaces).
I noticed two differences between the execution of MicroEmacs and ED/QED macros. One, ED/QED macros are kind of slow and take a while to run. MicroEmacs macros are very fast. Total run time for this macro in an 20 line routine was about 1-2 seconds. Two, when executing ED/QED macros you can see what is going on as it happens. The screen updates with each command. With MicroEmacs, the screen seems to update only at the end of the macro. When the macro went to the bottom of the file and then returned to the top, I thought it would display the movement, but it did not. If you do want to update the dislay while a macro is executing, there is a redraw screen command that you can use.
The documentation for the MicroEmacs macros is good in documenting the different commands, but it falls short of providing many examples. I used other macros that came with MicroEmacs to learn from. This can slow down the learning process, but there is no other alternative. In some ways I use this same technique in other languages. I keep bits of code around so I don’t have to memorize how to do a routine in a particular language, I just go though my old code.
; Line Numbering Macro
set %line_num @"Starting Line Number? "
end-of-file
set %tot_lines $curline ;LET tot_lines=line number @ EOF
beginning-of-file
!while &less $curline %tot_lines
beginning-of-line
insert-string %line_num
insert-string " "
set %line_num &add %line_num 10;LET line_num=line_num+10
next-line
!endwhile
beginning-of-file