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

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

     File management
     Buffer management
     Window management
     Overlay mode

This tutorial assumes  that  you  have mastered the basic EMACS commands
discussed in TEACH-EMACS-FUND-1 & 2.  If you don't feel comfortable using those
commands, you  should go back to TEACH-EMACS-FUND-1 or 2 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 ">>".

Remember that you can use  the  search  commands  to  refer  to  the  "Command
Summary" sections if you want information about commands quickly.


BUFFERS
_______

One of  EMACS' nicest features is its ability to control more than one file at
a time.  It does this by using multiple  buffers.   A  buffer  is  a  sort  of
working environment set aside for you to use to edit text.  Each file you edit
is placed  in  a buffer.  Although you can only edit one buffer at a time, you
can switch to a different one as often as you like.

Each buffer in EMACS has a name, which is always displayed in  parentheses  at
the bottom  of your screen.  The name of the buffer you're working with now is
called "TEACH-EMACS-FUND-3".  If you look down at the bottom of  your  screen,
you will see it in parentheses.

EMACS buffers generally have the same names as the files they contain.  If you
look down  at  the  bottom  of  your screen again, you'll see that is the case
right now.  The full Prime pathname which describes  this  file  is  displayed
next to the name of the buffer.


The Mode Line
-------------

The area  of  the  screen  that gives you information about your current EMACS
buffer is called the mode line.  As you go along,  you'll  discover  that  the
mode line  gives  you all sorts of information about what's going on in EMACS.

The number following the word "EMACS" on the mode line tells you  the  version
of EMACS  that  you're using.  An asterisk (*) in the mode line tells you that
the current buffer contains modified text that hasn't been saved to a file.

>> To demonstrate, simply press the space bar to insert a space.  Notice that
the asterisk now appears in the mode line.  The asterisk appears no matter how
insignificant the change may seem.

If you don't specify a filename when you start up EMACS, it puts  you  into  a
buffer it  calls  "main".   Otherwise, it puts you into a buffer with the same
name as the file you specified.


Switching to a New Buffer
-------------------------

To switch to or create a new buffer, you can use the {CTRL-X}B  command.   This
command  prompts  you for a buffer name.  It is similar to the {CTRL-X}{CTRL-F}
command described in "TEACH-EMACS-FUND-1", but it lets you choose the  name  of
the  buffer  instead  of  automatically assigning it a name.  This way, you can
work with two different versions of the same file.

Another good thing about creating a buffer yourself is that it doesn't have to
contain a permanent file.  You can use buffers for  different  purposes  while
you're in EMACS without having to worry about a file.

Try {CTRL-X}B now.  Remember, that since it switches you to a different buffer,
these instructions will disappear from your screen.  When you're ready to  come
back  to  this  buffer  to  continue  with  the  tutorial,  you'll have to type
{CTRL-X}B again, followed by the buffer name "TEACH-EMACS-FUND-3" and {RETURN},
to get back.  (As a time-saving hint, {CTRL-X}B{RETURN} will return you to  the
LAST buffer you were working with.)


>> Go ahead and type {CTRL-X}B.  When you're prompted for a buffer name, type
   in the  name  NEW  and confirm with {RETURN}.  Once you get to your new
   buffer, insert some text and play around with it for awhile.  When you're
   ready to  come  back  to  this tutorial, type:

     {CTRL-X}B{RETURN}

Notice that EMACS remembered your place when you came  back  to  this  buffer.
This is very useful when you start switching around to many different buffers.


Getting a List of Buffers
-------------------------

When you don't remember the names of all the buffers you've been working with,
you can  use  the  {CTRL-X}{CTRL-B}  command.  It lists all the buffers you've
used so far, the files they contain, whether or not they contain unsaved text,
and how many lines long they are.  Try this command now.


>> Type {CTRL-X}{CTRL-B} and watch a list of buffers appear at the top of your
   screen.  (It will disappear with your next command.)


If TEACH-EMACS-FUND-3 is the only file you've been working with since you
invoked EMACS, it will be the only one listed.  If you've worked with any
others, they will be listed as well.

FILES
_____

When you work with a file in EMACS, you are not really working  with  the  file
itself.  Instead, you are working with a copy of the file EMACS has placed in a
buffer.   As  was mentioned in TEACH-EMACS-FUND-1, you must save your text in a
file if you want to keep it permanently.  If you don't save your  changes,  the
original  version  of  the file remains unchanged.  Once you save your changes,
they become the new version of the file.


Saving Text in Files
--------------------

You already know about {CTRL-X}{CTRL-S} which automatically saves the text  in
your buffer  in  the current file.  There is one other command you should know
as well.

{CTRL-X}{CTRL-W} saves the text in your buffer in a file you specify.

Try using {CTRL-X}{CTRL-W} now.  The buffer "new"  that  you  created  earlier
should have  some  text  in  it that hasn't yet been saved in a file.  You can
switch to that buffer to try {CTRL-X}{CTRL-W}:


>> Go ahead and type {CTRL-X}B new {RETURN}.  Remember that you'll have to type
   it again (without needing to specify "new") to get back to this buffer.
   When you get to your NEW buffer, type {CTRL-X}{CTRL-W} and use any filename
   you like to save your text.  We'll assume you chose the name "NEW" for this
   file.


Inserting Files
---------------

At times you may need to include a copy of an existing file into your buffer.
When you type {CTRL-X}I  EMACS will prompt you for the filename.  The entire
contents of the selected file are inserted into your buffer at point.  This
action does not change the buffer name in the mode line or the pathname of
the file you're editing.


