update.
[chise/xemacs-chise.git.1] / etc / TUTORIAL
1 Copyright (c) 1985, 1996 Free Software Foundation, Inc. See end for conditions.
2
3 You are looking at the Emacs tutorial.
4
5 Emacs commands generally involve the CONTROL key (sometimes labelled
6 CTRL or CTL) or the META key.  On some keyboards, the META key is
7 labelled ALT or EDIT or something else (for example, on Sun keyboards,
8 the diamond key to the left of the spacebar is META).  If you have no
9 META key, you can use ESC instead.  Rather than write out META or
10 CONTROL each time we want you to prefix a character, we'll use the
11 following abbreviations:
12
13  C-<chr>  means hold the CONTROL key while typing the character <chr>
14           Thus, C-f would be: hold the CONTROL key and type f.
15  M-<chr>  means hold the META key down while typing <chr>.  If there
16           is no META key, type <ESC>, release it, then type the
17           character <chr>.
18
19 Important note: to end the Emacs session, type C-x C-c.  (Two characters.)
20 The characters ">>" at the left margin indicate directions for you to
21 try using a command.  For instance:
22 <<Middle of page left blank for didactic purposes. Text continues below.>>
23 >>  Now type C-v (View next screen) to move to the next screen.
24         (go ahead, do it by holding down the control key while typing v).
25         From now on, you should do this again whenever you finish
26         reading the screen.
27
28 Note that there is an overlap of two lines when you move from screen
29 to screen; this provides some continuity so you can continue reading
30 the text.
31
32 The first thing that you need to know is how to move around from place
33 to place in the text.  You already know how to move forward one screen,
34 with C-v.  To move backwards one screen, type M-v (hold down the META key
35 and type v, or type <ESC>v if you do not have a META, EDIT, or ALT key).
36
37 >>  Try typing M-v and then C-v, a few times.
38
39
40 * SUMMARY
41 ---------
42
43 The following commands are useful for viewing screenfuls:
44
45         C-v     Move forward one screenful
46         M-v     Move backward one screenful
47         C-l     Clear screen and redisplay everything
48                  putting the text near the cursor at the center.
49                  (That's control-L, not control-1.)
50
51 >> Find the cursor, and note what text is near it.
52    Then type C-l.
53    Find the cursor again and notice that the same text
54    is near the cursor now.
55
56
57 * BASIC CURSOR CONTROL
58 ----------------------
59
60 Moving from screenful to screenful is useful, but how do you
61 move to a specific place within the text on the screen?
62
63 There are several ways you can do this.  The most basic way is to use
64 the commands C-p, C-b, C-f, and C-n.  Each of these commands moves the
65 cursor one row or column in a particular direction on the screen.
66 Here is a table showing these four commands and shows the directions
67 they move:
68  
69                           Previous line, C-p
70                                   :
71                                   :
72    Backward, C-b .... Current cursor position .... Forward, C-f
73                                   :
74                                   :
75                             Next line, C-n
76
77 >> Move the cursor to the line in the middle of that diagram
78    using C-n or C-p.  Then type C-l to see the whole diagram
79    centered in the screen.
80
81 You'll probably find it easy to think of these by letter: P for
82 previous, N for next, B for backward and F for forward.  These are the
83 basic cursor positioning commands, and you'll be using them ALL the
84 time, so it would be of great benefit if you learn them now.
85
86 >> Do a few C-n's to bring the cursor down to this line.
87
88 >> Move into the line with C-f's and then up with C-p's.
89    See what C-p does when the cursor is in the middle of the line.
90
91 Each line of text ends with a Newline character, which serves to
92 separate it from the following line.  The last line in your file ought
93 to have a Newline at the end (but Emacs does not require it to have
94 one).
95
96 >> Try to C-b at the beginning of a line.  It should move to
97    the end of the previous line.  This is because it moves back
98    across the Newline character.
99
100 C-f can move across a Newline just like C-b.
101
102 >> Do a few more C-b's, so you get a feel for where the cursor is.
103    Then do C-f's to return to the end of the line.
104    Then do one more C-f to move to the following line.
105
106 When you move past the top or bottom of the screen, the text beyond
107 the edge shifts onto the screen.  This is called "scrolling".  It
108 enables Emacs to move the cursor to the specified place in the text
109 without moving it off the screen.
110
111 >> Try to move the cursor off the bottom of the screen with C-n, and
112    see what happens.
113
114 If moving by characters is too slow, you can move by words.  M-f
115 (Meta-f) moves forward a word and M-b moves back a word.
116
117 >> Type a few M-f's and M-b's.
118
119 When you are in the middle of a word, M-f moves to the end of the word.
120 When you are in whitespace between words, M-f moves to the end of the
121 following word.  M-b works likewise in the opposite direction.
122
123 >> Type M-f and M-b a few times, interspersed with C-f's and C-b's
124    so that you can observe the action of M-f and M-b from various
125    places inside and between words.
126
127 Notice the parallel between C-f and C-b on the one hand, and M-f and
128 M-b on the other hand.  Very often Meta characters are used for
129 operations related to the units defined by language (words, sentences,
130 paragraphs), while Control characters operate on basic units that are
131 independent of what you are editing (characters, lines, etc).
132
133 This parallel applies between lines and sentences: C-a and C-e move to
134 the beginning or end of a line, and M-a and M-e move to the beginning
135 or end of a sentence.
136
137 >> Try a couple of C-a's, and then a couple of C-e's.
138    Try a couple of M-a's, and then a couple of M-e's.
139
140 See how repeated C-a's do nothing, but repeated M-a's keep moving one
141 more sentence.  Although these are not quite analogous, each one seems
142 natural.
143
144 The location of the cursor in the text is also called "point".  To
145 paraphrase, the cursor shows on the screen where point is located in
146 the text.
147
148 Here is a summary of simple cursor-moving operations, including the
149 word and sentence moving commands:
150
151         C-f     Move forward a character
152         C-b     Move backward a character
153
154         M-f     Move forward a word
155         M-b     Move backward a word
156
157         C-n     Move to next line
158         C-p     Move to previous line
159
160         C-a     Move to beginning of line
161         C-e     Move to end of line
162
163         M-a     Move back to beginning of sentence
164         M-e     Move forward to end of sentence
165
166 >> Try all of these commands now a few times for practice.
167    These are the most often used commands.
168
169 Two other important cursor motion commands are M-< (Meta Less-than),
170 which moves to the beginning of the whole text, and M-> (Meta
171 Greater-than), which moves to the end of the whole text.
172
173 On most terminals, the "<" is above the comma, so you must use the
174 shift key to type it.  On these terminals you must use the shift key
175 to type M-< also; without the shift key, you would be typing M-comma.
176
177 >> Try M-< now, to move to the beginning of the tutorial.
178    Then use C-v repeatedly to move back here.
179
180 >> Try M-> now, to move to the end of the tutorial.
181    Then use M-v repeatedly to move back here.
182
183 You can also move the cursor with the arrow keys, if your terminal has
184 arrow keys.  We recommend learning C-b, C-f, C-n and C-p for three
185 reasons.  First, they work on all kinds of terminals.  Second, once
186 you gain practice at using Emacs, you will find that typing these CTRL
187 characters is faster than typing the arrow keys (because you do not
188 have to move your hands away from touch-typing position).  Third, once
189 you form the habit of using these CTRL character commands, you can
190 easily learn to use other advanced cursor motion commands as well.
191
192 Most Emacs commands accept a numeric argument; for most commands, this
193 serves as a repeat-count.  The way you give a command a repeat count
194 is by typing C-u and then the digits before you type the command.  If
195 you have a META (or EDIT or ALT) key, there is another alternative way
196 to enter a numeric argument: type the digits while holding down the
197 META key.  We recommend learning the C-u method because it works on
198 any terminal.
199
200 For instance, C-u 8 C-f moves forward eight characters.
201         
202 >> Try using C-n or C-p with a numeric argument, to move the cursor
203    to a line near this one with just one command.
204
205 Most commands use the numeric argument as a repeat count.  Certain
206 exceptional commands use it differently.  C-v and M-v are among the
207 exceptions.  When given an argument, they scroll the screen up or down
208 by that many lines, rather than by a screenfuls.  For example, C-u 4
209 C-v scrolls the screen by 4 lines.
210
211 >> Try typing C-u 8 C-v now.
212
213 This should have scrolled the screen up by 8 lines.  If you would like
214 to scroll it down again, you can give an argument to M-v.
215
216 If you are using the X Window system, there is probably a rectangular
217 area called a scroll bar at the right hand side of the Emacs window.
218 You can scroll the text by manipulating the scroll bar with the mouse.
219
220 >> Try pressing the middle button at the top of the highlighted area
221    within the scroll bar.  This should scroll the text to a position
222    determined by how high or low you click.
223
224 >> Move the mouse to a point in the scroll bar about three lines from
225 the top, and click the left button a couple of times.
226
227
228 * CURSOR CONTROL WITH AN X TERMINAL
229 -----------------------------------
230
231 If you have an X terminal, you will probably find it easier to use
232 the keys on the keypad to control the cursor.  The left, right, up,
233 and down arrow keys move in the expected direction; they function
234 exactly like C-b, C-f, C-p, and C-n, but are easier to type and to
235 remember.  You can also use C-left and C-right to move by words, and
236 C-up and C-down to move by blocks (e.g.  paragraphs, if you're
237 editing text).  If you have keys labelled HOME (or BEGIN) and END,
238 they will take you to the beginning and end of a line, respectively,
239 and C-home and C-end will move to the beginning and end of the file.
240 If your keyboard has PgUp and PgDn keys, you can use them to move up
241 and down a screenful at a time, like M-v and C-v.
242
243 All of these commands can take numeric arguments, as described above.
244 You can use a shortcut to enter these arguments: just hold down the
245 CONTROL or META key and type the number. For example, to move 12
246 words to the right, type C-1 C-2 C-right.  Note that it is very easy
247 to type this because you do not have to release the CONTROL key
248 between keystrokes.
249
250
251 * WHEN EMACS IS HUNG
252 --------------------
253
254 If Emacs stops responding to your commands, you can stop it safely by
255 typing C-g.  You can use C-g to stop a command which is taking too
256 long to execute.
257
258 You can also use C-g to discard a numeric argument or the beginning of
259 a command that you do not want to finish.
260
261 >> Type C-u 100 to make a numeric arg of 100, then type C-g.
262    Now type C-f.  It should move just one character,
263    because you canceled the argument with C-g.
264
265 If you have typed an <ESC> by mistake, you can get rid of it
266 with a C-g.
267
268
269 * DISABLED COMMANDS
270 -------------------
271
272 Some Emacs commands are "disabled" so that beginning users cannot use
273 them by accident.
274
275 If you type one of the disabled commands, Emacs displays a message
276 saying what the command was, and asking you whether you want to go
277 ahead and execute the command.
278
279 If you really want to try the command, type Space in answer to the
280 question.  Normally, if you do not want to execute the disabled
281 command, answer the question with "n".
282
283 >> Type `C-x n p' (which is a disabled command),
284    then type n to answer the question.
285
286
287 * WINDOWS
288 ---------
289
290 Emacs can have several windows, each displaying its own text.
291 Note that "window" as used by Emacs does not refer to separate
292 overlapping windows in the window system, but to separate panes
293 within a single X window. (Emacs can also have multiple X
294 windows, or "frames" in Emacs terminology.  This is described
295 later.)
296
297 At this stage it is better not to go into the techniques of
298 using multiple windows.  But you do need to know how to get
299 rid of extra windows that may appear to display help or
300 output from certain commands.  It is simple:
301
302         C-x 1   One window (i.e., kill all other windows).
303
304 That is Control-x followed by the digit 1.  C-x 1 expands the window
305 which contains the cursor, to occupy the full screen.  It deletes all
306 other windows.
307
308 >> Move the cursor to this line and type C-u 0 C-l.
309
310 (Remember that C-l redraws the screen.  If you give a
311 numeric argument to this command, it means "redraw the
312 screen and put the current line that many lines from the
313 top of the screen."  So C-u 0 C-l means "redraw the
314 screen, putting the current line at the top.")
315
316 >> Type Control-x 2
317    See how this window shrinks, while a new one appears
318    to display contents of this buffer.
319
320 >> Type C-x 1 and see the new window disappear.
321
322
323 * INSERTING AND DELETING
324 ------------------------
325
326 If you want to insert text, just type the text.  Characters which you
327 can see, such as A, 7, *, etc. are taken by Emacs as text and inserted
328 immediately.  Type <Return> (the carriage-return key) to insert a
329 Newline character.
330
331 You can delete the last character you typed by typing <Delete>.
332 <Delete> is a key on the keyboard, which may be labeled "Del".  In
333 some cases, the "Backspace" key serves as <Delete>, but not always!
334
335 More generally, <Delete> deletes the character immediately before the
336 current cursor position.
337
338 >> Do this now--type a few characters, then delete them
339    by typing <Delete> a few times.  Don't worry about this file
340    being changed; you will not alter the master tutorial.  This is
341    your personal copy of it.
342
343 When a line of text gets too big for one line on the screen, the line
344 of text is "continued" onto a second screen line.  A backslash ("\")
345 at the right margin indicates a line which has been continued.
346
347 >> Insert text until you reach the right margin, and keep on inserting.
348    You'll see a continuation line appear.
349
350 >> Use <Delete>s to delete the text until the line fits on one screen
351    line again.  The continuation line goes away.
352
353 You can delete a Newline character just like any other character.
354 Deleting the Newline character between two lines merges them into
355 one line.  If the resulting combined line is too long to fit in the
356 screen width, it will be displayed with a continuation line.
357
358 >> Move the cursor to the beginning of a line and type <Delete>.  This
359    merges that line with the previous line.
360
361 >> Type <Return> to reinsert the Newline you deleted.
362
363 Remember that most Emacs commands can be given a repeat count;
364 this includes text characters.  Repeating a text character inserts
365 it several times.
366
367 >>  Try that now -- type C-u 8 * to insert ********.
368
369 You've now learned the most basic way of typing something in
370 Emacs and correcting errors.  You can delete by words or lines
371 as well.  Here is a summary of the delete operations:
372
373         <Delete>     delete the character just before the cursor
374         C-d          delete the next character after the cursor
375
376         M-<Delete>   kill the word immediately before the cursor
377         M-d          kill the next word after the cursor
378
379         C-k          kill from the cursor position to end of line
380         M-k          kill to the end of the current sentence
381
382 Notice that <Delete> and C-d vs M-<Delete> and M-d extend the parallel
383 started by C-f and M-f (well, <Delete> is not really a control
384 character, but let's not worry about that).  C-k and M-k are like C-e
385 and M-e, sort of, in that lines are opposite sentences.
386
387 When you delete more than one character at a time, Emacs saves the
388 deleted text so that you can bring it back.  Bringing back killed text
389 is called "yanking".  You can yank the killed text either at the same
390 place where it was killed, or at some other place in the text.  You
391 can yank the text several times in order to make multiple copies of
392 it.  The command to yank is C-y.
393
394 Note that the difference between "Killing" and "Deleting" something is
395 that "Killed" things can be yanked back, and "Deleted" things cannot.
396 Generally, the commands that can remove a lot of text save the text,
397 while the commands that delete just one character, or just blank lines
398 and spaces, do not save the deleted text.
399
400 >> Move the cursor to the  beginning of a line which is not empty.
401    Then type C-k to kill the text on that line.
402 >> Type C-k a second time.  You'll see that it kills the Newline
403    which follows that line.
404
405 Note that a single C-k kills the contents of the line, and a second
406 C-k kills the line itself, and make all the other lines move up.  C-k
407 treats a numeric argument specially: it kills that many lines AND
408 their contents.  This is not mere repetition.  C-u 2 C-k kills two
409 lines and their newlines; typing C-k twice would not do that.
410
411 To retrieve the last killed text and put it where the cursor currently
412 is, type C-y.
413
414 >> Try it; type C-y to yank the text back.
415
416 Think of C-y as if you were yanking something back that someone took
417 away from you.  Notice that if you do several C-k's in a row, all of
418 the killed text is saved together, so that one C-y will yank all of
419 the lines.
420
421 >> Do this now, type C-k several times.
422
423 Now to retrieve that killed text:
424
425 >> Type C-y.  Then move the cursor down a few lines and type C-y
426    again.  You now see how to copy some text.
427
428 What do you do if you have some text you want to yank back, and then
429 you kill something else?  C-y would yank the more recent kill.  But
430 the previous text is not lost.  You can get back to it using the M-y
431 command.  After you have done C-y to get the most recent kill, typing
432 M-y replaces that yanked text with the previous kill.  Typing M-y
433 again and again brings in earlier and earlier kills.  When you have
434 reached the text you are looking for, you do not have to do anything to
435 keep it.  Just go on with your editing, leaving the yanked text where
436 it is.
437
438 If you M-y enough times, you come back to the starting point (the most
439 recent kill).
440
441 >> Kill a line, move around, kill another line.
442    Then do C-y to get back the second killed line.
443    Then do M-y and it will be replaced by the first killed line.
444    Do more M-y's and see what you get.  Keep doing them until
445    the second kill line comes back, and then a few more.
446    If you like, you can try giving M-y positive and negative
447    arguments.
448
449
450 * UNDO
451 ------
452
453 If you make a change to the text, and then decide that it was a
454 mistake, you can undo the change with the undo command, C-x u.
455
456 Normally, C-x u undoes the changes made by one command; if you repeat
457 the C-x u several times in a row, each repetition undoes one
458 additional command.
459
460 But there are two exceptions: commands that do not change the text do
461 not count (this includes cursor motion commands and scrolling
462 command), and self-inserting characters are usually handled in groups
463 of up to 20.  (This is to reduce the number of C-x u's you have to
464 type to undo insertion of text.)
465
466 >> Kill this line with C-k, then type C-x u and it should reappear.
467
468 C-_ is an alternative undo command; it works just the same as C-x u,
469 but it is easier to type several times in a row.  The disadvantage of
470 C-_ is that on some keyboards it is not obvious how to type it.  That
471 is why we provide C-x u as well.  On some terminals, you can type C-_
472 by typing / while holding down CTRL.
473
474 A numeric argument to C-_ or C-x u acts as a repeat count.
475
476
477 * FILES
478 -------
479
480 In order to make the text you edit permanent, you must put it in a
481 file.  Otherwise, it will go away when your invocation of Emacs goes
482 away.  You put your editing in a file by "finding" the file.  (This is
483 also called "visiting" the file.)
484
485 Finding a file means that you see the contents of the file within
486 Emacs.  In many ways, it is as if you were editing the file itself.
487 However, the changes you make using Emacs do not become permanent
488 until you "save" the file.  This is so you can avoid leaving a
489 half-changed file on the system when you do not want to.  Even when
490 you save, Emacs leaves the original file under a changed name in case
491 you later decide that your changes were a mistake.
492
493 If you look near the bottom of the screen you will see a line that
494 begins and ends with dashes, and contains the string "Emacs:
495 TUTORIAL".  This part of the screen always shows the name of the file
496 that you are visiting.  Right now, you are visiting a file called
497 "TUTORIAL" which is your personal scratch copy of the Emacs tutorial.
498 Whatever file you find, that file's name will appear in that precise
499 spot.
500
501 The commands for finding and saving files are unlike the other
502 commands you have learned in that they consist of two characters.
503 They both start with the character Control-x.  There is a whole series
504 of commands that start with Control-x; many of them have to do with
505 files, buffers, and related things.  These commands are two, three or
506 four characters long.
507
508 Another thing about the command for finding a file is that you have
509 to say what file name you want.  We say the command "reads an argument
510 from the terminal" (in this case, the argument is the name of the
511 file).  After you type the command
512
513         C-x C-f   Find a file
514
515 Emacs asks you to type the file name.  The file name you type appears
516 on the bottom line of the screen.  The bottom line is called the
517 minibuffer when it is used for this sort of input.  You can use
518 ordinary Emacs editing commands to edit the file name.
519
520 While you are entering the file name (or any minibuffer input),
521 you can cancel the command with C-g.
522
523 >> Type C-x C-f, then type C-g.  This cancels the minibuffer,
524    and also cancels the C-x C-f command that was using the
525    minibuffer.  So you do not find any file.
526
527 When you have finished entering the file name, type <Return> to
528 terminate it.  Then C-x C-f command goes to work, and finds the file
529 you chose.  The minibuffer disappears when the C-x C-f command is
530 finished.
531
532 In a little while the file contents appear on the screen, and you can
533 edit the contents.  When you wish to make your changes permanent,
534 type the command
535
536         C-x C-s   Save the file
537
538 This copies the text within Emacs into the file.  The first time you
539 do this, Emacs renames the original file to a new name so that it is
540 not lost.  The new name is made by adding "~" to the end of the
541 original file's name.
542
543 When saving is finished, Emacs prints the name of the file written.
544 You should save fairly often, so that you will not lose very much
545 work if the system should crash.
546
547 >> Type C-x C-s, saving your copy of the tutorial.
548    This should print "Wrote ...TUTORIAL" at the bottom of the screen.
549
550 NOTE: On some systems, typing C-x C-s will freeze the screen and you
551 will see no further output from Emacs.  This indicates that an
552 operating system "feature" called "flow control" is intercepting the
553 C-s and not letting it get through to Emacs.  To unfreeze the screen,
554 type C-q.  Then see the section "Spontaneous Entry to Incremental
555 Search" in the Emacs manual for advice on dealing with this "feature".
556
557 You can find an existing file, to view it or edit it.  You can also
558 find a file which does not already exist.  This is the way to create a
559 file with Emacs: find the file, which will start out empty, and then
560 begin inserting the text for the file.  When you ask to "save" the
561 file, Emacs will really create the file with the text that you have
562 inserted.  From then on, you can consider yourself to be editing an
563 already existing file.
564
565
566 * BUFFERS
567 ---------
568
569 If you find a second file with C-x C-f, the first file remains
570 inside Emacs.  You can switch back to it by finding it again with
571 C-x C-f.  This way you can get quite a number of files inside Emacs.
572
573 >> Create a file named "foo" by typing  C-x C-f foo <Return>.
574    Then insert some text, edit it, and save "foo" by typing  C-x C-s.
575    Finally, type C-x C-f TUTORIAL <Return>
576    to come back to the tutorial.
577
578 Emacs stores each file's text inside an object called a "buffer."
579 Finding a file makes a new buffer inside Emacs.  To see a list of the
580 buffers that currently exist in your Emacs job, type
581
582         C-x C-b   List buffers
583
584 >> Try C-x C-b now.
585
586 See how each buffer has a name, and it may also have a file name
587 for the file whose contents it holds.  Some buffers do not correspond
588 to files.  For example, the buffer named "*Buffer List*" does
589 not have any file.  It is the buffer which contains the buffer
590 list that was made by C-x C-b.  ANY text you see in an Emacs window
591 is always part of some buffer.
592
593 >> Type C-x 1 to get rid of the buffer list.
594
595 If you make changes to the text of one file, then find another file,
596 this does not save the first file.  Its changes remain inside Emacs,
597 in that file's buffer.  The creation or editing of the second file's
598 buffer has no effect on the first file's buffer.  This is very useful,
599 but it also means that you need a convenient way to save the first
600 file's buffer.  It would be a nuisance to have to switch back to
601 it with C-x C-f in order to save it with C-x C-s.  So we have
602
603         C-x s     Save some buffers
604
605 C-x s asks you about each buffer which contains changes that you have
606 not saved.  It asks you, for each such buffer, whether to save the
607 buffer.
608
609 >> Insert a line of text, then type C-x s.
610    It should ask you whether to save the buffer named TUTORIAL.
611    Answer yes to the question by typing "y".
612
613 * USING THE MENU
614 ----------------
615
616 If you are on an X terminal, you will notice a menubar at the
617 top of the Emacs screen.  You can use this menubar to access all
618 the most common Emacs commands, such as "find file".  You will
619 find this easier at first, because you don't need to remember
620 the keystrokes necessary to access any particular command.  Once
621 you are comfortable with Emacs, it will be easy to begin using
622 the keyboard commands because each menu item with a
623 corresponding keyboard command has the command listed next to
624 it.
625
626 Note that there are many items in the menubar that have no exact
627 keyboard equivalents.  For example, the Buffers menu lists all
628 of the available buffers in most-recently used order.  You can
629 switch to any buffer by simply findings its name in the Buffers
630 menu and selecting it.
631
632
633 * USING THE MOUSE
634 -----------------
635
636 When running under X, Emacs is fully integrated with the mouse.
637 You can position the text cursor by clicking the left button at
638 the desired location, and you can select text by dragging the
639 left mouse button across the text you want to select. (Or
640 alternatively, click the left mouse button at one end of the
641 text, then move to the other end and use Shift-click to select
642 the text.)
643
644 To kill some selected text, you can use C-w or choose the Cut
645 item from the Edit menu.  Note that these are *not* equivalent:
646 C-w only saves the text internally within Emacs (similar to C-k
647 as described above), whereas Cut does this and also puts the
648 text into the X clipboard, where it can be accessed by other
649 applications.
650
651 To retrieve text from the X clipboard, use the Paste item from
652 the Edit menu.
653
654 The middle mouse button is commonly used to choose items that
655 are visible on the screen.  For example, if you enter Info (the
656 on-line Emacs documentation) using C-h i or the Help menu, you
657 can follow a highlighted link by clicking the middle mouse
658 button on it.  Similarly, if you are typing a file name in
659 (e.g. when prompted by "Find File") and you hit TAB to show the
660 possible completions, you can click the middle mouse button on
661 one of the completions to select it.
662
663 The right mouse button brings up a popup menu.  The contents of
664 this menu vary depending on what mode you're in, and usually
665 contain a few commonly used commands, so they're easier to
666 access.
667
668 >> Press the right mouse button now.
669
670 You will have to hold the button down in order to keep the
671 menu up.
672
673
674 * EXTENDING THE COMMAND SET
675 ---------------------------
676
677 There are many, many more Emacs commands than could possibly be put
678 on all the control and meta characters.  Emacs gets around this with
679 the X (eXtend) command.  This comes in two flavors:
680
681         C-x     Character eXtend.  Followed by one character.
682         M-x     Named command eXtend.  Followed by a long name.
683
684 These are commands that are generally useful but used less than the
685 commands you have already learned about.  You have already seen two of
686 them: the file commands C-x C-f to Find and C-x C-s to Save.  Another
687 example is the command to end the Emacs session--this is the command
688 C-x C-c.  (Do not worry about losing changes you have made; C-x C-c
689 offers to save each changed file before it kills the Emacs.)
690
691 C-z is the command to exit Emacs *temporarily*--so that you can go
692 back to the same Emacs session afterward.
693
694 On systems which allow it, C-z "suspends" Emacs; that is, it returns
695 to the shell but does not destroy the Emacs.  In the most common
696 shells, you can resume Emacs with the `fg' command or with `%emacs'.
697
698 On systems which do not implement suspending, C-z creates a subshell
699 running under Emacs to give you the chance to run other programs and
700 return to Emacs afterward; it does not truly "exit" from Emacs.  In
701 this case, the shell command `exit' is the usual way to get back to
702 Emacs from the subshell.
703
704 The time to use C-x C-c is when you are about to log out.  It's also
705 the right thing to use to exit an Emacs invoked under mail handling
706 programs and other miscellaneous utilities, since they may not know
707 how to cope with suspension of Emacs.  In ordinary circumstances,
708 though, if you are not about to log out, it is better to suspend Emacs
709 with C-z instead of exiting Emacs.
710
711 There are many C-x commands.  Here is a list of the ones you have learned:
712
713         C-x C-f         Find file.
714         C-x C-s         Save file.
715         C-x C-b         List buffers.
716         C-x C-c         Quit Emacs.
717         C-x u           Undo.
718
719 Named eXtended commands are commands which are used even less
720 frequently, or commands which are used only in certain modes.  An
721 example is the command replace-string, which globally replaces one
722 string with another.  When you type M-x, Emacs prompts you at the
723 bottom of the screen with M-x and you should type the name of the
724 command; in this case, "replace-string".  Just type "repl s<TAB>" and
725 Emacs will complete the name.  End the command name with <Return>.
726
727 The replace-string command requires two arguments--the string to be
728 replaced, and the string to replace it with.  You must end each
729 argument with <Return>.
730
731 >> Move the cursor to the blank line two lines below this one.
732    Then type M-x repl s<Return>changed<Return>altered<Return>.
733
734    Notice how this line has changed: you've replaced
735    the word c-h-a-n-g-e-d with "altered" wherever it occurred,
736    after the initial position of the cursor.
737
738
739 * AUTO SAVE
740 -----------
741
742 When you have made changes in a file, but you have not saved them yet,
743 they could be lost if your computer crashes.  To protect you from
744 this, Emacs periodically writes an "auto save" file for each file that
745 you are editing.  The auto save file name has a # at the beginning and
746 the end; for example, if your file is named "hello.c", its auto save
747 file's name is "#hello.c#".  When you save the file in the normal way,
748 Emacs deletes its auto save file.
749
750 If the computer crashes, you can recover your auto-saved editing by
751 finding the file normally (the file you were editing, not the auto
752 save file) and then typing M-x recover-file<return>.  When it asks for
753 confirmation, type yes<return> to go ahead and recover the auto-save
754 data.
755
756
757 * ECHO AREA
758 -----------
759
760 If Emacs sees that you are typing commands slowly it shows them to you
761 at the bottom of the screen in an area called the "echo area."  The echo
762 area contains the bottom line of the screen.
763
764
765 * MODELINE
766 -----------
767
768 The line immediately above the echo area it is called the "modeline".
769 The mode line says something like this:
770
771 --**-XEmacs: TUTORIAL          (Fundamental)--L670--58%----------------
772
773 This line gives useful information about the status of Emacs and
774 the text you are editing.
775
776 You already know what the filename means--it is the file you have
777 found.  -NN%-- indicates your current position in the text; it means
778 that NN percent of the text is above the top of the screen.  If the
779 top of the file is on the screen, it will say --Top-- instead of
780 --00%--.  If the bottom of the text is on the screen, it will say
781 --Bot--.  If you are looking at text so small that all of it fits on
782 the screen, the mode line says --All--.
783
784 The stars near the front mean that you have made changes to the text.
785 Right after you visit or save a file, that part of the mode line shows
786 no stars, just dashes.
787
788 The part of the mode line inside the parentheses is to tell you what
789 editing modes you are in.  The default mode is Fundamental which is
790 what you are using now.  It is an example of a "major mode".  
791
792 Emacs has many different major modes.  Some of them are meant for
793 editing different languages and/or kinds of text, such as Lisp mode,
794 Text mode, etc.  At any time one and only one major mode is active,
795 and its name can always be found in the mode line just where
796 "Fundamental" is now.
797
798 Each major mode makes a few commands behave differently.  For example,
799 there are commands for creating comments in a program, and since each
800 programming language has a different idea of what a comment should
801 look like, each major mode has to insert comments differently.  Each
802 major mode is the name of an extended command, which is how you can
803 switch to that mode.  For example, M-x fundamental-mode is a command to
804 switch to Fundamental mode.
805
806 If you are going to be editing English text, such as this file, you
807 should probably use Text Mode.
808 >> Type M-x text-mode<Return>.
809
810 Don't worry, none of the commands you have learned changes Emacs in
811 any great way.  But you can observe that M-f and M-b now treat
812 apostrophes as part of words.  Previously, in Fundamental mode,
813 M-f and M-b treated apostrophes as word-separators.
814
815 Major modes usually make subtle changes like that one: most commands
816 do "the same job" in each major mode, but they work a little bit
817 differently.
818
819 To view documentation on your current major mode, type C-h m.
820
821 >> Use C-u C-v once or more to bring this line near the top of screen.
822 >> Type C-h m, to see how Text mode differs from Fundamental mode.
823 >> Type q to remove the documentation from the screen.
824
825 Major modes are called major because there are also minor modes.
826 Minor modes are alternatives not to the major modes, just minor
827 modifications of them.  Each minor mode can be turned on or off by
828 itself, independent of all other minor modes, and independent of your
829 major mode.  So you can use no minor modes, or one minor mode, or any
830 combination of several minor modes.
831
832 One minor mode which is very useful, especially for editing English
833 text, is Auto Fill mode.  When this mode is on, Emacs breaks the line
834 in between words automatically whenever you insert text and make a
835 line that is too wide.
836
837 You can turn Auto Fill mode on by doing M-x auto-fill-mode<Return>.
838 When the mode is on, you can turn it off by doing M-x
839 auto-fill-mode<Return>.  If the mode is off, this command turns it on,
840 and if the mode is on, this command turns it off.  We say that the
841 command "toggles the mode".
842
843 >> Type M-x auto-fill-mode<Return> now.  Then insert a line of "asdf "
844    over again until you see it divide into two lines.  You must put in
845    spaces between them because Auto Fill breaks lines only at spaces.
846
847 The margin is usually set at 70 characters, but you can change it
848 with the C-x f command.  You should give the margin setting you want
849 as a numeric argument.
850
851 >> Type C-x f with an argument of 20.  (C-u 2 0 C-x f).
852    Then type in some text and see Emacs fill lines of 20
853    characters with it.  Then set the margin back to 70 using
854    C-x f again.
855
856 If you makes changes in the middle of a paragraph, Auto Fill mode
857 does not re-fill it for you.
858 To re-fill the paragraph, type M-q (Meta-q) with the cursor inside
859 that paragraph.
860
861 >> Move the cursor into the previous paragraph and type M-q.
862
863
864 * SEARCHING
865 -----------
866
867 Emacs can do searches for strings (these are groups of contiguous
868 characters or words) either forward through the text or backward
869 through it.  Searching for a string is a cursor motion command;
870 it moves the cursor to the next place where that string appears.
871
872 The Emacs search command is different from the search commands
873 of most editors, in that it is "incremental".  This means that the
874 search happens while you type in the string to search for.
875
876 The command to initiate a search is C-s for forward search, and C-r
877 for reverse search.  BUT WAIT!  Don't try them now.
878
879 When you type C-s you'll notice that the string "I-search" appears as
880 a prompt in the echo area.  This tells you that Emacs is in what is
881 called an incremental search waiting for you to type the thing that
882 you want to search for.  <Return> terminates a search.
883
884 >> Now type C-s to start a search.  SLOWLY, one letter at a time,
885    type the word 'cursor', pausing after you type each
886    character to notice what happens to the cursor.
887    Now you have searched for "cursor", once.
888 >> Type C-s again, to search for the next occurrence of "cursor".
889 >> Now type <Delete> four times and see how the cursor moves.
890 >> Type <RET> to terminate the search.
891
892 Did you see what happened?  Emacs, in an incremental search, tries to
893 go to the occurrence of the string that you've typed out so far,
894 highlighting it for your convenience.  To go to the next occurrence of
895 'cursor' just type C-s again.  If no such occurrence exists Emacs
896 beeps and tells you the search is currently "failing", C-g would also
897 terminate the search.
898
899 NOTE: On some systems, typing C-s will freeze the screen and you will
900 see no further output from Emacs.  This indicates that an operating
901 system "feature" called "flow control" is intercepting the C-s and not
902 letting it get through to Emacs.  To unfreeze the screen, type C-q.
903 Then see the section "Spontaneous Entry to Incremental Search" in the
904 Emacs manual for advice on dealing with this "feature".
905
906 If you are in the middle of an incremental search and type <Delete>,
907 you'll notice that the last character in the search string is erased
908 and the search backs up to the last place of the search.  For
909 instance, suppose you have typed "c", to search for the first
910 occurrence of "c".  Now if you type "u", the cursor will move
911 to the first occurrence of "cu".  Now type <Delete>.  This erases
912 the "u" from the search string, and the cursor moves back to
913 the first occurrence of "c".
914
915 If you are in the middle of a search and type a control or meta
916 character (with a few exceptions--characters that are special in
917 a search, such as C-s and C-r), the search is terminated.
918
919 The C-s starts a search that looks for any occurrence of the search
920 string AFTER the current cursor position.  If you want to search for
921 something earlier in the text, type C-r instead.  Everything that we
922 have said about C-s also applies to C-r, except that the direction of
923 the search is reversed.
924
925
926 * MULTIPLE WINDOWS
927 ------------------
928
929 One of the nice features of Emacs is that you can display more than one
930 window on the screen at the same time.
931
932 >> Move the cursor to this line and type C-u 0 C-l.
933
934 >> Now type C-x 2 which splits the screen into two windows.
935    Both windows display this tutorial.  The cursor stays in the top window.
936
937 >> Type C-M-v to scroll the bottom window.
938    (If you do not have a real Meta key, type ESC C-v.)
939
940 >> Type C-x o ("o" for "other") to move the cursor to the bottom window.
941 >> Use C-v and M-v in the bottom window to scroll it.
942    Keep reading these directions in the top window.
943
944 >> Type C-x o again to move the cursor back to the top window.
945    The cursor in the top window is just where it was before.
946
947 You can keep using C-x o to switch between the windows.  Each
948 window has its own cursor position, but only one window actually
949 shows the cursor.  All the ordinary editing commands apply to the
950 window that the cursor is in.  We call this the "selected window".
951
952 The command C-M-v is very useful when you are editing text in one
953 window and using the other window just for reference.  You can keep
954 the cursor always in the window where you are editing, and advance
955 through the other window sequentially with C-M-v.
956
957 C-M-v is an example of a CONTROL-META character.  If you have a real
958 META key, you can type C-M-v by holding down both CTRL and META while
959 typing v.  It does not matter whether CTRL or META "comes first,"
960 because both of these keys act by modifying the characters you type.
961
962 If you do not have a real META key, and you use ESC instead, the order
963 does matter: you must type ESC followed by CTRL-v; CTRL-ESC v will not
964 work.  This is because ESC is a character in its own right, not a
965 modifier key.
966
967 >> Type C-x 1 (in the top window) to get rid of the bottom window.
968
969 (If you had typed C-x 1 in the bottom window, that would get rid
970 of the top one.  Think of this command as "Keep just one
971 window--the window I am already in.")
972
973 You do not have to display the same buffer in both windows.  If you
974 use C-x C-f to find a file in one window, the other window does not
975 change.  You can find a file in each window independently.
976
977 Here is another way to use two windows to display two different
978 things:
979
980 >> Type C-x 4 C-f followed by the name of one of your files.
981    End with <Return>.  See the specified file appear in the bottom
982    window.  The cursor goes there, too.
983
984 >> Type C-x o to go back to the top window, and C-x 1 to delete
985    the bottom window.
986
987
988 * RECURSIVE EDITING LEVELS
989 --------------------------
990
991 Sometimes you will get into what is called a "recursive editing
992 level".  This is indicated by square brackets in the mode line,
993 surrounding the parentheses around the major mode name.  For
994 example, you might see [(Fundamental)] instead of (Fundamental).
995
996 To get out of the recursive editing level, type ESC ESC ESC.  That is
997 an all-purpose "get out" command.  You can also use it for eliminating
998 extra windows, and getting out of the minibuffer.
999
1000 >> Type M-x to get into a minibuffer; then type ESC ESC ESC to get out.
1001
1002 You cannot use C-g to get out of a recursive editing level.  This is
1003 because C-g is used for canceling commands and arguments WITHIN the
1004 recursive editing level.
1005
1006
1007 * GETTING MORE HELP
1008 -------------------
1009
1010 In this tutorial we have tried to supply just enough information to
1011 get you started using Emacs.  There is so much available in Emacs that
1012 it would be impossible to explain it all here.  However, you may want
1013 to learn more about Emacs since it has many other useful features.
1014 Emacs provides commands for reading documentation about Emacs
1015 commands.  These "help" commands all start with the character
1016 Control-h, which is called "the Help character".
1017
1018 To use the Help features, type the C-h character, and then a
1019 character saying what kind of help you want.  If you are REALLY lost,
1020 type C-h ? and Emacs will tell you what kinds of help it can give.
1021 If you have typed C-h and decide you do not want any help, just
1022 type C-g to cancel it.
1023
1024 (Some sites rebind the character C-h.  They really should not do this
1025 as a blanket measure, so complain to the system administrator.
1026 Meanwhile, if C-h does not display a message about help at the bottom
1027 of the screen, try typing M-x help RET instead.)
1028
1029 The most basic HELP feature is C-h c.  Type C-h, a c, and a
1030 command character or sequence, and Emacs displays a very brief
1031 description of the command.
1032
1033 >> Type C-h c Control-p.
1034   The message should be something like
1035
1036         C-p runs the command previous-line
1037
1038 This tells you the "name of the function".  Function names are used
1039 mainly for customizing and extending Emacs.  But since function names
1040 are chosen to indicate what the command does, they can serve also as
1041 very brief documentation--sufficient to remind you of commands you
1042 have already learned.
1043
1044 Multi-character commands such as C-x C-s and (if you have no META or
1045 EDIT or ALT key) <ESC>v are also allowed after C-h c.
1046
1047 To get more information about a command, use C-h k instead of C-h c.
1048
1049 >> Type C-h k Control-p.
1050
1051 This displays the documentation of the function, as well as its
1052 name, in an Emacs window.  When you are finished reading the
1053 output, type q to get rid of the help text.
1054
1055 Here are some other useful C-h options:
1056
1057    C-h f        Describe a function.  You type in the name of the
1058                 function.
1059
1060 >> Try typing C-h f previous-line<Return>.
1061    This prints all the information Emacs has about the
1062    function which implements the C-p command.
1063
1064    C-h a        Hyper Apropos.  Type in a keyword and Emacs will list
1065                 all the functions and variables whose names contain
1066                 that keyword.  The commands that can be invoked with
1067                 Meta-x, an asterisk will be displayed to the left.
1068
1069 >> Type C-h a newline<Return>.
1070
1071 This displays a list of all functions and variables with "newline" in
1072 their names.  Press <Return> or click the middle mouse button to find
1073 out more about a function or variable.  Type `q' to exit hyper-apropos.
1074
1075
1076 * CONCLUSION
1077 ------------
1078
1079 Remember, to exit Emacs permanently use C-x C-c.  To exit to a shell
1080 temporarily, so that you can come back in, use C-z.  (under X, this
1081 iconifies the current Emacs frame.)
1082
1083 This tutorial is meant to be understandable to all new users, so if
1084 you found something unclear, don't sit and blame yourself - complain!
1085
1086
1087 COPYING
1088 -------
1089
1090 This tutorial descends from a long line of Emacs tutorials
1091 starting with the one written by Stuart Cracraft for the original Emacs.
1092 Ben Wing updated the tutorial for X Windows.  Martin Buchholz and
1093 Hrvoje Niksic added more corrections for XEmacs.
1094
1095 This version of the tutorial, like GNU Emacs, is copyrighted, and
1096 comes with permission to distribute copies on certain conditions:
1097
1098 Copyright (c) 1985, 1996 Free Software Foundation
1099
1100    Permission is granted to anyone to make or distribute verbatim copies
1101    of this document as received, in any medium, provided that the
1102    copyright notice and permission notice are preserved,
1103    and that the distributor grants the recipient permission
1104    for further redistribution as permitted by this notice.
1105
1106    Permission is granted to distribute modified versions
1107    of this document, or of portions of it,
1108    under the above conditions, provided also that they
1109    carry prominent notices stating who last altered them.
1110
1111 The conditions for copying Emacs itself are more complex, but in the
1112 same spirit.  Please read the file COPYING and then do give copies of
1113 GNU Emacs to your friends.  Help stamp out software obstructionism
1114 ("ownership") by using, writing, and sharing free software!