Copyright (c) Hyperion Entertainment and contributors.

AmigaOS Manual: AmigaDOS Using the Editors

From AmigaOS Documentation Wiki
Revision as of 05:41, 25 January 2014 by Steven Solie (talk | contribs) (→‎ED)
Jump to navigation Jump to search

A text editor or word processing program is necessary for creating or editing text files and script files. Amiga Workbench software comes with three text editors. This chapter describes them in the following order:

  • ED
  • MEmacs
  • EDIT

Each of the Amiga editors can be used separately for editing AmigaDOS scripts and programs; ED and MEmacs can be used for creating these files. If you are comfortable with the UNIX Emacs editor, you may prefer using the MEmacs editor. If you need to edit files containing binary code or you need to edit files too large to fit into memory, use EDIT. If you are not familiar with any of the editors, we recommend that you use the ED editor.

Each editor has the basic functionality of a word processor, however, none of these editors support style formatting options, such as italics, page numbering, or different fonts. If you need these features, you can purchase third party word processing software containing such features for your Amiga.

ED

ED is a full screen ASCII text editor that uses menus and function keys to access its features. It is easy to use and is suitable for editing scripts, startup files, MountLists, and other simple files. Use either a mouse or the keyboard to perform operations with ED. Although ED's menus are preprogrammed, when you are familiar with the program, you can reconfigure them as needed.

Note
ED does not accept files containing binary code. To edit this type of file, use EDIT or MEmacs.

The bottom line of the ED window is the status line used for displaying messages, prompts, and commands. Error messages displayed on the status line remain until you enter another ED command. Figure 4-1 illustrates the ED window showing the status line.

Figure 4-1. ED Window with Status Line

The format for ED is the following:

ED [FROM] <filename> [SIZE <n>] [WITH <filename>] [WINDOW <window specification>] [TABS <n>] [WIDTH | COLS <n>] [HEIGHT | ROWS <n>]

The FROM argument specifies the source file to be edited. This argument is required, but the FROM keyword is optional.

The SIZE argument changes the ED buffer size. ED has a default text buffer size of 40,000 bytes. For example:

1> ED Script SIZE 55000

increase the size of the buffer to 55,000 bytes.

The WITH argument specifies an ED command file that can contain any sequence of ED extended mode commands. When WITH is specified, ED executes the commands contained in the command file. The WITH argument's keywords is required if you use WITH.

The WINDOW argument specifies the console type, such as RAX:0/0/640/256/EdWindow or CONSOLE:. The WINDOW argument's keyword is required if you use WINDOW.

TABS sets the tab stop interval, which is the number of spaces to the right that the cursor moves when you press the Tab key. The default value for TABS is 3.

The WIDTH and HEIGHT arguments adjust the size of the ED window by specifying the number of characters to display horizontally and vertically. By default the ED window is 640 x 200 picels or approximately 88 characters wide by 21 lines high.

Starting ED

Start ED from a Shell or with the Workbench Execute Command menu item. Open ED at the prompt by entering ED and a new or existing file name, as follows:

1> ED <filename>

where <filename> is the name of an existing file or a new file to be used for saving your work. If the file name specified cannot be found in the current directory, ED opens a blank window and displays the message Creating new file.

Using ED

All ED commands have key sequences and many are available through menus. You can enter ED commands in either of the following ways:

  • By choosing the command's menu item.
  • By typing in the command's key sequence and pressing Return.

In addition, you can use the mouse to perform some commands, such as those that control cursor movement.

You can work on files in ED with the following two command modes:

Immediate
Commands are executed as soon as typed. EP opens in immediate mode.
Extended
Commands are not executed until you press Return or Esc.

Immediate Commands

In immediate mode, ED executes commands right away. Specify an immediate command by pressing a single key or Ctrl+key combination or by using the mouse. All immediate commands have corresponding extended versions.

Immediate commands control the following:

  • Cursor movement
  • Text scrolling
  • Text insertion
  • Text deletion
  • Repetition of commands

Moving the Cursor in Immediate Mode

The cursor can be positioned anywhere in text by moving the pointer to the desired spot and clicking the selection button. To move the cursor with the keyboard, use the arrow keys, Tab, and Ctrl+key combinations.

Note
In ED, the Tab key only moves the cursor. It does not insert Tab characters or spaces in a line.

