The first part of this tutorial acquainted you with the basics of the Emacs editor. We now introduce some additional emacs commands and and more information on the use of emacs to write and test Scheme programs. After that, we give a brief introduction to the Elm mail reading program and the Netscape Web browser. You can also access the course newsgroup through Netscape.
(define cat 'cheshire)
When you typed the right parenthesis, it bounced back and matched the left parenthesis. In this way, you will always be able to tell which pairs of parentheses have been properly closed. At this point, let's save the Emacs buffer to the file pets.ss by entering C-x C-w. You can tell that it has been saved by noting that the two asterisks are no longer at the left end of the banner line.
To start up a Scheme process in one of the two buffers, enter M-x run-scheme. We should now have our file pets.ss in one half of the screen, and Scheme in the other. This is probably the way in which you will prefer to do your work. Try switching between the Scheme buffer and the file buffer using C-x o.
We load the file pets.ss into Scheme by typing the expression (load "pets.ss") at the Scheme prompt. This causes Scheme to read and evaluate the expressions in the file just as if they had been typed in at the prompt. We call this loading the file. Now enter cat in response to the Scheme prompt. (Do not quote the symbol cat this time.) Instead of a message indicating an unbound variable, cheshire is returned. We have bound the variable cat to the value cheshire and when Scheme evaluated the atom cat, it returned its value.
Now to get back to the file pets.ss, type C-o again. Use C-n or the down-arrow to skip a line below what has been typed, go to the beginning of the following line and then type
(define dog 'beagle)
Save the buffer again using C-x C-w and return to Scheme using C-o. In order for Scheme to know the new definition, we must load the file again. You may load the file pets.ss again by either typing the statement again, or by using the arrow keys to move up to the previous line where you loaded the file. Move the cursor to the end of the line (did you remember C-e?) and then press <CR>. Emacs should have copied the load expression to the last prompt, causing Scheme to evaluate the load expression again, just as if you had typed it again. Respond to the Scheme prompt with dog. We get the answer beagle. Now go back to the pets.ss buffer using C-x o.
(cons cat (cons dog '())))
and watch carefully how the second line was indented and how the parentheses match as each pair is closed. When typing expressions into Scheme directly (within Emacs), the expressions will also be indented. The Tab key may be used to re-indent the current line if the indentation is not right. (Note that the cursor need not be at the beginning of the line.)
Now save the file, return to the Scheme buffer, and load the file pets.ss. When you get the Scheme prompt, enter couple. You should get the answer (cheshire beagle). Now while in Scheme, enter
> (cons 'a couple)
and you get the answer (a cheshire beagle). (What happens if you now type couple again?). Now kill the Scheme process by entering (exit). To hide the *scheme* buffer, change to the other buffer with C-x o and type C-x 1 which will make the current buffer the only one on the screen. These two operations, C-x o followed by C-x 1, can be accomplished by simply typing C-x 0.
The *scheme* is hidden but not gone. You can bring it into the foreground by typing C-x b and then entering *scheme* at the prompt (it may be the default, in which case, just press <CR>). Kill the buffer by typing C-x k and pressing <CR> at the prompt.
We now return to Scheme to make a point. Type M-x run-scheme again. When you get the Scheme prompt, >, enter cat. You get an error message since the previous Scheme process was terminated and the variable cat is not bound to a value in the current process. Next enter
> (load "pets.ss")
If we now enter cat, we get the answer cheshire.
> (define mylist (cons 'one (cons 'three (cons 'five '()))))
If you type mylist in response to the next prompt, you should see the list (one three five). Now press the up-arrow key enough times to get back to the definition of mylist. Using C-p, move the cursor up to the end of (cons 'one. Press C-o. This opens up a blank line below the line (cons 'one. You move to the beginning of that blank line by pressing C-n and pressing Tab indents the cursor under the ' in 'one. (You may also use C-j to open a new line and move to the correct indentation automatically). Now type (cons 'two. We move to the next line using C-n and re-indent the line using Tab. Pressing the space bar to add spaces moves the line to the right, but Tab or DEL will bring it back. Now move to the next line and edit the 'five to be 'four and indent the last line to be correct (go to that line and hit Tab). You also have to add one right parenthesis at the end of the last line to close all of the parentheses. Your screen should now look like this:
> (define mylist (cons 'one (cons 'two (cons 'three (cons 'four '())))))
With the cursor at the end of the last line, press <CR> to evaluate this expression. Now type mylist and you should see the answer (one two three four). This exercise was designed to show you how to edit in Scheme itself instead of going into an Emacs buffer. The commands for moving around in both are essentially the same, when Scheme is run within Emacs. When Scheme is run outside of Emacs from the shell prompt, it does not have any fancy editing commands.
Now move the cursor to the end of the expression, and press C-w. The lines between where the mark was set and where you pressed C-w should disappear, but they are not gone forever. They are in something called the Kill Buffer. If you now type C-y (yank from kill buffer) the lines will be restored.
Now go to the other buffer, pets.ss, and position the cursor at the bottom of the file. Press C-y again, and another copy of the expression will appear. You may copy expressions either way using this method, from one buffer to another, from Scheme and to Scheme, and within one file. This is analogous to the cut and paste operations many word processors provide.
We are now finished, and you may exit Emacs by typing C-x
To read mail in Emacs, use the command M-x rmail. A new
buffer pops up displaying your first email message, and you are in
rmail mode. In this mode many keys, including the normal letter
keys, invoke commands special to rmail mode. Space and
DEL scroll the current message down and up, respectively.
n and p move to the next and previous messages,
respectively. d deletes the current message. q saves
undeleted messages and exits rmail mode. C-o prompts for a
file name and the current message is saved in the named file.
r replies to the current message, popping up a new buffer to compose the message. This is similar to C-x m, but the To: field is filled in for you and when the cursor is positioned in the body you may use C-c C-y to yank the message you are replying to into the current buffer with some indentation.
In any emacs mode (so far we have introduced Scheme mode, text mode, and rmail mode), the command C-h C-h m may be used to display in a separate buffer a summary of all the mode-specific commands.
|C-j||Go to next line and indent a Scheme expression (in Scheme mode).|
|C-o||Opens a blank line below the current line.|
|Tab||Indents a Scheme expression without the newline (in Scheme mode).|
|C-x 2||Split the window into two buffers.|
|C-x o||Move the cursor to the other buffer.|
|C-x 1||Make the current buffer the only buffer.|
|C-x 0||Make the other buffer the only buffer.|
|C-x k||Kill the current buffer.|
|C-x b||Switch to a different buffer.|
|C-@||Set a mark: a place from which to cut or copy.|
|C-w||Cut the marked text and put in the Kill Buffer.|
|C-y||Yank the contents of the Kill Buffer to current cursor position.|
|C-x C-z||Pauses to shell. Return to Emacs by entering fg.|
|C-h C-h m||Lists mode-specific commands.|
|M-x rmail||Read email.|
|Space||Scroll to next screen of this message.|
|DEL||Scroll to previous screen of this message.|
|d||Delete the current message.|
|r||Reply to this message.|
|C-o||Save this message. Prompts for a file name.|
|q||Save undeleted messages and exit rmail.|
|(load "filename.ss")||Reads and evaluates the expressions in filename.ss.|
|(exit)||Terminates the current Scheme session.|
Either way, Netscape starts by displaying the IU Bloomington home page. Under the heading On the IUB campus the item List of all IUB departments, units, and divisions is underlined. This means it is a WWW link to another page of information. Just click on a link to follow it. Try this one. A new page appears with a list of items, one of which is Computer Science. Click on it to brings up the Computer Science Department's home page. Follow the Courses link and then the C211 link to bring up the home page of this course, which was passed out in hard-copy form on the first day of class as the course description.
If you know the Universal Resource Locator (URL) of a page, you can jump to it directly at any time you are running Netscape by pulling down the File menu and selecting Open. This pops up a window in which to enter the URL. The URL of the C211 home page is http://copper.ucs.indiana.edu/~c211/home.html. Next time you can use it to avoid the long navigation outlined in the last paragraph.
Generally clicking a link calls up another Netscape page, though some links have other behavior such as displaying a simple text page or a directory structure, or perhaps starting a postscript file viewer or a newsgroup viewer. If you have followed a link to a page and want to return to the original page, click on the left arrow or Back button at the top or bottom of the Netscape window.
You might like to access the WWW from home with a modem connection, rather than the high-speed network connection provided all UCS microcomputers. This is possible using the UNIX command lynx while logged into a UNIX machine using a standard terminal emulator. Lynx does not support color and graphics as Netscape does, but it provides basic Web browsing capability.
You can access our class newsgroup from WWW by calling up the C211 home page using Netscape and first selecting Communications and then selecting ac.c.211. This may be the most convenient way four you to read our newsgroup. You may also use the newsgroup reader trn by using the UNIX command
trn -q ac.c.211
If you want to browse through other newsgroups, just enter trn. Some other local groups you may be interested in are cs.general, cs.students, and iu.general. There is a protocol to posting articles to non-class newsgroups. You should subscribe to news.announce.newusers and read it before posting anything outside of our class newsgroup.
trn asks you several questions. If you are in doubt, or do not remember what to do, type h for "help" and trn will show you a list of commands and a short description. trn will pick a default action if you hit the space bar, which is often what you want.
When you enter a newsgroup you are often shown a list of threads which are postings that share a common topic. Most of the time you will just want to hit the space bar to be shown the articles that you have not yet read.
While you are reading an article, hit s and then enter a file name to which the article will be saved. It is saved in a directory named News; to save it in another directory, you should give the path to that directory. For example, to save it in your home directory, type s ~/welcome.txt. Try this, then exit trn by typing q several times.
Often you may wish to go back to an article that you previously read. By default, trn only shows you articles you haven't seen yet. To reread a message, enter the newsgroup (even if there are zero unread articles), and then use P and N to move backward and forward among the unread articles (P for "previous" and N for "next"). Lower-case p and n will also move you backward and forward among articles that you haven't read yet. You can also type the number of the article you want to see; the number is shown at the top and bottom of each article. You can get an index of all articles that were posted in a newsgroup by typing U when you get the prompt [npq]. You get another prompt [+tsan] to which you respond with a +. This produces the index of all articles. You can get more details about using trn by reading the man pages for trn.
If you want to post a reply to an article, you may type f while reading an article in the right newsgroup (f stands for "followup"). You will be prompted for a subject for your article, and then asked for a "Distribution". That will tell trn how far you want your message to be sent. You should always type iu there when posting to our newsgroup. That will make sure that your message doesn't go to a newsgroup with the same name somewhere in Australia. Answer the rest of the questions. When asked what editor to use, you may type emacs. When you are done editing your message, save it and exit from the editor. If you are sure that you want to post; type send. If you are outside of trn you can post a message by sending an email message to the name of the newsgroup.
After starting elm you will be presented with a list of messages in your incoming mailbox and a menu of options at the bottom of the screen. Following is a sample:
At the bottom of the screen is a menu listing the most frequently used commands in elm. To invoke any of these commands just type the single character. When you are mailing a message you can compose the note using an editor. We have setup your configurations such that you can use emacs to compose your messages. To send a note type m. You will then be prompted with:
Command: Mail Send the message to:
Then type the user name(s) of the person(s) to whom you want to send the note. The following example sends a message to Raja Sooriamurthi. (Text typed in bold denotes user input.)
Command: Mail To: Raja Sooriamurthi Subject of message: Question on p2 hw4The Emacs editor will then be automatically invoked. After composing the message leave emacs as usual (C-x C-c). You will then have the options:
Command: Mail To: Raja Sooriamurthi Please choose one of the following options by parenthesized letter: s e)dit message, edit h)eaders, s)end it, or f)orget it.
If you now want to cancel the message you may do so by typing f or else s will send the message. To quit from elm and to return to the Unix prompt type q.
There are several other options that you can use in elm. From the main menu type o to get a list some of the other options. We'll also be giving a demonstration of these during the first lab sessions.
Don't forget to log out of the computer when you are all finished.
At this point you should have the basics that you will need for doing the work in this class. However, there is much more that you can do with UNIX and Emacs that these tutorials don't cover. Read the various handouts from UCS listed at the beginning of this tutorial to learn more, and don't be afraid to ask questions of your instructors.