/* TEACH-EMACS-FUND-2, EMACSSRC>EMACS*, ENVIRONMENTS AND TOOLS, 06/30/86
/* Tutorial file for EMACS "fundamental" mode - file 2 of 4
/* Copyright (c) 1986, Prime Computer Inc., Natick, MA 01760

You are looking at Part 2 of the EMACS tutorial for fundamental mode.  This
module will teach you the following EMACS functions:

     Retrieving data from the kill ring
     Moving regions of data
     Searching and replacing
     Using the HELP facility

This tutorial assumes  that  you  have mastered the basic EMACS commands
discussed in  TEACH-EMACS-FUND-1.   If  you  don't  feel  comfortable using
those commands, you  should go back to TEACH-EMACS-FUND-1 and practice with
them for a while.

Note:  This tutorial follows the  conventions  of  TEACH-EMACS-FUND-1 --  you
are expected to  type  {CTRL-V} when you come to the end of each screen and
follow all instructions preceded by ">>".

Hold down the CONTROL key and press V to continue with this tutorial.


YANKING BACK AND MOVING KILLED TEXT
-----------------------------------

Now suppose  you  kill  something, and then you decide that you want to get it
back?  Well, whenever you kill something bigger than a character, EMACS  saves
it for you.  To yank it back, just type {CTRL-Y}.  Note that you don't have to
be in  the  same  place  to use {CTRL-Y}.  Consequently, this is a good way to
move text around.


>> For instance, type {CTRL-N} a couple of times to position the cursor at the
   beginning of some line on the screen.  Kill that line with  {CTRL-K}.   Now
   type {CTRL-Y} to yank the text back.


>> Next, move the cursor to the beginning of some line  and  type  {CTRL-K}  4
   times.  Then type {CTRL-Y} and watch what happens.


If you  type  several {CTRL-K}s in a row, the text that is killed is all saved
together so that one {CTRL-Y} will yank back all of the lines.

As we said earlier, you can also use {CTRL-Y} to move text around.


>> Try this now.  Type {CTRL-K} several times.


Now to retrieve the killed text:


>> Move the cursor to the point where you would like the yanked lines to
   be moved.


>> Type {CTRL-Y}.  Then move the cursor down a few  lines  and  type  {CTRL-Y}
   again.  You now see how to copy some text.


What do  you do if you have some text you want to yank back, and then you kill
something else?  {CTRL-Y} yanks back the more recent kill.  But  the  previous
text is  not  lost!   You  can get back to it using the {ESC}Y command.  After
you've typed {CTRL-Y} to get the most recent kill,  {ESC}Y  will  replace  the
yanked text with the previous kill.

Typing {ESC}Y  again  and again will bring in earlier and earlier kills.  When
you have reached the text you are looking for, you can just go away and  leave
it there.   If  you  {ESC}Y  enough times, you come back to the starting point
(the most recent kill).  This happens because EMACS saves the  last  11  kills
that you  make  on  a  stacked ring.  For that reason, it is very difficult to
lose anything that you delete.


>> Play around with {CTRL-Y} and {ESC}Y now.  Kill a line, move around, kill a
   second line.  Then type {CTRL-Y} to get back the second killed line.  Next,
   type {ESC}Y and it will be replaced by the first killed  line.   Type  more
   {ESC}Ys and  see what you get.  Keep typing them until the second kill line
   comes back, and then type a few more.

   If you like, you can try giving {ESC}Y positive and negative arguments.


Command Summary
---------------

Here's a recap of the killing and yanking commands you've learned so far:

     {BACKSPACE}        Deletes the character immediately before point

     {CTRL-D}           Deletes the character immediately after point

     {ESC}{BACKSPACE}   Kills the word immediately before point

     {ESC}D             Kills the word immediately after point

     {CTRL-K}           Kills all text from point to end of line

     {CTRL-Y}           Yanks back most recent kill and reinserts it
                        in your file at point.

     {ESC}Y             Replaces most recent text you've reinserted
                        with a previous kill.


THE MARK AND THE REGION
-----------------------

So far you've learned how to kill and move characters, words, and lines.   But
what  if  you have a large amount of text that you want move or kill?  In
EMACS you do this by defining a region.

A region begins at a place called the mark and ends wherever point is currently
located. Therefore, to  define  a  region,  you must first set a mark and then
move the cursor to the place where you want the region to end.

The {CTRL-@} command sets the mark at point.  After you type {CTRL-@}, you can
move point away, leaving the mark behind you.  If you set the mark and then go
do something else, you may forget where you put the mark later.  To  find  out
where it  is,  you can type {CTRL-X}{CTRL-X}.  This command exchanges the mark
and the point -- it moves the cursor to where you last sent the mark.  Notice,
however, that the boundaries of the region do not change since the  same  area
of text is still bounded by a mark and point.

Once you've  defined a region of text, you can delete it with {CTRL-W}.  EMACS
will save this deleted text just like any other text you kill.  You can always
get it back with {CTRL-Y} or {ESC}Y.


>> Move the cursor to the "O" in the word "Once" in the  paragraph  above  and
   the type  {CTRL-@}.   Then  move  the  cursor  to the period after the last
   sentence in that same paragraph.


>> Next, type {CTRL-X}{CTRL-X} and watch what happens.  Type  {CTRL-X}{CTRL-X}
   again and  then type {CTRL-W} to delete the region.  Notice the position of
   the cursor after you type {CTRL-W}.  Finally, type {CTRL-Y} to  make  your
   region reappear at point.


>> Now type {CTRL-X}{CTRL-X} again and then type  {CTRL-W}.   Notice  how  the
   same text  is still deleted even though the positions of the mark and point
   have reversed.


>> Try working with these commands a little more on your own.  They are  among
   the most useful EMACS commands and you should know them well.


Command Summary
---------------

Here's a list of the commands that deal with regions:

     {CTRL-@}             Sets a mark at point

     {CTRL-X}{CTRL-X}     Exchanges the positions of the mark and point

     {CTRL-W}             Deletes the region bounded by the mark and point


SEARCHING AND REPLACING
_______________________

You may  be  wondering  if there are easier ways to move around a file than by
using the cursor moving commands.  Perhaps the easiest way  is  by  using  the
SEARCH commands.   EMACS  allows  you to search forward or backward from point
for the character string you specify.

The SEARCH commands are:

     {CTRL-S}    Forward Search
     {CTRL-R}    Reverse Search

(NOTE:  If you have not used -NOXOFF on the command line that invoked EMACS,
the {CTRL-S} keystroke may freeze your display until you press {CTRL-Q}.  You
will have either to re-start EMACS with -NOXOFF added to the command, or use
either {ESC}s or {ESC}S to do your forward searches.)

When you type either of these commands, EMACS prompts you at the bottom of the
screen for the string you want to search for.  When you see the  prompt,  type
the string  followed  by  {RETURN}.   EMACS  will then move point to the first
occurrence of that string that it finds.  If EMACS can't find  that  string  in
the direction you specified, it will respond with an error message.

If you  make  a mistake while typing in a search string, you can use any EMACS
command to correct it before you type {RETURN}.  Also, if you begin typing  in
a search string and then decide you don't want EMACS to do the search, you can
type {CTRL-G} to abort the search request.

Try using the search commands now:


>> Type {CTRL-S} HOTDOG {RETURN}.  This will put you at the  end  of  this  file
   where there are instructions on how to get back.


Notice that  a  forward  search leaves the cursor positioned after the located
string while a reverse search leaves you positioned before it.

When you do a search, EMACS might locate the wrong string.  For example, if you
search for "the", what do you think the odds are that you'll find the right
occurrence?  Fortunately, EMACS "remembers" any search string.  Therefore, to
repeat a search, all you have to do is type the forward or reverse search
command immediately followed by a {RETURN}.


>> Type {CTRL-S} you {RETURN},  then  type  just  {CTRL-S}  {RETURN}.   What
   happens?  After  doing  this  type  {CTRL-R}  {RETURN}  and  then  {CTRL-R}
   {RETURN} again.  Where are you now?


One more useful command for searching, as  well  as  editing  in  general,  is
{CTRL-C}.  It causes whatever EMACS command you last entered to be executed.
It is particularly useful with commands that take several keystrokes to
complete.  Try it now.


>> Type {CTRL-R} EMACS {RETURN} and then type {CTRL-C}.  Now  type  some  text
   anywhere on a line followed by {CTRL-C}.  Notice what happens.


Now that you've learned how to move around in a file with the SEARCH commands,
you have  an  easy way to refer back to any commands you may have forgotten in
this tutorial.  Just specify "Command Summary" as a search string,  and  EMACS
will take you back to the list of commands that appears after each section.


REPLACEMENT COMMANDS
--------------------

A very  common  editing  task  is replacing one character string with another.
EMACS gives you two ways to do this.   One  is  by  using  the  {ESC}X Replace
command.  This  command replaces all occurrences of one character string with a
second character string WITHIN THE CURRENT REGION.


>> Put a  region  around  the  paragraph  above.   Then  type  {ESC}X  Replace
   character {RETURN}  word  {RETURN}.   This should replace all occurrences of
   the string "character" with the string "word".


Practice this command a few more times if you like.

In many instances, what you really want to do is  see  what  you're  going  to
replace before  it  happens.   The  {ESC}%  command allows you to do this.  It
starts the same way as {ESC}X Replace.  That is, it will  prompt you for two
character strings.  However, after you type the final {RETURN}, things change.
EMACS goes  to  the  first occurrence of the first string and then prompts for
you to type one of four things:


           {CTRL-G}  Tells EMACS to stop searching and replacing.  Any strings
                     already changed remain changed.

           {SPACE}   Tells EMACS to make the change you specifed and moves  to
                     the next occurrence of the string.

           {RETURN}  Tells EMACS not to  make  the  change  but  to  look  for
                     another occurrence.

           .         Tells EMACS to make this change and then stop searching.


The extent covered by the QUERY REPLACE function is the same as for the GLOBAL
REPLACE function.


>> If you want, try this:  Type {ESC}% EMACS  {RETURN}  emacs  {RETURN}  Don't
   worry about returning back.  EMACS will do it for you.


Command Summary
---------------

Here's a list of the commands for searching and replacing:

     {CTRL-S}           Forward Search

     {CTRL-R}           Backward Search

     {ESC}X Replace     Replace one string with another in region

     {ESC}%             Query before replacing in region


HELP COMMANDS
_____________

The final basic EMACS commands you should know about are  the  HELP  commands.
You can  use them at any time to find out how to do something or why something
happened differently than you expected it to.

{CTRL-_} ("CONTROL underscore") is the most basic help command.  When you type
it, EMACS responds with the following prompt:

     Help on tap:  C, A, D, L, or ?  for more info

which lists the various help options.  EMACS then  waits  for  you  to  choose
which one  you  want.   If  you want to abort the help request, type {CTRL-G}.
Otherwise, type one of the characters listed in the  prompt.   The  "?"   will
give you a list of what all the other options do.  They are listed below.


Command Summary
---------------

Once you type {CTRL-_}, you have the following options:


     C  Explains what the command you type does

     A  Lists commands related to subject you specify

     D  Invokes the "Describe" function

     L  Lists last 20 characters you typed

     ?  Summarizes all of above options at top of screen


Three of them -- C, A, and L, are used most often.  Try them  now  to  see  how
they work.


>> First, type {CTRL_} and notice the prompt at the  bottom  of  your  screen.
   Then type C.


>> When you see the "Explain key" prompt, type the {CTRL-F} command.


EMACS will then tell you what this command does at the bottom of  the  screen.


>> Try this command several more times to get explanations of different  EMACS
   commands.  Try  typing  in  commands  that  you  don't  know -- {ESC}L, for
   example, or {CTRL-J}.  What happens?


>> Now type {CTRL-_} and then A.  You'll see the prompt


  Apropos:

       >> Now type the word "delete", followed by {RETURN}.

EMACS will respond with a list of commands at the  top  of  your  screen  that
pertain to deleting text.  Don't worry if this lists types over what's already
on your  screen.   It will disappear when you type your next command.  You can
also use {CTRL-L} to make it disappear.  (Remember, it refreshes your screen.)


>> This HELP command is one of the most useful, so try it again several  times
   with a variety of subjects.


Since this  option  finds  commands  on  the  basis  of their definitions, the
subject you specify may not match the commands you have in mind.  If you don't
get the results you want the first time, don't  give  up.   Try  stating  your
subject in  a  different  way.   If  you  use  "kill"  instead of "delete" for
instance, EMACS will show you a whole new group of commands.


>> Now type {CTRL-_} and then L.


The last twenty keystrokes you've typed will  appear  at  the  bottom  of  the
screen.  You  may  see  the  notation  "^".  It stands for CONTROL.  This HELP
option is very useful when you've just typed something that's made a change to
your text and you don't know what you did.  When you see a keystroke that  you
don't recognize, you can use the C option to find out what it does.


>> This time, type {CTRL-_L}.  What happens?


You can type the HELP option you want immediately after the  {CTRL-_}  without
waiting for the prompt.


CONCLUSION
__________

This concludes "TEACH-EMACS-FUND-2".


>> If you're here because you searched for the string  "HOTDOG",  type the
   sequence {CTRL-R} {RETURN} twice.


>> If you would to practice the functions you have just learned, use EMACS to
   edit the file of your own choosing that you created after completing
   TEACH-EMACS-FUND-1.  Move some of the lines around; search for strings;
   replace strings; and use the HELP facility.


>> If you want to continue on to TEACH-EMACS-FUND-3 (or another file), type
   {CTRL-X}{CTRL-F} followed by TEACH-EMACS-FUND-3 (or the name of the other
   file) and {RETURN}.


>> If you want to get out of EMACS and back to PRIMOS, type  {CTRL-X}{CTRL-C}.
   If you see the message:
        "Above list of modified buffer(s) not saved to file(s).  Quit anyway?"
   Enter "YES".

END OF TEACH-EMACS-FUND-2
