7.3 Ed - Euphoria Editor

7.3.1 Introduction

The Euphoria download package includes a handy, text-mode editor, ed, that's written completely in Euphoria. Many people find ed convenient for editing Euphoria programs and other files, but there is no requirement that you use it.

7.3.2 Summary

Usage:

  1. ed filename
  2. ed

After any error, just type ed, and you'll be placed in the editor, at the line and column where the error was detected. The error message will be at the top of your screen.

Euphoria-related files are displayed in color. Other text files are in mono. You'll know that you have misspelled something when the color does not change as you expect. Keywords are blue. Names of routines that are built in to the interpreter appear in magenta. Strings are green, comments are red, most other text is black. Balanced brackets (on the same line) have the same color. You can change these colors as well as several other parameters of ed. See "user-modifiable parameters" near the top of ed.ex.

The arrow keys move the cursor left, right, up or down. Most other characters are immediately inserted into the file.

In Windows, you can "associate" various types of files with ed.bat. You will then be put into ed when you double-click on these types of files - e.g. .e, .pro, .doc etc. Main Euphoria files ending in .ex, .exd or .exw might better be associated with eui.exe, euid.exe, or euiw.exe, respectively.

ed is a multi-file/multi-window text-based editor. Esc c will split your screen so you can view and edit up to 10 files simultaneously, with cutting and pasting between them. You can also use multiple edit windows to view and edit different parts of a single file.

7.3.3 Special Keys

Some PC keys do not work in a Linux or FreeBSD or Windows text console, or in Telnet, and some keys do not work in an xterm under X windows. Alternate keys have been provided. In some cases you might have to edit ed.ex to map the desired key to the desired function. e.g. you'll have to use C-t and C-b instead of C-Home and C-End.

