home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 18 / forth / tutorial.txt < prev    next >
Encoding:
Text File  |  1986-09-18  |  19.7 KB  |  488 lines

  1.         You are looking at the EMACS tutorial.
  2.  
  3. This file is TUTORIAL.TXT.  For best effect, you should read this from
  4. inside EMACS.  To start EMACS inside Forth, type  edit .  To start EMACS
  5. from the destop, double-click the EMACS.TOS icon.  Once EMACS is running,
  6. type ^X^V tutorial.txt  .  The next paragraph tells what ^X^V means.
  7.  
  8. EMACS commands generally involve the Control key or the Esc key (Esc
  9. stands for Escape).  Rather than write out ESCAPE or CONTROL each time
  10. we want you to prefix a character, we'll use the following abbreviations:
  11.  
  12.     ^<chr>    means hold the Control key while typing the character <chr>
  13.         Thus, ^F would be: hold the Control key and type F
  14.     ESC-<chr>    means type <Esc>, release it, then type the character <chr>
  15.  
  16.        Important note: if you must exit at some point, type ^X^A.
  17.  
  18. The characters ">>" at the left margin indicate directions for you to try 
  19. using a command. For instance:
  20.  
  21. >>  Now type ^V (View next screen) to move to the next screen. (go ahead,
  22.     do it by depressing the Control key and V together). From now on,
  23.     you'll be expected to do this whenever you finish reading the screen.
  24.  
  25. Note that there is an overlap when going from screen to screen; this
  26. provides some continuity when moving through the file.
  27.  
  28. The first thing that you need to know is how to move around from place to
  29. place in the file. You already know how to move forward a screen, with ^V.
  30. To move backwards a screen, type ESC-v.
  31.  
  32. >>  Try typing ESC-v and then ^V to move back and forth a few times.
  33.  
  34. NOTE: In EMACS, ESC-v and ESC-V are two different commands. They may do the
  35. same thing, or they may not. All of the ESC- commands listed in this tutorial
  36. use the lower case form of the command.  However, CONTROL characters do not
  37. come in separate lower case and upper case forms, so there is no distinction
  38. between ^v and ^V.  Conventionally, CONTROL characters are written using the
  39. upper case letter, as in ^V or ^X, but you need not hold down the shift key
  40. to type a CONTROL character.
  41.  
  42.  
  43. SUMMARY
  44. -------
  45.  
  46. The following commands are useful for viewing screenfuls:
  47.  
  48.     ^V    Move forward one screenful
  49.     ESC-v    Move backward one screenful
  50.     ^L    Clear screen and redisplay everything.
  51.  
  52. ^L is used to fix the screen display if it gets messed-up for some reason.
  53.  
  54.  
  55. BASIC CURSOR CONTROL
  56. --------------------
  57.  
  58. Getting from screenful to screenful is useful, but how do you reposition
  59. yourself within a given screen to a specific place? There are several ways
  60. you can do this. One way (not the best, but the most basic) is to use the
  61. commands previous, backward, forward, and next. As you can imagine, these
  62. commands (which are given to EMACS as ^P, ^B, ^F, and ^N respectively)
  63. move the cursor from where it currently is to a new place in the given
  64. direction. Here, in a more graphical form are the commands:
  65.  
  66.               Previous line, ^P  (or up-arrow)
  67.                   :
  68.                   :
  69.    Backward, ^B .... Current cursor position .... Forward, ^F
  70.       (or left-arrow)          :                 (or right-arrow)
  71.                   :
  72.               Next line, ^N  (or down-arrow)
  73.  
  74. You'll probably find it easy to think of these by letter: P for previous, N
  75. for next, B for backward and F for forward. These are the basic cursor
  76. positioning commands and you'll be using them ALL the time so it would be of
  77. great benefit if you learn them now.  You can use the arrow keys if you
  78. prefer (but the control keys can be typed without moving your hands!).
  79.  
  80. >> Do a few ^N's to bring the cursor down to this line.
  81.  
  82. >> Move into the line with ^F's and then notice
  83.    what ^P does when the cursor is in the middle of the line.
  84.  
  85. EMACS pretends that lines are separated by a single Linefeed character,
  86. although the Atari system actually stores a Carriage Return, Linefeed pair
  87. at the end of each line in a file.
  88.  
  89. >> Try to ^B at the beginning of a line. Do a few more ^B's.
  90.    Then do ^F's back to the end of the line and beyond.
  91.  
  92. On some systems, you can also use the arrow keys to move around.  If your
  93. keyboard has arrow keys, try them out now.
  94.  
  95. When you go off the top or bottom of the screen, the text beyond the edge is
  96. shifted onto the screen so that the cursor is always visible.
  97.  
  98. >> Try to move the cursor off the bottom of the screen with ^N and
  99.    see what happens.
  100.  
  101. If moving by characters is too slow, you can also move by words. ESC-f moves
  102. forward a word and ESC-b moves back a word.  Remember that ESC has to be
  103. typed and released, rather than being held down like with the CONTROL key.
  104.  
  105. >> Type a few ESC-f's and ESC-b's. Intersperse them with ^F's and ^B's.
  106.  
  107. Notice the parallel between ^F and ^B on the one hand, and ESC-f and ESC-b
  108. on the other hand. Very often Escape characters are used for operations
  109. related to English text whereas Control characters operate on the basic
  110. textual units that are independent of what you are editing (characters,
  111. lines, etc).
  112.  
  113. Two other simple cursor motion commands are ESC-< (Escape Less-than), moves
  114. to the beginning of the file, and ESC-> (Escape Greater-than), which moves
  115. to the end of the file. You probably don't need to try them, since finding
  116. this spot again will be boring. If you need the shift key to type a "<",
  117. then you must also use the shift key to type ESC-<.  Otherwise, you would be
  118. typing ESC-,.
  119.  
  120. The location of the cursor in the text is also called "point" or "dot". To
  121. paraphrase, the cursor shows on the screen where point is located in the
  122. text.
  123.  
  124. Here is a summary of simple moving operations including the word and
  125. sentence moving commands:
  126.  
  127.     ^F    Move forward a character
  128.     ^B    Movard a character
  129.  
  130.     ESC-f    Move forward a word
  131.     ESC-b    Move backward a word
  132.  
  133.     ^N    Move to next line
  134.     ^P    Move to previous line
  135.  
  136.     ^A    Move to beginning of line
  137.     ^E    Move to end of line
  138.  
  139.     ^X^P    Scroll window back, showing previous line
  140.     ^X^N    Scroll window forward, showing next line
  141.  
  142.     ESC-,    Go to beginning of window
  143.     ESC-.    Go to end of window
  144.  
  145.     ESC-<    Go to beginning of file
  146.     ESC->    Go to end of file
  147.  
  148. >> Try all of these commands now a few times for practice.
  149.    Since the last two will take you away from this screen,
  150.    you can come back here with ESC-v's and ^V's. These are
  151.    the most often used EMACS commands.
  152.  
  153. Like most other commands in EMACS, these commands can be given arguments
  154. which cause them to be executed repeatedly. The way you give a command a
  155. repeat count is by typing a ^U and then the number before you type the
  156. command. Typing ^U without any digits will give a multiple of 4.  That is,
  157. one ^U gives an argument of 4, two ^U's gives an argument of 16, etc.
  158.  
  159. For instance, ^U 8 ^F moves forward eight characters, while ^U ^U ^F
  160. moves forward sixteen characters.
  161.  
  162. >> Try giving a suitable argument to ^N or ^P to come as close as you can
  163.    to this line in one jump.
  164.  
  165.  
  166. QUITTING FROM COMMANDS
  167. ----------------------
  168.  
  169. The character used in EMACS to quit out of all commands which request input
  170. is ^G.  For example, you can use ^G to discard a numeric argument or the
  171. beginning of a command that you don't want to finish.  
  172.  
  173. >> Type ^U 100 to make a numeric arg of 100, then type ^G.
  174.    Now type ^F. How many characters does it move?
  175.    If you have typed an <ESC> by mistake, you can get rid of it
  176.    with a ^G.
  177.  
  178.  
  179. ERRORS
  180. ------
  181.  
  182. Sometimes you may do something which EMACS doesn't allow. If it is something
  183. simple, such as typing a control key sequence which is not associated with
  184. any command, EMACS will just beep at you. Otherwise, EMACS will also display
  185. an informative error message.
  186.  
  187.  
  188. INSERTING AND DELETING
  189. ----------------------
  190.  
  191. If you want to type text, just do it. Characters which you can see, such as
  192. A, 7, *, etc. are taken by EMACS as text and inserted immediately.
  193. The <Backspace> key may also be typed as a ^H.  More generally, <Backspace>
  194. deletes the character immediately before the current cursor position.
  195.  
  196. >> Do this now, type a few characters and then delete them
  197.    by typing <Backspace> a few times. Don't worry about this file
  198.    being changed; you won't affect the master tutorial. This is just
  199.    a copy of it.
  200.  
  201. >> Now start typing text until you reach the right margin, and keep
  202.    typing. When a line of text gets too big for one line on the
  203.    screen, a dollar sign at the right edge indicates that there are more
  204.    characters to the right of the screen.
  205.  
  206. >> Use <Backspace>'s to delete the text until the line fits on one screen
  207.    line again. The dollar sign goes away.
  208.  
  209. >> Move the cursor to the beginning of a line and type <Backspace>. This
  210.    deletes the line separator before the line and merges the line onto
  211.    the previous line. The resulting line may be too long to fit, in
  212.    which case it has a dollar sign at the right margin.
  213.  
  214. >> Type <Return> to insert the separator again.
  215.  
  216. Remember that most EMACS commands can be given a repeat count;  Note that
  217. this includes characters which insert themselves.
  218.  
  219. >>  now -- type ^U 8 * and see what happens.
  220.  
  221. If you want to create a blank line in between two lines, move to the second
  222. of the two lines and type ^O.
  223.  
  224. >>  Try moving to a line and typing ^O now.
  225.  
  226. You've now learned the most basic way of typing something in EMACS and
  227. correcting errors. You can delete by words or lines as well. Here is a
  228. summary of the delete operations:
  229.  
  230.     ^H (<BS>)    delete the character just before the cursor
  231.     ^D            delete the next character after the cursor
  232.  
  233.     ESC-h         kill the word immediately before the cursor
  234.     ESC-d         kill the next word after the cursor
  235.  
  236.     ^K         kill from the cursor position to end of line
  237.  
  238. Notice that ^H and ^D vs. ESC-h and ESC-d extend the parallel started by
  239. ^F and ESC-f.
  240.  
  241. Now suppose you kill something, and then you decide that you want to get
  242. it back?  Well, whenever you kill something with ^K, EMACS saves it for
  243. you.  To yank it back, use ^Y. Note that you don't have to be in the same
  244. place to do ^Y; This is a good way to move text around.  Also note that
  245. the difference between "Killing" and "Deleting" something is that "Killed"
  246. things can be yanked back, and "Deleted" things cannot.
  247.  
  248. For instance, type ^N a couple times to postion the cursor at some line on
  249. this screen.
  250.  
  251. >> Do this now, move the cursor and kill that line with ^K.
  252.  
  253. Note that a single ^K kills the contents of the line, and a second ^K
  254. kills the line itself, and make all the other lines move.
  255.  
  256. The text that has just disappeared is saved so that you can retrieve it. To
  257. retrieve the last killed text and put it where the cursor currently is, type
  258. ^Y.
  259.  
  260. >> Try it; type ^Y to yank the text back.
  261.  
  262. Think of ^Y as if you were yanking something back that someone took away
  263. from you. Notice that if you do several ^K's in a row the text that is
  264. killed is all saved together so that one ^Y will yank all of the lines.
  265.  
  266. >> Do this now, type ^K several times.
  267.  
  268. Now to retrieve that killed text:
  269.  
  270. >> Type ^Y. Then move the cursor down a few lines and type ^Y
  271.    again. You now see how to copy some text.
  272.  
  273. The region doesn't have to fit all on one screen.  You can set the mark
  274. somewhere, then move anywhere else in the file and the mark will still
  275. be where you set it.
  276.  
  277.  
  278. REGIONS
  279. -------
  280.  
  281. Suppose that you want to move a whole bunch of lines from one place to
  282. another.  You could use a lot of ^K's to kill the lines and then yank
  283. them back somewhere else with ^Y, but that could get tiresome if you
  284. really have a lot of lines to move.  There is a better way.
  285.  
  286. Emacs has a thing called the "region".  The region is everything between
  287. the cursor and another place in the buffer.  The other place is called
  288. the "mark".  To set the mark, you use ^<space>, i.e. hold down the CONTROL
  289. key and type the space bar.
  290.  
  291. >> Try typing ^<space> .  Notice the "[Mark set]" at the bottom.
  292.  
  293. Now if you move the cursor somewhere else, the mark will stay at the place
  294. where the cursor was when you typed the ^<space> .  You can find out where
  295. the mark is with ^X^X .  ^X^X swaps the cursor and the mark.
  296.  
  297. >> Move the cursor a few spaces forward and then type ^X^X several
  298.    times.  Notice how the cursor jumps back and forth.
  299.  
  300. The region is everything between the cursor and the mark.  It doesn't
  301. matter which is first; the cursor can be either before or after the mark.
  302. You can kill the region with ^W .
  303.  
  304. >> Type ^X^X to remind yourself where the region is, then type ^W and
  305.    watch it disappear.  Type ^Y to yank it back.
  306.  
  307. As with ^K, you can yank killed text back at some place other than where
  308. you killed it.
  309.  
  310. If you kill the region with ESC-w instead of ^W, the region won't disappear,
  311. but you will still be able to yank it back somewhere else.  This is a
  312. good way to make several copies of something.  Just grab the region with
  313. ESC-w, then put a copy of it somewhere else with ^Y.  If you want several
  314. copies, just keep typing ^Y.
  315.  
  316. Here is a summary of the region operations:
  317.  
  318.     ^<space>     set the mark
  319.         ^X^X         exchange the mark and the cursor
  320.     ^W         kill the region (between the mark and the cursor)
  321.     ESC-w         kill the region without making it go away
  322.  
  323.  
  324. FILES
  325. -----
  326.  
  327. In order to make the text you edit permanent, you must put it in a file.
  328. Otherwise, it will go away when your invocation of EMACS goes away. You put
  329. your editing in a file by "visiting" the file. What visiting means is that
  330. you see the contents of the file in your EMACS; and, loosely speaking, what
  331. you are editing is the file itself. However, the changes still don't become
  332. permanent until you "save" the file. This is so you can avoid leaving a
  333. half-changed or incorrect file around when you don't want to.
  334.  
  335. If you look near the botton of the screen you will see a line that looks
  336. like " -- ForthEMACS -- tutorial.txt -- File: tutorial.txt". The
  337. "tutorial.txt" refers to the name of the buffer that you are currently
  338. using, your own temporary copy of the text of the EMACS tutorial.
  339. The "File: tutorial.txt" refers to the name of the file that is associated
  340. with the buffer.  This is the disk file that will be written if you "save"
  341. the file.  The buffer name is not necessarily the same as the file name;
  342. for instance, it is possible to read a different file into an already-exiting
  343. buffer.
  344.  
  345. The commands for visiting and saving files are unlike the other commands you
  346. have learned in that they start with a different character. They both start
  347. with the character Control-X. There is a whole series of commands that start
  348. with Control-X; many of them have to do with files, buffers, and related
  349. things, and all of them consist of Control-X followed by some other
  350. character.
  351.  
  352. Another thing about the command for visiting a file is that you have to say
  353. what file name you want. We say the command "reads an argument from the
  354. terminal" (in this case, the argument is the name of the file). After you
  355. type the command
  356.  
  357.     ^X^V   Visit a file
  358.  
  359. EMACS will ask you for the file name. You should end the name with the
  360. Return key. After this command, you will see the contents of the file in
  361. your EMACS. You can edit the contents. When you wish to make the changes
  362. permanent, issue the command
  363.  
  364.     ^X^S   Save the file
  365.  
  366. A new version of the file will be created. When the operation is finished,
  367. EMACS displays a message.
  368.  
  369. If you forget to save a file, then visit a different file, EMACS will not
  370. throw away the changes you have made to the first file.  You can go back to
  371. the first file and save it whenever you want.
  372.  
  373.  
  374. GETTING OUT AND QUITTING
  375. ------- --- --- --------
  376.  
  377. The command to tell EMACS that you'd like to stop editing is ^Z. This
  378. puts you back in Forth where you can do whatever you want.  You can then
  379. get back into EMACS by typing "edit", which will put you back in EMACS
  380. just where you left off.  ^Z automatically saves the file your are editing.
  381.  
  382. If you do not want your file to be saved before you go back to Forth, you
  383. can use ^X^A instead of ^Z.
  384.  
  385. If you want to save your file and stay in EMACS, you can use ^X^S.
  386.  
  387. If you want EMACS to really go away (giving back its memory), but you want
  388. to stay in Forth, you can use the Forth command "unload-emacs".  This doesn't
  389. automatically save any files.
  390.  
  391.  
  392. MODE LINE
  393. ---------
  394.  
  395. At the bottom of the screen is an area called the echo area or mini-buffer.
  396. The echo area contains the bottommost line of the screen. The line
  397. immediately above them is called the MODE LINE. The mode line says something
  398. like:
  399.  
  400.    -* ForthEMACS -- tutorial.txt -- File: tutorial.txt
  401.  
  402. This is a very useful "information" line.
  403.  
  404. The star means that you have made changes to the text. Right after you visit
  405. or save a file, there is no star.
  406.  
  407. The first name "tutorial.txt" is the name of this buffer.  It is usually
  408. (but not always) the same as the name of the file you are editing.
  409. "File: tutorial.txt" means that this buffer is associated with the file
  410. named "tutorial.txt".  A buffer does not have to be associated with a file.
  411.  
  412.  
  413. EDITING TWO FILES AT ONCE
  414. ------- --- ----- -- ----
  415.  
  416. You don't have to get in and out of EMACS every time that you want to edit
  417. another file.  Just use ^X ^V to visit the next file.  If you want to look
  418. at 2 files at the same time, you can split the screen in half with ^X 2 .
  419. To get back to just one window, type ^X 1 .
  420.  
  421. >> Type  ^X 2  to split the screen into 2 windows.
  422.  
  423. Once you have 2 windows, you can switch back and forth between them with
  424. ^X n .  
  425.  
  426. >> Type  ^X n  several times to switch between the windows.  Try using
  427.    ^V  and  ESC v  in one of the windows.  Note that they scroll
  428.    independently of one another.
  429.  
  430. Once you have 2 windows, you can look at a different buffer in each window.
  431. To switch to a different buffer, use ^X ^O .  Pieces of text may be moved
  432. from one window to another using the  ^K , ^W , and ^Y commands that you
  433. have already learned.  Just kill the text in one window, switch windows
  434. using ^X n , then yank the text back into the other window.
  435.  
  436. You can have more than 2 windows if you want.  Try typing ^X 2 inside a
  437. window that has already been split.
  438.  
  439. >> Type  ^X 1  to get back to one window.
  440.  
  441. RUNNING OUT OF MEMORY
  442. ------- --- -- ------
  443.  
  444. Sometimes when you have been editing for a long time, EMACS will run out of
  445. memory.  When this happens you can get some back with a command which allows
  446. you to throw away buffers that you are not using anymore.  Another command
  447. allows you to see which buffers you have.
  448.  
  449. >> Type  ^X ^B  to see which buffers you have.  This will split the screen
  450.    into 2 windows; remember the  ^X 1  command to get back to 1 window.
  451.  
  452. You can throw away a buffer with  ^X k .  You will be asked which buffer
  453. you want to throw away.  You can't throw away a buffer that is currently
  454. being displayed on the screen, so you may need to first use  ^X ^O to switch
  455. to a different buffer.
  456.  
  457. Unfortunately, if you have already run out of memory, sometimes ^X^B won't
  458. work (it needs memory too).  If so, switch to the buffer "main" with
  459. ^X ^O main  , then use ^X k to throw away the buffer you were viewing
  460. when Emacs ran out of memory.  If you have made changes to that buffer and
  461. you don't want to lose them, throw out some other buffer instead (remember
  462. the name of a file you have recently edited and toss it).
  463.  
  464. GETTING HELP
  465. ------- ----
  466.  
  467. The file EMACS.REF contains a complete list of EMACS commands grouped
  468. by function.
  469.  
  470. CONCLUSION
  471. ----------
  472.  
  473. Remember, to exit use ^X^A.
  474.  
  475. You'll probably find that if you use EMACS for a few days you won't be able
  476. to give it up. Initially it may give you trouble. But remember that this is
  477. the case with any editor, especially one that can do as many things as EMACS.
  478.  
  479.  
  480. ACKNOWLEDGEMENTS
  481. ----------------
  482.  
  483. Over the years, versions of EMACS have been written for many different
  484. machines.  Many, many people have contributed to the development of EMACS.
  485. In particular, Richard Stallman wrote the very first version.  The EMACS
  486. used in File Forth is derived from a version called MicroEMACS, which was
  487. written by Dave Conroy.
  488.