Move the cursor one position in any direction by pressing the appropriate arrow key. If the cursor is on the right edge of the screen, ED scrolls the text to the left do display the rest of the line. ED scrolls the text vertically one line at a time and horizontally ten characters at a time. You cannot move the cursor beyond the left edge of the line. If you try to move the cursor beyond the top or bottom of the file, ED displays a Top of File or Bottom of File message.

Additional key combinations that control cursor movement are:

Shift+up arrow Top of the file.
Shift+down arrow Bottom of the file.
Shift+left arrow Left edge of the ED window (regardless of the margin setting).
Sift+right arrow End of the current line.
Ctrl+] Right edge of current line (if cursor is already there, it is moved to the left edge).
Ctrl+E Start of the first line on the screen (if cursor is already there, it is moved to the end of the last line on the screen).
Ctrl+T Start of the next word.
Ctrl+R Space following the previous word.
Tab The next tab position (multiple of the TABS value; 3 by default).

If your file has more lines than can fit in the ED window, you can scroll through the file vertically. Scroll one line at a time by pressing the up or down cursor key to move in the corresponding direction. Move the text in jumps by pressing:

Ctrl+D Moves 12 lines down through the file.
Ctrl+U Moves 12 lines up through the file.

These commands do not move the cursor position in the window; they redraw the text in the window with the new line at the cursor position.

If something disturbs your screen, such as an alert from another program appearing in the ED window or message remarks in the status line, press:

Ctrl+V Refreshes the window display.

Inserting Text in Immediate Mode

Any characters typed in immediate mode are inserted at the current cursor position and the cursor is shifted to the right. Any characters to the right of the cursor are shifted to make room for new text. If the line is wider than the width of the window, the window scrolls to the right to show what you are typing. If you move the cursor beyond the end of the line, ED inserts spaces between the end of the line and any new characters inserted.

There is maximum limit of 255 characters in a line. If you add more characters, ED displays a Line Too Long message.

To split the current line at the cursor, press Return. Any text to the left of the cursor remains on the original line. All text under and to the right of the cursor moves down onto a new line. Pressing Return at the end of the line creates a new blank line.

Deleting Text in Immediate Mode

ED has no type over mode. To replace a word or line, you must delete the existing words and insert new information with the following keys and key combinations:

Backspace Deletes the character to the left of the cursor.
Del Deletes the character highlighted by the cursor.
Ctrl+O If the cursor is over a space, all spaces up to the next character are deleted. If the cursor is over a character, all characters up to the next space are deleted.
Ctrl+Y Deletes all characters from the cursor to the end of the line.

When text is deleted, any characters remaining on the line shift to the left and any text beyond the right edge of the screen becomes visible.

Changing Case in Immediate Mode

You can change the case of text by positioning the cursor and pressing Ctrl+F. If the letter is lower case, it becomes upper case and vice versa. Ctrl+F does not change non-alphabetic characters or symbols.

After you press Ctrl+F, the cursor moves to the right. You can hold down Ctrl+F to repeat the command until you change all the letters on the line.

Extended Commands

In extended mode, commands are displayed on the command line - or status line - at the bottom of the window. ED does not execute these commands until you press Return or Esc. If you use Esc to execute extended commands, ED remains in extended mode. If you use Return to execute extended commands, ED returns to immediate mode.

Extended commands manage the following:

  • Program control
  • Cursor movement
  • Text modification
  • Block control
  • Searching and exchanging text

To enter extended mode, press Esc. An asterisk appears as a prompt in the status line. Extended commands consist of one or two characters. Multiple extended commands can be typed on a single command line by separating them with a semicolon. Commands can be grouped together for ED to repeat automatically. Use Backspace to correct mistakes.

You can also execute commands through the programmable menu and function keys. Reconfigure the menus and functions keys by assigning a command to the key or menu item of your choice as described on page 4-21.

Using String Delimiters

In some cases, commands require arguments, such as a number or a text strig. A string argument for an ED command must be enclosed in a pair of identical delimiter characters. In unambiguous situations you may omit the trailing delimiter. Valid delimiters include ", /, \, !, :, +, -, and %. You cannot use the same delimiter character inside your string. Invalid delimiter characters include letters, numbers, spaces, semicolons, question marks, brackets, and control characters.

Using a File Requester

You can also ask ED to use a file requester, allowing you to view the contents of the drives and directories in your system.

