UCSD Pascal In Depth: Editor

Written in

by

Part 1: The Editor

Related: UCSD p-System Info
Note: This Blog Post was written in the USCD Pascal Editor, on an Apple II emulator. There may be a few more typos than usual.

The p-System comes with an editor. It’s a full-screen editor, with some fairly
advanced features for the time, like auto-indent, bookmarks, and cut and
paste. It’s modal, which is hardly surprising, considering that modal editors
were the latest usability improvement of the age, compared to the
line-oriented editors of the previous decade.

It’s a bit slow on the AppleII, which is pretty understandable, given that,
like the rest of the system tools, it’s entirely written in interpreted
p-code. Running it in the emulator with the speed cranked up to the equivalent
of 150+ MHz, it’s pretty darn snappy.

One of the WEIRDEST things about the p-System Editor is that when you’re in
Insert mode, the esc key throws away all of your edits. Well, actually,
that’s true for every mode. Hitting esc just aborts whatever edits you were
making, and puts things back to the way they were before you started editing.

It’s just more-tragic when you’ve just typed in a bunch of text, and it goes
away because you’ve been trained by newer software to use esc as a safe
escape hatch to get out of the current mode. The folks who designed vi at
least got that one right.

The Modes

The available modes in the Editor are displayed on the top line of the
display. They are:

  • Insert
  • Delete
  • Copy
  • eXchange
  • Find
  • Replace
  • Jump
  • Adjust
  • Set
  • Margin
  • Zap
  • Quit (not really a MODE, per-se)

Navigation

WHen you’re “not in a mode”, you are able to navigate the file with a few
shortcut commands. Unfortunately, since this is “not a mode”, the keys used
for navigation aren’t displayed on the screen. You just need to memorize them.

At least on the Apple IIe, there are usable cursor keys, so you don’t need to
memorize the keys for moving around on the screen. If you were working on an
Apple II+, you’d need to know that Ctrl-O and Ctrl-L are your up and down
arrow keys, respectively.

Pressing P moves “in the current direction” by a page. The what, now? Yes,
the editor has a “direction” that it remembers. This is used to determine
which direction the “next page” command goes in, as well as find and replace.
You set the direction by pressing the > and < keys.

Other “useful” keys in navigation mode include using the spacebar to move one
character, and the return key to move one line, in the current direction. You
can also use the tab key to move 8 characters at a time. The = key jumps to
the most-recently inserted, found, or replaced text.

Insert Mode

This is the text-entry mode for the editor. Anything you type in this mode is
inserted into the file, “pushing down” whatever is after it in the file.
Inserting additional text within a line is…odd. If you enter Insert mode
when the cursor is in a line that has text in it already, the line is split at
the cursor, and the text on the right is pushed over to the right margin,
which shows how much you can type before you’re going to have to re-wrap the
line.

Speaking of line-wrapping, the Editor doesn’t do that automatically, unless
you’re in the “filling” mode (see Set, below). By default, the editor starts
in auto-indenting, but non-wrapping mode, as is probably best for typing in
Pascal programs. If you’re using it to write, say, a blog post, you’ll want
to change that.

In the non-fill default mode, lines can be longer than 80 characters, but any
text off the edge of the screen is just not accessible, and a ! is displayed
on the right side of the screen. There are key commands for the 40-column
Apples to scroll to the right or left to see either half of the nominally
80-column text, but nothing at all to scroll farther for lines that are
longer than 80 columns.

When you’re done inserting text, you use Ctrl-C to save your changes. I think,
of all the weirdness in this editor, the convention of “Ctrl-C accepts, esc
rejects changes” is probably the most-jarring. It just feels wrong to use
Ctrl-C as anything other than an interrupt key.

Delete Mode

This is pretty straightforward. You go into Delete mode, and you can use the
arrow keys, or space and return, like you would in navigation mode. As you do
so, the Editor deletes the text you move over from the screen. When you press
Ctrl-C, the Editor deletes all of that text from the file. Deleted text goes
into a buffer, for use with the Copy mode.

