Screen Editor Application Notes

Introduction

This document details some of the useful command sequences, options, configurations and techniques for getting the most out of the Screen Editor, se.

It is assumed that the reader has a copy of se installed on his machine and is reasonably familiar with using it. Other useful programs from Software Tools are mentioned, such as the text formatter fmt, the paginator pg and the list files lf program. Also mentioned are other Public Domain programs such as arc. A reasonable familiarity with Unix is also assumed.

Topics covered include: setting up se according to the user's needs; solutions to common problems; using se with other software; and useful se command language idioms.

Using the Screen Editor with other software

An editor that cannot interface with other software is no use to anyone. Se talks to other programs via the most standard interface of all: the plain ASCII file. Unlike word processors, se's documents are not stored in any special format, but are simply normal ASCII text files. In fact, se has no “word processor” mode at all — there are plenty of word processors available!

Se is used to generate files that can be fed into other applications: text formatters, programming language compilers, electronic mail systems and so on. So, how does one connect se into other software? Most programs will have facilities to “import” or “export” files. Sometimes a menu of possible file formats is provided, sometimes the file name tells the program how to interpret the data. In either case, the option we want is ASCII text. Avoid options such as WordStar format, Lotus worksheet or dBase data — they won't work.

Calling the Shell

One of the very useful features of se is its ability to invoke a shell. This means that it is possible to type a Unix shell command on the se command line and make it execute. The advantage is that there is no need to exit from se merely to find out, say, the name of a file.

By way of example, here is the command to display a list of the files in the current directory:

!ls
The list of files appears in the usual way, then se displays the message ‘type return to continue:’. When you have finished reading the display, press return; se will re-draw the editing screen exactly as it was before.

There are some problems with shell escapes, as these commands are called. The obvious one is that you can forget where you are and log out of the machine while se is still running unseen. This will lose your editing buffer, so it is usually wise to write the buffer into a file before using the shell escape.

In fact, se displays a message ‘No writes since last change’ on the status line if the buffer hasn't been saved during a shell escape. This is also important if the command that you execute refers to the file that you are editing.

Document Preparation

As mentioned above, se is not a word processor. However, it is possible to use it to create well-laid-out documents by adding a “text formatter” to se. Such a program is fmt, the Software Tools Text Formatter.

Using fmt one can create documents that can be read either on the screen or printed out. Input to fmt, as created with se, consists of a mixture of formatting commands and text. An fmt command is distinguished from the text around it by the following convention: a command begins in column one with a full-stop.

Clearly, it is easy to get se to spot commands for you. To search for the next fmt command in a file, type:

/^\./
Note the use of the caret ‘^’ metacharacter to match “start of line”. Also, the special meaning of dot has been escaped.

Fmt's inline function syntax uses square brackets ‘[’ and ‘@’]. To find the next function call in a file, type:

/\[/
Note the use of ‘\’ to escape the special meaning of ‘[’.

In order to get se to recognise fmt comments, use the following commands, either on the command line or in a .RC file:

of/"/'/.#/\n/
oc
The ‘oc’ option acts as a toggle when used on the command line.

Once the fmt document is ready to test, it is useful to run fmt from within se. The shell escape mechanism allows this and also allows the use of a pipe into pg to see the result of special effects such as underlining or boldfacing. Try the following commands with an fmt document in the buffer:

w
!fmt % | pg -m
First, the file is written to disk to ensure that fmt gets the latest version. Then the percent character ‘%’ is used to give the current file name in the shell command. The ‘-m’ option to pg tells it to expect an fmt metafile. Remember that se has one level of shell command history; to repeat the preview command, type:
w
!!
and se will place the previous shell command back on the command line for editing; pressing return will cause it to be executed. So, with the shell history feature it is possible to spend an entire session in se, while calling up other programs via the shell escape. The “pling-pling-return-return” sequence soon becomes well-known.

Programming with SE

Programmers find se a very powerful tool. They are not even put off by the complexity of pattern-matching metacharacters...

It was for programmers that the Source-Code Mode was incorporated. The following list shows the quote and comment symbols for a number of popular languages, together with the corresponding file suffix.

C           .c   .h  of|"|'|/*|*/|#|\n|
BASIC       .bas     of|"|"|'|\n|||
BASIC       .bas     of|"|'|REM|\n|||
Pascal      .pas     of|"|'|(*|*)|(*$|*)|
Pascal      .pas     of|"|'|{|}|{$|}|
occam       .occ     of|"|'|--|\n|||
PostScript  .ps      of|"|'|%|\n|||
Ratfor      .r       of|"|'|#|\n|||
fmt         .fmt     of|"|'|.#|\n|||
TeX         .tex     of|"|'|%|\n|||
Algol-68    .a68     of|"|'|#|#|||
PL/1        .pl1     of|"|'|/*|*/|||

Configuring SE

Se has been designed to be as flexible as possible; most of its features can be customised in some way to suit the user. In fact, very few users actually run se in its default state; most make at least a few changes.

Environment Variables

It is possible to configure se to look for its important files anywhere in the file system. These are the message file, the help file and the startup file. In fact, only the message file is mandatory for se to operate; the help and startup files are optional.

In each case an “environment variable” can be set up to indicate the location of the file itself. A “sensible” default is used if the environment variable has not been set up.

File              Default Name      Environment Variable
message file      SE.MSG            SE_MSG
help file         SE.HLP            SE_HLP
startup file      SE.RC             SE_RC
As an example, here is the command required to tell se to look in a file called ‘HELP.SE’ in the directory ‘C:\TOOLS’ whenever the user asks for help:
C> set se_hlp=C:\tools\help.se
Similar commands are used to set the other files up. Remember to put the ‘set’ commands in your ‘AUTOEXEC.BAT’ file so that they are executed each time you reboot.

The Startup File

Once se is able to find all the files it needs, you can turn your attention to the contents of the startup file. This file contains a mixture of normal se commands and special language-sensitive commands. The idea is that many of the configuration parameters of se depend on what kind of text is in the file you are editing. For instance, in many programming languages, auto-indent is very helpful; in normal text, it is a nuisance.

When se reads a file, either with a ‘e’ command or from the command line, it looks at the name of the file in order to determine what it contains. In most systems, the suffix of the file name is a good indication of the type. For instance, ‘prog.p’ is a Pascal program whereas ‘note.text’ is a file of plain text.

In the startup file se recognises a special construct consisting of a line beginning with a curly bracket ‘{’. This is followed by either the keyword ‘LANG’ or ‘TERM’. The ‘LANG’ keyword is followed by a list of file suffices. If the suffix of the file being read matches any of the suffices following the keyword, all the commands up to the next closing curly bracket ‘}’ are executed; if not, they are ignored.

The ‘TERM’ keyword does a similar job with terminal types.

An example of a typical startup file will make this clear. Note the use of a hash ‘#’ to introduce comments:

# Startup file for 'se'
oa
# Pascal
{ LANG pas p
oia
ol$
}
# Documents
{ LANG txt doc
ol%
}
In this example, ‘oa’ is obeyed no matter what kind of file is being edited. However, if a Pascal program is edited ‘oia’ and ‘ol$’ are obeyed because the file suffices match. If a text file is edited, ‘ol%’ is obeyed. If some other kind of file, with an unrecognised suffix, is edited, the only effect is to obey the ‘oa’.

A slight problem arises with options like ‘oa’ because they toggle the state of some option. Since the .RC file is read every time a new file is read into se, options like ‘oa’ would not behave as desired. The problem is solved by a simple rule: before reading the .RC file, se restores all options to their default states. This means that all reserved words are erased, key bindings are put back to the default set, and default screen colours are set up. In addition, of course, toggle-type options such as ‘oa’, ‘or’, ‘oc’ and ‘oy’ are put back to a known state.

Any of se's commands or options may be put in the startup file. It is possible to arrange for different types of file to set up different colours for se's screen (on a colour system). Different prompts can be set; insert mode can be turned on.

The most powerful use of this ability is to put key-binding ‘ob’ commands in the startup file. In this way, it is possible to customise the whole keyboard according to the work being done. Another example from the world of programming:

oa
{ LANG bas
ob[a-p]"PRINT"
ob[a-r]"RETURN"
ob[a-g]"GOSUB"
}
{ LANG c h
oia
ob[a-b]"break;"
ob[a-r]"return;" 
ob[a-p]"printf ("
ob[a-u]"unsigned"
ob[a-i]kill_all "#include <stdio.h>"
}
The last example shows the use of the ‘kill_all’ function to ensure that the ‘#include’ begins in column one. In fact, an even better version would use the ‘left’ cursor function eight times to move the cursor back to the ‘s’, ready for the user to overtype the filename.

In practice, you would put ‘of’ and ‘oc’ commands in the language-dependent blocks as well.

Configuring the Message File

All the text that se displays in the form of messages on the status line is held in a file. This is known as the “message file” and is read in by se when the editor starts up. By changing the message file, you can change the wording of the error messages, or even arrange for se's messages to use a different language altogether.

The message file contains, as the first line, the version number of se that it works with. This is to avoid the situation where a new version of the editor requires more messages than the previous version, but the old message file is still installed on the system. If you upgrade to a new version of se, and you want to use a specially-modified message file from the old version, make sure that you compare the lengths of the message files. New messages will normally be added to the end of the file and you should ensure that any extra ones from the new version are added to your old file.

We have already seen how environment variables are used to tell se where to find the message file. There is one special point to note about the file itself; it is possible to make a message ring the terminal's bell or bleeper. This is done by making the first character of the message a control-G character (ASCII 7, BEL). Two messages are normally modified in this way: ‘No room for any more lines’ and ‘Buffer hasn't been saved’. These messages are severe enough to justify an audible warning. However, if the user objects to the noise all that is required is to remove the control-G characters from the message file. Note that another way to make se silent is to use the ‘oq’ option. This has the effect of silencing all the bleeps normally produced, not just those that are specified by the message file.

When creating a modified or translated message file, remember that space on the status line is limited and messages should not be too long. In fact, a useful modification for experienced users is a file of terse messages.