|
|
1.1 root 1: .ds a \fR*\ \fP
2: .TH SAM 9.1
3: .CT 1 editor
4: .SH NAME
5: sam \- screen editor with structural regular expressions
6: .SH SYNOPSIS
7: .B sam
8: [
9: .I option ...
10: ] [
11: .I files
12: ]
13: .PP
14: .I sam
15: .B -r
16: .I machine
17: .PP
18: .B sam.save
19: .SH DESCRIPTION
20: .I Sam
21: is a multi-file editor.
22: It modifies a local copy of a Unix file.
23: The copy is here called a
24: .IR file ;
25: a Unix file is distinguished by the trademarked
26: adjective.
27: The files are listed in a menu available through mouse button 3
28: or the
29: .B n
30: command.
31: Each file has an associated name, usually the name of the
32: Unix file from which it was read, and a `modified' bit that indicates whether
33: the editor's file agrees with the Unix file.
34: The Unix file is not read into
35: the editor's file until it first becomes the current file\(emthat to
36: which editing commands apply\(emwhereupon its menu entry is printed.
37: The options are
38: .TP
39: .B -d
40: Do not download the terminal part of
41: .I sam.
42: Editing will be done with the command language only, as in
43: .IR ed (1).
44: .TP
45: .BI -r " machine
46: Run the host part remotely
47: on the specified machine, the terminal part locally.
48: This extends graphic editing to files on machines that
49: don't ordinarily support it or across
50: .RI non- nfs (8)
51: connections.
52: .SS Regular expressions
53: Regular expressions are as in
54: .IR egrep
55: (see
56: .IR gre (1)),
57: with the addition of
58: .B @
59: and
60: .BR \en .
61: A regular expression may never contain a literal newline character.
62: The elements of regular expressions are:
63: .TP
64: .B .
65: Match any character except newline.
66: .TP
67: .B \en
68: Match newline.
69: .TP
70: .B \ex
71: For any character except
72: .B n
73: match the character (here
74: .BR x ).
75: .TP
76: .B @
77: Match any character.
78: .TP
79: .B [abc]
80: Match any character in the square brackets.
81: .B \en
82: may be mentioned.
83: .TP
84: .B [^abc]
85: Match any character not in the square brackets, but never a newline.
86: Both these forms accept a range of
87: .SM ASCII
88: characters indicated by
89: a dash, as in
90: .BR a-z .
91: .TP
92: .B ^
93: Match the null string immediately after a newline.
94: .TP
95: .B $
96: Match the null string immediately before a newline.
97: .PP
98: Any other character except newline matches itself.
99: .PP
100: In the following,
101: .I r1
102: and
103: .I r2
104: are regular expressions.
105: .TP
106: .BI ( r1 )
107: Match what
108: .I r1
109: matches.
110: .TP
111: .IB r1 | r2
112: Match what
113: .I r1
114: or what
115: .IR r2
116: matches.
117: .TP
118: .IB r1 *
119: Match zero or more adjacent matches
120: of
121: .IR r1 .
122: .TP
123: .IB r1 +
124: Match one or more adjacent matches of
125: .IR r1 .
126: .TP
127: .IB r1 ?
128: Match zero or one matches of
129: .IR r1 .
130: .PP
131: The operators
132: .BR * ,
133: .B +
134: and
135: .B ?
136: are highest precedence, then catenation, then
137: .B |
138: is lowest.
139: The empty
140: regular expression stands for the last complete expression encountered.
141: A regular expression in
142: .I sam
143: matches the longest leftmost substring formally
144: matched by the expression.
145: Searching in the reverse direction is equivalent
146: to searching backwards with the catenation operations reversed in
147: the expression.
148: .SS Addresses
149: An address identifies a substring in a file.
150: In the following, `character
151: .IR n '
152: means the null string
153: after the
154: .IR n -th
155: character in the file, with 1 the
156: first character in the file.
157: `Line
158: .IR n '
159: means the
160: .IR n -th
161: match,
162: starting at the beginning of the file, of the regular expression
163: .L .*\en? .
164: (The peculiar properties of a last line without a newline are
165: temporarily undefined.)
166: All files always have a current substring, called dot,
167: that is the default address.
168: .SS Simple Addresses
169: .TP
170: .BI # n
171: The empty string after character
172: .IR n ;
173: .B #0
174: is the beginning of the file.
175: .TP
176: .I n
177: Line
178: .IR n .
179: .TP
180: .BI / regexp /
181: .PD0
182: .TP
183: .BI ? regexp ?
184: The substring that matches the regular expression,
185: found by looking toward the end
186: .RB ( / )
187: or beginning
188: .RB ( ? )
189: of the file,
190: and if necessary continuing the search from the other end to the
191: starting point of the search.
192: The matched substring may straddle
193: the starting point.
194: .PD
195: .TP
196: .B 0
197: The string before the first full line.
198: This is not necessarily
199: the null string; see
200: .B +
201: and
202: .B -
203: below.
204: .TP
205: .B $
206: The null string at the end of the file.
207: .TP
208: .B .
209: Dot.
210: .TP
211: .B \&'
212: The mark in the file (see the
213: .B k
214: command below).
215: .TP
216: \f(CW"\f2regexp\f(CW"\f1\f1
217: Preceding a simple address (default
218: .BR . ),
219: refers to the address evaluated in the unique file whose menu line
220: matches the regular expression.
221: .SS Compound Addresses
222: In the following,
223: .I a1
224: and
225: .I a2
226: are addresses.
227: .TP
228: .IB a1 + a2
229: The address
230: .I a2
231: evaluated starting at the end of
232: .IR a1 .
233: .TP
234: .IB a1 - a2
235: The address
236: .I a2
237: evaluated looking in the reverse direction
238: starting at the beginning of
239: .IR a1 .
240: .TP
241: .IB a1 , a2
242: The substring from the beginning of
243: .I a1
244: to the end of
245: .IR a2 .
246: If
247: .I a1
248: is missing,
249: .B 0
250: is substituted
251: If
252: .I a2
253: is missing,
254: .B $
255: is substituted.
256: .TP
257: .IB a1 ; a2
258: Like
259: .IB a1 , a2,
260: but with
261: .I a2
262: evaluated at the end of, and dot set to,
263: .IR a1 .
264: .PP
265: The operators
266: .B +
267: and
268: .B -
269: are high precedence, while
270: .B ,
271: and
272: .B ;
273: are low precedence.
274: .PP
275: In both
276: .B +
277: and
278: .B -
279: forms, if
280: .I a2
281: is a line or character address with a missing
282: number, the number defaults to 1.
283: If
284: .I a1
285: is missing,
286: .L .
287: is substituted.
288: If both
289: .I a1
290: and
291: .I a2
292: are present and distinguishable,
293: .B +
294: may be elided.
295: .I a2
296: may be a regular
297: expression; if it is delimited by
298: .LR ? 's,
299: the effect of the
300: .B +
301: or
302: .B -
303: is reversed.
304: .PP
305: It is an error for a compound address to represent a malformed substring.
306: Some useful idioms:
307: .IB a1 +-
308: .RI ( a1 \&\f5-+\fP )
309: selects the line containing
310: the end (beginning) of a1.
311: .BI 0/ regexp /
312: locates the first match of the expression in the file.
313: (The form
314: .B 0;//
315: sets dot unnecessarily.)
316: .BI ./ regexp ///
317: finds the second following occurrence of the expression,
318: and
319: .BI .,/ regexp /
320: extends dot.
321: .SS Commands
322: In the following, text demarcated by slashes represents text delimited
323: by any printable
324: .SM ASCII
325: character except alphanumerics.
326: Any number of
327: trailing delimiters may be elided, with multiple elisions then representing
328: null strings, but the first delimiter must always
329: be present.
330: In any delimited text,
331: newline may not appear literally;
332: .B \en
333: may be typed for newline; and
334: .B \e/
335: quotes the delimiter, here
336: .LR / .
337: Backslash is otherwise interpreted literally, except in
338: .B s
339: commands.
340: .PP
341: Most commands may be prefixed by an address to indicate their range
342: of operation.
343: Those that may not are marked with a
344: .L *
345: below.
346: If a command takes
347: an address and none is supplied, dot is used.
348: The sole exception is
349: the
350: .B w
351: command, which defaults to
352: .BR 0,$ .
353: In the description, `range' is used
354: to represent whatever address is supplied.
355: Many commands set the
356: value of dot as a side effect.
357: If so, it is always set to the `result'
358: of the change: the empty string for a deletion, the new text for an
359: insertion, etc. (but see the
360: .B s
361: and
362: .B e
363: commands).
364: .br
365: .ne 1.2i
366: .SS Text commands
367: .PD0
368: .TP
369: .BI a/ text /
370: .TP
371: or
372: .TP
373: .B a
374: .TP
375: .I lines of text
376: .TP
377: .B .
378: Insert the text into the file after the range.
379: Set dot.
380: .TP
381: .B c\fP
382: .br
383: .ns
384: .TP
385: .B i\fP
386: Same as
387: .BR a ,
388: but
389: .B c
390: replaces the text, while
391: .B i
392: inserts
393: .I before
394: the range.
395: .TP
396: .B d
397: Delete the text in the range.
398: Set dot.
399: .TP
400: .BI s/ regexp / text /
401: Substitute
402: .I text
403: for the first match to the regular expression in the range.
404: Set dot to the modified range.
405: In
406: .I text
407: the character
408: .B &
409: stands for the string
410: that matched the expression.
411: Backslash behaves as usual unless followed by
412: a digit:
413: .BI \e d
414: stands for the string that matched the
415: subexpression begun by the
416: .IR d -th
417: left parenthesis.
418: If
419: .I s
420: is followed immediately by a
421: number
422: .IR n ,
423: as in
424: .BR s2/x/y/ ,
425: the
426: .IR n -th
427: match in the range is substituted.
428: If the
429: command is followed by a
430: .BR g ,
431: as in
432: .BR s/x/y/g ,
433: all matches in the range
434: are substituted.
435: .TP
436: .BI m " a1
437: .br
438: .ns
439: .TP
440: .BI t " a1
441: Move the range to after
442: .I a1
443: .RB ( m ),
444: or copy it
445: .RB ( t ).
446: Set dot.
447: .SS Display commands
448: .TP
449: .B p
450: Print the text in the range.
451: Set dot.
452: .TP
453: .B =
454: Print the line address and character address of the range.
455: .TP
456: .B =#
457: Print just the character address of the range.
458: .SS File commands
459: .TP
460: .BI \*ab " file-list
461: Set the current file to the first file named in the list
462: that
463: .I sam
464: also has in its menu.
465: The list may be expressed
466: .BI < Unix-command
467: in which case the file names are taken as words (in the shell sense)
468: generated by the Unix command.
469: .TP
470: .BI \*aB " file-list
471: Same as
472: .BR b ,
473: except that file names not in the menu are entered there,
474: and all file names in the list are examined.
475: .TP
476: .B \*an
477: Print a menu of files.
478: The format is:
479: .RS
480: .TP \w'\ \ or\ blank\ \'u
481: .BR ' " or blank
482: indicating the file is modified or clean,
483: .TP
484: .BR - " or \&" +
485: indicating the the file is unread or has been read
486: (in the terminal,
487: .B *
488: means more than one window is open),
489: .TP
490: .BR . " or blank
491: indicating the current file,
492: .TP
493: a blank,
494: .TP
495: and the file name.
496: .RE
497: .TP 0
498: .BI \*aD " file-list
499: Delete the named files from the menu.
500: If no files are named, the current file is deleted.
501: It is an error to
502: .B D
503: a modified file, but a subsequent
504: .B D
505: will delete such a file.
506: .SS I/O Commands
507: .TP
508: .BI \*ae " filename
509: Replace the file by the contents of the named Unix file.
510: Set dot to the beginning of the file.
511: .TP
512: .BI r " filename
513: Replace the text in the range by the contents of the named Unix file.
514: Set dot.
515: .TP
516: .BI w " filename
517: Write the range (default
518: .BR 0,$ )
519: to the named Unix file.
520: .TP
521: .BI \*af " filename
522: Set the file name and print the resulting menu entry.
523: .PP
524: If the file name is absent from any of these, the current file name is used.
525: .B e
526: always sets the file name,
527: .B r
528: and
529: .B w
530: do so if the file has no name.
531: .TP
532: .BI < " Unix-command
533: Replace the range by the standard output of the
534: Unix command.
535: .TP
536: .BI > " Unix-command
537: Sends the range to the standard input of the
538: Unix command.
539: .TP
540: .BI | " Unix-command
541: Send the range to the standard input, and replace it by
542: the standard output, of the
543: Unix command.
544: .TP
545: .BI \*a! " Unix-command
546: Run the
547: Unix command.
548: .TP
549: .BI \*acd " directory
550: Change working directory.
551: If no directory is specified,
552: .B $HOME
553: is used.
554: .PP
555: In any of
556: .BR < ,
557: .BR > ,
558: .B |
559: or
560: .BR ! ,
561: if the
562: .I Unix command
563: is omitted the last
564: .I Unix command
565: (of any type) is substituted.
566: If
567: .I sam
568: is downloaded,
569: .B !
570: sets standard input to
571: .FR /dev/null ,
572: and otherwise
573: unassigned output
574: .RB ( stdout
575: for
576: .B !
577: and
578: .BR > ,
579: .B stderr
580: for all) is placed in
581: .F $HOME/sam.err
582: and the first few lines are printed.
583: .SS Loops and Conditionals
584: .TP
585: .BI x/ regexp / " command
586: For each match of the regular expression in the range, run the command
587: with dot set to the match.
588: Set dot to the last match.
589: If the regular
590: expression and its slashes are omitted,
591: .L /.*\en/
592: is assumed.
593: Null string matches potentially occur before every character
594: of the range and at the end of the range.
595: .TP
596: .BI y/ regexp / " command
597: Like
598: .B x,
599: but run the command for each substring that lies before, between,
600: or after
601: the matches that would be generated by
602: .BR x .
603: There is no default behavior.
604: Null substrings potentially occur before every character
605: in the range.
606: .TP
607: .BI \*aX/ regexp / " command
608: For each file whose menu entry matches the regular expression,
609: run the command.
610: If the expression is omitted, the command is run
611: in every file.
612: .TP
613: .BI \*aY/ regexp / " command
614: Same as
615: .BR X ,
616: but for files that do not match the regular expression,
617: and the expression is required.
618: .TP
619: .BI g/ regexp / " command
620: .br
621: .ns
622: .TP
623: .BI v/ regexp / " command
624: If the range contains
625: .RB ( g )
626: or does not contain
627: .RB ( v )
628: a match for the expression,
629: set dot to the range and run the command.
630: .PP
631: These may be nested arbitrarily deeply, but only one instance of either
632: .B X
633: or
634: .B Y
635: may appear in a \%single command.
636: An empty command in an
637: .B x
638: or
639: .B y
640: defaults to
641: .BR p ;
642: an empty command in
643: .B X
644: or
645: .B Y
646: defaults to
647: .BR f .
648: .B g
649: and
650: .B v
651: do not have defaults.
652: .SS Miscellany
653: .TP
654: .B k
655: Set the current file's mark to the range. Does not set dot.
656: .TP
657: .B \*aq
658: Quit.
659: It is an error to quit with modified files, but a second
660: .B q
661: will succeed.
662: .TP
663: .BI \*au " n
664: Undo the last
665: .I n
666: (default 1)
667: top-level commands that changed the contents or name of the
668: current file, and any other file whose most recent change was simultaneous
669: with the current file's change.
670: Successive
671: .BR u 's
672: move further back in time.
673: The only commands for which u is ineffective are
674: .BR cd ,
675: .BR u ,
676: .BR q ,
677: .B w
678: and
679: .BR D .
680: .TP
681: (empty)
682: If the range is explicit, set dot to the range.
683: If
684: .I sam
685: is downloaded, the resulting dot is selected on the screen;
686: otherwise it is printed.
687: If no address is specified (the
688: command is a newline) dot is extended in either direction to
689: line boundaries and printed.
690: If dot is thereby unchanged, it is set to
691: .B .+1
692: and printed.
693: .PD
694: .SS Grouping and multiple changes
695: Commands may be grouped by enclosing them in braces
696: .BR {} .
697: Commands within the braces must appear on separate lines (no backslashes are
698: required between commands).
699: Semantically, an opening brace is like a command:
700: it takes an (optional) address and sets dot for each sub-command.
701: Commands within the braces are executed sequentially, but changes made
702: by one command are not visible to other commands (see the next section
703: of this manual).
704: Braces may be nested arbitrarily.
705: .PP
706: When a command makes a number of changes to a file, as in
707: .BR x/re/c/text/ ,
708: the addresses of all changes to the file are computed in the original file.
709: If the changes are in sequence,
710: they are applied to the file.
711: Successive insertions at the same address are catenated into a single
712: insertion composed of the several insertions in the order applied.
713: .SS The terminal
714: What follows refers to behavior of
715: .I sam
716: when downloaded, that is, when
717: operating as a display editor on a bitmap display.
718: This is the default
719: behavior; invoking
720: .I sam
721: with the
722: .B -d
723: (no download) option provides access
724: to the command language only.
725: .PP
726: Each file may have zero or more windows open.
727: Each window is equivalent
728: and is updated simultaneously with changes in other windows on the same file.
729: Each window has an independent value of dot, indicated by a highlighted
730: substring on the display.
731: Dot may be in a region not within
732: the window.
733: There is usually a `current window',
734: marked with a dark border, to which typed text and editing
735: commands apply.
736: Text may be typed and edited as in
737: .IR mux (9.1);
738: also the escape key (ESC) selects (sets dot to) text typed
739: since the last mouse button hit.
740: .PP
741: The button 3 menu controls window operations.
742: The top of the menu
743: provides the following operators, each of which prompts with one or
744: more
745: .IR mux -like
746: cursors to prompt for selection of a window or sweeping
747: of a rectangle.
748: `Sweeping' a null rectangle gets a large window, disjoint
749: from the command window or the whole screen, depending on
750: where the null rectangle is.
751: .TF reshape
752: .TP
753: .B new
754: Create a new, empty file.
755: .TP
756: .B xerox
757: Create a copy of an existing window.
758: .TP
759: .B reshape
760: As in
761: .I mux.
762: .TP
763: .B close
764: Delete the window.
765: In the last window of a file,
766: .B close
767: is equivalent to a
768: .B D
769: for the file.
770: .TP
771: .B write
772: Equivalent to a
773: .B w
774: for the file.
775: .PD
776: .PP
777: Below these operators is a list of available files, starting with
778: .BR ~~sam~~ ,
779: the command window.
780: Selecting a file from the list makes the most recently
781: used window on that file current, unless it is already current, in which
782: case selections cycle through the open windows.
783: If no windows are open
784: on the file, the user is prompted to open one.
785: Files other than
786: .B ~~sam~~
787: are marked with one of the characters
788: .B -+*
789: according as zero, one, or more windows
790: are open on the file.
791: A further mark
792: .L .
793: appears on the file in the current window and
794: a single quote,
795: .BR ' ,
796: on a file modified since last write.
797: .PP
798: Nothing can be done without a command window, for which
799: .I sam
800: prompts initially.
801: The command window is an ordinary window except that text typed to it
802: is interpreted as commands for the editor rather than passive text,
803: and text printed by editor commands appears in it.
804: The behavior is like
805: .I mux,
806: with a `command point' that separates commands being typed from
807: previous output.
808: Commands typed in the command window apply to the
809: current open file\(emthe file in the most recently
810: current window.
811: .SS Manipulating text
812: Button 1 changes selection, much like
813: .I mux.
814: Pointing to a non-current window with button 1 makes it current;
815: within the current window, button 1 selects text, thus setting dot.
816: Double-clicking selects text to the boundaries of words, lines,
817: quoted strings or bracketed strings, depending on the text at the click.
818: .PP
819: Button 2 provides a menu of editing commands:
820: .PD0
821: .TP
822: .B cut
823: Delete dot and save the deleted text in the snarf buffer.
824: .TP
825: .B paste
826: Replace the text in dot by the contents of the snarf buffer.
827: .TP
828: .B snarf
829: Save the text in dot in the snarf buffer.
830: .TP
831: .B look
832: Search forward for the next occurrence of the literal text in dot.
833: If dot is the null string, the text in the snarf buffer is
834: used.
835: The snarf buffer is unaffected.
836: .TP
837: .B <mux>
838: Exchange snarf buffers with
839: .IR mux.
840: .TP
841: .BI / regexp
842: Search forward for the next match of the last regular expression
843: typed in a command.
844: (Not in command window.)
845: .TP
846: .B send
847: Send the text in dot, or the snarf buffer if
848: dot is the null string, as if it were typed to the command window.
849: Saves the sent text in the snarf buffer.
850: (Command window only.)
851: .TP
852: .B scroll
853: .TP
854: .B noscroll
855: Select whether to reveal automatically text
856: that appears off the end of the command window.
857: (Command window only.)
858: .PD
859: .SS Abnormal termination
860: If
861: .I sam
862: terminates other than by a
863: .B q
864: command (by hangup, deleting its layer, etc.), modified
865: files are saved in an
866: executable file,
867: .FR $HOME/sam.save .
868: This program, when executed, asks whether to write
869: each file back to a Unix file.
870: The answer
871: .L y
872: causes writing; anything else skips the file.
873: .SH FILES
874: .F $HOME/sam.save
875: .br
876: .F $HOME/sam.err
877: .SH SEE ALSO
878: .IR ed (1),
879: .IR sed (1),
880: .IR vi (1),
881: .IR gre (1)
882: .SH BUGS
883: The
884: .B u
885: command undoes characters\(emand backspaces\(emtyped directly
886: into a file window in unpredictable increments.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.