MicroEmacs Macros

Authors

Publication

Pub Details

Date

Pages

See all articles from QL Hacker's Journal 31

Thierry Godefroy has ported over the latest version of MicroEmacs 4.00 to the QL. He has added Pointer Environment support for MicroEmacs, including menu items for all the commands. This has made MicroEmacs much more appealing and much easier to use. Just before this port, I had been playing with a little with configuring MicroEmacs and tinkering with macros. I have tried using macros in the past, but I had not quite figured out how to use them. With all the commands now available from pulldown menus, it is very easy to execute a macro from a file.

Now that I know how to execute macros from a file, the next thing was to figure out what would be useful to write as a macro.

I’ve looked over some macros that I found on the MicroEmacs web page. These macros helped create HTML files. These macros would query the user for any information it needed when creating HTML constructs. This means that an application could be written in macros, querying the user for certain data, and generate an end product. Given the maths functions built into MicroEmacs, one could write short little calculating programs, just like we did, years ago, on the ZX81.

The macro I wrote to show how this works is a simple mail-merge like application. The user creates a document, with fields marked out where they want information to go. Here is a short example:

@fname@ @lname@ 
@street@ 
@city@ 

Hello @fname@, 

How are you today?  How is your wife @wife@? 

Signed, 

Here there are fields marked for first name, last name, street, city, and wifes’ name. Since this is a text editor, I used an at sign (@) at the beginning and end of each field to make it distinct from the rest of the test.

The macro will first query the user for the information and then it will go through the text file, replacing the marked fields with the user provided data. A macro like this can be useful if you are writing a Christmas letter that you to make a little more personal, but still save time in writing. The macro is faster than editing the document yourself, or even running the same search-and-replace queries.

The command

set %variable @"String" 

tells MicroEmacs to query the user for input, showing “String” on the command line, and store the data in the variable %variable. Without the at sign (@), the string “String” would be stored in %variable.

;This macro will query the user for some items 
; and then replace them with marked fields in the 
; text file. 

goto-line 1 
set %fname @"First Name : " 
set %lname @"Last Name : " 
set %addr @"Street Address : " 
set %city @"City : " 
set %wife @"Wife's First Name : " 

write-message "Replacing Text ..." 

replace-string "@fname@" %fname 
; Need to goto to the beginning of the 
; file because the search starts from 
; where the cursor is to the end of file. 
beginning-of-file 
replace-string "@lname@" %lname 
beginning-of-file 
replace-string "@street@" %addr 
beginning-of-file 
replace-string "@city@" %city 
beginning-of-file 
replace-string "@wife@" %wife 
beginning-of-file 

write-message "Done ..." 

When Thierry introduced spell checking with MicroEmacs 4.00, it only allowed spell checking of a single word, already marked. I thought it would be a good idea to write a macro that would talk through a file and spell check them all. Thierry has since mentioned that he is looking to expand the spell checking capability to be more user friendly. But, still the idea of writing a macro to walk through a file, word by word, seemed like a good challenge. Below is the macro.

store-procedure get-word 
   set $kill "" 
   !force next-word 
   set-mark 
   !force end-of-word 
   copy-region 
   set %word $kill 
;   write-message &cat "The Word is : " %word 
!endm 

end-of-file 
set %end $curline 
beginning-of-file 

!while &less $curline %end 
   get-word 
   write-message &cat "Word is : " %word 
!endwhile 

Products

 

Downloadable Media

 

Image Gallery

Scroll to Top