Delete Delete the current character above the cursor
Backspace Move the cursor to the left and delete a character
C-Delete Delete the current line (not available on all platforms)
C-d Delete the current line (same as C-Delete)
Insert re-insert the preceding series of Deletes before the current line/character
C-Left Move to the start of the previous word. On Unix, use C-l
C-Right Move to the start of the next word. On Unix, use C-r
Home Move to the beginning of the current line
End Move to the end of the current line
C-Home Move to the beginning of the file (euid.exe only, others use C-t
C-End Move to the end of the file (euid.exe only, others use C-b
PgUp Move up one screen. On Unix use C-u
PgDn Move down one screen. On Unix use C-p
F1..F10 Select a new window. The windows are numbered from top to bottom with the top window on the screen being F1
F12 User definable key (see CUSTOM_KEYSTROKES near top of ed.ex. Default action is to insert -- for a Euphoria comment

7.3.4 Escape Commands

Press and release the Esc key, then press one of the following keys:

h Get help text for the editor, or Euphoria. The screen is split so you can view your program and the help text at the same time.
c "Clone" the current window, i.e. make a new edit window that is initially viewing the same file at the same position as the current window. The sizes of all windows are adjusted to make room for the new window. You might want to use Esc l to get more lines on the screen. Each window that you create can be scrolled independently and each has its own menu bar. The changes that you make to a file will initially appear only in the current window. When you press an F-key to select a new window, any changes will appear there as well. You can use Esc n to read a new file into any window.
q Quit (delete) the current window and leave the editor if there are no more windows. You'll be warned if this is the last window used for editing a modified file. Any remaining windows are given more space.
s Save the file being edited in the current window, then quit the current window as Esc q above.
w Save the file but do not quit the window.
e Save the file, and then execute it with euid, euiw or eui. When the program finishes execution you'll hear a beep. Hit Enter to return to the editor. This operation may not work if you are very low on extended memory. You can't supply any command-line arguments to the program.
d Run an operating system command. After the beep, hit Enter to return to the editor. You could also use this command to edit another file and then return, but Esc c is probably more convenient.
n Start editing a new file in the current window. Deleted lines/chars and search strings are available for use in the new file. You must type in the path to the new file. Alternatively, you can drag a file name from a Windows file manager window into the console window for ed. This will type the full path for you.
f Find the next occurrence of a string in the current window. When you type in a new string there is an option to "match case" or not. Press y if you require upper/lower case to match. Keep hitting Enter to find subsequent occurrences. Any other key stops the search. To search from the beginning, press C-Home before Esc f. The default string to search for, if you don't type anything, is shown in double quotes.
r Globally replace one string by another. Operates like Esc f command. Keep hitting Enter to continue replacing. Be careful - there is no way to skip over a possible replacement.
l Change the number of lines displayed on the screen. Only certain values are allowed, depending on your video card. Many cards will allow 25, 28, 43 and 50 lines. In a Linux/FreeBSD text console you're stuck with the number of lines available (usually 25). In a Linux/FreeBSD xterm window, ed will use the number of lines initially available when ed is started up. Changing the size of the window will have no effect after ed is started.
m Show the modifications that you've made so far. The current edit buffer is saved as editbuff.tmp, and is compared with the file on disk using the Windows fc command, or the Linux/FreeBSD diff command. Esc m is very useful when you want to quit the editor, but you can't remember what changes you made, or whether it's ok to save them. It's also useful when you make an editing mistake and you want to see what the original text looked like.
ddd Move to line number ddd. e.g. Esc 1023 Enter would move to line 1023 in the file.
CR Esc Carriage-Return, i.e. Esc Enter, will tell you the name of the current file, as well as the line and character position you are on, and whether the file has been modified since the last save. If you press Esc and then change your mind, it is harmless to just hit Enter so you can go back to editing.

7.3.5 Recalling Previous Strings

The Esc n, Esc d, Esc r and Esc f commands prompt you to enter a string. You can recall and edit these strings just as you would at the command line. Type up-arrow or down-arrow to cycle through strings that you previously entered for a given command, then use left-arrow, right-arrow and the delete key to edit the strings. Press Enter to submit the string.

7.3.6 Cutting and Pasting

When you C-Delete (or C-d) a series of consecutive lines, or Delete a series of consecutive characters, you create a "kill-buffer" containing what you just deleted. This kill-buffer can be re-inserted by moving the cursor and then pressing Insert.

A new kill-buffer is started, and the old buffer is lost, each time you move away and start deleting somewhere else. For example, cut a series of lines with C-Delete. Then move the cursor to where you want to paste the lines and press Insert. If you want to copy the lines, without destroying the original text, first C-Delete them, then immediately press Insert to re-insert them. Then move somewhere else and press Insert to insert them again, as many times as you like. You can also Delete a series of individual characters, move the cursor, and then paste the deleted characters somewhere else. Immediately press Insert after deleting if you want to copy without removing the original characters.

Once you have a kill-buffer, you can type Esc n to read in a new file, or you can press an F-key to select a new edit window. You can then insert your kill-buffer.

7.3.7 Use of Tabs

The standard tab width is 8 spaces. The editor assumes tab=8 for most files. However, it is more convenient when editing a program for a tab to equal the amount of space that you like to indent. Therefore you will find that tabs are set to 4 when you edit Euphoria files (or .c, or .h or .bas files). The editor converts from tab=8 to tab=4 when reading your program file, and converts back to tab=8 when you save the file. Thus your file remains compatible with the tab=8 world. If you would like to choose a different number of spaces to indent, change the line at the top of ed.ex that says "constant PROG_INDENT = 4".

7.3.8 Long Lines

Lines that extend beyond the right edge of the screen are marked with an inverse video character in the 80th column. This warns you that there is more text "out there" that you can't see. You can move the cursor beyond the 80th column. The screen will scroll left or right so the cursor position is always visible.

7.3.9 Maximum File Size

Like any Euphoria program, ed can access all the memory on your machine. It can edit huge files, and unless disk swapping occurs, most operations will be very fast.

7.3.10 Non-text Files

ed is designed for editing pure text files, although you can use it to view other files. As ed reads in a file, it replaces certain non-printable characters (less than ASCII 14) with ASCII 254 - small square. If you try to save a non-text file you will be warned about this. Since ed opens all files as "text" files, a control-z character (26) embedded in a file will appear to ed to be the end of the file.

7.3.11 Line Terminator

The end-of-line terminator on Linux/FreeBSD/OSX/OPENBSD/NETBSD is simply \n. On Windows, text files have lines ending with \r\n. If you copy a Windows file to Linux/FreeBSD and try to modify it, ed will give you a choice of either keeping the \r\n terminators, or saving the file with \n terminators.

7.3.12 Source Code

The complete source code to this editor is in bin\ed.ex and bin\syncolor.e. You are welcome to make improvements. There is a section at the top of ed.ex containing "user-modifiable" configuration parameters that you can adjust. The colors and the cursor size may need adjusting for some operating environments.