To invoke a file requester for a load or save command, you must place a question mark (?) before the required string argument. Be sure to include a space before the question mark (for example, sa ?/Text/). Normally, when a command is followed by a string. ED treats the string as the file to be loaded or saved and attempts the operation immediately. However, the question mark indicates that you want to specify the file through a file requester. You must still specify a string after the question mark, but the string becomes the text that appears in the file requester title bar.

ED Menus

ED has two sets of command menu assignments: default and expanded. The default menu assignments, as illustrated in Figure 4-2, are set up by the S:Ed-startup file, which is automatically executed each time you run ED. The S:Ed-startup file is a command file of ED extended mode commands, without the Escape characters. You can edit this file to set up custom menus, as described on page 4-21, or define preprogrammed function key assignments with the Set FN Key menu item.

Figure 4-2. Default Menu Assignments

Enabling Expanded Menus

The expanded command menu assignments, as illustrated in Figure 4-3, can be enabled by renaming or deleting the default S:Ed-startup file. If ED cannot find a file named S:Ed-startup, it opens with the expanded set of menus, providing more options.

Figure 4-3. Expanded Menu Assignments

Rather then deleting your S-Ed-startup file, we recommend that you rename it as follows:

  1. In the Workbench window, go to the Window menu and select Show All Files.
  2. Double-click on the S drawer icon.
  3. Click on the Ed-startup icon.
  4. Go to the Icons menu and choose Rename.
  5. Delete the name in the Rename requester's New Name text gadget and enter a new name for Ed-startup.
  6. Select OK.

You can also create your own customized file of startup options. Avoid including Quit commands in the S:Ed-startup file since they can cause ED to quit immediately after opening.

The menu items in both the default and expanded menus have the same function regardless of which set you use. All of the ED commands are available through the keyboard using extended mode commands even if they do not appear in any menu.

The following sections describe the menu items found in the expanded menus and their corresponding extended and immediate mode commands. An ellipsis (...) indicates that an argument is required or that a menu item opens a requester or prompt.

Project Menu

The following are the expanded Project menu items:

New Esc,N,W Creates a new file, replacing the existing file. The message Edits will be lost-type Y to confirm: is displayed. Press any key (except Y) to abort the command.
Open... Esc,O,P... Opens a file. Specify the file by entering the path to the file as a properly delimited string. (If slashes appear in the path to a file, do not use the slash as a delimiter.) The message Edits will be lost-type Y to confirm: reminds you that you are replacing the current file.
Insert File... Esc,I,F... Inserts a file into the current file. ED reads into memory the specified file at the point immediately following the current line.
Write Block... Esc,W,B... Writes the currently marked block to a specified file. ED overwrites any other files with that name and copies the block to the file.
Save Esc,S,A Saves the text to the current file, overwriting the existing text in the file. Use Save As to save to different file. SA followed by Q is equivalent to the X command.
Save As... Esc,S,A... Saves the text to the specified file name.
Save & Exit Esc,X Exits ED, saving the current file to the designated file name. ED writes the text it is holding in memory to the file that was specified when ED was opened and then terminates.
About Esc,S,H Shows the current state of the editor. The screen display information, such as the value of tab stops, current margins, block marks, and the name of the file being edited.
Quit Esc,Q Exits ED without saving changes. If you made any changes to the file, ED asks if you want to quit. If you press Y, ED terminates immediately without saving the changes to the file.

Edit Menu

The following are commands used for editing:

Undo Line Esc,U Reverses changes made to the current line. However, ED cannot undo a line deletion. Once you have moved from the current line, the U command cannot undo a change.
Star Block Esc,B,S Identify the beginning and end of a block of text. To specify a block of text to be moved, inserted, or deleted, place the cursor on the first line that you want in the block and enter the BS command. Move the cursor to the last line that you want in the block and enter the BE command.
You cannot start or finish a block in the middle of a line.
Show Block Esc,S,B Redraws the display so the block is at the top of the screen.
Insert Block Esc,I,B Inserts a copy of the block after the current line. The block remains defined until you change the text. Use IB to insert copies of the block throughout the document.
Delete Block Esc,D,B Deletes a block.
Delete Line Esc,D
Ctrl+B
Deletes the entire line.

Movement Menu

The following commands move the cursor around the screen:

Top Esc,T Top of the file; first line of the file is brought to the top of the window.
Bottom Esc,B Bottom of the file; last line of the file is brought to the bottom of the window.
Go To Line... Esc,M... Move the cursor to the specified line. Enter the line number on the status line and press Return. The line specified is brought to the top of the window. If no number is given, the cursor goes to the top of the window.
Next Page Esc,P,D
Ctrl+D
Go to next page.
Previous Page Esc,P,U
Ctrl+U
Go to previous page.

Search Menu

The following commands let you search through the file for specific instances of text. You can substitute one pattern of text with another (search and replace) and have ED request confirmation of (query) each replace. If the specified text is not found or there are no more instances of the text, the message Search failed is displayed. When using the Find and Replace menu commands, ED prompts for the text strings. Enter the text without delimiters. When using extended mode, include delimited strings with the command.

Find...
Find Next
Esc,s... Finds the next occurrence of the specified string of text. The search starts one character beyond the current cursor position and continues forward through the file. If the string is found, the cursor moves to the start of the located string. The search is case-sensitive, unless the Ignore Case command is used. Find Next repeats the command.
Reverse Find...
Reverse Find
Next
Esc,B,F... Searches backwards through the file for the specified string. This command finds the last occurrence of the string before the current cursor position. The search continues through to the beginning of the file. Reverse Find Next repeats the command.
Replace... Esc,E... Exchanges one occurrence of text with another.
In extended mode, enter the strings enclosed by three delimiters. For example, to replace the word to with too, enter "to"too". Specify empty strings by typing two delimiters with nothing between them. If the first string is empty, ED inserts the second string at the current cursor position. If the second string is empty, ED searches for the next occurrence of the first string and then deletes it. Note that ED ignores margin settings when exchanging text.
Global Replace Esc,R,P,E... Exchanges all occurrences of text.
Query-Replace... Esc,E,Q... Searches for the text to be exchanged and requests verification by displaying Exchange?. Enter Y to exchange or another other key to abort.
Global Query-Replace... Esc,R,P,E,Q... Searches for all occurrences of the text to be exchanged and requests verification for each. Enter Y to exchange or any other key to abort.

Settings Menu

The following commands are used for setting up your ED environment:

Set FN Key... Esc,S,F... Defines the function keys and other programmable keys. Defining function key and Ctrl+key commands is similar to defining menu items. See page 4-15 for instructions for defining function keys and an example of the Set FN Key command.
Show FN Key... Esc,D,F
<key>
Displays the setting for the function key specified by <key>. Enter a space and a key slot number for <key>.
Reset Keys Esc,R,K Resets the key definitions to the default. See page 4-16 for a table of special key mappings.
Right Margin... Esc,S,R... Sets the right margin. Use the SR command followed by a number indicating the column position.
Left Margin... Esc,S,L... Sets the left margin. Use the SL command followed by a number indicating the column position. The left margin should not be set beyond the right edge of the screen.
Ignore Case Esc,U,C Specifies a case-insensitive search. UC instructs all subsequent searches not to make any distinction between upper and lower case next. To make searches case-sensitive again, use the LC command.
Case Sensitive Esc,L,C Specifies a case-sensitive search.

Set FN Key

Set FN Key is used to define function keys and other programmable keys. There are 57 immediate command key slots ranging from 1 to 57. Any slot number can be redefined and any numbers within the range that do not appear in the special key mappings on page 4-16 are not defined.

The following is the syntax for the Set FN Key command:

SF <slot number> /command string/

Define Ctrl+key combinations by substituting a caret (^) and the other character for the slot number.

Example Script

This example script assigns function keys to cursor control commands. You can also enter these as a series of extended mode commands. The Top of File, Bottom of File, End of Page, Next Page, Next Line, and Previous Line commands are assigned to the F1 through F6 keys, respectively. Quotation marks are used as delimiters.

SF 1 "t"
SF 2 "b"
SF 3 "ep"
SF 4 "pd"
SF 5 "n"
SF 6 "p"

Special Key Mappings

The following table shows the default key definitions used in the Reset Keys command:

