You are looking at the EMACS tutorial.  Comments on this document
should be sent to Rubenstein@Sumex-AIM and/or McLure@SRI-KL.

EMACS commands are generally prefixed by the CONTROL key or the META
(sometimes labelled EDIT) key (<ESC> if you don't have META or EDIT on
your keyboard).  Rather than write out META or CONTROL each time we
want you to prefix a character, we'll use the following abbreviations:

 C-<char>	means hold the CONTROL key down while typing a character.
 M-<char>    	means hold the META key down while typing a character.
		if you don't have an META key, then type <ESC>, release
		it, then type the character.

Thus, C-F would be hold the control key and type F.  You will often
be asked to type characters to see how they work; don't actually do
this, however, until you see >> at the left of the screen.
For instance:
<<Blank lines inserted here by startup of TEACH-EMACS>>
>>  Now type C-V (View next screen) to move to the next screen.
	(go ahead, do it by depressing the control key and V together).

Note that there is an overlap when going from screen to screen; this
provides some continuity when moving through the file.

The first thing that you need to know is how to move around from
place to place in the file.  You already know how to move forward a
screen, with C-V.  To move backwards a screen, type M-V (depress the
META key and type V, <ESC>V if you don't have a META or EDIT key.

>>  Try typing M-V and then C-V to move back and forth a few times.

SUMMARY
-------

The following commands are useful for viewing screenfuls:

	C-V	Move forward one screenful
	M-V	Move backward one screenful
	C-L	'Refresh' the current screen.

>> Try this now.  (You'll notice that it centers the screen where
   the cursor currently is.  If this happens to move this text off the
   screen, just do a C-V to see it again.) Do a C-L for refresh.

BASIC CURSOR CONTROL
--------------------

Getting from screenful to screenful is useful, but how do you
reposition yourself within a given screen to a specific place?
There are several ways you can do this.  One way (not the best, but
the most basic) is to use the commands previous, backward, forward
and next.  As you can imagine these commands (which are given to
EMACS as C-P, C-B, C-F, and C-N  respectively) move the cursor from
where it currently is to a new place in the given direction.  Here,
in a more graphical form are the commands:
 
			  Previous line, C-P
				  :
				  :
   Backward, C-B .... Current cursor position .... Forward, C-F
				  :
				  :
			  Next line, C-N

You'll probably find it easy to think of these by letter.  P for previous,
N for next, B for backward and F for forward.  These are the basic cursor
positioning commands and you'll be using them ALL the time so it would
be of great benefit if you learn them now.

>> Try doing a few C-N's to bring the cursor down to this line.
   Move into the line with C-F's and up with C-P's. Now use
   these four commands to play around a little. Try moving off
   the top of this screen and see what happens.

When you go off the top or bottom of the screen, the text beyond
the edge is shifted onto the screen so that your instructions can
be carried out while keeping the cursor on the screen.

A faster way to move around is to move by words or even entire
sentences.   Here is a summary of simple moving operations including
the word and sentence moving commands:

	C-F	Move forward a character
	C-B	Move backward a character

	M-F	Move forward a word
	M-B	Move backward a word

	C-N	Move to next line
	C-P	Move to previous line

	C-A	Move to beginning of line
	C-E	Move to end of line

	M-A	Move back to beginning of sentence
	M-E	Move forward to end of sentence

>> Try all of these commands now a few times for practice.
   These are the most often used commands.

Like all other commands in EMACS, these commands can be given
arguments which cause them to be executed repeatedly.  The way you
give arguments is by prefixing  with M- the number of times you want
it repeated.  For instance, M-8 C-F moves forward eight characters.
(If you don't have an EDIT key and you use <ESC> for META, then if
you give an argument more than one digit long, you should use 
just one <ESC> before the first digit instead of an <ESC> before
each digit.)
	
>> Try giving a suitable argument to C-N or C-P to come as close
   as you can to this line in one jump.

The only apparent exception to this is the screen moving commands,
C-V and M-V.  When given an argument, they scroll the screen up or
down by that many lines, rather than screenfuls.  This proves to be
much more useful.

>> Try typing M-8 C-V now.

Did it scroll the screen up by 8 lines?  If you would like to
scroll it down you can give an argument to M-V.


INSERTING AND DELETING
----------------------

If you want to type text, just do it.  Characters which you can see,
such as A, 7, *, etc. are taken by EMACS as text and inserted
immediately.  You can delete the last character you typed by doing
<DEL>.  More generally, <DEL> will delete the character immediately
before the current cursor position.

>> Do this now, type a few characters and then delete them
   by typing <DEL> a few times.

Remember that all EMACS commands can be given a repeat count;  Note
that this includes characters which insert themselves.

>>  Try that now -- type M-8 * and see what happens.

You've now learned the most basic way of typing something in
EMACS and correcting errors.  You can delete by words or lines
as well.  Here is a summary of the delete operations:

	<del>	delete the character just before the cursor
	C-D	delete the next character after the cursor
	M-D	kill the next word after the cursor
	C-K	kill from the cursor position to end of line
	M-<del>	kill the word immediately before the cursor

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, use C-Y.  Note
that you don't have to be in the same place to do C-Y;  This is a
good way to move text around.  Also note that the difference between
"Killing" and "Deleting" something is that "Killed" things can be
yanked back, and "Deleted" things cannot.

For instance, type C-N a couple times to postion the cursor
at some line on this screen.

  >> Do this now, move the cursor and kill that line with C-K.

Note that a single C-K will kill the contents of the line, and a
second C-K will delete the line itself, and make all the other lines
move up.  If you give C-K a repeat count, it will delete that many
lines AND their contents.

The text that has just disappeared is saved so that you can
retrieve it.  To retrieve the last killed text and put it where
the cursor currently is type C-Y.

 >> Try it; type C-Y to yank the text back.

Think of C-Y as if you were yanking something back that someone
took away from you.  Notice that if you do several C-K's all at once
the text that is killed is all saved for you so that if you  want
it back you can yank it back.

 >> Do this now, type C-K several times.

Now to retrieve that killed text:

 >> Move the cursor down a few lines and type C-Y to retrieve the
	lines that you killed.  This is how you move text from place
	to place.  You can even make copies of a line by killing it
	and yanking it back as many times as you want.


SEARCHING
---------

EMACS can do searches for strings either forward through the
file or backward through it.  This type of search is somewhat
different from what you may be familiar with.  It is a search
that is performed as you type in the thing to search for.  The
command to inititate a search is C-S for forward search, and
C-R for reverse search.  BUT WAIT!  Don't do them now.  When
you type C-S you'll notice that the mode line changes to
'I-Search' and below it you get 'Search:' This tells you that
EMACS is in what is called an incremental search waiting for
you to type the thing that you want to search for.

>>  Now type C-S to start a search.  SLOWLY, one letter at a time,
	type the word 'cursor', pausing after you type each
	character to notice what happens to the cursor.

Did you see what happened?  EMACS, in an incremental search, tries
to go to the occurence of the string that you've typed out so far.
To go to the next occurence of 'cursor' just type C-S again.  If no
such occurence exists EMACS beeps and tells you that it is a failing
search.  To get out of a search tell EMACS that you want to stop
searching with <ESC>.  More generally, EMACS can be told to stop
whatever it is doing with C-G so you could also type C-G.

If you are in the middle of an incremental search and type <Del> or
<RUBOUT>, you'll notice that the last character in the search string
is erased and the search backs up to the previous occurence of that
string. For instance, suppose you currently have typed 'cu' and you
see that your cursor is at the first occurence of 'cu'. If you now
type <Del> or <RUBOUT>, the 'u' on the search line is erased and
you'll be repostioned in the text to the occurence of 'c'
immediately before the first 'cu'. This provides a useful means for
backing up while you are searching. Also, if you are in the middle
of a search and happen to type a control character, the cursor will
go back to the place where you originally started the search.

The C-S starts a search that looks for any occurence of the search
string AFTER the current cursor position.  But what if you want to
search for something earlier in the text?  To do this one should
type C-R for Reverse search.  Everything that applies to C-S applies
to C-R except that the direction of the search is reversed.


EXTENDING THE COMMAND SET
-------------------------

There are many, many more EMACS commands than could possibly be put
on all the control and meta characters.  EMACS gets around this with
the X (eXtend) command.  This comes in two flavors:

	C-X	Character eXtend
	M-X	Named command eXtend

These are commands that are generally useful but used less than the
commands you have already learned about.  As an example, one command
that is used infrequently is the command to tell EMACS that you'd
like to stop editing.  The command to do this is C-X C-Z.  Think of
it as Z for zapping yourself.

There are many C-X commands.  The ones you need immediately are:

	C-X C-V		Visit file.  This is how you read in a file
			to edit it.  When you type this, EMACS asks
			you for a file name to visit.  You would respond
			with the name of the file.  Then EMACS brings it
			in for editing.  If the file doesn't exist, then
			EMACS assumes that you are creating a new file.
	C-X C-S		Save file.  This is a command that tells EMACS
			to save the file you are currently looking at
			onto disk.  It is recommended you give this
			ocassionally to prevent losing any work in the
			case of a system crash.
	C-X C-Z		Quit EMACS.  This does NOT save your file.  The
			standard way to save and exit is C-X C-S C-X C-Z.
			If you don't like this, there is a way to have
			EMACS save your buffer at frequent intervals and
			when you exit.  This is explained below.

Named eXtend commands are commands which are used even less
frequently, or commands which are used only in certain modes.  An
example of this type of command is the Replace command.  When you
type M-X, EMACS will prompt you at the bottom of the screen with MM
(EMACS calls named eXtend commands MM commands) and then you can
type the name of the command you want to execute, in this case,
"Replace String".  Just type "REP<esc>" and EMACS will complete the
command.  Then you type the string that you want to replace, an
<esc>, the string you want to replace it with, and a return.

 >> Try this now;  type M-X rep<esc>try<esc>you can do<return>
	See how the previous line changed?  All the "try"s were
	changed to "you can do"


MODE LINE
---------

If EMACS sees that you are typing commands slowly it shows them to
you at the bottom of the screen in an area called the echo lines.
This is just the last few lines at the bottom.  The line immediately
above these is called the MODE LINE.  You may notice that it begins
with EMACS (Fundamental) ...more stuff...  This is a very useful
'information' line.  To understand EMACS it is best to consider that
it operates in a variety of modes.  The default mode is Fundamental
which is what you are in now.  There are modes for editing different
languages and text, such as LISP mode, Text mode, etc.  The mode
line serves to show you various things about your current state.
For instance, on the mode line here you'll notice that it says Main.
EMACS operates with things called buffers.  This is a place that it
puts your file while you are editing it.  There are names for
buffers.  The default buffer upon startup of EMACS is Main.  You'll
notice that after the Main and before the --nn%-- comes a filename
which contains your own directory name.  That is the name of the file
you are now visiting.  It is a temporary copy of the master file of
this tutorial text.


GETTING MORE HELP
-----------------

In this tutorial we have tried to supply just enough information to
get you started using EMACS.  There is so much available in EMACS that
it would be impossible to explain it all here.  However, you may want
to learn more about EMACS since it has numerous desirable features
that you don't know about yet.  EMACS has a great deal of internal
documentation.  All of these commands can be accessed through the HELP
character.  If there is no key labelled "HELP" on your keyboard, you
can type the <HELP> character as C-_ H (two keystrokes) on the ITS
system or as just C-_ on Tenex or Twenex (or with the <HOLD> key, on
Datamedia terminals).  Be warned: on many terminals it is necessary to
hunt around for a way to type a C-_.  To use the HELP features, type
the <HELP> character, and then a character saying what kind of help you
want.  If you are REALLY lost, type <HELP> ?  and EMACS will tell you
what kinds of help it can give.  The options which are most useful are
the following:

 	<HELP> C	Character describe.  You type in the character.
			Multi-character commands such as C-X C-Z
			and (if you have no META or EDIT key) <ESC>V
			are also allowed.
	<HELP> D	Describe a named command.  You type in a command.
	<HELP> A	Apropos.  Type in a keyword and EMACS will
			list all the commands containing that keyword.
			More than one keyword can be specified,
			seperated by C-O
	<HELP> I	Run the INFO program.  INFO contains the
			complete documentation for EMACS, in 
			great detail.  Here is where you can find out
			about, for instance, special commands for editing
			LISP code, handling buffers, replacing text, filling
			and justifying text, etc.

 >> Go ahead and try some of these.  Type <HELP> C C-K.  Emacs will tell
	you what that character does.  Try typing <HELP> A WORD to find
	out all the commands that have to do with words.  When EMACS
	prompts you with --MORE--, type a space to see more or a C-L
	to get your text back.  INFO is a fairly sophisticated
	documentation finder and is somewhat complicated.  It probably
	isn't a good idea to try to use INFO just yet. Use EMACS for
	a few days, gain some familiarity and confidence in giving
	commands. And then try INFO out.

CONCLUSION
----------

You'll probably find that if you use EMACS for a few days you won't
be able to give it up.  Initially it may give you trouble.  But remember
that this is the case with any editor, especially one that can do many,
many things.  And EMACS can do practically everything.
