5 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
14 \%\&\\$3\f(CW\\$1\fP\&\\$2
19 \%\&\\$3\f(CI\\$1\fP\&\\$2
33 is an interactive text editor with a command language that makes heavy use
34 of regular expressions.
35 Although the language is syntactically similar to
37 the details are interestingly different.
38 This tutorial introduces the command language, but does not discuss
39 the screen and mouse interface.
40 With apologies to those unfamiliar with the Ninth Edition Blit software,
41 it is assumed that the similarity of
47 mouse language easy to learn.
51 command language applies identically to two environments:
54 on an ordinary terminal
57 and in the command window of a
60 that is, one using the bitmap display and mouse.
65 This tutorial describes the command language of
67 an interactive text editor that runs on Blits and
68 some computers with bitmap displays.
69 For most editing tasks, the mouse-based editing features
70 are sufficient, and they are easy to use and to learn.
72 The command language is often useful, however, particularly
73 when making global changes.
74 Unlike the commands in
76 which are necessary to make changes,
78 commands tend to be used
79 only for complicated or repetitive editing tasks.
80 It is in these more involved uses that
81 the differences between
83 and other text editors are most evident.
86 language makes it easy to do some things that other editors,
87 including programs like
91 do not handle gracefully, so this tutorial serves partly as a
94 manner of manipulating text.
95 The examples below therefore concentrate entirely on the language,
96 assuming that facility with the use of the mouse in
98 is at worst easy to pick up.
101 can be run without the mouse at all (not
105 flag, and it is this domain that the tutorial
106 occupies; the command language in these modes
109 A word to the Unix adept:
112 is syntactically very similar to
114 it is fundamentally and deliberately different in design and detailed semantics.
115 You might use knowledge of
117 to predict how the substitute command works,
118 but you'd only be right if you had used some understanding of
120 workings to influence your prediction.
121 Be particularly careful about idioms.
122 Idioms form in curious nooks of languages and depend on
123 undependable peculiarities.
125 idioms simply don't work in
128 makes one substitution in the whole file, not one per line.
131 Much of the purpose of this tutorial is to publish them
134 a matter of learning, not cunning.
136 The tutorial depends on familiarity with regular expressions, although
137 some experience with a more traditional Unix editor may be helpful.
138 To aid readers familiar with
140 I have pointed out in square brackets [] some of
141 the relevant differences between
145 Read these comments only if you wish
146 to understand the differences; the lesson is about
152 Another typographic convention is that output appears in
154 while typed input appears as
159 keeps a copy of the text it is editing.
160 This copy is called a
162 To avoid confusion, I have called the permanent storage on disc a
169 To get started, we need some text to play with.
170 Any text will do; try something from
171 James Gosling's Emacs manual:
175 This manual is organized in a rather haphazard manner. The first
176 several sections were written hastily in an attempt to provide a
177 general introduction to the commands in Emacs and to try to show
178 the method in the madness that is the Emacs command structure.
188 command adds text until a line containing just a period, and sets the
194 to what was typed \(em everything between the
198 would leave dot set to only the last line.]
201 command prints the current text:
204 This manual is organized in a rather haphazard manner. The first
205 several sections were written hastily in an attempt to provide a
206 general introduction to the commands in Emacs and to try to show
207 the method in the madness that is the Emacs command structure.
211 would print only the last line.]
214 command adds its text
234 command that changes (replaces) the current text,
237 that deletes it; these are illustrated below.
239 To see all the text, we can specify what text to print;
240 for the moment, suffice it to say that
242 specifies the entire file.
244 users would probably type
246 which in practice is the same thing, but see below.]
250 This manual is organized in a rather haphazard manner. The first
251 several sections were written hastily in an attempt to provide a
252 general introduction to the commands in Emacs and to try to show
253 the method in the madness that is the Emacs command structure.
257 command described below,
262 set dot to the text they touch.
267 set dot to the new text,
269 to the text printed, and so on.
270 Similarly, all commands
273 by default operate on the current
276 for which some commands (such as
278 default to the entire file].
280 Things are not going to get very interesting until we can
284 which specify a piece of the file.
287 for example, sets dot to the first line of the file.
297 command didn't need to specify dot; the
300 It's therefore easy to delete the first line utterly;
301 the last command left dot set to line one:
305 This manual is organized in a rather haphazard manner. The first
308 to reflect changes to the file.)
310 The address \f(CW/\f2text\f(CW/\f1
311 sets dot to the first appearance of
315 matches the first line containing
319 is not found, the search restarts at the beginning of the file
320 and continues until dot.
325 It's difficult to indicate typographically, but in this example no newline appears
328 the text to be printed is the string
333 may be left off \(em it is the default command.
334 When downloaded, however, the default is instead to select the text,
336 and to make it visible by moving the window on the file if necessary.
339 indicates on the display the next occurrence of the text.)
341 Imagine we wanted to change the word
345 Obviously, what's needed is another
347 command, but the method used so far to insert text includes a newline.
348 The syntax for including text without newlines is to surround the
349 text with slashes (which is the same as the syntax for
350 text searches, but what is going on should be clear from context).
351 The text must appear immediately after the
357 Given this, it is easy to make the required change:
359 .WC /haphazard/c/thoughtless/
361 This manual is organized in a rather thoughtless manner. The first
363 [Changes can always be done with a
365 command, even if the text is smaller than a line].
366 You'll find that this way of providing text to commands is much
367 more common than is the multiple-lines syntax.
368 If you want to include a slash
370 in the text, just precede it with a backslash
372 and use a backslash to protect a backslash itself.
374 .WC /Emacs/c/Emacs\e\e360/
376 general introduction to the commands in Emacs\e360 and to try to show
378 We could also make this particular change by
380 .WC /Emacs/a/\e\e360/
383 This is as good a place as any to introduce the
385 command, which undoes the last command.
388 will undo the penultimate command, and so on.
392 general introduction to the commands in Emacs and to try to show
395 This manual is organized in a rather haphazard manner. The first
397 Undoing can only back up; there is no way to undo a previous
402 We've seen the simplest forms of addresses, but there is more
403 to learn before we can get too much further.
404 An address selects a region in the file \(em a substring \(em
405 and therefore must define the beginning and the end of a region.
408 selects from the beginning of line thirteen to the end of line thirteen, and
410 selects from the beginning of the word
414 Addresses may be combined with a comma:
418 selects lines thirteen through fifteen. The definition of the comma
419 operator is to select from the beginning of the left hand address (the
420 beginning of line 13) to the end of the right hand address (the
423 A few special simple addresses come in handy:
425 (a period) represents dot, the current text,
427 (line zero) selects the null string at the beginning of the file, and
429 selects the null string at the end of the file
430 [not the last line of the file].
435 selects from the beginning of the file to the end of line thirteen,
439 selects from the beginning of the current text to the end of the file, and
443 selects the whole file [that is, a single string containing the whole file,
444 not a list of all the lines in the file].
448 addresses: they refer to specific places in the file.
450 also has relative addresses, which depend
452 and in fact we have already seen one form:
454 finds the first occurrence of
456 searching forwards from dot.
459 it finds depends on the value of dot.
460 What if you wanted the first occurrence
462 dot? Just precede the pattern with a minus sign, which reverses the direction
467 In fact, the complete syntax for forward searching is
471 but the plus sign is the default, and in practice is rarely used.
472 Here is an example that includes it for clarity:
476 selects the first occurrence of
478 in the file; read it as ``go to line 0, then search forwards for
482 is optional, this can be written
488 finds the last occurrence in the file, so
492 selects the text from the first to last
495 Slightly more interesting:
499 (there is an implicit
501 at the beginning) selects the second
505 Line numbers may also be relative.
509 selects the second previous line, and
513 selects the fifth following line (here the plus sign is obligatory).
515 Since addresses may select (and dot may be) more than one line,
516 we need a definition of `previous' and `following:'
521 of dot, and `following'
527 For example, if the file contains \f(CWA\f(CIAA\f(CWA\f1,
528 with dot set to the middle two
530 (the slanting characters),
532 sets dot to the first
538 Except under odd circumstances (such as when the only occurrence of the
539 text in the file is already the current text), the text selected by a
540 search will be disjoint from dot.
544 paragraph containing dot, however long it is, use
548 which will include the
550 that begins the paragraph, and exclude the one that ends it.
552 When typing relative line number addresses, the default number is
554 so the above could be written slightly more simply:
559 What does the address
563 mean? It looks like it does nothing, but recall that dot need not be a
564 complete line of text.
566 selects the line after the end of the current text, and
568 selects the line before the beginning. Therefore
570 selects the line before the line after the end of dot, that is,
571 the complete line containing the end of dot.
572 We can use this construction to expand a selection to include a complete line,
573 say the first line in the file containing
577 general introduction to the commands in Emacs and to try to show
585 Above, we changed one occurrence of
589 but if the name of the editor is really changing, it would be useful
592 instances of the name in a single command.
596 (extract), for just that job.
598 \f(CWx/\f2pattern\f(CW/\f2command\f1.
599 For each occurrence of the pattern in the selected text,
601 sets dot to the occurrence and runs command.
602 For example, to change
609 This manual is organized in a rather haphazard manner. The first
610 several sections were written hastily in an attempt to provide a
611 general introduction to the commands in vi and to try to show
612 the method in the madness that is the vi command structure.
615 works by subdividing the current text
617 \(em the whole file) into appearances of its textual argument
619 and then running the command that follows
621 with dot set to the text.
622 We can read this example as, ``find all occurrences of
624 in the file, and for each one,
625 set the current text to the occurrence and run the command
627 which will replace the current text by
629 [This command is somewhat similar to
632 command. The differences will develop below, but note that the
633 default address, as always, is dot rather than the whole file.]
637 command is sufficient to undo an
639 command, regardless of how many individual changes the
645 This manual is organized in a rather haphazard manner. The first
646 several sections were written hastily in an attempt to provide a
647 general introduction to the commands in Emacs and to try to show
648 the method in the madness that is the Emacs command structure.
653 is not the only command
657 command can be used to put proprietary markings on
660 .WC 0,$x/Emacs/a/{TM}/
662 general introduction to the commands in Emacs{TM} and to try to show
664 [There is no way to see the changes as they happen, as in
666 .CW g/Emacs/s//&{TM}/p ;
667 see the section on Multiple Changes, below.]
671 command is also useful when driven by an
673 but be careful that you say what you mean;
680 sets dot to the text in the slashes, printing only that text
681 is not going to be very
682 informative. But the command that
684 runs can contain addresses. For example, if we want to print all
691 general introduction to the commands in Emacs{TM} and to try to show
692 the method in the madness that is the Emacs{TM} command structure.
694 Finally, let's restore the state of the file with another
696 command, and make use of a handy shorthand:
697 a comma in an address has its left side default to
699 and its right side default to
701 so the easy-to-type address
703 refers to the whole file:
705 .WC ",x/Emacs/ /{TM}/d
707 This manual is organized in a rather haphazard manner. The first
708 several sections were written hastily in an attempt to provide a
709 general introduction to the commands in Emacs and to try to show
710 the method in the madness that is the Emacs command structure.
714 does: for each occurrence of Emacs,
717 that follows, and delete it.
722 for searches in addresses and in
724 commands is not simple text, but rather
725 .I regular\ expressions.
726 Unix has several distinct interpretations of regular expressions.
731 including parentheses
733 for grouping and an `or' operator
735 for matching strings in parallel.
737 makes two extensions:
740 (the most overloaded character in Unix) matches any character
742 newline, the regular expression
744 (think of it as a big dot) matches any character, even newlines;
745 and the character sequence
747 matches a newline character.
748 Replacement text, such as used in the
752 commands, is still plain text, but the sequence
754 represents newline in that context, too.
756 Here is an example. Say we wanted to double space the document, that is,
757 turn every newline into two newlines.
758 The following all do the job:
761 .WC ",x/\en/ c/\en\en/
765 The last example is slightly different, because it puts a newline
767 each line; the other examples place it after.
768 The first two examples manipulate newlines directly
772 use regular expressions:
774 is the empty string at the end of a line, while
776 is the empty string at the beginning.
778 These solutions all have a possible drawback: if there is already a blank line
779 (that is, two consecutive newlines), they make it much larger (four
780 consecutive newlines).
781 A better method is to extend every group of newlines by one:
785 The regular expression operator
792 takes every sequence of newlines and adds another
795 A more common example is indenting a block of text by a tab stop.
796 The following all work,
797 although the first is arguably the cleanest (the blank text in slashes is a tab):
803 The last example uses the pattern (idiom, really)
807 matches the longest possible string of non-newline characters.
808 Taking initial tabs away is just as easy:
812 In these examples I have specified an address (the whole file), but
813 in practice commands like these are more likely to be run without
814 an address, using the value of dot set by selecting text with the mouse.
820 command is a looping construct:
821 for each match of a regular expression,
822 it extracts (sets dot to) the match and runs a command.
824 also has a conditional,
826 \f(CWg/\f2pattern\f(CW/\f2command\f1
827 runs the command if dot contains a match of the pattern
829 without changing the value of dot.
833 runs the command if dot does
835 contain a match of the pattern.
840 are historical and have no mnemonic significance. You might
845 users should read the above definitions very carefully; the
849 is fundamentally different from that in
851 Here is an example of the difference between
858 changes each occurrence of the word
860 in the file to the word
872 anywhere in the file.
874 Neither of these commands is particularly interesting in isolation,
875 but they are valuable when combined with
881 One way to think about the
883 command is that, given a selection (a value of dot)
884 it iterates through interesting subselections (values of dot within).
885 In other words, it takes a piece of text and cuts it into smaller pieces.
886 But the text that it cuts up may already be a piece cut by a previous
888 command or selected by a
891 most interesting property is the ability to define a sequence of commands
892 to perform a particular task.\(dg
895 The obvious analogy with shell pipelines is only partially valid,
896 because the individual
898 commands are all working on the same text; it is only how the text is
899 sliced up that is changing.
901 A simple example is to change all occurrences of
905 certainly the command
907 .WC ",x/Emacs/ c/emacs/
909 will work, but we can use an
911 command to save retyping most of the word
914 .WC ",x/Emacs/ x/E/ c/e/
917 to separate commands on a line to make them easier to read.)
918 What this command does is find all occurrences of
923 with dot set to that text,
925 find all occurrences of the letter
930 with dot set to that text,
934 to change the character to lower case.
935 Note that the address for the command \(em the whole file, specified by a comma
936 \(em is only given to the leftmost
937 piece of the command; the rest of the pieces have dot set for them by
938 the execution of the pieces to their left.
940 As another simple example, consider a problem
941 solved above: printing all lines in the file containing the word
944 .WC ",x/.*\en/ g/Emacs/p
945 general introduction to the commands in Emacs and to try to show
946 the method in the madness that is the Emacs command structure.
948 This command says to break the file into lines
950 and for each line that contains the string
955 with dot set to the line (not the match of
957 which prints the line.
958 To save typing, because
960 is a common pattern in
965 is followed immediately by a space, the pattern
968 Therefore, the above could be written more succinctly:
972 The solution we used before was
976 which runs the command
978 with dot set to each match of
980 in the file (recall that the idiom
982 prints the line containing the end of dot).
984 The two commands usually produce the same result
987 form will print a line twice if it contains
989 twice). Which is better?
991 is easier to type and will be much faster if the file is large and
992 there are few occurrences of the string, but it is really an odd special case.
993 .CW ",x/.*\en/ g/Emacs/p
994 is slower \(em it breaks each line out separately, then examines
995 it for a match \(em but is conceptually cleaner, and generalizes more easily.
996 For example, consider the following piece of the Emacs manual:
998 command name="append-to-file", key="[unbound]"
999 Takes the contents of the current buffer and appends it to the
1000 named file. If the files doesn't exist, it will be created.
1002 command name="apropos", key="ESC-?"
1003 Prompts for a keyword and then prints a list of those commands
1004 whose short description contains that keyword. For example,
1005 if you forget which commands deal with windows, just type
1006 "@b[ESC-?]@t[window]@b[ESC]".
1010 This text consists of groups of non-empty lines, with a simple format
1011 for the text within each group.
1012 Imagine that we wanted to find the description of the `apropos'
1014 The problem is to break the file into individual descriptions,
1015 and then to find the description of `apropos' and to print it.
1016 The solution is straightforward:
1018 .WC ,x/(.+\en)+/\ g/command\ name="apropos"/p
1019 command name="apropos", key="ESC-?"
1020 Prompts for a keyword and then prints a list of those commands
1021 whose short description contains that keyword. For example,
1022 if you forget which commands deal with windows, just type
1023 "@b[ESC-?]@t[window]@b[ESC]".
1025 The regular expression
1027 matches one or more lines with one or more characters each, that is,
1028 the text between blank lines, so
1030 extracts each description; then
1031 .CW g/command\ name="apropos"/
1032 selects the description for `apropos' and
1036 Imagine that we had a C program containing the variable
1038 but we wanted to change it to
1040 This command is a first cut:
1044 but is obviously flawed: it will change all
1046 in the file, not just the
1049 A better solution is to use an
1051 command to extract the identifiers, and then use
1056 .WC ",x/[a-zA-Z_][a-zA-Z_0-9]*/ g/n/ v/../ c/num/
1058 It looks awful, but it's fairly easy to understand when read
1060 A C identifier is an alphabetic or underscore followed by zero or more
1061 alphanumerics or underscores, that is, matches of the regular expression
1062 .CW [a-zA-Z_][a-zA-Z_0-9]* .
1065 command selects those identifiers containing
1069 is a trick: it rejects those identifiers containing more than one
1070 character. Hence the
1072 applies only to free-standing
1075 There is still a problem here:
1076 we don't want to change
1078 that are part of the character constant
1084 that is just what we need:
1085 \f(CWy/\f2pattern\f(CW/\f2command\f1
1086 runs the command on the pieces of text
1088 matches of the pattern;
1094 Here is the final command:
1096 .WC ",y/\e\en/ x/[a-zA-Z_][a-zA-Z_0-9]*/ g/n/ v/../ c/num/
1100 (with backslash doubled to make it a literal character)
1101 removes the two-character sequence
1103 from consideration, so the rest of the command will not touch it.
1104 There is more we could do here; for example, another
1106 could be prefixed to protect comments in the code.
1107 I won't elaborate the example any further, but you should have
1108 an idea of the way in which the looping and conditional commands
1111 may be composed to do interesting things.
1115 There is another way to arrange commands.
1116 By enclosing them in brace brackets
1118 commands may be applied in parallel.
1119 This example uses the
1121 command, which reports the line and character numbers of dot,
1124 to report on appearances of
1126 in our original file:
1129 This manual is organized in a rather haphazard manner. The first
1130 several sections were written hastily in an attempt to provide a
1131 general introduction to the commands in Emacs and to try to show
1132 the method in the madness that is the Emacs command structure.
1140 general introduction to the commands in Emacs and to try to show
1142 the method in the madness that is the Emacs command structure.
1144 (The number before the semicolon is the line number;
1145 the numbers beginning with
1147 are character numbers.)
1148 As a more interesting example, consider changing all occurrences of
1152 and vice versa. We can type
1165 g/Emacs/ v/....../ c/vi/
1166 g/vi/ v/.../ c/Emacs/
1170 to make sure we don't change strings embedded in words.
1174 You might wonder why, once
1178 in the above example,
1179 the second command in the braces doesn't put it back again.
1180 The reason is that the commands are run in parallel:
1181 within any top-level
1183 command, all changes to the file refer to the state of the file
1184 before any of the changes in that command are made.
1185 After all the changes have been determined, they are all applied
1188 This means, as mentioned, that commands within a compound
1189 command see the state of the file before any of the changes apply.
1190 This method of evaluation makes some things easier (such as the exchange of
1194 and some things harder.
1195 For instance, it is impossible to use a
1197 command to print the changes as they happen,
1198 because they haven't happened when the
1201 An indirect ramification is that changes must occur in forward
1202 order through the file,
1203 and must not overlap.
1208 has a few commands to connect to Unix processes.
1211 which runs the command with input and output connected to the terminal.
1214 Wed May 28 23:25:21 EDT 1986
1217 (When downloaded, the input is connected to
1219 and only the first few lines of output are printed;
1220 any overflow is stored in
1221 .CW $HOME/sam.err .)
1224 is a prompt to indicate when the command completes.
1226 Slightly more interesting is
1228 which provides the current text as standard input to the Unix command:
1238 it replaces the current text with the standard output of the Unix command:
1243 Wed May 28 23:26:44 EDT 1986
1247 which is a combination of
1251 the current text is provided as standard input to the Unix command,
1252 and the Unix command's standard output is collected and used to
1253 replace the original text.
1260 on the file, sorting the lines of the text lexicographically.
1268 commands, not Unix shell operators.
1270 The next example converts all appearances of
1275 .WC ",x/Emacs/ | tr a-z A-Z
1278 is run once for each occurrence of
1280 Of course, you could do this example more efficiently with a simple
1282 command, but here's a trickier one:
1283 given a Unix mail box as input,
1286 headers to distinct fortunes:
1288 .WC ",x/^Subject:.*\en/ x/[^:]*\en/ < /usr/games/fortune
1290 (The regular expression
1292 refers to any character
1295 and newline; the negation operator
1297 excludes newline from the list of characters.)
1299 .CW /usr/games/fortune
1300 is run once for each
1304 line is changed to a different fortune.
1306 A few other text commands
1308 For completeness, I should mention three other commands that
1309 manipulate text. The
1311 command moves the current text to after the text specified by the
1312 (obligatory) address after the command.
1317 moves the next line containing
1319 to the beginning of the file.
1322 (another historic character) copies the text:
1326 would make, at the beginning of the file, a copy of the next line
1330 The third command is more interesting: it makes substitutions.
1332 \f(CWs/\f2pattern\f(CW/\f2replacement\f(CW/\f1.
1333 Within the current text, it finds the first occurrence of
1334 the pattern and replaces it by the replacement text,
1335 leaving dot set to the entire address of the substitution.
1338 This manual is organized in a rather haphazard manner. The first
1339 .WC s/haphazard/thoughtless/
1341 This manual is organized in a rather thoughtless manner. The first
1343 Occurrences of the character
1345 in the replacement text stand for the text matching the pattern.
1349 "TTTT"his manual is organized in a rather thoughtless manner. The first
1351 There are two variants. The first is that a number may be specified
1354 to indicate which occurrence of the pattern to substitute; the default
1359 "TTTT"his manual was organized in a rather thoughtless manner. The first
1361 The second is that suffixing a
1363 (global) causes replacement of all occurrences, not just the first.
1367 "xxxx"xxx xxxxxx xxx xxxxxxxxx xx x xxxxxx xxxxxxxxxxx xxxxxxx xxx xxxxx
1369 Notice that in all these examples
1371 set to the entire line.
1373 [The substitute command is vital to
1375 because it is the only way to make changes within a line.
1376 It is less valuable in
1378 in which the concept of a line is much less important.
1381 substitution idioms are handled well by
1383 basic commands. Consider the commands
1389 which are equivalent in
1397 and for which the context search is likely unnecessary because the desired
1398 text is already dot.
1405 which changes the first
1407 on each line; the same command in
1409 will only change the first one in the whole file.
1416 but what is more likely meant is
1421 operates under different rules.]
1425 So far, we have only been working with a single file,
1428 is a multi-file editor.
1429 Only one file may be edited at a time, but
1430 it is easy to change which file is the `current' file for editing.
1431 To see how to do this, we need a
1434 the easiest way to do this is to start it
1435 with a list of Unix file names to edit.
1437 $ \f(CIecho *.ms\f(CW
1438 conquest.ms death.ms emacs.ms famine.ms slaughter.ms
1439 $ \f(CIsam -d *.ms\f(CW
1442 (I'm sorry the Horsemen don't appear in liturgical order.)
1445 is an indication that the Unix file
1447 has been read, and is now the current file.
1449 does not read the Unix file until
1452 file becomes current.
1456 command prints the names of all the files:
1465 This list is also available in the menu on mouse button 3.
1468 tells the name of just the current file:
1473 The characters to the left of the file name encode helpful information about
1475 The minus sign becomes a plus sign if the file has a window open, and an
1476 asterisk if more than one is open.
1477 The period (another meaning of dot) identifies the current file.
1478 The leading blank changes to an apostrophe if the file is different
1479 from the contents of the associated Unix file, as far as
1482 This becomes evident if we make a change.
1488 If the file is restored by an undo command, the apostrophe disappears.
1494 The file name may be changed by providing a new name with the
1498 .CW "f pestilence.ms
1502 prints the new status of the file,
1503 that is, it changes the name if one is provided, and prints the
1505 A file name change may also be undone.
1514 is downloaded, the current file may be changed simply by selecting
1515 the desired file from the menu (selecting the same file subsequently
1516 cycles through the windows opened on the file).
1519 command can be used to choose the desired file:\(dg
1521 \(dg A bug prevents the
1523 command from working when downloaded.
1524 Because the menu is more convenient anyway, and
1526 of choosing files from the command language is slated to change,
1527 the bug hasn't been fixed.
1535 prints the name (actually, executes an implicit
1537 command) because the Unix file
1539 is being read for the first time.
1540 It is an error to ask for a file
1542 doesn't know about, but the
1546 menu with a new file, and make it current.
1549 ?no such file `flood.pic'
1564 will accept a list of file names.
1566 simply takes the first file in the list, but
1569 The list may be typed on one line \(em
1571 .WC "B devil.tex satan.tex 666.tex emacs.tex
1573 \(em or generated by a Unix command \(em
1577 The latter form requires a Unix command;
1579 does not understand the shell file name metacharacters, so
1581 attempts to load a single file named
1585 form is of course derived from
1590 is not the only useful command to run subservient to
1594 .WC "B <grep -l Emacs *
1596 will load only those files containing the string
1598 Finally, a special case: a
1600 with no arguments creates an empty, nameless file within
1608 .WC "D devil.tex satan.tex 666.tex emacs.tex
1610 eradicates the files from
1612 memory (not from the Unix machine's disc).
1614 without any file names removes the current file from
1617 There are three other commands that relate the current file
1621 command writes the file to disc;
1622 without arguments, it writes the entire file to the Unix file associated
1623 with the current file in
1625 (it is the only command whose default address is not dot).
1626 Of course, you can specify an address to be written,
1627 and a different file name, with the obvious syntax:
1629 .WC "1,2w /tmp/revelations
1630 /tmp/revelations: #44
1633 responds with the file name and the number of characters written to the file.
1636 command on the button 3 menu is identical in function to an unadorned
1640 The other two commands,
1644 read data from Unix files.
1647 command clears out the current file,
1648 reads the data from the named file (or uses the current file's old name if
1649 none is explicitly provided), and sets the file name.
1652 command, but puts the information in the current file instead of a new one.
1654 without any file name is therefore an easy way to refresh
1656 copy of a Unix file.
1660 doesn't complain if the file is modified. The principle is not
1661 to protect against things that can be undone if wrong.]
1662 Since its job is to replace the whole text,
1664 never takes an address.
1670 but it doesn't clear the file:
1671 the text in the Unix file replaces dot, or the specified text if an
1676 has essentially the effect of
1684 will set the name of the file if the current file has no name already defined;
1686 sets the name even if the file already has one.
1688 There is a command, analogous to
1690 that iterates over files instead of pieces of text:
1694 The syntax is easy; it's just like that of
1696 \(em \f(CWX/\f2pattern\f(CW/\f2command\f1.
1697 (The complementary command is
1701 The effect is to run the command in each file whose menu entry
1702 (that is, whose line printed by an
1704 command) matches the pattern.
1705 For example, since an apostrophe identifies modified files,
1709 writes the changed files out to disc.
1710 Here is a longer example: find all uses of a particular variable
1711 in the C source files:
1713 .WC "X/\e.c$/ ,x/variable/+-p
1717 command to identify which file the variable appears in:
1720 X/\e.c$/ ,g/variable/ {
1731 command guarantees that only the names of files containing the variable
1732 will be printed (but beware that
1734 may confuse matters by printing the names of files it reads in during
1738 command shows where in the file the variable appears, and the
1740 command prints the line.
1744 command is handy as the target of an
1746 This example deletes from the menu all C files that do not contain
1747 a particular variable:
1749 .WC "X/\e.c$/ ,v/variable/ D
1751 If no pattern is provided for the
1753 the command (which defaults to
1755 is run in all files, so
1761 up for a fresh start.
1763 But rather than working any further, let's stop now:
1770 Some of the file manipulating commands can be undone:
1776 restores the previous state of the file,
1783 And, of course, so is