sam, B, E, sam.save, samterm, samsave - screen editor with structural regular expressions
is a multi-file editor.
It modifies a local copy of an external file.
The copy is here called a
The files are listed in a menu available through mouse button 3
Each file has an associated name, usually the name of the
external file from which it was read, and a `modified' bit that indicates whether
the editor's file agrees with the external file.
The external file is not read into
the editor's file until it first becomes the current file---that to
which editing commands apply---whereupon its menu entry is printed.
The options are
Autoindent. In this mode, when a newline character is typed
in the terminal interface,
copies leading white space on the current line to the new line.
Do not `download' the terminal part of
Editing will be done with the command language only, as in
Run the host part remotely
on the specified machine, the terminal part locally.
Start the host part from the specified file on the remote host.
Only meaningful with the
Start the terminal part from the specified file. Useful
Regular expressions are as in
with the addition of
to represent newlines.
A regular expression may never contain a literal newline character.
regular expression stands for the last complete expression encountered.
A regular expression in
matches the longest leftmost substring formally
matched by the expression.
Searching in the reverse direction is equivalent
to searching backwards with the catenation operations reversed in
An address identifies a substring in a file.
In the following, `character
means the null string
character in the file, with 1 the
first character in the file.
starting at the beginning of the file, of the regular expression
All files always have a current substring, called dot,
that is the default address.
The empty string after character
is the beginning of the file.
is the beginning of the file.
The substring that matches the regular expression,
found by looking toward the end
of the file,
and if necessary continuing the search from the other end to the
starting point of the search.
The matched substring may straddle
the starting point.
When entering a pattern containing a literal question mark
for a backward search, the question mark should be
specified as a member of a class.
The string before the first full line.
This is not necessarily
the null string; see
The null string at the end of the file.
The mark in the file (see the
Preceding a simple address (default
refers to the address evaluated in the unique file whose menu line
matches the regular expression.
In the following,
evaluated starting at the end of
evaluated looking in the reverse direction
starting at the beginning of
The substring from the beginning of
to the end of
evaluated at the end of, and dot set to,
are high precedence, while
are low precedence.
is a line or character address with a missing
number, the number defaults to 1.
are present and distinguishable,
may be elided.
may be a regular
expression; if it is delimited by
the effect of the
It is an error for a compound address to represent a malformed substring.
Some useful idioms:
selects the line containing
the end (beginning) of a1.
locates the first match of the expression in the file.
sets dot unnecessarily.)
finds the second following occurrence of the expression,
In the following, text demarcated by slashes represents text delimited
by any printable
character except alphanumerics.
Any number of
trailing delimiters may be elided, with multiple elisions then representing
null strings, but the first delimiter must always
In any delimited text,
newline may not appear literally;
may be typed for newline; and
quotes the delimiter, here
Backslash is otherwise interpreted literally, except in
Most commands may be prefixed by an address to indicate their range
Those that may not are marked with a
If a command takes
an address and none is supplied, dot is used.
The sole exception is
command, which defaults to
In the description, `range' is used
to represent whatever address is supplied.
Many commands set the
value of dot as a side effect.
If so, it is always set to the `result'
of the change: the empty string for a deletion, the new text for an
insertion, etc. (but see the
lines of text
Insert the text into the file after the range.
replaces the text, while
Delete the text in the range.
for the first match to the regular expression in the range.
Set dot to the modified range.
stands for the string
that matched the expression.
Backslash behaves as usual unless followed by
stands for the string that matched the
subexpression begun by the
is followed immediately by a
match in the range is substituted.
command is followed by a
all matches in the range
the range to after
Print the text in the range.
Print the line address and character address of the range.
Print just the character address of the range.
* b file-list
Set the current file to the first file named in the list
also has in its menu.
The list may be expressed
<Plan 9 command
in which case the file names are taken as words (in the shell sense)
generated by the Plan 9 command.
* B file-list
except that file names not in the menu are entered there,
and all file names in the list are examined.
Print a menu of files.
The format is:
' or blank
indicating the file is modified or clean,
- or +
indicating the file is unread or has been read
(in the terminal,
means more than one window is open),
. or blank
indicating the current file,
and the file name.
* D file-list
Delete the named files from the menu.
If no files are named, the current file is deleted.
It is an error to
a modified file, but a subsequent
will delete such a file.
* e filename
Replace the file by the contents of the named external file.
Set dot to the beginning of the file.
Replace the text in the range by the contents of the named external file.
Write the range (default
to the named external file.
* f filename
Set the file name and print the resulting menu entry.
If the file name is absent from any of these, the current file name is used.
always sets the file name;
do so if the file has no name.
< Plan 9-command
Replace the range by the standard output of the
Plan 9 command.
> Plan 9-command
Send the range to the standard input of the
Plan 9 command.
| Plan 9-command
Send the range to the standard input, and replace it by
the standard output, of the
Plan 9 command.
* ! Plan 9-command
Plan 9 command.
* cd directory
Change working directory.
If no directory is specified,
In any of
Plan 9 command
is omitted the last
Plan 9 command
(of any type) is substituted.
(using the mouse and raster display, i.e. not using option
sets standard input to
for all) is placed in
and the first few lines are printed.
Loops and Conditionals
For each match of the regular expression in the range, run the command
with dot set to the match.
Set dot to the last match.
If the regular
expression and its slashes are omitted,
Null string matches potentially occur before every character
of the range and at the end of the range.
but run the command for each substring that lies before, between,
the matches that would be generated by
There is no default regular expression.
Null substrings potentially occur before every character
in the range.
* X/regexp/ command
For each file whose menu entry matches the regular expression,
make that the current file and
run the command.
If the expression is omitted, the command is run
in every file.
* Y/regexp/ command
but for files that do not match the regular expression,
and the expression is required.
If the range contains
or does not contain
a match for the expression,
set dot to the range and run the command.
These may be nested arbitrarily deeply, but only one instance of either
may appear in a single command.
An empty command in an
an empty command in
do not have defaults.
Set the current file's mark to the range. Does not set dot.
It is an error to quit with modified files, but a second
* u n
Undo the last
top-level commands that changed the contents or name of the
current file, and any other file whose most recent change was simultaneous
with the current file's change.
move further back in time.
The only commands for which u is ineffective are
`redoes,' undoing the undo, going forwards in time again.
If the range is explicit, set dot to the range.
is downloaded, the resulting dot is selected on the screen;
otherwise it is printed.
If no address is specified (the
command is a newline) dot is extended in either direction to
line boundaries and printed.
If dot is thereby unchanged, it is set to
Grouping and multiple changes
Commands may be grouped by enclosing them in braces
Commands within the braces must appear on separate lines (no backslashes are
required between commands).
Semantically, an opening brace is like a command:
it takes an (optional) address and sets dot for each sub-command.
Commands within the braces are executed sequentially, but changes made
by one command are not visible to other commands (see the next
Braces may be nested arbitrarily.
When a command makes a number of changes to a file, as in
the addresses of all changes to the file are computed in the original file.
If the changes are in sequence,
they are applied to the file.
Successive insertions at the same address are catenated into a single
insertion composed of the several insertions in the order applied.
What follows refers to behavior of
when downloaded, that is, when
operating as a display editor on a raster display.
This is the default
(no download) option provides access
to the command language only.
Each file may have zero or more windows open.
Each window is equivalent
and is updated simultaneously with changes in other windows on the same file.
Each window has an independent value of dot, indicated by a highlighted
substring on the display.
Dot may be in a region not within
There is usually a `current window',
marked with a dark border, to which typed text and editing
Text may be typed and edited as in
also the escape key (ESC) selects (sets dot to) text typed
since the last mouse button hit.
The button 3 menu controls window operations.
The top of the menu
provides the following operators, each of which uses one or
cursors to prompt for selection of a window or sweeping
of a rectangle.
`Sweeping' a null rectangle gets a large window, disjoint
from the command window or the whole screen, depending on
where the null rectangle is.
Create a new, empty file.
Create a copy of an existing window.
Delete the window.
In the last window of a file,
is equivalent to a
for the file.
Equivalent to a
for the file.
Below these operators is a list of available files, starting with
the command window.
Selecting a file from the list makes the most recently
used window on that file current, unless it is already current, in which
case selections cycle through the open windows.
If no windows are open
on the file, the user is prompted to open one.
Files other than
are marked with one of the characters
according as zero, one, or more windows
are open on the file.
A further mark
appears on the file in the current window and
a single quote,
on a file modified since last write.
The command window, created automatically when
starts, is an ordinary window except that text typed to it
is interpreted as commands for the editor rather than passive text,
and text printed by editor commands appears in it.
The behavior is like
with an `output point' that separates commands being typed from
Commands typed in the command window apply to the
current open file---the file in the most recently
Button 1 changes selection, much like
Pointing to a non-current window with button 1 makes it current;
within the current window, button 1 selects text, thus setting dot.
Double-clicking selects text to the boundaries of words, lines,
quoted strings or bracketed strings, depending on the text at the click.
Button 2 provides a menu of editing commands:
Delete dot and save the deleted text in the snarf buffer.
Replace the text in dot by the contents of the snarf buffer.
Save the text in dot in the snarf buffer.
Send the text in the selection as a plumb
message. If the selection is empty,
the white-space-delimited block of text is sent as a plumb message
attribute defining where the selection lies (see
Search forward for the next occurrence of the literal text in dot.
If dot is the null string, the text in the snarf buffer is
The snarf buffer is unaffected.
Exchange snarf buffers with
Search forward for the next match of the last regular expression
typed in a command.
(Not in command window.)
Send the text in dot, or the snarf buffer if
dot is the null string, as if it were typed to the command window.
Saves the sent text in the snarf buffer.
(Command window only.)
listens to the
If plumbing is not active,
creates a named pipe
which acts as an additional source of commands. Characters written to
the named pipe are treated as if they had been typed in the command window.
is a shell-level command that causes an instance of
running on the same terminal to load the named
uses either plumbing or the named pipe, whichever service is available.
If plumbing is not enabled,
the option allows a line number to be specified for
the initial position to display in the last named file
(plumbing provides a more general mechanism for this ability).
is a shell-level command that can be used as
in a Unix environment.
and then does not exit until
is changed, which is taken as a signal that
is done being edited.
terminates other than by a
command (by hangup, deleting its window, etc.), modified
files are saved in an
This program, when executed, asks whether to write
each file back to a external file.
causes writing; anything else skips the file.