Copy Mode

In Copy mode, you can copy text either from the delete buffer, or from another
file on the disk. Copy mode asks you if you want to copy from the buffer, or
from a section of a file.

Copying from the buffer works perfectly straightforwardly. The one oddness is
that if you used esc to cancel a delete operation, it’s still copied into the
buffer. That’s the “copy” for “copy and paste” on this system.

Copying text from another file uses a syntax like this:
File.Text[start,end] where start and end are markers in the other file (see
the Set mode, below). Given how painful it is to format text in the Editor, I
can definitely see the use of making up some pre-formatted blocks in another
file, if they’re commonly-used pieces of code or text.

Exchange Mode

This is for fixing small typos, primarily. You go into eXchange mode, and type
over whatever you want to replace. Irritatingly, there is no way to insert or
delete while you’re in this mode, so exchanging text that’s not exactly the
same length isn’t possible.

Find Mode

The Find mode has two modes for searching – Token and Literal. Token is more
or less equivalent to word-search mode in modern editors. It looks for the
search term surrounded by anything that is not a letter or a number. In
literal mode, the Find command will find the search term even if it’s embedded
inside other text.

You specify the text to search for by entering a delimiter charcter, then the
text, then another delimiter. The Apple Pascal manual suggests using the /
character, because it’s typable without shift, and not frequently found in
text. I guess the Unix sed editor uses / as a delimiter for the same reason.

Replace Mode

This is just like Find, but you can specify what you want to replace the found
text with. You can enable “Verify” to have the Editor ask you whether you want
to replace the text.

Jump Mode

You can jumo to the beginning or end of the file, or to a specific marker. For
more on markers, see the Set mode, below.

Adjust

This mode adjusts the indentation of text. You can push lines around via the
arrow keys. You can also align text to the right, left, or center.

Set

This mode has a couple of disjoint features. The easy one to describe is
setting markers. These are like HTML anchors. You can use the Jump command to
move to previously-marked locations in a file. The markers are stored in the
hidden blocks at the beginning of the text file (about which more, later).

And then there is the “environment” of the editor. This allows you to see and
set some settings for the editor. It also shows you all of the set markers in
the file. I already mentioned “fill” mode, which is useful for typing text,
rather than Pascal programs. You can also set the margins for use with the
Margin command (see below). There are three margins – a right, left, and
paragraph margin. See discussion of those below.

Margin

The Margin command is only available if auto-indent is false, and filling is
true, in the editor environment. Pressing M will reformat the text in the
current paragraph, to make it fit within the margins. It also does some
additional formatting, like putting two spaces after a period (sigh). I am
definitely not going to adjust my style to make the Margin command happy,
this far into writing this post, but I’ll keep it in mind for the future.

This is what the Editor considers a properly-formatted paragraph. Note that the first line of the paragraph is indented 5 spaces, and there are two spaces after every period. I really used to write like this, back when I used a typewriter for school work.

Zap

A potentially very useful/destructive command. This deletes everything from
the cursor to the location of the last find or insert. This seems like an
utterly bizarre feature to even have, but it turns out to be somewhat
logical, as a kind of workaround for the clunkiness of Exchange mode. If you
want to replace some text with something shorter or longer, you can use
Insert mode to add the new text, then move the cursor to the beginning of the
old text, and Zap it. So simple! At least zapped text goes into the delete
buffer, so you can easily undo it when it removes much more text than you
intended.

Quit

Not a mode, but you do have some choices here. Primarily, whether to save
your work, and if so, to the system.wrk.text file, or to another file. There
is a tendency for thiungs to end up in the Workfile, unless you’re paying
close attention. This is part of the design of the edit-compile-run loop,
where by default, every IDE command targets the same file.

This is also how you choose another file for editing. Starting the editor
always loads the system.wrk.text file, if it exists.

Next up: The Filesystem

Leave a comment