U.S. Geological Survey

Xed: A multi-platform programmer's text editor

User's Guide

Download

The new home of XED is <http://geology.usgs.gov/tools/xed/>

It is also possible to obtain the package through anonymous ftp: <ftp://geology.usgs.gov/pub/xed/xed-1.24.tar.gz>

The package is about 170k in size and contains only source code. Please contact me for assistance if it is difficult for you to compile on your system.

Introduction

Xed is a programmer's text editor for use on UNIX computers with the X Window System, Macintosh computers, and 80386-based MS-DOS computers. It is designed to be small, fast, simple to use, and easy to customize. It is not intended to replace word processors or desktop publishing systems; rather it provides a rudimentary tool for programmers and system administrators that avoids the cumbersome and primitive character of alternatives such as emacs and vi. Xed has the advantage that it can deal effectively with Macintosh, MS-DOS, and UNIX text files, and can properly display tabbed text. Xed is distributed freely, with all source and executable code.

Getting in:

UNIX and MS-DOS users specify the input files on the command line. For example, xed temp.dat causes the editor to load the file temp.dat. If you specify no file on the command line, the editor will prompt you for a file name when you save the file. If you specify more than one file, all of the files will be loaded at the same time, and you can switch from one file to another, copying and moving blocks of lines among files as well as within files.

The Macintosh version prompts the user for a file to edit when the application is launched.

The MS-DOS version is built with the Watcom C/386 compiler and requires that the Rational Systems, Inc. DOS-Extender (DOS4GW.EXE) be located somewhere along the user's execution path, which is specified by the PATH environment variable. An 80386 CPU and extended memory are required for the MS-DOS version to work.

Getting out:

To exit, saving your file, press F1 or Alt-X. To quit without saving, press F2 or Alt-Q. Macintosh users may use the standard File - Quit menu option or its command-key equivalent, or may simply close the main window by using the mouse.

X Windows resources