Slot# Key/Key Sequence Function
1-10 F1 through F10 Not defined
11-20 Shift+F1 to Shift+F10 Not defined
21 Shift+left arrow Move to beginning of line
22 Shift+right arrow Move to end of line
23 Shift+up arrow Move to top of document
24 Shift+down arrow Move to bottom of document
25 Del Delete character at cursor
26 Not defined Not defined
27 Ctrl+A Insert line
28 Ctrl+B Delete line
29 Ctrl+C Not defined
30 Ctrl+D Move down 12 lines
31 Ctrl+E Move to top or bottom of screen
32 Ctrl+F Change case
33 Ctrl+G Repeat last extended command line
34 Ctrl+H Delete character left of cursor
35 Ctrl+I Move cursor to next tab position
36 Ctrl+J Not defined
37 Ctrl+K Not defined
38 Ctrl+L Not defined
39 Ctrl+M Return
40 Ctrl+N Not defined
41 Ctrl+O Delete word or spaces
42 Ctrl+P Not defined
43 Ctrl+Q Not defined
44 Ctrl+R Move to end of previous word
45 Ctrl+S Not defined
46 Ctrl+T Move start of next word
47 Ctrl+U Move up 12 lines
48 Ctrl+V Redisplay window
49 Ctrl+W Not defined
50 Ctrl+X Not defined
51 Ctrl+Y Delete to end of line
52 Ctrl+Z Not defined
53 Ctrl+[ Esc (enter extended command mode)
54 Not defined Not defined
55 Ctrl+] Move to end or start of line, depending on cursor position
56 Not defined Not defined
57 Not defined Not defined

Command Menu

The following commands are for manipulating files:

Extended Command... Esc,C,M... Enters extended command mode; equivalent to pressing Ctrl+[ or Esc.
Repeat Last Esc,R,E Attempts to repeat the last command.
Run File... Esc,R,F... Loads and executes a command file of extended mode commands.
ARexx Command... Esc,R,X... Runs the specified ARexx program.
Redisplay Esc,V,W Redraws the ED window and clears the status line; equivalent to pressing Ctrl+V.

Other ED Commands

There are also ED commands that do not appear in menus. These commands are listed here in functional groups. Use them in extended mode by entering the following key sequences.

Program Control

The following are program control commands:

Extend Margins Esc,E,X Extends the margins for the current line. Once you enter the EX command, ED ignores the right margin on the current line.
Status Line Message Esc,S,M... Prints a given string on the status line.
Exit with Query Esc,X,Q Exits ED unless changes were made to the file. If changes have been made, the message File has been changed-type Y to save and exit: is displayed. Press any key (except Y) to abort the exit. XQ is equivalent to clicking the close gadget on the ED window.

Cursor Control

The following commands are used for controlling the cursor:

End Page Esc,E,P End of a page.
Previous Esc,P Start of the previous line.
Character Left Esc,C,L One place to the left.
Character Right Esc,C,R One place to the right.
Current End Esc,C,E End of the current line.
Current Start Esc,C,S Start of the current line.
Tab Esc,T,B Next tab position.
Word Next Esc,W,N Start of the next word.
Word Previous Esc,W,P Space after previous word.

Modifying Text

The following commands edit text on the screen:

Insert Before Esc,I Inserts the specified string on the line before the cursor. Specify a new line's string after the I command to insert text before the current line containing the cursor.
Insert After Esc,A Inserts the specified string on the line after the cursor. This command works in the same way as I, except that the string is inserted on a new line beneath the current cursor position.
Split Esc,S Splits the current line at the cursor position.
Join Esc,J Joins the next line to the end of the current line.
Delete Esc,D Deletes the current line.
Delete Character Esc,D,C Deletes the character under the cursor.
Delete Left Esc,D,L Deletes the character to the left of the cursor.
Delete Word Esc,D,W Deletes to the end of the current word.
End Line Esc,E,L Deletes to the end of the current line.
Flip Case Esc,F,C Switches the case of the selected letters, one at a time.
Set Tab Esc,S,T Sets the tab stop. To change the current setting of tabs, use the ST command followed by a number.
Next Esc,N Start of the next line.

Repeating Commands in Extended Mode

Pressing Ctrl+G repeats a command line. You can set up execute complex sets of editing commands many times.

You can repeat a command a specified number of times by entering the number before the command. For example:

4 E/rename/copy/

exchanges the next four occurrences of "rename" to "copy".

Use the RP (Repeat) extended command to repeat a command until ED returns an error, such as reaching the end of the file. For example:

T;RP E/rename/copy/

moves the cursor to the top of the file, then exchanges all occurrences of "rename" with "copy". The T command (Top of File) changes all occurrences of Rename in the whole file. Otherwise, only the occurrences after the current cursor position are changed.

To execute command groups repeatedly, you can group the commands together in parentheses. You can also nest command groups. For example:

RP (F/Workbench/;3A//)

inserts three blank lines (the null string//) after every line containing Workbench.

To interrupt any sequence of extended commands, press any key during execution. If an error occurs, ED abandons the command sequence.

Customizing ED

You can customize ED with commands that change the menus and function key setup. These commands can be entered individually within ED. They can also be saved as a script, such as S:Ed-startup, or as a file specified using the WITH argument. To execute the file from within ED, use the Run File (Esc,R,F) extended command. For information about changing the function keys, see page 4-15.

\ Set Menu Item || Esc,S,I || Defines the menu headings and items. There are 120 menu item slots ranging from 0 to 119. The slot type identifies the contents of the slot and is a number from 0 to 4. The 0 slot type must be the last defined slot. Do not create a menu without items; if you specify a menu heading, include menu items after it. See below for the syntax of the Set Menu Item command and a table of the slot types.
Enable Menu Esc,E,M Enables menus. You must follow the Set Menu Item commands with EM to enable the menu commands. See page 4-22 for an example script using the Enable Menu command.

Set Menu Item

The following is the syntax for the Set Menu Item command:

SI <slot number> <slot type> /string1/string2/

The following table shows the slot types and functions used with the Set Menu Item command:

Type Function String Input
0 End of Menus No arguments
1 Menu Heading String1 = heading name
2 Menu Item String1 = item name
String2 = command string
3 Submenu Heading String1 = heading name
String2 = command string
4 Separator bar No arguments

Example Script

The following is an example script using the Set Menu Item and Enable Menu commands. Quotation marks are used as the delimiters.

SI 0 1 "Project"
SI 1 2 "Open . . . " "op ? /Open file:/"
SI 2 2 "Save ... " "sa"
SI 3 4
SI 4 2 "Quit!" "q"
SI 5 1 "Move"
SI 6 2 "Top" "t"
SI 7 2 "Bottom" "b"
SI 8 0
EM

This script produces the menus illustrated in Figure 4-4:

Figure 4-4. ED Custom Menu Example

Printing From ED

Use the following steps to print a file that is open in the current ED window:

  1. Choose the Save As menu item to display a file requester.
  2. Enter prt: in the Drawer field.
  3. Select OK.

This prints the file, but does not save it to disk. If you wish to save the file you must select the Save menu item or Save As and a file name.

Quitting ED

You can exit ED in one of the following three ways:

  • Esc,X. This method exits ED and saves the current file to a designated file name that was specified when ED was opened.
  • Esc,X,Q or click on the ED window's close gadget. This method exits ED if no changes were made to the file. If changes were made to the file, ED lets you save the changes or exit without saving.
  • Esc,Q or select the Quit item in the Project menu. This method exits ED without saving any changes if you confirm the status line warning that changes will be lost.

ARexx Support

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:

  • The first session's port name is ED
  • The second session's is ED_1
  • The third session's is Ed_2 and so on

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:

address 'Ed' 'RV /stem/'

assigns values to the following variables:

stem.LEFT Current left margin
stem.RIGHT Current right margin
stem.TABSTOP Current tab stop setting
stem.LMAX Maximum number of lines visible on screen
stem.WIDTH Width of the screen in characters
stem.X Cursor X position in the ED window (1 is the left edge)
stem.Y Cursor Y position in the ED window (1 is the top line)
stem.BASE Window base (normally 0, but non-zero when the screen is shifted to the right)
stem.EXTEND Extended margin value (Extend Margins command)
stem.FORCECASE Case sensitivity flag (Ignore Case = 1, Case Sensitive = 0)
stem.LINE Current line number in the file (1 is the first line)
stem.FILENAME Name of the file being edited
stem.CURRENT Text of the current line
stem.LASTCMD Last extended command issued
stem.SEARCH Lst string searched for

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.

ED/ARexx Example Program

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:

RX /transpose.ed/

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 */
/*string into '213'. */
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 */
  currpos = currpos - 1
else do /*Otheriwse, report error and exit */
'sm/Cusor must be at position 2 or further to the right/'
exit 10
end
 
/*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 */
/*memory. */
'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 */
  end
exit /*Program has finished */
 
/*Function to swap two characters */
Swapch: procedure */
parse arg cpos,clin
  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 */

MEmacs

To Be Continued...