This page provides some instructions for using Emacs with Scheme. If you're not a regular Emacs user, I would strongly recommend taking some time to learn the basics now, because this will save you an enormous amount of time and effort (and probably frustration) in the long run. Emacs has a built-in tutorial that can be started by typing the command CTRL-h t.
If you already had a Pomona Linux account before taking CS 131, you will need to do a couple of things first in order to set up your account properly:
Add the following two lines to your top-level ~/.emacs file (if you don't already have a .emacs file, you'll need to create one):
(load "/common/cs/share/emacs/common.emacs") (load "/common/cs/share/emacs/cs131.emacs")
Add /common/cs/cs131 to your PATH variable.
If you requested a new account for CS 131, you don't need to do the above steps because your account should already be set up properly.
To start the Scheme interpreter by itself, type scheme at the Linux prompt. To load in a file, use the built-in load function at the Scheme prompt:
> (load "whatever.ss") >Alternatively, you can type scheme whatever.ss at the Linux prompt, which loads in the file automatically on startup.
To exit the Scheme interpreter, type (exit) at the Scheme prompt.
To start Emacs, type emacs at the Linux prompt.
In general, it's more useful to run an interactive Scheme session inside Emacs, rather than from the Linux command line. This allows you to use all of the powerful editing features of Emacs in your Scheme session. To run Scheme within Emacs, start up Emacs and then type ESC x run-scheme followed by Return.
You can then split the Emacs window into two subwindows using CTRL-x 2 (or CTRL-x 3 if you prefer vertical subwindows), and open your Scheme file in one of the subwindows. That way, you can see and edit your definitions alongside your interactive Scheme session. To toggle between the subwindows, type CTRL-x o. To open a file in a subwindow, type CTRL-x CTRL-f. See the CS 131 Emacs Quick Reference Guide for more information about basic editing commands.
You should use the extension .ss for your Scheme source files. This will cause Emacs to automatically enter Scheme mode when a Scheme file is opened.
Here are some useful commands to know about in Scheme mode:
To highlight an entire S-expression, left-double-click the mouse on the expression's opening left parenthesis (or on its first character if it is not a list).
ESC CTRL-f (or CTRL-[ CTRL-f) with the cursor on an opening left parenthesis moves forward one entire S-expression.
ESC CTRL-b (or CTRL-[ CTRL-b) with the cursor to the immediate right of a closing right parenthesis moves backward one entire S-expression.
ESC CTRL-k (or CTRL-[ CTRL-k) with the cursor on an opening left parenthesis kills/cuts one entire S-expression. You can then yank/paste it back wherever you like using CTRL-y. Equivalently, you can first double-click on an expression's left parenthesis to highlight it, then kill/cut it using CTRL-w.
CTRL-c CTRL-e repositions the cursor at the Scheme prompt.
To re-execute an earlier Scheme command in the interaction window, just place the cursor on the earlier line (or use CTRL-r to search backwards for a particular string) and then hit Return. You can also edit the earlier line if desired before hitting Return.
To have the interpreter evaluate an S-expression in your Scheme file, place the cursor immediately after the expression's closing right parenthesis and type CTRL-x CTRL-e. For example, if you edit a function definition in your Scheme file and you want to send the new updated definition to the interpreter without having to save and reload your file, simply place the cursor at the end of the (define ...) expression and type CTRL-x CTRL-e.
To send an entire region of code to the Scheme interpreter, highlight the region with the mouse and type CTRL-c CTRL-r.
To reset the interpreter (or interrupt an infinite loop, etc.) type CTRL-c CTRL-c. At the break> prompt, just type r (or ? for more options).