\subsection{Scheme Mode}

        This is a major mode that won't do you any good unless you
have a compiler or an interpreter for the Scheme programming language
on your system.  Having one is not as normal as having, say, a C
compiler, but it's becoming more and more common, so I'll cover it
too.  Much of what is true for Scheme mode is true for Lisp mode as
well, if you prefer to write in Lisp.

        Well, to make matters painful, Emacs comes with two different
Scheme modes, because people couldn't decide how they wanted it to
work.  The one I'm describing is called ``{\tt cmuscheme}'', and later
on, in the section on customizing Emacs, I'll talk about how there can
be two different Scheme modes and what to do about it.  For now, don't
worry about it if things in your Emacs don't quite match up to what I
say here.  A customizable editor means an unpredictable editor, and
there's no way around that!

% todo: this won't work unless Emacs knows where to find the scheme
% interpreter.  Should we talk about that?  Yes, in the section on
% elisp, mention setting scheme-program-name.

        You can run an interactive Scheme process in Emacs, with the
command {\tt M-x run-scheme}.  This creates a buffer named ``{\tt
*scheme*}'', which has the usual Scheme prompt in it.  I'll call this
the ``process buffer''.  You can type in Scheme expressions at the
prompt, hit \key{Return}, and Scheme will evaluate them and display
the answer.  Thus, in order to interact with the Scheme process, you
could just type all your function definitions and applications in at
the prompt.  Chances are you have previously-written Scheme source
code in a file somewhere, and it would be easier to do your work in
that file and send the definitions over to the Scheme process buffer
as necessary.

        If that source file ends in ``{\tt .ss}'' or ``{\tt .scm}'',
it will automatically be brought up in {\bf Scheme mode} when you find
it with {\tt C-x~C-f}.  If for some reason, it doesn't come up in
Scheme mode, you can do it by hand with {\tt M-x scheme-mode}.  This
{\tt scheme-mode} is not the same thing as the buffer running the
Scheme process; rather, the source code buffer's being in {\tt
scheme-mode} means that it has special commands for communicating with
the process buffer.

% Oram says above hard to understand, though made clearer by following
% paragraph.

        If you put yourself inside a function definition in the Scheme
source code buffer and type {\tt C-c~C-e}, then that definition will
be ``sent'' to the process buffer---exactly as if you had typed it
into the process buffer yourself.  {\tt C-c~M-e} sends the definition
and then brings you to the process buffer to do some interactive work.
{\tt C-c~C-l} loads a file of Scheme code (this one works from either
the process buffer or the source code buffer).  And like other
programming language modes, hitting \key{Tab} anywhere on a line of
code correctly indents that line.

        If you're at the prompt in the process buffer, you can use
{\tt M-p} and {\tt M-n} to move through your previous commands (also
known as the {\bf input history}).  So if you are debugging the
function {\tt `rotate'}, and have already applied it to arguments in
the process buffer, like so:

\begin{screen}
   \begin{tt}
{\tt > (rotate '(a b c d e))}
   \end{tt}
\end{screen}

        then you can get back to that command by typing {\tt M-p} at
the prompt later on.  There should be no need to retype long
expressions at the Scheme prompt---get into the habit of using the
input history and you'll save a lot of time.
