Sam - A Bitmap Editor with Structural Regular Expressions

rob at alice.UUCP rob at alice.UUCP
Fri Jul 15 08:47:18 AEST 1988


This is the ad for sam, which is going in the toolchest imminently.
I think only the sun version is going in right away, but the others
are available from me, if you get the toolchest version.
at the moment, an old version (mostly missing some bug fixes) for
the 630 is in the toolchest in the dmd-pgmg package.

	Rob Pike
----

Sam is unique in its comfortable union of an interactive cut-and-paste
editing style with a powerful command language based on the
composition of regular expressions.  It may be controlled by mouse for
convenient general editing, or by typing ASCII commands in an ed-like
language for doing repetitive or complex tasks.  Unlike most editors
with two styles of use, though, the interactive and command-language
parts work in concert, rather than in competition.

The command language is syntactically similar to that of ed(1), but
with the current text (dot) an arbitrary string rather than a line of
the file.  In fact, sam has almost no notion of lines--a file is
treated as a single string, and regular expressions match substrings,
not lines.  Newline is treated as an ordinary character.  Commands fall
into two major groups:  matching and selecting text, and making
changes.  The selection commands can be nested to refine the selection.
For instance,
        x/rob/ p
extracts all occurrences of the string 'rob' (just those three
letters) and prints them.  This is not very interesting; instead we
could say
        x/.*\n/ g/rob/ p
(extract all newline-terminated lines, select those that match rob,
and print) to print all lines containing rob, exactly as in ed's
`g/rob/p'.  To print all lines containing 'rob' but not 'robot':
        x/.*\n/ g/rob/ v/robot/ p
These commands may be nested arbitrarily, allowing complex commands
to be composed like shell pipelines.

Sam usually runs in a window on a bitmap display, dividing its window
into subwindows.  Each window has a cut-and-paste editor with the usual
properties of such things, including multiple windows per file, cut
and paste between windows, scroll bars, and so on.  The mouse may be
used to select the current text for the command language, and also to
edit the commands themselves:  the command language runs in an
otherwise ordinary window of its own.  In the other direction, text
selected by the command language, such as by line number or regular
expression search, is made the current text on the screen and
highlighted, where it may be cut, pasted, and so on.  This simply but
conveniently connects the two editing methods.

Some general features:  sam allows editing an arbitrary number of files
simultaneously, with easy access to all files from the mouse or
command language; a general undo that can restore all files after any
editing operation, with multiple undoes going further back in time;
and the ability to use the command language without invoking the
terminal part at all so it can be used ed-like or in shell scripts.
Finally, because sam is written as two communicating programs--a part
that provides file access and implements the command language, and a
part that provides the interactive features--the two parts may be run
on separate machines so that sam can provide cut-and-paste editing for
machines that have no bitmap display.  (In Computer Science Research at
Bell Labs we use sam on our SUN's to edit files on our Cray.)

Sam is available for several systems, including System V, 9th Edition,
4.[23]BSD and SUNOS, with terminal support for 5620s, 630s, SUNWindows
and X11.  Because of its two-headed nature, any combination of host and
terminal will work.

For more information, see the paper, ``The text editor sam'', by Rob
Pike, pages 813-845 of the November 1987 issue (Vol.  17 #11) of
Software--Practice and Experience.



More information about the Comp.unix.questions mailing list