X-windows resources may be specified in an app-defaults file (typically stored in /usr/lib/X11/app-defaults, a .Xdefaults file, or on the command line. Most standard resource specifications are interpreted by xed. In addition, Xed recognizes the resources backup, keymap, status_fg, and status_bg.

The backup resource, if specified, causes Xed to make a copy of the current on-disk version of the file, naming the copy filename.bak.

The keymap resource should specify a pathname for a file containing the key definitions, if other than the default key bindings are to be used. Additional instructions for changing the key bindings are given below.

The status_fg and status_bg resources, if specified, govern the foreground and background colors, respectively, of the status line and menus. These default to the background and foreground colors, respectively, of the main window, so that by default, the status line and menu colors will be the reverse of the main window's foreground and background colors.

Macintosh specifics

Some default key assignments in the Macintosh version differ from those in the MS-DOS and UNIX versions. The biggest difference is that the Macintosh version uses the command key (a.k.a. the "apple" key) wherever MS-DOS and UNIX versions use the "alt" key.

Macintosh users can alter the default size and shape of the main window by editing the WIND resource of Xed using ResEdit.

Getting around:

The top line of the screen or window is used as a status line, and indicates the line in the file that the cursor is on, the column that the cursor is on, the insert state, the autoindent state, the tab width, and the file name. If the file name is preceded by a plus sign, changes have been made to the file. An example is shown below:
L  10  C   12  IA4  +foo.dat
This status line indicates that the cursor is on column 12 of line 10 of the file foo.dat, that the file has been modified i.e. that the copy in memory has changes that have not yet been saved to disk. Insert is active, as is autoindent. Tabs expand to 4 spaces. If you do not have write permission for the file, the plus sign will not appear; instead, the designation (Read Only) will precede the file name. If the file has been loaded as binary data, the designation (binary) will appear as well.

The X-windows and Macintosh versions pay attention to the pointer, i.e. the mouse. If you click the mouse anywhere in the window, the cursor moves to the character position nearest the point where the mouse button was pressed. The DOS version does not watch the mouse, since the DOS version of Xed operates in text mode, and mouse operations in DOS text modes are inherently clumsy.

Users should note that Xed considers tab width to be a variable. The default tab width is 4 spaces. Many documents created in the UNIX world assume that tabs are eight spaces, so you can alter the tab width by pressing Ctrl-Tab. Note also that tab characters are initially visible in Xed, and you cannot place the cursor onto any of the spaces that result from tab expansion. By pressing Ctrl-v, you can toggle the tab visibility through three states, an invisible state, a minimally visible state (the default), and a maximally visible state in which one can distinguish the tab fill characters (which fill the space between a tab and the following text) from true spaces.

Menu operation

Xed actions may be chosen by pressing appropriate function keys or by selecting items from menus. In the MS-DOS and X Windows version, menus are ordinarily hidden and are activated by a keystroke (Escape). In the X Windows version, clicking on the status line also brings up the menus. On the Macintosh, the menus appear on the main menu bar. Once activated, the menus can be browsed by using the arrow keys and the Home, and End keys. To select a menu item, highlight it using the arrow keys and press Enter or Return. In the X Windows version and on the Macintosh, menu items can be selected using the mouse.

The X Windows version has a rudimentary help facility associated with its menus. To find out what keystrokes can be used to produce the effect of a particular menu selection, highlight a menu item and press the question mark. Xed will print on the xterm from which it was launched brief descriptions of all keystrokes that produce this action. Note that these descriptions will refer to an "Alt" modifier key that may not be present on your system. This really refers to the Mod1 modifier key.

Getting from one file to another:

Xed is capable of editing any number of files at a time. It keeps a circular linked list of files you are editing. To switch from one file to another, use Alt-> (that's the Alt key followed by the "greater than" sign) to move to the next file, or Alt-< for the previous file in the list. To edit another file in addition to those you specified on the command line, press Alt-E (Command-O on the Mac). You are prompted for the file name, and the file is subsequently loaded and added to the linked list of files.

In the X Windows and MS-DOS versions, you can enter a directory specification at the "Edit file:" prompt. If Xed determines that the name you entered is a directory, it presents you with a list of files in that directory. Use the arrow keys to select a file from the list; if you choose another directory (identified with a trailing slash character), the corresponding list will appear.

Editing binary files:

Xed has the ability to read and write binary files. Editing binary files is somewhat problematic, of course, and the strategy Xed uses may not be satisfactory for some purposes. At present, the only way to specify that a file be interpreted as binary is to open the file from within the editor (not on the command line), following its name with a space and the letters -b. Since space can be a legitimate character in a Macintosh file name, this facility presently does not work on the Macintosh version.

When asked to read a file as binary data, Xed creates a hexadecimal display similar to that produced by the DOS utility DEBUG; each line has sixteen bytes displayed as hexadecimal numbers, followed by a tab, a pound sign (#), and the ASCII equivalents of those sixteen bytes. Non-printable characters are displayed in the ASCII section as periods.

You can edit this hexadecimal display as you like; no special binary editing mode exists. When asked to save the file, however, Xed will look through each line, converting pairs of hexadecimal digits back to binary bytes and writing them to the output file. When it encounters a character that is neither a hexadecimal digit nor a whitespace (blank or tab), it skips to the beginning of the next line and continues the conversion.

Key assignments:

One of the main goals for Xed was to make keys do what they look like they should do. For example, the Page Down key should page down, the Delete key should delete, and the Home key should move the cursor towards the beginning of the line or file.

Since there aren't keys specifically made for many important functions, many keys have arbitrary assignments. These are intended to mimic other packages (e.g. Qedit and WordStar on MS-DOS systems) but do so in only a limited fashion.

To change what a particular key does, you'll need to modify a simple table in the source code and recompile the program.

A more dynamic configuration occurs under X Windows; if the X display name does not begin with a colon (i.e. if Xed is running on another machine), Xed looks for a file in the user's home directory named xed.hostname where hostname is the name of the host on which the window is to be displayed. This file, if it exists, is assumed to be the binary output of the configuration program xed_config (see below). Its contents replace the default keymap table.

For those keys that are significant when modified using Shift, Ctrl or Alt, the modified action is either the same or is complementary to the action of the unmodified key. For example, the left arrow key moves the cursor left one space, while Ctrl-Left moves the cursor left one word. Similarly, the Home key moves the cursor to the beginning of the line, and Ctrl-Home moves it to the beginning of the file.

Printing

Under MS-DOS and X Windows, Xed has the ability to create a PostScript representation of the current file and transmit the PostScript file to a printer. On UNIX, the name of the PostScript file is derived from tmpnam; this is not practical on MS-DOS, so under MS-DOS the name is always temp.ps. The UNIX version issues the command lp -c filename.ps through a call to the system function; on MS-DOS the PostScript file must be sent to the printer manually, for example, by PRINT TEMP.PS or COPY TEMP.PS LPT1.

Items under the Print menu control the layout of the printed page.

Moving, copying, and deleting blocks of text:

Block operations are restricted to whole lines. You cannot move or copy a marked block when the cursor is inside the block. This limitation is significantly different than most professional text editors. It should really be improved, but I have learned to live with it.

If the block starts and ends on the same line, and the end follows the start, the intervening text is copied to the paste buffer, and can be inserted elsewhere by pressing Ctrl-p.

Balancing parenthetical expressions:

KEY_FIND_MATCH operates only if the character at the cursor position is a parenthesis, bracket, brace, the greater-than or less-than sign. It causes the editor to search for the opposite symbol. For example, with the cursor on the left parenthesis, pressing Ctrl-F3 causes the cursor to move to the matching right parenthesis. Consider the following example.
if (((c = getc(stdin)) != EOF) && ord[c] != 'a') {
   abc        d     dc       b                 a
Here matching letters appear on the line below matching parentheses. KEY_FIND_MATCH operates either forward or backward, depending on whether the character at the cursor position is a left-symbol (one of (, [, {, or <) or the corresponding right-symbol ( respectively, ), ], }, or >).

Search and replace:

The search and replace facilities are simplistic. You specify a search target by using Ctrl-f (for a forward search) or Alt-f (reverse). To find the next occurrence, type Ctrl-L. To replace, use Alt-p to set the text in the paste buffer, then use Ctrl-r to replace only once, or Alt-r to replace every occurrence from the cursor position to the end of the file.

Note that the text pasting operation respects the insert state. If Insert is off (no 'I' appears in the status line), the paste operation overwrites characters already in the line. This effect occurs both when KEY_PASTE is invoked directly (with Ctrl-p) and during replace operations.

Autoindent:

Autoindent is likely to be unfamiliar to nonprogrammers. This function causes an initial string of whitespaces to be inserted whenever a KEY_NEW_LINE is executed; the initial string of whitespaces is taken from the preceding line. Whitespace includes blanks and tabs.

Line breaking:

Xed provides a facility for breaking a long line into a paragraph. Alt-B enables you to set the right margin, which is 76 characters by default. By pressing Ctrl-B, you can break the current line into separate lines, each ending to the left of the right margin. Words will not be split during this operation.

Character conversion:

The current character (i.e. the character that the cursor is on) can be converted as follows:
to upper case		Alt-1		(Command-1 on Macintosh)
to lower case		Alt-2		(Command-2 on Macintosh)
switch case		Alt-3		(Command-3 on Macintosh)
to hexadecimal		Ctrl-F2
from hexadecimal	Ctrl-F4

Retrieving deleted lines

Xed puts lines deleted through KEY_DEL_LINE (Ctrl-y) into a stack, and the most recently deleted line can be inserted through KEY_UNDEL_LINE (Ctrl-u). The stack is of unlimited size, because it is implemented as a linked list. In edit.c there are commented lines that would cause deleted blocks to be appended to the stack of deleted lines; because this policy could cause memory to become crowded it was not enabled, though users can change that decision by modifying edit.c and recompiling.

Xed actions

The following list gives short descriptions of the actions that Xed is capable of performing. To find the details of how an action is performed, find its entry in the switch table of function process_key() of source file xed.c. The action names themselves are used (in the UNIX environment) to build an alternate keymap description file; the procedure is described under "Using xed_config" below.
KEY_SET_TAB_WIDTH
Allows user to specify new tab width
KEY_FIND_MATCH
Moves cursor to matching symbol
KEY_WRITE_BLOCK
Write marked block to a new file
KEY_DEL_BLOCK
Delete the marked block
KEY_SEARCH_BACKWARD
Specify a string and find its previous occurrence
KEY_SEARCH_FORWARD
Specify a string and find its next occurrence
KEY_FIND_NEXT
Continue the last search
KEY_FIND_NEXT_NONPRINTABLE
Move to the next non-printing character
KEY_SET_PASTE_TEXT
Enter text into the paste buffer
KEY_PASTE
Insert the contents of the paste buffer at the cursor position
KEY_REPLACE_ALL
Replace all subsequent occurrences of the search string with the paste text
KEY_REPLACE_ONCE
Replace the next occurrence of the search string with the text in the paste buffer
KEY_DEL_SPACE_TO_RIGHT
Delete whitespace (blanks and tabs) to the right of the cursor
KEY_TOGGLE_TAB_VISIBILITY
Change the appearance of tab characters and tab fill characters
KEY_DEL_LINE
Delete the current line
KEY_UNDEL LINE
Undelete a line (insert the most recently deleted line at the cursor position)
KEY_WORD_LEFT
Move to the beginning of the previous word
KEY_WORD_RIGHT
Move to the beginning of the next word
KEY_MOVE_TO_TOP_OF_SCREEN
Move to the top line displayed (not the status line)
KEY_MOVE_TO_BOTTOM_OF_SCREEN
Move to the bottom line displayed
KEY_MOVE_TO_BEG_OF_FILE
Move to the first line in the file
KEY_MOVE_TO_END_OF_FILE
Move to the last line in the file
KEY_SCROLL_UP
Scroll the file up, keeping the cursor on the same line
KEY_SCROLL_DOWN
Scroll the file down, keeping the cursor on the same line
KEY_TOGGLE_AUTOINDENT
If autoindent is active, turn it off, and vice versa.
KEY_DEL_TO_BEG_OF_LINE
Delete all characters to the left of the cursor on the current line
KEY_DEL_TO_END_OF_LINE
Delete all characters to the right on the current line, including the cursor position
KEY_IGNORE
Ignore this keystroke
KEY_SAVE_AND_EXIT
Write the current file to disk and remove it from memory
KEY_QUIT
Remove the current file from memory; prompt if it has changed
KEY_QUIT_ALL
Forgetting all changes, return to the system.
KEY_SAVE_FILE
Write the current file to disk
KEY_GO_TO_LINE
Move to a specified line (specify by number)
KEY_COPY_BLOCK
Insert a copy of the marked block before the current line
KEY_MOVE_BLOCK
Insert the marked block before the current line
KEY_MARK_BLOCK_START
Set the beginning of the marked block
KEY_MARK_BLOCK_END
Set the end of the marked block
KEY_HIDE_BLOCK
Unmark the current marked block
KEY_DUP_LINE
Duplicate the current line
KEY_DUP_CHAR
Duplicate the character at the cursor position
KEY_MOVE_LEFT
Move one character to the left
KEY_MOVE_RIGHT
Move one character to the right
KEY_MOVE_UP
Move to the preceding line
KEY_MOVE_DOWN
Move to the following line
KEY_MOVE_TO_BEG_OF_LINE
Move to the first character of the current line
KEY_MOVE_TO_END_OF_LINE
Move to the space following the last character in the current line
KEY_PAGE_UP
Move up about one screenfull of lines
KEY_PAGE_DOWN
Move down about one screenfull of lines
KEY_TOGGLE_INSERT
Switch from inserting to overwriting or the reverse
KEY_NEW_LINE
Create a new line, moving to it
KEY_DEL_LEFT
Delete the character to the left of the cursor
KEY_DEL_RIGHT
Delete the character at the cursor position
KEY_READ_FILE
Insert the contents of a specified file before the current line
KEY_UPPER_CASE
Change the character at the cursor position to its upper-case equivalent
KEY_LOWER_CASE
Change the character at the cursor position to its lower-case equivalent
KEY_TOGGLE_CASE
If the character at the cursor is lower case, make it upper, and vice versa
KEY_TO_HEX
Replace the character at the cursor with its two-character hexadecimal code
KEY_FROM_HEX
Replace two hex characters starting at the cursor with the byte value
KEY_TO_BINARY
Replace the character at the cursor with eight binary digits
KEY_HEX_TO_BINARY
Replace one hex character at the cursor with four binary digits
KEY_BREAK_LINE
Make the current line as short as the previous one, continuing on the next line
KEY_CHANGE_NAME
Change the name of the current file
KEY_REFORMAT_PARAGRAPH
Wrap the current line according to the right margin
KEY_SET_RIGHT_MARGIN
Set the value of the right margin; by default it is 76 characters
KEY_SUBSTITUTE
Insert the string from the keymap table into the text
KEY_ANOTHER_FILE
Begin editing another file
KEY_PREV_FILE
Go to the previous file in the linked list
KEY_NEXT_FILE
Go to the next file in the linked list
KEY_TOGGLE_BINARY
On output, interpret the current text as hexadecimal code
KEY_SHOW_MENUS
Activate the menus
KEY_PRINT_SIZE
Set the size of printed type
KEY_PRINT_TOP
Set the top margin for printing
KEY_PRINT_BOTTOM
Set the bottom margin for printing
KEY_PRINT_LEFT
Set the left margin for printing
KEY_PRINT_RIGHT
Set the right margin for printing
KEY_PRINT_NUMBER
Indicate whether printed lines should be numbered
KEY_PRINT_ORIENTATION
Indicate how the letters should be oriented on the printed page
KEY_PRINT_FOOTER
Indicate whether the file name and date should be printed
KEY_PRINT_COMMAND
Set the system command used to print the PostScript file
KEY_PS_PRINT
Create a PostScript version of the current file
KEY_PS_PRINT_BLOCK
Create a PostScript version of the current block

Default key actions sorted by key group

Here and in the tables that follow, the editor action names are given without the prefix KEY_ in order to simplify the tables.

Fn keys

	Fn or Shift-Fn		Ctrl-Fn		Alt-Fn
F1	SAVE_AND_EXIT		CHANGE_NAME	reserved
F2	QUIT			TO_HEX		reserved
F3	SAVE_FILE		FIND_MATCH	reserved
F4	GO_TO_LINE		FROM_HEX	reserved
F5	COPY_BLOCK		WRITE_FILE	reserved
F6	MOVE_BLOCK		DEL_BLOCK	reserved
F7	MARK_BLOCK_START	READ_FILE	reserved
F8	MARK_BLOCK_END		PS_PRINT	reserved
F9	DUP_LINE		BREAK_LINE	reserved
F10	DUP_CHAR		TOGGLE_BINARY	reserved

Numeric Keypad

		key			Ctrl-key
KP_7		MOVE_TO_BEG_OF_LINE	MOVE_TO_BEG_OF_FILE
KP_8		MOVE_UP			MOVE_TO_TOP_OF_SCREEN
KP_9		PAGE_UP			SCROLL_UP
KP_4		MOVE_LEFT   		WORD_LEFT
KP_5		IGNORE			IGNORE
KP_6		MOVE_RIGHT		WORD_RIGHT
KP_1		MOVE_TO_END_OF_LINE	MOVE_TO_END_OF_FILE
KP_2		MOVE_DOWN		MOVE_TO_BOTTOM_OF_SCREEN
KP_3		PAGE_DOWN		SCROLL_DOWN
KP_0		TOGGLE_INSERT		TOGGLE_AUTOINDENT
KP_Decimal	DEL_RIGHT		DEL_TO_EOL
KP_Enter	NEW_LINE		not assigned

"Gray" keys (so called because these keys are darker on IBM keyboards)

		key or Shift-key	Ctrl-key
Insert		TOGGLE_INSERT		TOGGLE_AUTOINDENT
Delete		DEL_RIGHT		DEL_TO_END_OF_LINE
Home		MOVE_TO_BEG_OF_LINE	MOVE_TO_BEG_OF_FILE
End		MOVE_TO_END_OF_LINE	MOVE_TO_END_OF_FILE
Page Up		PAGE_UP			SCROLL_UP
Page Down	PAGE_DOWN		SCROLL_DOWM
Left		MOVE_LEFT		WORD_LEFT
Right		MOVE_RIGHT		WORD_RIGHT
Up		MOVE_UP			MOVE_TO_TOP_OF_SCREEN
Down		MOVE_DOWN		MOVE_TO_BOTTOM_OF_SCREEN
Backspace	DEL_LEFT		DEL_TO_BEG_OF_LINE
Tab		(tab)			SET_TAB_WIDTH

Alt-letters (on Macintosh, use Command key instead)

Alt-b		SET_RIGHT_MARGIN
Alt-e		ANOTHER_FILE	on Macintosh use Command-O instead
Alt-f		SEARCH_BACKWARDS
Alt-p		SET_PASTE_TEXT
Alt-q		QUIT		on Macintosh use Command-Q instead
Alt-r		REPLACE_ALL
Alt-x		SAVE_AND_EXIT	on Macintosh use Command-W instead
Alt-1		UPPER_CASE
Alt-2		LOWER_CASE
Alt-3		TOGGLE_CASE
Alt->		NEXT_FILE
Alt-<		PREV_FILE

Control-letters

Ctrl-w	SCROLL_DOWN
Ctrl-e	MOVE_UP
Ctrl-r	REPLACE_ONCE
Ctrl-t	DEL_SPACE_TO_RIGHT
Ctrl-y	DEL_LINE
Ctrl-u	UNDEL LINE
Ctrl-i	(tab)
Ctrl-p	PASTE

Ctrl-s	MOVE_LEFT
Ctrl-d	MOVE_RIGHT
Ctrl-f	SEARCH_FORWARD
Ctrl-g	DEL_RIGHT
Ctrl-l	FIND_NEXT

Ctrl-z	SCROLL_DOWM
Ctrl-x	MOVE_DOWN
Ctrl-v	TOGGLE_TAB_VISIBILITY
Ctrl-b	REFORMAT_PARAGRAPH

Default key actions sorted by function:

File and session management

CHANGE_NAME		CTRL-F1
ANOTHER_FILE		Alt-E
PS_PRINT		CTRL-F8, Print
PREV_FILE		Alt-<
NEXT_FILE		Alt->
READ_FILE		CTRL-F7
SAVE_FILE		F3, SHFT-F3
SAVE_AND_EXIT		ALT-x, F1, SHFT-F1
QUIT			ALT-q, F2, SHFT-F2

Block operations

MARK_BLOCK_START	F7, SHFT-F7
MARK_BLOCK_END		F8, SHFT-F8
COPY_BLOCK		F5, SHFT-F5
MOVE_BLOCK		F6, SHFT-F6
DEL_BLOCK		CTRL-F6
WRITE_BLOCK		CTRL-F5

Cursor movement

MOVE_UP			 CTRL-SHFT-E, CTRL-e, KP_8, SHFT-Up, Up
MOVE_DOWN		 CTRL-SHFT-X, CTRL-x, Down, KP_2, SHFT-Down
MOVE_LEFT		 CTRL-SHFT-S, CTRL-s, KP_4, Left, SHFT-Left
MOVE_RIGHT		 CTRL-SHFT-D, CTRL-d, KP_6, Right, SHFT-Right
MOVE_TO_BEG_OF_LINE	 Home, KP_7, SHFT-Home
MOVE_TO_END_OF_LINE	 End, KP_1, SHFT-End
MOVE_TO_TOP_OF_SCREEN	 CTRL-KP_8, CTRL-Up
MOVE_TO_BOTTOM_OF_SCREEN CTRL-Down, CTRL-KP_2
MOVE_TO_BEG_OF_FILE	 CTRL-Home, CTRL-KP_7
MOVE_TO_END_OF_FILE	 CTRL-End, CTRL-KP_1
PAGE_UP			 KP_9, Prior, SHFT-Prior
PAGE_DOWN		 KP_3, Next, SHFT-Next
WORD_LEFT		 CTRL-KP_4, CTRL-Left
WORD_RIGHT		 CTRL-KP_6, CTRL-Right
SCROLL_UP		 CTRL-KP_9, CTRL-Prior, CTRL-SHFT-W, CTRL-w
SCROLL_DOWN		 CTRL-KP_3, CTRL-Next, CTRL-SHFT-Z, CTRL-z
GO_TO_LINE		 F4, SHFT-F4

Search and replace

SEARCH_FORWARD		CTRL-f
SEARCH_BACKWARD		ALT-f
FIND_NEXT		CTRL-SHFT-L, CTRL-l
REPLACE_ONCE		CTRL-r
REPLACE_ALL		ALT-r
SET_PASTE_TEXT		ALT-p
PASTE			CTRL-p
FIND_MATCH		CTRL-F3

Insert and delete

NEW_LINE		KP_Enter, Return, SHFT-KP_Enter, SHFT-Return
DUP_CHAR		F10, SHFT-F10
DUP_LINE		F9, SHFT-F9
DEL_LEFT		BackSpace, SHFT-BackSpace
DEL_RIGHT		CTRL-SHFT-G, CTRL-g, Delete, KP_Decimal,
			SHFT-Delete
DEL_LINE		CTRL-SHFT-Y, CTRL-y
UNDEL_LINE		CTRL-SHFT-U, CTRL-u
DEL_SPACE_TO_RIGHT	CTRL-SHFT-T, CTRL-t
DEL_TO_BEG_OF_LINE	CTRL-BackSpace
DEL_TO_END_OF_LINE	CTRL-Delete, CTRL-KP_Decimal
LOWER_CASE		ALT-2
UPPER_CASE		ALT-1
TOGGLE_CASE		ALT-3
BREAK_LINE		CTRL-F9
REFORMAT_PARAGRAPH	CTRL-b, CTRL-SHFT-B

Miscellaneous

SET_TAB_WIDTH		CTRL-Tab
TOGGLE_TAB_VISIBILITY	CTRL-SHFT-V, CTRL-v
TOGGLE_INSERT		Insert, KP_0, SHFT-Insert
TOGGLE_AUTOINDENT	CTRL-Insert, CTRL-KP_0
SET_RIGHT_MARGIN	ALT-b
IGNORE			CTRL-KP_5, KP_5

Menu actions

The menu items are simple structures consisting of a descriptive string and an editor action code. When an item is selected, the action code is executed through a call to process_key. These tables show the menu items and their corresponding actions.

File

Open			KEY_ANOTHER_FILE
Merge			KEY_READ_FILE
Save			KEY_SAVE_FILE
Save As			KEY_CHANGE_NAME
Close			KEY_SAVE_AND_EXIT
Prev file		KEY_PREV_FILE
Next file		KEY_NEXT_FILE
Print			KEY_PS_PRINT
Add keys		KEY_ADD_KEYS
Quit			KEY_QUIT

View

Toggle insert		KEY_TOGGLE_INSERT
Toggle autoindent	KEY_TOGGLE_AUTOINDENT
Toggle tab visibility	KEY_TOGGLE_TAB_VISIBILITY
Set tab width		KEY_SET_TAB_WIDTH
Set right margin	KEY_SET_RIGHT_MARGIN
Scroll up		KEY_SCROLL_UP
Scroll down		KEY_SCROLL_DOWN

Move

Word left		 KEY_WORD_LEFT
Word right		 KEY_WORD_RIGHT
Move to top of screen	 KEY_MOVE_TO_TOP_OF_SCREEN
Move to bottom of screen KEY_MOVE_TO_BOTTOM_OF_SCREEN
Move to beg of line	 KEY_MOVE_TO_BEG_OF_LINE
Move to end of line	 KEY_MOVE_TO_END_OF_LINE
Move to beg of file	 KEY_MOVE_TO_BEG_OF_FILE
Move to end of file	 KEY_MOVE_TO_END_OF_FILE
Page up			 KEY_PAGE_UP
Page down		 KEY_PAGE_DOWN
Find match		 KEY_FIND_MATCH
Go to line		 KEY_GO_TO_LINE

Find

Search forward		KEY_SEARCH_FORWARD
Search backward		KEY_SEARCH_BACKWARD
Find next		KEY_FIND_NEXT
Find nonprintable	KEY_FIND_NEXT_NONPRINTABLE
Set paste text		KEY_SET_PASTE_TEXT
Paste			KEY_PASTE
Replace once		KEY_REPLACE_ONCE
Replace all		KEY_REPLACE_ALL

Block

Mark start		KEY_MARK_BLOCK_START
Mark end		KEY_MARK_BLOCK_END
Copy			KEY_COPY_BLOCK
Move			KEY_MOVE_BLOCK
Save As			KEY_WRITE_BLOCK
Delete			KEY_DEL_BLOCK
Print			KEY_PS_PRINT_BLOCK
Hide			KEY_HIDE_BLOCK

Change

Del space to right	KEY_DEL_SPACE_TO_RIGHT
Del line		KEY_DEL_LINE
UnDelete line		KEY_UNDEL_LINE
Del to beg of line	KEY_DEL_TO_BEG_OF_LINE
Del to end of line	KEY_DEL_TO_END_OF_LINE
Dup char		KEY_DUP_CHAR
Dup line		KEY_DUP_LINE
New line		KEY_NEW_LINE
Break line		KEY_BREAK_LINE
Reformat paragraph	KEY_REFORMAT_PARAGRAPH
Toggle Binary File	KEY_TOGGLE_BINARY

Convert

Upper case		KEY_UPPER_CASE
Lower case		KEY_LOWER_CASE
Toggle case		KEY_TOGGLE_CASE
To hex			KEY_TO_HEX
From hex		KEY_FROM_HEX
To binary		KEY_TO_BINARY
Hex to binary		KEY_HEX_TO_BINARY

Print

Type size		KEY_PRINT_SIZE
Top margin		KEY_PRINT_TOP
Bottom margin		KEY_PRINT_BOTTOM
Left margin		KEY_PRINT_LEFT
Line numbers		KEY_PRINT_NUMBER
Page orientation	KEY_PRINT_ORIENTATION
Page footers		KEY_PRINT_FOOTER
Set print command	KEY_PRINT_COMMAND
PS Print		KEY_PS_PRINT

Programmer's Guide

Design:

Xed is intended to be simple, fast, and easily customized. Note that "full-featured" is not one of the stated goals. The design goals have been approached using three specific strategies:
  1. The operation of the editor is minimally modal, which means that most of the time you can execute most of the commands. This is in sharp contrast to vi, in which the things you can do at any time are dictated by the mode you are in, and you have to press a specific key to exit your current mode before you can do anything else.
  2. The relationship between keystrokes and editing operations is determined by a table which presently resides in the source code. To make the keys do different things, just change the table and recompile. In principle, this table could be read from disk at run time, but most users will want to set it up once and keep it that way.
  3. The main source exists in two code files. One source file contains the editor code, the other contains the user interface. Certain performance penalties accompany this strict division, because I have forced the editor code to be (nearly) oblivious of the user interface. But it should not be difficult to rewrite the user interface for a different platform, e.g. SunView, DECWindows, MS- Windows, or OS/2.
    The MS-DOS version also has some code files to handle those user interface tasks that are handled by the system in UNIX and on the Macintosh. The X version has an icon bitmap file because this is difficult to change intelligently with a text editor. The Macintosh version has file I/O operations in a separate module, and has some utility routines in separate files. In addition, the Macintosh version requires appropriate resources, which are contained in a ResEdit 'rsrc' file.

Compilation:

The source was written in Standard C where possible. File I/O is done only through standard library calls on MS-DOS and UNIX systems. The Macintosh only dimly approximates the standard I/O of the C library, so some routines roughly compatible with Standard C were devised for this project. These are contained in the file Mac_fileIO.c

No attempt was made to enable this code to be ported to 16-bit platforms. There are superb programmer's editors available for 16-bit DOS, and if they suit your needs you should use one of them. Qedit by SemWare is highly recommended. The only editor I have seen that runs in protected mode on MS-DOS systems is MicroEmacs and is distributed with the NDP compilers by MicroWay. Emacs fanatics might like it; I don't.

Xed was developed initially under UNIX on a Data General AViiON workstation running a MC88100 CPU. The GNU C compiler was used to build it, and it is compatible with X11R3, X11R4, and X11R5. It has been successfully built on an HP/UX system version 7.05 by installing the GNU C compiler version 2.1 and defining the symbol _SYS_FILE_INCLUDED to enable the definition of struct file in edit.h. It has also been built on a Sun SPARCstation IPX running OpenWindows, using the ANSI compiler acc.

How to change the key assignments:

To configure the keyboard differently than I have, just edit the keymap table in xed.c to reflect your desires. The anatomy of an entry is shown below. Each entry is a structure consisting of two 32-bit integers, whose values are specified using the names of predefined constants, and a character string. The first value indicates the key struck and the associated modifier keys, Control, Shift, and Alt. The second value is the editor action you want taken when this key is pressed. To determine exactly what each editor action does, look in process_key() in xed.c. The third value is a string that is inserted in the text if the key action is KEY_SUBSTITUTE.

The keystroke is described by the logical OR of the modifier keys (CTRL, SHFT, ALT) with the KeySym, the name X11 uses for the key. Neither the Mac nor MS-DOS has as convenient a way of describing keys as X11, so I have provided equivalent keysyms for both Mac and MS-DOS keys in a header file. The Mac keysyms are named MK_key, while the MS-DOS keysyms are named DK_key. A section of the X-windows keymap table is reproduced below.

{CTRL |    0 |   0 | XK_BackSpace,	KEY_DEL_TO_BEG_OF_LINE,	NULL},
{CTRL |    0 |   0 | XK_KP_Decimal,	KEY_DEL_TO_END_OF_LINE,	NULL},
{CTRL |    0 |   0 | XK_Delete,		KEY_DEL_TO_END_OF_LINE,	NULL},
{CTRL |    0 |   0 | XK_Escape,		KEY_SHOW_VARIABLES,	NULL},
{   0 |    0 | ALT | XK_1,		KEY_UPPER_CASE,		NULL},
{   0 |    0 | ALT | XK_2,		KEY_LOWER_CASE,		NULL},
{   0 |    0 | ALT | XK_3,		KEY_TOGGLE_CASE,	NULL},
{   0 |    0 | ALT | XK_b,		KEY_SET_RIGHT_MARGIN,	NULL},
{   0 |    0 | ALT | XK_n,		KEY_ANOTHER_FILE,	NULL},
The symbols CTRL, SHFT, and ALT indicate the activity of these modifier keys. A zero in one of those columns means that the corresponding modifier is not activated. Caps Lock is treated like Shift. The symbols beginning with XK_ are KeySyms, which are defined in the header file /usr/include/X11/keysymdef.h on UNIX, in DOSKEYS.H on MS-DOS, and in Mac_keysym.h on the Macintosh.

Macintosh and DOS keymaps look the same, except the keysyms begin with M or D, respectively, and the Mac has no ALT modifier column; instead the modifier CMD is used. The reason why Command is used instead of Alt is that the Alt key on the Mac is the Option key, and some Alt-keystrokes are not reported directly but instead modify the following key; these are intended to allow Mac users to put accents on letters.

Note that in X11, an upper case KeySym, like XK_D, must always be used with SHFT. Note also that the window manager may usurp some keys for its own use, not permitting the application to see these keys. On the DG AViiON, for example, Motif is usually configured to use Alt-F1 through Alt-F10, Alt-Tab, Alt-space, and Alt-Esc, so it will do no good to define key bindings for them. The window manager's key usage is controlled by its rc file (e.g. .mwmrc).

Using xed_config

UNIX users may store server- or user-specific keymap tables in binary files in their home directories. The binary files are created by the program xed_config, which reads a text file describing key assignments and writes the key assignments as a keymap table that Xed can read and use.

Use xed_config as follows:

xed_config keymap-text-file xed.hostname

The keymap text file is read and converted to binary format; the results are stored in file xed.hostname, which should be put in the user's home directory on the machine that runs the Xed client. For example, I sometimes run Xed on an HP 9000, but I control and display it from a (remote) DG AViiON 300, which has a very different keyboard. The HP's hostname is rprobe, and the DG's hostname is limulus. Therefore, I place in my home directory on rprobe a file called xed.limulus, which is used to define the keys when Xed is displayed on limulus.

The format of the file read by xed_config is governed by the following rules:

  1. The action of one key is described completely by one line of the file.
  2. A description consists of modifiers, an X KeySym, and an xed action code.
  3. Modifiers are optional and consist of one or more of SHFT, CTRL, or ALT, where ALT indicates a key that generates the X Windows code Mod1.
  4. Legal xed action codes are given in the file xed_acts.h, and
  5. Legal X KeySyms are given in /usr/include/X11/keysymdef.h.
To determine the X KeySym and modifiers generated by a particular combination of keys on your keyboard, run the program xkeys, which accompanies Xed.

The output file generated by xed_config consists of a number of 12-byte binary entries, each consisting of (a) a four-byte modified X KeySym, (b) an xed action code, and (c) a four-byte NULL.

How to change the menus

In the DOS and X Windows versions, you can add an item to an existing menu by finding that menu's xed_menu structure, and adding an element to the choice array; each element of this array is a structure containing the menu item text and an xed_action. The last element in each choice array must have a NULL pointer as the text. The choice arrays are limited in size to MAX_MENU_ITEMS each; change this constant to enlarge or shrink the array.

Macintosh users can alter the appearance of the menus through ResEdit, but altering their actions will require changes to the menu-handling code.

Needed enhancements:

A number of features do not work as well as they should. There should be a help facility of some sort. There should be a macro facility of some sort. Blocks should not be restricted to whole lines. The file selection procedure activated when a user tries to edit a directory using KEY_ANOTHER_FILE should be activated when a directory is specified on the command line.

The Mac user interface has some rough spots that could be made quicker and smoother. For example, the routine refresh_window is called in more situations than is necessary, causing the display to flicker annoyingly occasionally. The Macintosh version does not properly process the "Open Documents" apple event. File I/O on the Mac is too slow, and the officially recommended method of saving files (by making a copy, deleting the original, and renaming the copy) is not followed.

How to get Xed

Xed can be obtained via anonymous ftp to geochange.er.usgs.gov in the directory pub/tools/xed. Bugs and suggestions should be reported to the technical contact (below). Remember that unimplemented features are not bugs.

Technical contact:

	Peter N. Schweitzer
	MS 918 National Center
	U.S. Geological Survey
	Reston, VA 20192

Tel:	(703) 648-6533
FAX:	(703) 648-6560
email:	pschweitzer@usgs.gov