You can also control ED from ARexx by sending and receiving commands through ED's ARexx port. Each copy of ED running concurrently has an individual ARexx port name that must be specified to handle information for the correct session. The ARexx port names are assigned as follows:
Many of ED's extended commands can be used from ARexx. By using ED's RV command in ARexx programs, you can send information from ED to ARexx. This gives information about the status of ED, such as the current line number of the name of the file being edited.
The RV command accepts the name of the ARexx stem variable to store its argument information. For example, in ARexx:
assigns values to the following variables:
Window base (normally 0, but non-zero when the screen is shifted to the right) |
|
Any valid ARexx symbol can be substituted for "stem". Enclose the name in proper delimiters. These variables can be treated as ordinary ARexx stem variables.
The example program, Transpose.ed, illustrates the use of several extended commands from ARexx. This program transposes two characters when launched from ED. For example, if a line contains the string 123 and the cursor is highlighted the 3, Transpose.ed changes the string to 213.
Enter this program and save it as REXX:Transpose.ed. Then, open ED and edit an existing file or create a new one. Place the cursor one character to the right of the ones to be transposed, press Esc, and enter:
The program executes and the characters are transposed if ARexx is running and everything is entered correctly. The entire file name, including the extension, must be specified to run the program.
/*Transpose.ed: An example program to transpose two characters. */
/*Given string `123', if cursor is on 3, this macro converts */
HOST = address () /*find out which ED session invoked this program*/
address VALUE HOST /*...and talk to that session */
`rv''/CURR/' /*Ask ED to store info in stem variable CURR */
/*Obtain two pieces of information: */
currpos = CURR.X /*1.position of cursor on line */
currling = CURR.CURRENT /*2. Contents of current line */
if /currpos >2) then /*Work only on the current line */
else do /*Otheriwse, report error and exit */
`sm/Cusor must be at position 2 or further to the right/'
/*Next the code needs to reverse the CURRPOSth and CURRPOSth-1 */
/*characters and then replace the current line with the new one. */
/*drop CURR. CURR is no longer needed; dropping it saves some */
`d' /*Tell ED to delete current line */
currlin = swapch (currpos,currlin) /*Swap the two characters */
`i/'||currlin||'/' /*Insert modified line */
do i = 1 to currpos /*Place cursor back where it started */
`cr' /*ED's `cursor right' command */
exit /*Program has finished */
/*Function to swap two characters */
ch1 = substr(clin,cpos1) /*Get character */
clin = delstr(clin,cpos1) /*Delete it from string */
clin = insert(ch1,clin,cpos-2,1) /*Insert to create transposition */
return clin /*Return modified string */