home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume3 / mg2a / part01 next >
Encoding:
Internet Message Format  |  1989-02-03  |  53.1 KB

  1. Path: xanth!mcnc!uvaarpa!umd5!ames!necntc!ncoast!allbery
  2. From: BLARSON@ECLA.USC.EDU (Bob Larson)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i025: Mg 2a part 1 of 15
  5. Message-ID: <12401298994.47.BLARSON@ECLA.USC.EDU>
  6. Date: 26 May 88 04:49:58 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: BLARSON@ECLA.USC.EDU (Bob Larson)
  9. Lines: 1500
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. comp.sources.misc: Volume 3, Issue 25
  13. Submitted-By: "Bob Larson" <BLARSON@ECLA.USC.EDU>
  14. Archive-Name: mg2a/Part1
  15.  
  16. #    This is a shell archive.
  17. #    Remove everything above and including the cut line.
  18. #    Then run the rest of the file through sh.
  19. #----cut here-----cut here-----cut here-----cut here----#
  20. #!/bin/sh
  21. # shar:    Shell Archiver
  22. #    Run the following text with /bin/sh to create:
  23. #    README
  24. #    tutorial
  25. #    mg2a.change
  26. #    random.c
  27. #    regex.h
  28. # This archive created: Wed May 25 19:20:50 1988
  29. # By:    blarson
  30. cat << \SHAR_EOF > README
  31. Mg 2a README  May 15, 1988
  32.  
  33. Mg (mg) is a Public Domain EMACS style editor.  It is "broadly"
  34. compatible with GNU Emacs, the latest creation of Richard M.
  35. Stallman, Chief GNUisance and inventor of Emacs.  GNU Emacs (and other
  36. portions of GNU as they are released) are essentially free, (there are
  37. handling charges for obtaining it) and so is Mg.  You may never have
  38. to learn another editor.  (But probably will, at least long enough to
  39. port Mg...)  Mg was formerly named MicroGnuEmacs, the name change was
  40. done at the request of Richard Stallman. 
  41.  
  42. Mg is not associated with the GNU project, and most of it does not
  43. have the copyright restrictions present in GNU Emacs.  (However, some
  44. of the system dependent modules and the regular expression module do
  45. have copyright notices, specificly the VMS/primos termcap routines and
  46. the amiga specific routines.  Look at the source code for exact
  47. copyright restrictions.)  The Mg authors individually may or may not
  48. agree with the opinions expressed by Richard Stallman in "The GNU
  49. Manifesto".
  50.  
  51. To avoid GNU copyright restrictions, replace the re_search.c, regex.h
  52. and regex.c files with empty files.
  53.  
  54. Documentation of Mg is in the TeX file mg.tex.  This should be
  55. formatted with the TeX text formatter and printed.  A start twords a mg
  56. programmers guied in in mgprog.doc, and some of the changes from 1b
  57. are mentioned briefly in mg2a.change.
  58.  
  59. This program is intended to be a small, fast, and portable editor for
  60. people who can't (or don't want to) run real Emacs thing for one
  61. reason or another.  It is compatible with GNU because there shouldn't
  62. be any reason to learn more than one Emacs flavor.  We have excised
  63. most MicroEMACS features that were incompatible with the big brother,
  64. and added missing features that seemed essential.
  65.  
  66. There are at least two other major versions of MicroEMACS in
  67. circulation.  One comes from Daniel Lawrence, (based on an old version
  68. from Dave Conroy) and is several versions have been posted to usenet.
  69. It uses a 3.x version numbering scheme, and the latest I know about is
  70. 3.9i.  It has some features not found in Mg, missing others, is
  71. bigger, and is incompatible with GNU Emacs.  It might be a better
  72. choice for you if you *must* have something not present here and can't
  73. run GNU.
  74.  
  75. Another variety uses a different numbering scheme, and is up to v30.
  76. This also comes from mod.sources, and is the latest version from the
  77. original MicroEMACS author Dave Conroy.  Mg is derived from this
  78. version, and for the most part has replaced it.
  79.  
  80. Mg is continuing to diverge from other MicroEmacs varients.
  81. Significant modifacations would me nessisary to adapt code from either
  82. the 3.x strains or v30.  Command functions and key mapping, for
  83. instance, are completely different.
  84.  
  85. This is the third distribution release of Mg.  (It went through four
  86. beta releases to iron out the changes made by the various authors.)
  87. Prior releases were known as MicroGnuEmacs 1a and MicroGnuEmacs 1b.
  88. Beyond the work of Dave Conroy, author of the original public domain
  89. v30, the current version contains the work of:
  90.  
  91.     blarson@ecla.usc.edu        Bob Larson
  92.     mic@emx.utexas.edu        Mic Kaczmarczik
  93.     mwm@violet.berkeley.edu        Mike Meyer
  94.     sandra@cs.utah.edu        Sandra Loosemore
  95.     mp1u+@andrew.cmu.edu        Michael Portuesi
  96.     RCKG01M@CALSTATE.BITNET        Stephen Walton
  97.     hakanson@mist.cs.orst.edu    Marion Hakanson
  98.  
  99. People who have worked on previos versions of Mg:
  100.  
  101.     rtech!daveb@sun.com        Dave Brower
  102.  
  103. These systems are known to work in the current version:
  104.  
  105.     4.2 & 4.3 BSD Unix, SunOs 3.2, Ultrix-32
  106.     System V
  107.     OS9/68k
  108.     VMS
  109.     Amiga
  110.     Primos
  111.     Atari ST
  112.  
  113. Ms-Dos support is planned, but did not get done in time for this
  114. release.  (Jeff Siegal <jbs@eddie.mit.edu> was the one doing it.)
  115. The Ms-Dos files will probably be distributed seperatly when it
  116. becomes available.
  117.  
  118. Cpm/68k support was dropped due to compiler bugs.  Eunice support was
  119. dropped because of lack of interest.  Mg 1b does support those
  120. systems.
  121.  
  122. One change to late to make it into mg.tex is readding bsmap-mode (only
  123. if BSMAP is #defined when compiling).  This is a toggle that controls
  124. input mapping to exchange the ^H (backspace) and DEL characters.  Like
  125. GNU emacs input keymaps, it is not displayed on the mode line and will
  126. cause them to be treated as each other for echoing.  (With bsmap-mode
  127. enabled, DEL will echo ^H in the echo line.)
  128.  
  129.  
  130. How to Make a Mg
  131. ---------------------------
  132.  
  133. On UNIX at least, it's easy.  (Note that even on these systems you may
  134. want to change a compile time option.)  If you have BSD UNIX, do:
  135.  
  136.     ln sys/bsd/Makefile .
  137.     make
  138.  
  139. For System V, do:
  140.  
  141.     ln sys/sysv/Makefile .
  142.     make
  143.  
  144. There are several other directories under sys: osk, vms, amiga, atari,
  145. prime.  You should follow the directions contained therein to make one
  146. of those versions.
  147.  
  148. For most systems (everyting except the amiga, and atari currently),
  149. the termcap terminal definition is used.  There is a readme file in
  150. the default subdirectory of the sys directory explaining what entries
  151. are used and how.  (Termcap is a way to do display manipulation in a
  152. terminal independent manner.) Besides the normal startup file (usually
  153. .mg) terminal specific initialization files may be used.  (For
  154. example, in .mg.vt100 you may want to (global-set-key "\e[A"
  155. 'previous-line) to have the up arrow key work.)
  156.  
  157. Some changes made to make this version more like Gnu Emacs may break
  158. startup files.    Gnu Emacs 18 has both backward-delete-char and
  159. delete-backward-char that apperently do the same thing.     This version
  160. has only the latter because that is what is documented in my manual
  161. (version 17) and bound by Gnu Emacs to DEL.
  162.  
  163. ----------------------------------------------------------------------
  164.  
  165. Known limitaions:
  166.  
  167. Recursive bindings may cause help and key rebinding code to go into
  168. an infinite loop, aborting with a stack overflow.
  169.  
  170. Overwrite mode does not work in macros.     (Characters are inserted
  171. rather than overwriting.)
  172.  
  173. Dired mode has some problems:  Rename does not update the buffer.
  174. Doing a dired again will update the buffer (whether it needs it or
  175. not) and will lose any marks for deletion.  .. and . are not
  176. recognized as special cases.
  177.  
  178. On systems with 16 bit integers, the kill buffer cannot exceed 32767
  179. bytes.
  180.  
  181.  
  182.  
  183. New implementation oddities:
  184.  
  185. insert and define-key are new commands corresponding to the mocklisp
  186. functions in Gnu Emacs.     (Mg does not have non-command functions.)
  187. (Mg's insert will only insert one string.)
  188.  
  189. The display wrap code does not work at all like that of GNU emacs.
  190.  
  191. ------------------------------------------------------------------------
  192.  
  193. If you have a change to make that you think should be incorporated
  194. into the next version of Mg, send it the mg-support mail
  195. list. Addresses are:
  196.  
  197.     mg-support%ais1@ecla.usc.edu
  198.     {cit-vax,sdcrdcf,trwrb}!oberon!ais1!mg-support
  199.  
  200. Support for additional systems and terminals should include being
  201. available for beta testing as other changes are made.  (Send a short
  202. note to mg-support.)  Currently, beta test copies of Mg are made
  203. available via Internet ftp, so beta testers need access to the
  204. Internet.  (UUCP sites that are customers of uunet can get it via
  205. them.  Contact uunet!uunet-request for details.) If you can't reach
  206. one of us via a computer network, I suppose you could send a change to
  207. my snail mail address below on 5" os9 format disks or 9 track tape
  208. (ANSI variable label or Prime magsav format), but this effectivly
  209. rules you out as a potential beta tester.  (Don't expect the disk or
  210. tape back unless you inculude a SASE with sufficent postage.)  I will
  211. not be sending out copies on magnetic media, so please don't ask.  If
  212. you somehow got an incomplete or non-standard copy, (i.e. missing one
  213. of the sys directories mentioned here as working) complain to who you
  214. got it from not to me.
  215.  
  216.     Robert Larson
  217.     309 S. Alexandria Ave.
  218.     Apt. 117
  219.     Los Angeles, CA  90020
  220.  
  221. Alternatively, and under the same conditions, you can send either a 3"
  222. AmigaDOS format disk or a 9 track tape (Unix tar format) to:
  223.  
  224.     Mike Meyer
  225.     P.O. Box 4730
  226.     Berkeley, CA 94704
  227.     
  228. SHAR_EOF
  229. cat << \SHAR_EOF > tutorial
  230. Copyright (c) 1985 Richard M. Stallman.  See end for copying conditions.
  231.  
  232. You are looking at the Emacs tutorial.
  233.  
  234. Emacs commands generally involve the CONTROL key or the META (ESC)
  235. key.  Rather than write out META or CONTROL each time we want you to
  236. prefix a character, we'll use the following abbreviations:
  237.  
  238.  C-<chr>  means hold the CONTROL key while typing the character <chr>
  239.       Thus, C-f would be: hold the CONTROL key and type f.
  240.  M-<chr>  means type <ESC>, release it, then type the character <chr>.
  241.  
  242. The characters ">>" at the left margin indicate directions for you to
  243. try using a command.  For instance:
  244.  
  245. >>  Now type C-v (View next screen) to move to the next screen.
  246.     (go ahead, do it by depressing the control key and v together).
  247.     From now on, you'll be expected to do this whenever you finish
  248.     reading the screen.
  249.  
  250. Note that there is an overlap when going from screen to screen; this
  251. provides some continuity when moving through the file.
  252.  
  253. The first thing that you need to know is how to move around from
  254. place to place in the file.  You already know how to move forward a
  255. screen, with C-v.  To move backwards a screen, type M-v (type <ESC>v).
  256.  
  257. >>  Try typing M-v and then C-v to move back and forth a few times.
  258.  
  259.  
  260. SUMMARY
  261. -------
  262.  
  263. The following commands are useful for viewing screenfuls:
  264.  
  265.     C-v    Move forward one screenful
  266.     M-v    Move backward one screenful
  267.     C-l    Clear screen and redisplay everything
  268.          putting the text near the cursor at the center.
  269.          (That's control-L, not control-1.
  270.           There is no such character as control-1.)
  271.  
  272. >> Find the cursor and remember what text is near it.
  273.    Then type a C-l.
  274.    Find the cursor again and see what text is near it now.
  275.  
  276.  
  277. BASIC CURSOR CONTROL
  278. --------------------
  279.  
  280. Getting from screenful to screenful is useful, but how do you
  281. reposition yourself within a given screen to a specific place?  There
  282. are several ways you can do this.  One way (not the best, but the most
  283. basic) is to use the commands previous, backward, forward and next.
  284. As you can imagine these commands (which are given to Emacs as C-p,
  285. C-b, C-f, and C-n respectively) move the cursor from where it
  286. currently is to a new place in the given direction.  It is also
  287. possible to move the cursor with the arrow keys, but this requires you
  288. move your hand from the keyboard, it is also not supported on other
  289. machines that do support Emacs.  Emacs runs on everything from a CP/M
  290. machine to large mainframes. Here then, in a more graphical form are
  291. the commands:
  292.  
  293.               Previous line, C-p
  294.                   :
  295.                   :
  296.    Backward, C-b .... Current cursor position .... Forward, C-f
  297.                   :
  298.                   :
  299.               Next line, C-n
  300.  
  301. >> Move the cursor to the line in the middle of that diagram
  302.    and type C-l to see the whole diagram centered in the screen.
  303.  
  304. You'll probably find it easy to think of these by letter.  P for
  305. previous, N for next, B for backward and F for forward.  These are
  306. the basic cursor positioning commands and you'll be using them ALL
  307. the time so it would be of great benefit if you learn them now.
  308.  
  309. >> Do a few C-n's to bring the cursor down to this line.
  310.  
  311. >> Move into the line with C-f's and then up with C-p's.
  312.    See what C-p does when the cursor is in the middle of the line.
  313.  
  314. >> Try to C-b at the beginning of a line.  Do a few more C-b's.
  315.    Then do C-f's back to the end of the line and beyond.
  316.  
  317. When you go off the top or bottom of the screen, the text beyond
  318. the edge is shifted onto the screen so that your instructions can
  319. be carried out while keeping the cursor on the screen.
  320.  
  321. >> Try to move the cursor off the bottom of the screen with C-n and
  322.    see what happens.
  323.  
  324. If moving by characters is too slow, you can move by words.  M-f
  325. (ESC-f) moves forward a word and M-b moves back a word.
  326.  
  327. >> Type a few M-f's and M-b's.  Intersperse them with C-f's and C-b's.
  328.  
  329. Notice the parallel between C-f and C-b on the one hand, and M-f and
  330. M-b on the other hand.  Very often Meta characters are used for
  331. operations related to English text whereas Control characters operate
  332. on the basic textual units that are independent of what you are
  333. editing (characters, lines, etc). C-a and C-e move to the beginning or
  334. end of a line.
  335.  
  336. >> Try a couple of C-a's, and then a couple of C-e's.
  337.    See how repeated C-a's do nothing.
  338.  
  339. Two other simple cursor motion commands are M-< (Meta Less-than),
  340. which moves to the beginning of the file, and M-> (Meta Greater-than),
  341. which moves to the end of the file.  You probably don't need to try
  342. them, since finding this spot again will be boring.  On most terminals
  343. the "<" is above the comma and you must use the shift key to type it.
  344. On these terminals you must use the shift key to type M-< also;
  345. without the shift key, you would be typing M-comma.
  346.  
  347. The location of the cursor in the text is also called "point".  To
  348. paraphrase, the cursor shows on the screen where point is located in
  349. the text.
  350.  
  351. Here is a summary of simple moving operations including the word and
  352. sentence moving commands:
  353.  
  354.     C-f    Move forward a character
  355.     C-b    Move backward a character
  356.  
  357.     M-f    Move forward a word
  358.     M-b    Move backward a word
  359.  
  360.     c-n    Move to next line
  361.     C-p    Move to previous line
  362.  
  363.     C-a    Move to beginning of line
  364.     C-e    Move to end of line
  365.  
  366.     M-<    Go to beginning of file
  367.     M->    Go to end of file
  368.  
  369. >> Try all of these commands now a few times for practice.
  370.    Since the last two will take you away from this screen,
  371.    you can come back here with M-v's and C-v's.  These are
  372.    the most often used commands.
  373.  
  374. Like all other commands in Emacs, these commands can be given
  375. arguments which cause them to be executed repeatedly.  The way you
  376. give a command a repeat count is by typing C-u and then the digits
  377. before you type the command.  
  378.  
  379. For instance, C-u 8 C-f moves forward eight characters.
  380.     
  381. >> Try giving a suitable argument to C-n or C-p to come as close
  382.    as you can to this line in one jump.
  383.  
  384. The only apparent exception to this is the screen moving commands,
  385. C-v and M-v.  When given an argument, they scroll the screen up or
  386. down by that many lines, rather than screenfuls.  This proves to be
  387. much more useful.
  388.  
  389. >> Try typing C-u 8 C-v now.
  390.  
  391. Did it scroll the screen up by 8 lines?  If you would like to
  392. scroll it down you can give an argument to M-v.
  393.  
  394.  
  395. WHEN EMACS IS HUNG
  396. -----------------
  397.  
  398. If Emacs gets into an infinite (or simply very long) computation which
  399. you don't want to finish, you can stop it safely by typing C-g.
  400. You can also use C-g to discard a numeric argument or the beginning of
  401. a command that you don't want to finish.
  402.  
  403. >> Type C-u 100 to make a numeric arg of 100, then type C-g.
  404.    Now type C-f.  How many characters does it move?
  405.    If you have typed an <ESC> by mistake, you can get rid of it
  406.    with a C-g.
  407.  
  408. WINDOWS
  409. -------
  410.  
  411. Emacs can have several windows, each displaying its own text.
  412. At this stage it is better not to go into the techniques of
  413. using multiple windows.  But you do need to know how to get
  414. rid of extra windows that may appear to display help or
  415. output from certain commands.  It is simple:
  416.  
  417.     C-x 1    One window (i.e., kill all other windows).
  418.  
  419. That is Control-x followed by the digit 1.
  420. C-x 1 makes the window which the cursor is in become
  421. the full screen, by getting rid of any other windows.
  422.  
  423. >> Move the cursor to this line and type C-l (Control-L).
  424. >> Type M-x. The cursor will move to the bottom of the screen.
  425. >> Type the words "describe-bindings" and hit return.
  426.    See how this window shrinks, while a new one appears
  427.    to display which functions are connected to which keys.
  428.  
  429. >> Type C-x 1 and see the documentation listing window disappear.
  430.  
  431.  
  432. INSERTING AND DELETING
  433. ----------------------
  434.  
  435. If you want to insert text, just type it.  Characters which you can
  436. see, such as A, 7, *, etc. are taken by Emacs as text and inserted
  437. immediately.  Type <Return> (the carriage-return key) to insert a
  438. Newline character.
  439.  
  440. You can delete the last character you typed by typing <DEL>.  More
  441. generally, <DEL> deletes the character immediately before the current
  442. cursor position.
  443.  
  444. >> Do this now, type a few characters and then delete them
  445.    by typing <DEL> a few times.  Don't worry about this file
  446.    being changed; you won't affect the master tutorial.  This is just
  447.    a copy of it.
  448.  
  449. >> Now start typing text until you reach the right margin, and keep
  450.    typing.  When a line of text gets too big for one line on the
  451.    screen, the line of text is "continued" off the edge of the screen.
  452.    The dollar sign at the right margin indicates a line which has
  453.    been continued.
  454. >> Use <DEL>s to delete the text until the line fits on one screen
  455.    line again.  The continuation mark goes away.
  456.  
  457. >> Move the cursor to the beginning of a line and type <DEL>.  This
  458.    deletes the newline before the line and merges the line onto
  459.    the previous line.  The resulting line may be too long to fit, in
  460.    which case it has a continuation mark.
  461. >> Type <Return> to reinsert the Newline you deleted.
  462.  
  463. Remember that most Emacs commands can be given a repeat count;
  464. this includes characters which insert themselves.
  465.  
  466. >>  Try that now -- type C-u 8 * and see what happens.
  467.  
  468. You've now learned the most basic way of typing something in
  469. Emacs and correcting errors.  You can delete by words or lines
  470. as well.  Here is a summary of the delete operations:
  471.  
  472.     <DEL>        delete the character just before the cursor
  473.     C-d            delete the next character after the cursor
  474.  
  475.     M-<DEL>      kill the word immediately before the cursor
  476.     M-d         kill the next word after the cursor
  477.  
  478.     C-k         kill from the cursor position to end of line
  479.  
  480. Notice that <DEL> and C-d vs M-<DEL> and M-d extend the parallel
  481. started by C-f and M-f (well, <DEL> isn't really a control
  482. character, but let's not worry about that).
  483.  
  484. Now suppose you kill something, and then you decide that you want to
  485. get it back?  Well, whenever you kill something bigger than a
  486. character, Emacs saves it for you.  To yank it back, use C-y.  You
  487. can kill text in one place, move elsewhere, and then do C-y; this is
  488. a good way to move text around.  Note that the difference
  489. between "Killing" and "Deleting" something is that "Killed" things
  490. can be yanked back, and "Deleted" things cannot.  Generally, the
  491. commands that can destroy a lot of text save it, while the ones that
  492. attack only one character, or nothing but blank lines and spaces, do
  493. not save.
  494.  
  495. For instance, type C-n a couple times to postion the cursor
  496. at some line on this screen.
  497.  
  498. >> Do this now, move the cursor and kill that line with C-k.
  499.  
  500. Note that a single C-k kills the contents of the line, and a second
  501. C-k kills the line itself, and make all the other lines move up.  If
  502. you give C-k a repeat count, it kills that many lines AND their
  503. contents.
  504.  
  505. The text that has just disappeared is saved so that you can
  506. retrieve it.  To retrieve the last killed text and put it where
  507. the cursor currently is, type C-y.
  508.  
  509. >> Try it; type C-y to yank the text back.
  510.  
  511. Think of C-y as if you were yanking something back that someone
  512. took away from you.  Notice that if you do several C-k's in a row
  513. the text that is killed is all saved together so that one C-y will
  514. yank all of the lines.
  515.  
  516. >> Do this now, type C-k several times.
  517.  
  518. Now to retrieve that killed text:
  519.  
  520. >> Type C-y.  Then move the cursor down a few lines and type C-y
  521.    again.  You now see how to copy some text.
  522.  
  523.  
  524. FILES
  525. -----
  526.  
  527. In order to make the text you edit permanent, you must put it in a
  528. file.  Otherwise, it will go away when your invocation of Emacs goes
  529. away.  You put your editing in a file by "finding" the file.  What
  530. finding means is that you see the contents of the file in your Emacs;
  531. and, loosely speaking, what you are editing is the file itself.
  532. However, the changes still don't become permanent until you "save" the
  533. file.  This is so you can have control to avoid leaving a half-changed
  534. file around when you don't want to.
  535.  
  536. If you look near the bottom of the screen you will see a line that
  537. begins and ends with dashes, and contains the string:
  538.      "Mg: TUTORIAL"
  539. Your copy of the Emacs tutorial is called "TUTORIAL".  Whatever
  540. file you find, that file's name will appear in that precise
  541. spot.
  542.  
  543. The commands for finding and saving files are unlike the other
  544. commands you have learned in that they consist of two characters.
  545. They both start with the character Control-x.  There is a whole series
  546. of commands that start with Control-x; many of them have to do with
  547. files, buffers, and related things, and all of them consist of
  548. Control-x followed by some other character.
  549.  
  550. Another thing about the command for finding a file is that you have
  551. to say what file name you want.  We say the command "reads an argument
  552. from the terminal" (in this case, the argument is the name of the
  553. file).  After you type the command
  554.  
  555.     C-x C-f   Find a file
  556.  
  557. Emacs asks you to type the file name.  It echoes on the bottom line of
  558. the screen.  When you type <Return> to end the file name it disappears. 
  559.  
  560. >> Type C-x C-f, then type C-g.  This cancels the  C-x C-f command 
  561.    that was using the minibuffer.  So you do not find any file.
  562.  
  563. In a little while the file contents appear on the screen.  You can
  564. edit the contents.  When you wish to make the changes permanent,
  565. issue the command
  566.  
  567.     C-x C-s   Save the file
  568.  
  569. The contents of Emacs are written into the file.  
  570.  
  571. When saving is finished, Emacs prints the name of the file written.
  572. You should save fairly often, so that you will not lose very much
  573. work if the system should crash.
  574.  
  575. >> Type C-x C-s, saving your copy of the tutorial.
  576.    This should print "Wrote TUTORIAL" at the bottom of the screen.
  577.  
  578. To make a new file, just find it "as if" it already existed.  Then
  579. start typing in the text.  When you ask to "save" the file, Emacs
  580. will really create the file with the text that you have inserted.
  581. From then on, you can consider yourself to be editing an already
  582. existing file.
  583.  
  584.  
  585. BUFFERS
  586. -------
  587.  
  588. If you find a second file with C-x C-f, the first file remains inside
  589. Emacs.  This way you can get quite a number of files inside Emacs. 
  590.  
  591. The object inside Emacs which holds the text read from one file
  592. is called a "buffer."  Finding a file makes a new buffer inside Emacs.
  593. To see a list of the buffers that exist in Emacs, type
  594.  
  595.     C-x C-b   List buffers
  596.  
  597. >> Try C-x C-b now.
  598.  
  599. See how each buffer has a name, and it may also have a file name
  600. for the file whose contents it holds.  Some buffers do not correspond
  601. to files.  For example, the buffer named "*Buffer List*" does
  602. not have any file.  It is the buffer which contains the buffer
  603. list that was made by C-x C-b.  ANY text you see in an Emacs window
  604. has to be in some buffer.
  605.  
  606. >> Type C-x 1 to get rid of the buffer list.
  607.  
  608. If you make changes to the text of one file, then find another file,
  609. this does not save the first file.  Its changes remain inside Emacs,
  610. in that file's buffer.  The creation or editing of the second file's
  611. buffer has no effect on the first file's buffer.  This is very useful,
  612. but it also means that you need a convenient way to save the first
  613. file's buffer.  It would be a nuisance to have to switch back to
  614. it with C-x C-f in order to save it with C-x C-s.  So we have
  615.  
  616.     C-x s     Save some buffers
  617.  
  618. C-x s goes through the list of all the buffers you have
  619. and finds the ones that contain files you have changed.
  620. For each such buffer, C-x s asks you whether to save it.
  621.  
  622.  
  623. EXTENDING THE COMMAND SET
  624. -------------------------
  625.  
  626. There are many, many more Emacs commands than could possibly be put
  627. on all the control and meta characters.  Emacs gets around this with
  628. the X (eXtend) command.  This comes in two flavors:
  629.  
  630.     C-x    Character eXtend.  Followed by one character.
  631.     M-x    Named command eXtend.  Followed by a long name.
  632.  
  633. These are commands that are generally useful but used less than the
  634. commands you have already learned about.  You have already seen two
  635. of them: the file commands C-x C-f to Find and C-x C-s to Save.
  636. Another example is the command to tell Emacs that you'd like to stop
  637. editing and get rid of Emacs.  The command to do this is C-x C-c.
  638. (Don't worry; it offers to save each changed file before it kills the
  639. Emacs.)
  640.  
  641. C-z is the usual way to exit Emacs, because it is always better not to
  642. kill the Emacs if you are going to do any more editing.  On systems
  643. which allow it, C-z exits from Emacs to a CLI but does not destroy the
  644. Emacs; you can resume editing by ending that CLI or depth arranging.
  645.  
  646. You would use C-x C-c if you were running out of memory.  You would
  647. also use it to exit an Emacs invoked under mail handling programs and
  648. other random utilities, since they may not believe you have really
  649. finished using the Emacs if it continues to exist. 
  650.  
  651. There are many C-x commands.  The ones you know are:
  652.  
  653.     C-x C-f        Find file.
  654.     C-x C-s        Save file.
  655.     C-x C-b        List buffers.
  656.     C-x C-c        Quit Emacs.
  657.  
  658. Named eXtended commands are commands which are used even less
  659. frequently, or commands which are used only in certain modes.  These
  660. commands are usually called "functions".  An example is the function
  661. replace-string, which globally replaces one string with another.  When
  662. you type M-x, Emacs prompts you at the bottom of the screen with
  663. M-x and you should type the name of the function you wish to call; in
  664. this case, "query-replace".  Just type "que<TAB>" and Emacs will
  665. complete the name.  End the command name with <Return>.
  666. Then type the two "arguments"--the string to be replaced, and the string
  667. to replace it with--each one ended with a Return.
  668.  
  669. >> Move the cursor to the blank line two lines below this one.
  670.    Then type M-x repl s<Return>changed<Return>altered<Return>.
  671.  
  672.    Notice how this line has changed: you've replaced
  673.    the word c-h-a-n-g-e-d with "altered" wherever it occured
  674.    after the cursor.
  675.  
  676.  
  677. MODE LINE
  678. ---------
  679.  
  680. If Emacs sees that you are typing commands slowly it shows them to you
  681. at the bottom of the screen in an area called the "echo area."  The echo
  682. area contains the bottom line of the screen.  The line immediately above
  683. it is called the MODE LINE.  The mode line says something like
  684.  
  685. --**-Mg: TUTORIAL                 (fundamental)------------------------
  686.  
  687. This is a very useful "information" line.
  688.  
  689. The stars near the front mean that you have made changes to the text.
  690. Right after you visit or save a file, there are no stars, just dashes.
  691.  
  692. The part of the mode line inside the parentheses is to tell you what
  693. modes you are in.  The default mode is fundamental which is what you
  694. are in now.  It is an example of a "mode".  There are several modes in
  695. Emacs for editing different styles of text, such as indent, bsmap,
  696. fill, etc.  Each mode makes a few commands behave differently.
  697.  
  698. One mode which is very useful, especially for editing English text, is
  699. Auto Fill mode.  When this mode is on, Emacs breaks the line in
  700. between words automatically whenever the line gets too long.  You can
  701. turn this mode on by doing M-x auto-fill-mode<Return>.  When the mode
  702. is on, you can turn it off by doing M-x auto-fill-mode<Return>.
  703.  
  704. >> Type M-x auto-fill-mode<Return> now.  Then insert a line of "asdf "
  705.    over again until you see it divide into two lines.  You must put in
  706.    spaces between them because Auto Fill breaks lines only at spaces.
  707.  
  708. The margin is usually set at 70 characters, but you can change it
  709. with the C-x f command.  You should give the margin setting you want
  710. as a numeric argument.
  711.  
  712. >> Type C-x f with an argument of 20.  (C-u 2 0 C-x f).
  713.    Then type in some text and see Emacs fill lines of 20
  714.    characters with it.  Then set the margin back to 70 using
  715.    C-x f again.
  716.  
  717. If you make changes in the middle of a paragraph, Auto Fill mode
  718. does not re-fill it for you.
  719. To re-fill the paragraph, type M-q (Meta-q) with the cursor inside
  720. that paragraph.
  721.  
  722. >> Move the cursor into the previous paragraph and type M-q.
  723.  
  724. SEARCHING
  725. ---------
  726.  
  727. Emacs can do searches for strings (these are groups of contiguous
  728. characters or words) either forward through the file or backward
  729. through it.  To search for the string means that you are trying to
  730. locate it somewhere in the file and have Emacs show you where the
  731. occurrences of the string exist.  This type of search is somewhat
  732. different from what you may be familiar with.  It is a search that is
  733. performed as you type in the thing to search for.  The command to
  734. initiate a search is C-s for forward search, and C-r for reverse
  735. search.  BUT WAIT!  Don't do them now.  When you type C-s you'll
  736. notice that the string "I-search" appears as a prompt in the echo
  737. area.  This tells you that Emacs is in what is called an incremental
  738. search waiting for you to type the thing that you want to search for.
  739. <ESC> terminates a search.
  740.  
  741. >> Now type C-s to start a search.  SLOWLY, one letter at a time,
  742.    type the word 'cursor', pausing after you type each
  743.    character to notice what happens to the cursor.
  744. >> Type C-s to find the next occurrence of "cursor".
  745. >> Now type <DEL> four times and see how the cursor moves.
  746. >> Type <ESC> to terminate the search.
  747.  
  748. Did you see what happened?  Emacs, in an incremental search, tries to
  749. go to the occurrence of the string that you've typed out so far.  To go
  750. to the next occurrence of 'cursor' just type C-s again.  If no such
  751. occurrence exists Emacs beeps and tells you that it is a failing
  752. search.  C-g would also terminate the search.
  753.  
  754. If you are in the middle of an incremental search and type <DEL>,
  755. you'll notice that the last character in the search string is erased
  756. and the search backs up to the last place of the search.  For
  757. instance, suppose you currently have typed 'cu' and you see that your
  758. cursor is at the first occurrence of 'cu'.  If you now type <DEL>,
  759. the 'u' on the search line is erased and you'll be repositioned in the
  760. text to the occurrence of 'c' where the search took you before you
  761. typed the 'u'.  This provides a useful means for backing up while you
  762. are searching. 
  763.  
  764. If you are in the middle of a search and happen to type a control
  765. character (other than a C-s or C-r, which tell Emacs to search for the
  766. next occurrence of the string), the search is terminated.
  767.  
  768. The C-s starts a search that looks for any occurrence of the search
  769. string AFTER the current cursor position.  But what if you want to
  770. search for something earlier in the text?  To do this, type C-r for
  771. Reverse search.  Everything that applies to C-s applies to C-r except
  772. that the direction of the search is reversed.
  773.  
  774.  
  775. GETTING MORE HELP
  776. -----------------
  777.  
  778. In this tutorial we have tried to supply just enough information to
  779. get you started using Emacs.  There is so much available in Emacs that
  780. it would be impossible to explain it all here.  However, you may want
  781. to learn more about Emacs since it has numerous desirable features
  782. that you don't know about yet.  
  783.  
  784.  
  785. CONCLUSION
  786. ----------
  787.  
  788. Remember, to exit Emacs permanently use C-x C-c.  To exit to a shell
  789. temporarily, so that you can come back in, use C-z.
  790.  
  791. This tutorial is meant to be understandable to all new users, so if
  792. you found something unclear, don't sit and blame yourself - complain!
  793.  
  794.  
  795. COPYING
  796. -------
  797.  
  798. This tutorial, like all of GNU Emacs, is copyrighted, and comes with
  799. permission to distribute copies on certain conditions:
  800.  
  801. Copyright (c) 1985 Richard M. Stallman
  802.  
  803.    Permission is granted to anyone to make or distribute verbatim copies
  804.    of this document as received, in any medium, provided that the
  805.    copyright notice and permission notice are preserved,
  806.    and that the distributor grants the recipient permission
  807.    for further redistribution as permitted by this notice.
  808.  
  809.    Permission is granted to distribute modified versions
  810.    of this document, or of portions of it,
  811.    under the above conditions, provided also that they
  812.    carry prominent notices stating who last altered them.
  813.  
  814. The conditions for copying Emacs itself are slightly different
  815. but in the same spirit.  Please read the file COPYING and then
  816. do give copies of GNU Emacs to your friends.
  817. Help stamp out ownership of software by using, writing,
  818. and sharing free software!
  819.  
  820. Mg itself is public domain, and may be given away freely.  See the
  821. README file about differences from GNU emacs, and why Mg exists.
  822.  
  823. *******************************************************************************
  824. ***        This document heavily cut by Randy M. Spencer to apply to        ***
  825. ***      Mg written my Mike Meyer and gang.  It was released            ***
  826. ***      at the AAA users group meeting in Lafayette CA, an Amiga Users     ***
  827. ***      Group.  My profound thanks to Richard Stallman for his work, I     ***
  828. ***      am proud to carry his initials.                                    ***
  829. ***     Additional modifacations were done by Robert A. Larson for Mg        ***
  830. ***     version 2a, mainly the name change from MicroGnuEmacs to Mg.        ***
  831. *******************************************************************************
  832.  
  833. See other files accompanying this for more system specific information.
  834. SHAR_EOF
  835. cat << \SHAR_EOF > mg2a.change
  836. Here is a list of some of the changes from Mg version 1b to 2a, in
  837. reverse semi-cronological order.  Much is only of interest if you are
  838. modifying Mg.  Some things may only apply relitive to beta versions.
  839. (I tried to edit these out.)
  840.  
  841.  
  842.     The kill buffer should now avoid growing bigger than possible.
  843. (malloc takes an unsigned arg, which may only be 16 bits.)  This is a
  844. temporary hack until the kill buffer code is rewriten.
  845.  
  846.     Bcopy is NOT used properly, the third argument should be declared
  847. unsigned but isn't.  16 bit int systems need to treat the third agument
  848. as unsigned.
  849.  
  850.     Added functions set-default-mode, global-unset-key, and
  851. local-unset-key.  dired_ functions in system dependent code now need
  852. to set bp->b_nmodes to 0.
  853.  
  854.     Function key binding should finally work properly.  #define FKEYS
  855. if you have function keys that don't fit into a char.
  856.  
  857.     Termcap XKEYS code completly rewritten.  It does not use the FKEYS
  858. code.  Terminal-dependant initialization files may now be present.
  859.  
  860.     System dependent routine startupfile now takes a single char *
  861. arguement.  It is NULL for the normal startup file, the terminal type
  862. name for the terminal dependent file.  The BSD version no longer tries
  863. to use .emacs if .mg isn't found.  BSD, SYS V, and OSK versions can
  864. look for a system-wide startup file if STARTUPFILE is #defined to the
  865. directory to look in.
  866.  
  867.     Extend.c now has a dependancy on key.h.
  868.  
  869.     Insert-file now uses adjustname.
  870.  
  871.     Optional SYSCLEANUP macro.
  872.  
  873.     Various changes to make mg smaller and faster.
  874.  
  875.     Portability issuses: Identifiers should now be unique in first 7
  876. chars.  (Change dired_makename to d_makename in fileio.c.) Lint found
  877. various bugs. 
  878.  
  879.     Character set dependent portion of def.h moved to
  880. sys/default/chrdef.h.  Cinfo.c moved there.  tty/termcap/* moved
  881. there. 
  882.  
  883.     Bug fixes: insert-file, fill-paragraph, startup code, "make lint"
  884. in bsd makefile.
  885.  
  886.     "varargs.h" in sys/default is for systems that worked with the
  887. non-varargs code on mg1.  It does not work on systems that don't
  888. happen to pass arguments that way.
  889.  
  890.     fncmp is now also used to compare buffer names.  Buffer names are
  891. now case sensitive iff file names are.
  892.  
  893.     The #ifndef ... in some files moved after the #include "def.h".
  894. This should be better for systems that define various things in
  895. sysdef.h.  Let me know what I missed.
  896.  
  897.     Minibuffer and search commands modified so ^H does the same as ^?,
  898. ^\ as ^Q, and ^] as ^S.  bsmap-mode may be done by key bindings,
  899. flow-mode still needs to toggle system-dependent capture of ^S/^Q.
  900. re_search.c probably needs to change also.
  901.  
  902.     dired mode.     (requires a significant amount of system dependent code.)
  903.  
  904.     Two case, non-case sensitive systems are now fully supported.  The
  905. routine fncmp is used to compare file names.  (strcmp may be used on
  906. monocase or case sensitive systems.)
  907.  
  908.     If NO_DIR is not defined, adjustname (the replacement for
  909. adjustcase) must append the directory name to the filename if it
  910. doesn't have one already.
  911.  
  912.     Cleanup and rearangement.  symbol.c has been renamed to keymap.c.
  913. The key name function has been moved to cinfo.c to reduce the number
  914. of files dependent on character set.
  915.  
  916.     The terminal type determining code has been moved out of
  917. sys/default/tty.c.  For unix systems, just "#define gettermtype()
  918. getenv("TERM")".  For VMS and Primos, it's a bit more compicated.
  919.  
  920.     I made some changes to the regular expression code to get it to
  921. compile under os9/68k.    It now compiles, but requires a number of
  922. routines not present in the library that would be difficult to
  923. implement.
  924.  
  925.     lalloc has be rewriten and split into lallocx (for lines not
  926. expected to grow) and lalloc.  The OFFSET macro may have to be defined
  927. in the system dependent file if the normal definition supplied will
  928. not work with your compiler.  (I considered alternatives, but could
  929. not think of one that used as little storage.  Use the offsetof macro
  930. if your compiler conforms to the ANSI C draft standard.)  The
  931. MALLOCROUND macro should be defined if you can predict the behavior of
  932. your libraries malloc.    It takes a single lvalue arguement, and rounds
  933. it up to the amount of memory that realy would be allocated by a
  934. malloc of that size.  (This is most important on memory tight systems.)
  935.  
  936. Apropos is new.     It has a few minor problems:  slow, displays only
  937. global key bindings, dosn't like lots of keys bound to the same
  938. function.  (Digit-argument is closest to causing problems.)  Its
  939. output should probably be the basis of future functions files.
  940.  
  941. The file reading and writing code has changed to fix a couple of
  942. long-standing bugs.  Files no longer get an extra newline at the end
  943. of the last line if it doesn't have one.  Line length is now only
  944. limited by memory and how big a number will fit in a short int.     See
  945. description below on what needs to change.
  946.  
  947. Umpteen minor bugs fixed.  If anyone is doing serious development
  948. based on 1b, some should be merged back in.  (Kill-buffer had several
  949. bugs, help didn't redisplay properly if the *help* buffer was already
  950. present, etc.)
  951.  
  952. The display wrap code is better that what was done before, but not at
  953. all what GNU emacs does in the same situation.
  954.  
  955. Compile options have been changed to make those things present in GNU
  956. emacs the default.   Compile-time options to turn on features not in
  957. GNU emacs and to turn of features that are in GNU emacs are documented
  958. below.
  959. SHAR_EOF
  960. cat << \SHAR_EOF > random.c
  961. /*
  962.  *        Assorted commands.
  963.  * The file contains the command
  964.  * processors for a large assortment of unrelated
  965.  * commands. The only thing they have in common is
  966.  * that they are all command processors.
  967.  */
  968. #include    "def.h"
  969.  
  970. /*
  971.  * Display a bunch of useful information about
  972.  * the current location of dot. The character under the
  973.  * cursor (in octal), the current line, row, and column, and
  974.  * approximate position of the cursor in the file (as a percentage)
  975.  * is displayed. The column position assumes an infinite position
  976.  * display; it does not truncate just because the screen does.
  977.  * This is normally bound to "C-X =".
  978.  */
  979. /*ARGSUSED*/
  980. showcpos(f, n)
  981. {
  982.     register LINE    *clp;
  983.     register long    nchar;
  984.     long        cchar;
  985.     register int    nline, row;
  986.     int        cline, cbyte;    /* Current line/char/byte */
  987.     int        ratio;
  988.  
  989.     clp = lforw(curbp->b_linep);        /* Collect the data.    */
  990.     nchar = 0;
  991.     nline = 0;
  992.     for (;;) {
  993.         ++nline;            /* Count this line    */
  994.         if (clp == curwp->w_dotp) {
  995.             cline = nline;        /* Mark line        */
  996.             cchar = nchar + curwp->w_doto;
  997.             if (curwp->w_doto == llength(clp))
  998.                 cbyte = '\n';
  999.             else
  1000.                 cbyte = lgetc(clp, curwp->w_doto);
  1001.         }
  1002.         nchar += llength(clp);        /* Now count the chars    */
  1003.         clp = lforw(clp);
  1004.         if (clp == curbp->b_linep) break;
  1005.         nchar++;            /* count the newline    */
  1006.     }
  1007.     row = curwp->w_toprow + 1;        /* Determine row.    */
  1008.     clp = curwp->w_linep;
  1009.     while (clp!=curbp->b_linep && clp!=curwp->w_dotp) {
  1010.         ++row;
  1011.         clp = lforw(clp);
  1012.     }
  1013.     /*NOSTRICT*/
  1014.     ratio = nchar ? (100L*cchar) / nchar : 100;
  1015.     ewprintf("Char: %c (0%o)  point=%ld(%d%%)  line=%d  row=%d  col=%d",
  1016.         cbyte, cbyte, cchar, ratio, cline, row, getcolpos());
  1017.     return TRUE;
  1018. }
  1019.  
  1020. getcolpos() {
  1021.     register int    col, i, c;
  1022.  
  1023.     col = 1;                /* Determine column.    */
  1024.     for (i=0; i<curwp->w_doto; ++i) {
  1025.         c = lgetc(curwp->w_dotp, i);
  1026.         if (c == '\t'
  1027. #ifdef    NOTAB
  1028.             && !(curbp->b_flag & BFNOTAB)
  1029. #endif
  1030.             ) {
  1031.             col |= 0x07;
  1032.             ++col;
  1033.         } else if (ISCTRL(c) != FALSE)
  1034.             ++col;
  1035.         ++col;
  1036.     }
  1037.     return col;
  1038. }
  1039. /*
  1040.  * Twiddle the two characters on either side of
  1041.  * dot. If dot is at the end of the line twiddle the
  1042.  * two characters before it. Return with an error if dot
  1043.  * is at the beginning of line; it seems to be a bit
  1044.  * pointless to make this work. This fixes up a very
  1045.  * common typo with a single stroke. Normally bound
  1046.  * to "C-T". This always works within a line, so
  1047.  * "WFEDIT" is good enough.
  1048.  */
  1049. /*ARGSUSED*/
  1050. twiddle(f, n)
  1051. {
  1052.     register LINE    *dotp;
  1053.     register int    doto;
  1054.     register int    cr;
  1055.     VOID     lchange();
  1056.  
  1057.     dotp = curwp->w_dotp;
  1058.     doto = curwp->w_doto;
  1059.     if(doto==llength(dotp)) {
  1060.         if(--doto<=0) return FALSE;
  1061.     } else {
  1062.         if(doto==0) return FALSE;
  1063.         ++curwp->w_doto;
  1064.     }
  1065.     cr = lgetc(dotp, doto--);
  1066.     lputc(dotp, doto+1, lgetc(dotp, doto));
  1067.     lputc(dotp, doto, cr);
  1068.     lchange(WFEDIT);
  1069.     return TRUE;
  1070. }
  1071.  
  1072. /*
  1073.  * Open up some blank space. The basic plan
  1074.  * is to insert a bunch of newlines, and then back
  1075.  * up over them. Everything is done by the subcommand
  1076.  * procerssors. They even handle the looping. Normally
  1077.  * this is bound to "C-O".
  1078.  */
  1079. /*ARGSUSED*/
  1080. openline(f, n)
  1081. {
  1082.     register int    i;
  1083.     register int    s;
  1084.  
  1085.     if (n < 0)
  1086.         return FALSE;
  1087.     if (n == 0)
  1088.         return TRUE;
  1089.     i = n;                    /* Insert newlines.    */
  1090.     do {
  1091.         s = lnewline();
  1092.     } while (s==TRUE && --i);
  1093.     if (s == TRUE)                /* Then back up overtop */
  1094.         s = backchar(f | FFRAND, n);    /* of them all.        */
  1095.     return s;
  1096. }
  1097.  
  1098. /*
  1099.  * Insert a newline.
  1100.  * If you are at the end of the line and the
  1101.  * next line is a blank line, just move into the
  1102.  * blank line. This makes "C-O" and "C-X C-O" work
  1103.  * nicely, and reduces the ammount of screen
  1104.  * update that has to be done. This would not be
  1105.  * as critical if screen update were a lot
  1106.  * more efficient.
  1107.  */
  1108. /*ARGSUSED*/
  1109. newline(f, n)
  1110. {
  1111.     register LINE    *lp;
  1112.     register int    s;
  1113.  
  1114.     if (n < 0) return FALSE;
  1115.     while (n--) {
  1116.         lp = curwp->w_dotp;
  1117.         if (llength(lp) == curwp->w_doto
  1118.         && lforw(lp) != curbp->b_linep
  1119.         && llength(lforw(lp)) == 0) {
  1120.             if ((s=forwchar(FFRAND, 1)) != TRUE)
  1121.                 return s;
  1122.         } else if ((s=lnewline()) != TRUE)
  1123.             return s;
  1124.     }
  1125.     return TRUE;
  1126. }
  1127.  
  1128. /*
  1129.  * Delete blank lines around dot.
  1130.  * What this command does depends if dot is
  1131.  * sitting on a blank line. If dot is sitting on a
  1132.  * blank line, this command deletes all the blank lines
  1133.  * above and below the current line. If it is sitting
  1134.  * on a non blank line then it deletes all of the
  1135.  * blank lines after the line. Normally this command
  1136.  * is bound to "C-X C-O". Any argument is ignored.
  1137.  */
  1138. /*ARGSUSED*/
  1139. deblank(f, n)
  1140. {
  1141.     register LINE    *lp1;
  1142.     register LINE    *lp2;
  1143.     register RSIZE    nld;
  1144.  
  1145.     lp1 = curwp->w_dotp;
  1146.     while (llength(lp1)==0 && (lp2=lback(lp1))!=curbp->b_linep)
  1147.         lp1 = lp2;
  1148.     lp2 = lp1;
  1149.     nld = (RSIZE) 0;
  1150.     while ((lp2=lforw(lp2))!=curbp->b_linep && llength(lp2)==0)
  1151.         ++nld;
  1152.     if (nld == 0)
  1153.         return (TRUE);
  1154.     curwp->w_dotp = lforw(lp1);
  1155.     curwp->w_doto = 0;
  1156.     return ldelete((RSIZE)nld, KNONE);
  1157. }
  1158.  
  1159. /*
  1160.  * Delete any whitespace around dot, then insert a space.
  1161.  */
  1162. justone(f, n) {
  1163.     (VOID) delwhite(f, n);
  1164.     return linsert(1, ' ');
  1165. }
  1166. /*
  1167.  * Delete any whitespace around dot.
  1168.  */
  1169. /*ARGSUSED*/
  1170. delwhite(f, n)
  1171. {
  1172.     register int    col, c, s;
  1173.  
  1174.     col = curwp->w_doto;
  1175.     while (((c = lgetc(curwp->w_dotp, col)) == ' ' || c == '\t')
  1176.             && col < llength(curwp->w_dotp))
  1177.         ++col;
  1178.     do {
  1179.         if (curwp->w_doto == 0) {
  1180.             s = FALSE;
  1181.             break;
  1182.         }
  1183.         if ((s = backchar(FFRAND, 1)) != TRUE) break;
  1184.     } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' || c == '\t');
  1185.  
  1186.     if (s == TRUE) (VOID) forwchar(FFRAND, 1);
  1187.     (VOID) ldelete((RSIZE)(col - curwp->w_doto), KNONE);
  1188.     return TRUE;
  1189. }
  1190. /*
  1191.  * Insert a newline, then enough
  1192.  * tabs and spaces to duplicate the indentation
  1193.  * of the previous line. Assumes tabs are every eight
  1194.  * characters. Quite simple. Figure out the indentation
  1195.  * of the current line. Insert a newline by calling
  1196.  * the standard routine. Insert the indentation by
  1197.  * inserting the right number of tabs and spaces.
  1198.  * Return TRUE if all ok. Return FALSE if one
  1199.  * of the subcomands failed. Normally bound
  1200.  * to "C-J".
  1201.  */
  1202. /*ARGSUSED*/
  1203. indent(f, n)
  1204. {
  1205.     register int    nicol;
  1206.     register int    c;
  1207.     register int    i;
  1208.  
  1209.     if (n < 0) return (FALSE);
  1210.     while (n--) {
  1211.         nicol = 0;
  1212.         for (i=0; i<llength(curwp->w_dotp); ++i) {
  1213.             c = lgetc(curwp->w_dotp, i);
  1214.             if (c!=' ' && c!='\t')
  1215.                 break;
  1216.             if (c == '\t')
  1217.                 nicol |= 0x07;
  1218.             ++nicol;
  1219.         }
  1220.         if (lnewline() == FALSE || ((
  1221. #ifdef    NOTAB
  1222.             curbp->b_flag&BFNOTAB) ?
  1223.             linsert(nicol, ' ') == FALSE : (
  1224. #endif
  1225.             ((i=nicol/8)!=0 && linsert(i, '\t')==FALSE) ||
  1226.             ((i=nicol%8)!=0 && linsert(i,  ' ')==FALSE))))
  1227.             return FALSE;
  1228.     }
  1229.     return TRUE;
  1230. }
  1231.  
  1232. /*
  1233.  * Delete forward. This is real
  1234.  * easy, because the basic delete routine does
  1235.  * all of the work. Watches for negative arguments,
  1236.  * and does the right thing. If any argument is
  1237.  * present, it kills rather than deletes, to prevent
  1238.  * loss of text if typed with a big argument.
  1239.  * Normally bound to "C-D".
  1240.  */
  1241. /*ARGSUSED*/
  1242. forwdel(f, n)
  1243. {
  1244.     if (n < 0)
  1245.         return backdel(f | FFRAND, -n);
  1246.     if (f & FFARG) {            /* Really a kill.    */
  1247.         if ((lastflag&CFKILL) == 0)
  1248.             kdelete();
  1249.         thisflag |= CFKILL;
  1250.     }
  1251.     return ldelete((RSIZE) n, (f & FFARG) ? KFORW : KNONE);
  1252. }
  1253.  
  1254. /*
  1255.  * Delete backwards. This is quite easy too,
  1256.  * because it's all done with other functions. Just
  1257.  * move the cursor back, and delete forwards.
  1258.  * Like delete forward, this actually does a kill
  1259.  * if presented with an argument.
  1260.  */
  1261. /*ARGSUSED*/
  1262. backdel(f, n)
  1263. {
  1264.     register int    s;
  1265.  
  1266.     if (n < 0)
  1267.         return forwdel(f | FFRAND, -n);
  1268.     if (f & FFARG) {            /* Really a kill.    */
  1269.         if ((lastflag&CFKILL) == 0)
  1270.             kdelete();
  1271.         thisflag |= CFKILL;
  1272.     }
  1273.     if ((s=backchar(f | FFRAND, n)) == TRUE)
  1274.         s = ldelete((RSIZE) n, (f & FFARG) ? KFORW : KNONE);
  1275.     return s;
  1276. }
  1277.  
  1278. /*
  1279.  * Kill line. If called without an argument,
  1280.  * it kills from dot to the end of the line, unless it
  1281.  * is at the end of the line, when it kills the newline.
  1282.  * If called with an argument of 0, it kills from the
  1283.  * start of the line to dot. If called with a positive
  1284.  * argument, it kills from dot forward over that number
  1285.  * of newlines. If called with a negative argument it
  1286.  * kills any text before dot on the current line,
  1287.  * then it kills back abs(arg) lines.
  1288.  */
  1289. /*ARGSUSED*/
  1290. killline(f, n) {
  1291.     register RSIZE    chunk;
  1292.     register LINE    *nextp;
  1293.     register int    i, c;
  1294.     VOID     kdelete();
  1295.  
  1296.     if ((lastflag&CFKILL) == 0)        /* Clear kill buffer if */
  1297.         kdelete();            /* last wasn't a kill.    */
  1298.     thisflag |= CFKILL;
  1299.     if (!(f & FFARG)) {
  1300.         for (i = curwp->w_doto; i < llength(curwp->w_dotp); ++i)
  1301.             if ((c = lgetc(curwp->w_dotp, i)) != ' ' && c != '\t')
  1302.                 break;
  1303.         if (i == llength(curwp->w_dotp))
  1304.             chunk = llength(curwp->w_dotp)-curwp->w_doto + 1;
  1305.         else {
  1306.             chunk = llength(curwp->w_dotp)-curwp->w_doto;
  1307.             if (chunk == 0)
  1308.                 chunk = 1;
  1309.         }
  1310.     } else if (n > 0) {
  1311.         chunk = llength(curwp->w_dotp)-curwp->w_doto+1;
  1312.         nextp = lforw(curwp->w_dotp);
  1313.         i = n;
  1314.         while (--i) {
  1315.             if (nextp == curbp->b_linep)
  1316.                 break;
  1317.             chunk += llength(nextp)+1;
  1318.             nextp = lforw(nextp);
  1319.         }
  1320.     } else {                /* n <= 0        */
  1321.         chunk = curwp->w_doto;
  1322.         curwp->w_doto = 0;
  1323.         i = n;
  1324.         while (i++) {
  1325.             if (lback(curwp->w_dotp) == curbp->b_linep)
  1326.                 break;
  1327.             curwp->w_dotp = lback(curwp->w_dotp);
  1328.             curwp->w_flag |= WFMOVE;
  1329.             chunk += llength(curwp->w_dotp)+1;
  1330.         }
  1331.     }
  1332.     /*
  1333.      * KFORW here is a bug. Should be KBACK/KFORW, but we need to
  1334.      * rewrite the ldelete code (later)?
  1335.      */
  1336.     return (ldelete(chunk,    KFORW));
  1337. }
  1338.  
  1339. /*
  1340.  * Yank text back from the kill buffer. This
  1341.  * is really easy. All of the work is done by the
  1342.  * standard insert routines. All you do is run the loop,
  1343.  * and check for errors. The blank
  1344.  * lines are inserted with a call to "newline"
  1345.  * instead of a call to "lnewline" so that the magic
  1346.  * stuff that happens when you type a carriage
  1347.  * return also happens when a carriage return is
  1348.  * yanked back from the kill buffer.
  1349.  * An attempt has been made to fix the cosmetic bug
  1350.  * associated with a yank when dot is on the top line of
  1351.  * the window (nothing moves, because all of the new
  1352.  * text landed off screen).
  1353.  */
  1354. /*ARGSUSED*/
  1355. yank(f, n)
  1356. {
  1357.     register int    c;
  1358.     register int    i;
  1359.     register LINE    *lp;
  1360.     register int    nline;
  1361.     VOID     isetmark();
  1362.  
  1363.     if (n < 0) return FALSE;
  1364.     nline = 0;                /* Newline counting.    */
  1365.     while (n--) {
  1366.         isetmark();            /* mark around last yank */
  1367.         i = 0;
  1368.         while ((c=kremove(i)) >= 0) {
  1369.             if (c == '\n') {
  1370.                 if (newline(FFRAND, 1) == FALSE)
  1371.                     return FALSE;
  1372.                 ++nline;
  1373.             } else {
  1374.                 if (linsert(1, c) == FALSE)
  1375.                     return FALSE;
  1376.             }
  1377.             ++i;
  1378.         }
  1379.     }
  1380.     lp = curwp->w_linep;            /* Cosmetic adjustment    */
  1381.     if (curwp->w_dotp == lp) {        /* if offscreen insert. */
  1382.         while (nline-- && lback(lp)!=curbp->b_linep)
  1383.             lp = lback(lp);
  1384.         curwp->w_linep = lp;        /* Adjust framing.    */
  1385.         curwp->w_flag |= WFHARD;
  1386.     }
  1387.     return TRUE;
  1388. }
  1389.  
  1390. #ifdef    NOTAB
  1391. /*ARGSUSED*/
  1392. space_to_tabstop(f, n)
  1393. int f, n;
  1394. {
  1395.     if(n<0) return FALSE;
  1396.     if(n==0) return TRUE;
  1397.     return linsert((n<<3) - (curwp->w_doto & 7), ' ');
  1398. }
  1399. #endif
  1400. SHAR_EOF
  1401. cat << \SHAR_EOF > regex.h
  1402. /* Definitions for data structures callers pass the regex library.
  1403.    Copyright (C) 1985 Richard M. Stallman
  1404.  
  1405. This program is distributed in the hope that it will be useful,
  1406. but without any warranty.  No author or distributor
  1407. accepts responsibility to anyone for the consequences of using it
  1408. or for whether it serves any particular purpose or works at all,
  1409. unless he says so in writing.
  1410.  
  1411.    Permission is granted to anyone to distribute verbatim copies
  1412.    of this program's source code as received, in any medium, provided that
  1413.    the copyright notice, the nonwarraty notice above
  1414.    and this permission notice are preserved,
  1415.    and that the distributor grants the recipient all rights
  1416.    for further redistribution as permitted by this notice,
  1417.    and informs him of these rights.
  1418.  
  1419.    Permission is granted to distribute modified versions of this
  1420.    program's source code, or of portions of it, under the above
  1421.    conditions, plus the conditions that all changed files carry
  1422.    prominent notices stating who last changed them and that the
  1423.    derived material, including anything packaged together with it and
  1424.    conceptually functioning as a modification of it rather than an
  1425.    application of it, is in its entirety subject to a permission
  1426.    notice identical to this one.
  1427.  
  1428.    Permission is granted to distribute this program (verbatim or
  1429.    as modified) in compiled or executable form, provided verbatim
  1430.    redistribution is permitted as stated above for source code, and
  1431.     A.    it is accompanied by the corresponding machine-readable
  1432.       source code, under the above conditions, or
  1433.     B.    it is accompanied by a written offer, with no time limit,
  1434.       to distribute the corresponding machine-readable source code,
  1435.       under the above conditions, to any one, in return for reimbursement
  1436.       of the cost of distribution.   Verbatim redistribution of the
  1437.       written offer must be permitted.    Or,
  1438.     C.    it is distributed by someone who received only the
  1439.       compiled or executable form, and is accompanied by a copy of the
  1440.       written offer of source code which he received along with it.
  1441.  
  1442.    Permission is granted to distribute this program (verbatim or as modified)
  1443.    in executable form as part of a larger system provided that the source
  1444.    code for this program, including any modifications used,
  1445.    is also distributed or offered as stated in the preceding paragraph.
  1446.  
  1447. In other words, you are welcome to use, share and improve this program.
  1448. You are forbidden to forbid anyone else to use, share and improve
  1449. what you give them.   Help stamp out software-hoarding!     */
  1450.  
  1451.  
  1452. #ifndef RE_NREGS
  1453. #define RE_NREGS 10
  1454. #endif
  1455.  
  1456. /* This data structure is used to represent a compiled pattern. */
  1457.  
  1458. struct re_pattern_buffer
  1459.   {
  1460.     char *buffer;    /* Space holding the compiled pattern commands. */
  1461.     int allocated;    /* Size of space that  buffer  points to */
  1462.     int used;        /* Length of portion of buffer actually occupied */
  1463.     char *fastmap;    /* Pointer to fastmap, if any, or zero if none. */
  1464.             /* re_search uses the fastmap, if there is one,
  1465.                to skip quickly over totally implausible characters */
  1466.     char *translate;    /* Translate table to apply to all characters before comparing.
  1467.                Or zero for no translation.
  1468.                The translation is applied to a pattern when it is compiled
  1469.                and to data when it is matched. */
  1470.     char fastmap_accurate;
  1471.             /* Set to zero when a new pattern is stored,
  1472.                set to one when the fastmap is updated from it. */
  1473.     char can_be_null;    /* Set to one by compiling fastmap
  1474.                if this pattern might match the null string.
  1475.                It does not necessarily match the null string
  1476.                in that case, but if this is zero, it cannot.  */
  1477.   };
  1478.  
  1479. /* Structure to store "register" contents data in.
  1480.  
  1481.    Pass the address of such a structure as an argument to re_match, etc.,
  1482.    if you want this information back.
  1483.  
  1484.    start[i] and end[i] record the string matched by \( ... \) grouping i,
  1485.    for i from 1 to RE_NREGS - 1.
  1486.    start[0] and end[0] record the entire string matched. */
  1487.  
  1488. struct re_registers
  1489.   {
  1490.     int start[RE_NREGS];
  1491.     int end[RE_NREGS];
  1492.   };
  1493.  
  1494.  
  1495. extern char *re_compile_pattern ();
  1496. /* Is this really advertised? */
  1497. extern VOID re_compile_fastmap ();
  1498. extern int re_search (), re_search_2 ();
  1499. extern int re_match (), re_match_2 ();
  1500.  
  1501. /* 4.2 bsd compatibility (yuck) */
  1502. extern char *re_comp ();
  1503. extern int re_exec ();
  1504.  
  1505. #ifdef SYNTAX_TABLE
  1506. extern char *re_syntax_table;
  1507. #endif
  1508. SHAR_EOF
  1509. #    End of shell archive
  1510. exit 0
  1511. -------
  1512.