Common Lisp Programming and emacs


Artificial Intelligence Laboratory

Editor's Note

This document was created by Sid Bos, a former UNI student of AI, in response to questions from several of his fellow students about how to use emacs to support Common Lisp programming. I thank Sid for the effort he put into to writing the original document. I have since made a number of modifications. I have re-formatted the document for use in 810:161, have made small changes to content and grammar, and this semester have modified it to work in our new Linux environment and CMU Common Lisp. Any errors should be construed as mine and reported to me for correction. -- EW


Gnu emacs can provide an interface to any Common Lisp system. On cowboy, it provides an interface to lisp, the CMU Common Lisp system.

If you would like to use this interface but are a little rusty on how to use emacs, be sure to review the next section before proceeding. If you are pretty comfortable with your user level in emacs, feel free to proceed directly to the Common Lisp portion of this page. If you want to see all of the commands discussed below in the context of a Common Lisp/editing session, jump directly to a short laundry list.

A Quick Refresher on emacs

emacs uses three types of control sequences to specify commands:

You will want to know the following commands in order to navigate as a power user within emacs:

Supporting Common Lisp within emacs

emacs provides different modes that are helpful when programming in different languages. They offer support for programming style (e.g.,automatic indentation) and syntax (e.g., parenthesis balancing). emacs' current mode should be displayed in the status bar at the bottom of its window.

In order to take advantage of built-in support for Common Lisp programming, you will need to be in lisp-mode. To switch to lisp-mode, type M-x lisp-mode. If you want emacs to enter lisp-mode automatically for files with a .lisp extension, add the following expression to your ~/.emacs file:

    (setq auto-mode-alist (append '(("\\.lisp$" . lisp-mode))

Yes, this is Common Lisp code. Gnu emacs is written almost entirely in Common Lisp!

Gnu emacs actually provides its own built-in Common Lisp interpreter, which you can run by typing

Esc-x ielm

Unfortunately, this version of Common Lisp is so incomplete that it won't be sufficient for programming in our class.

Instead, you can run and use lisp within emacs. Here are the relevant commands:

The following commands can be used within the buffer in which lisp is running. If you are at the command line within the lisp buffer,

I know that many of you have been clamoring for this capability!

A Common Lisp/Editing Session

Here is what you might do when you sit down at the machine with the intention to work on Common Lisp code.

When you're done, be sure to save your file to preserve the results of the session. (Even though the inferior gcl session loads directly from the unsaved buffer, you will want to save for future use!)

Eugene Wallingford ==== ==== September 7, 2001