The Text Editor sam Rob Pike
[email protected]−labs.com ABSTRACT Sam is an interactive multi-file text editor intended for bitmap displays. A textual command language supplements the mouse-driven, cut-and- paste interface to make complex or repetitive editing tasks easy to spec ify. The language is characterized by the composition of regular expres sions to describe the structure of the text being modified. The treatment of files as a database, with changes logged as atomic transactions, guides the implementation and makes a general ߢundoߣ mechanism straightfor ward. Sam is implemented as two processes connected by a low- bandwidth stream, one process handling the display and the other the editing algorithms. Therefore it can run with the display process in a bit map terminal and the editor on a local host, with both processes on a bitmap-equipped host, or with the display process in the terminal and the editor in a remote host. By suppressing the display process, it can even run without a bitmap terminal. This paper is reprinted from SoftwareߞPractice and Experience, Vol 17, number 11, pp. 813-845, November 1987. The paper has not been updated for the Plan 9 manuals. Although Sam has not changed much since the paper was written, the system around it certainly has. Nonethe less, the description here still stands as the best introduction to the edi tor. Introduction Sam is an interactive text editor that combines cut-and-paste interactive editing with an unusual command language based on the composition of regular expressions. It is writ ten as two programs: one, the ߢhost part,ߣ runs on a UNIX system and implements the command language and provides file access; the other, the ߢterminal part,ߣ runs asyn chronously on a machine with a mouse and bitmap display and supports the display and interactive editing.