>> Since you have just written a file called NEW, position yourself somewhere
   in your TEACH-EMACS-FUND-3 buffer and type {CTRL-X}I NEW {RETURN}.
   Notice that your new file is simply inserted into the buffer at point.


Creating Files
---------------

You can put a copy of a file in a buffer, or create a new file, by using the
{CTRL-X}{CTRL-F} command that you learned in TEACH-EMACS-FUND-1.  This command
automatically gives the buffer the same name as the file.

If you  already have an empty buffer and you want to put a file in it, you can
use {CTRL-X}{CTRL-R}.


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

These commands are related to working with files and buffers:


     {CTRL-X}{CTRL-F}  Finds or creates file you specify  and  puts  it  in  a
                       buffer with the same name.

     {CTRL-X}B         Finds or  creates  buffer  you  specify.   Buffer   may
                       contain file with a different name.

     {CTRL-X}{CTRL-R}  Reads file you specify into current buffer

     {CTRL-X}I         Inserts a file at point into current buffer

     {CTRL-X}{CTRL-B}  Lists all buffers used during current editing session

     {CTRL-X}{CTRL-W}  Saves text in file you specify.

     {CTRL-X}{CTRL-S}  Saves text in current file.

     {CTRL-X}{CTRL-C}  Exits EMACS and  takes  you  back  to  PRIMOS  command
                       level.


MULTIPLE WINDOWS
----------------

In EMACS,  it is possible to see the contents of two different buffers on your
screen at one time by using two windows.   To  divide  your  screen  into  two
windows, all you have to do is type {CTRL-X}2.  It divides your screen in half
horizontally by  placing  a dotted line across the middle of your screen.  The
top window displays the contents of your current buffer.   The  bottom  window
displays a new, empty buffer called "alternate".

After you  type  {CTRL-X}2,  the cursor moves to the bottom window, making the
buffer in that window the current buffer.  Any EMACS commands  you  then  type
will take effect in that window only.

If you  decide  you  want  to edit the text in the top window, you can use the
{CTRL-X}O command  to move  the cursor  to the "Other" window.  When you  want
to work  with  the  text in the bottom window again, {CTRL-X}O will again move
you to the other window.

You can use any EMACS commands you like when you  use  two  windows  with  the
restriction that  you  can only work with one buffer at a time.  Try using two
windows now:


>> Type {CTRL-X}2 and watch this file move to the  top  of  the  screen  only.
   Then type  {CTRL-X}O  to  make the top window the current window.  If these
   instructions disappear, use {CTRL-V} until they appear.


Notice that before you typed {CTRL-X}O, the  mode  line  read  "alternate"  to
describe the buffer in window two.  As soon as you moved to the top window, it
changed to reflect the new current buffer.



>> Now move the cursor to window 2 again using {CTRL-X}O.  Then type {CTRL-X}B
   followed by "new" {RETURN} to move the buffer called "new" into  window  2,
   making it the current buffer.  Don't forget to use {CTRL-X}O to move to the
   top window when you need to read these instructions.


Notice that  the  mode  line has changed again.  It now reads "new" to reflect
the current buffer.


>> Play around with the text  in  the  two  windows  for  awhile.   Try  using
   different EMACS  commands.   Type {CTRL-X}{CTRL-W} to save the text in the
   buffer "new" under any name you choose.  Then put a different  buffer  into
   the bottom window using {CTRL-X}{CTRL-F} or {CTRL-X}B.


>> When you're ready to get back to one window again, move the cursor  to  the
   top window.  Then type {CTRL-X}1  (that's the number one).


This file will take up the entire screen again.  If you had left the cursor in
the bottom  window,  the  buffer  in  that  window  would now be on the screen
instead.


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

These are the commands for working with multiple windows:

      {CTRL-X}2     Divides screen into two horizontal windows
      {CTRL-X}1     Makes screen one window again    (number one -> 1 window)
      {CTRL-X}O     Moves point to other window      (letter O -> Other window)


OVERLAY MODE
------------

By now you've worked with EMACS  long  enough  to  notice  how  EMACS  inserts
characters into  a buffer.  As EMACS inserts each new character, it shifts the
text following it on the line over one space.  Sometimes you  won't  want  the
insertion process  to  work this way.  To change it, you can use overlay mode.
Overlay mode permits you to type new characters onto  a  line  without  moving
other text.

Like other  modes in EMACS, overlay mode works in the current buffer only.  If
you switch to a new buffer, the usual method of inserting text will  still  be
in effect.   However, if you leave the current buffer in overlay mode, work in
a new one, and then go back to the first buffer, EMACS will remember that  you
had overlay mode in effect for that buffer.

Try overlay mode now:


>> Type {ESC}X overlay_on {RETURN}


Watch the notation "overlay" appear in the mode line to remind you that you've
put overlay mode in effect.


>> Then move to a different line of text in this file and type in some text at
   the beginning.  Notice how the new text overwrites  the  old  text  on  the
   line.


>> Now type {ESC}X overlay_off to turn off overlay mode.


The "overlay" notation will disappear from the mode  line  and  any  text  you
insert will be done in the usual manner.


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

Use the following commands for overlay mode:

     {ESC}X overlay_on      Puts overlay mode in effect in the current buffer.

     {ESC}X overlay_off     Turns off overlay mode in the current buffer.


CONCLUSION
----------

This concludes TEACH-EMACS-FUND-3.


>> If you want to  continue  on  to  TEACH-EMACS-FUND-4  (or  another  file),
   press {FIND FILE} followed  by TEACH-EMACS-FUND-4 (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-3
