Using Emacs as an IDE¶
This page is meant to provide an introduction to using Emacs as a Lisp IDE. The key bindings used in the example code snippets assume an Emacs configuration similar to that provided by the .emacs file that is included as part of the Setting up an IDE with Emacs on Windows or Mac OS X page. If you use ILISP, the key bindings reflect the bindings that are present in the current CVS version of ILISP.
Why Use Emacs?¶
- Emacs has fantastic support for working with Lisp code
- Not tying yourself into a single CL vendor’s editor
- Runs on virtually every OS and CL implementation
- Extensible
- Can be customized to do many common tasks
- Built-in support for different source code version control systems
- Vast number of add-on packages
- Emacs will probably always be around
- Emacs works well either with a mouse or without a mouse
- Emacs has a large user base with multiple newsgroups
- Benefits of using Emacs far outweigh the effort spent in learning it
Emacs Lisp vs Common Lisp¶
- Learning Emacs Lisp is useful and similar (but different from CL):
- Dynamic scope is everywhere
- No package system
- There are no reader (or reader-related) functions
- Does not support all the types that are supported in CL
- Incomplete implementation of CLOS (with the add-on EIEIO package)
- Not all of CL is supported
- No numerical tower support
- Some good Emacs Lisp learning resources:
Lisp Modes in Emacs¶
Inferior Lisp Mode¶
- Pros:
- Comes with Emacs
- Fast start-up, easy setup
- Supports many Lisp implementations
- Cons:
- Limited functionality (compared to ILISP and ELI)
- No multiprocessing support
- Some conflicts with comint mode
- Setup:
- Included with Emacs, so no separate installation required
ILISP¶
- Pros:
- Vastly superior to Inferior Lisp Mode in functionality
- Supports many Lisp implementations
- Cons:
- No multiprocessing support
- Some conflicts with comint mode
- Setup:
- A basic installation involves downloading the ILISP package from the web building it and configuring it
- Customization can be complex, useful to use instructions on CL Cookbook to get started
ELI: Emacs-Lisp Interface¶
- Pros:
- Supports multiprocessing (this is a big pro)
- Has commands that allow you to work with changed definitions
- Standard, consistent set of options for managing output
- Support for ACL and support from Franz is very good
- Cons:
- For CMUCL and SBCL, only limited functionality is available
- No built-in support for accessing either Franz or CL documentation
- Setup:
- Basic ELI setup is very straight-forward for ACL
SLIME: Superior Lisp Interaction Mode for Emacs¶
- Pros:
- Provides REPL which is hooked to implementation directly in Emacs
- Has integrated Common Lisp debugger with Emacs interface
- Interactive object-inspector in Emacs buffer
- Has own minor mode which enhances lisp-mode in many ways
- Supports every common Common Lisp implementation
- Readily available from MELPA
- Actively maintained
- Symbol completion
- Cross-referencing
- Can perform macroexpansions
- Cons:
- Installing SLIME without MELPA can be tricky
- Setup:
- Installing it from MELPA is straightforward. Search package-list-packages for ‘slime’ and click to install. If MELPA is configured correctly, it will install itself and all dependencies.
- Run slime with M-x slime
Lisp Modes in Emacs - Which One to Choose?¶
- My Recommendation:
- Inferior Lisp Mode for casual CL programming only
- ELI if you use ACL
- SLIME otherwise
Working with Lisp Code¶
- Lisp Editing
- Evaluating and Compiling Lisp
- Searching Lisp Code
- Note: Example code assumes you are using a setup similar to what is defined in the .emacs file from the CL Cookbook site
Working with Lisp Code - Editing¶
Working with Lisp Code - Evaluating and Compiling Lisp¶
- buffer
- region
- defun
- sexp (previous/next)
- DWIM
- Example code ( s11.lisp )
{% include code/s11.lisp %}
Working with Lisp Code - Searching Lisp Code¶
Lisp Documentation in Emacs - Learning About Lisp Symbols¶
Lisp Documentation in Emacs - Lisp Documentation¶
- CL HyperSpec
- CLtL2
- ACL Documenation
- Example code ( s23.lisp )
{% include code/s23.lisp %}
Miscellaneous¶
Project Management¶
Debugging¶
- ILISP has a standarized set of key bindings for debugging across implementations (“C-c C-b C-h” for a list of them).
Questions/Answers¶
Controlling evaluation output¶
I get irritated by ELI’s switching to an output buffer when I evaluate a sexp in a Lisp source buffer.
fi:pop-up-temp-window-behavior
variable. Alternatively, you can
useViewing HyperSpec from within Emacs¶
I like having access to the HyperSpec when I’m in Emacs, but why does it have to use an external browser? Why can’t I just see the HyperSpec in Emacs?
(global-set-key [(shift f1)]
'(lambda ()
(interactive)
(let ((browse-url-browser-function
'browse-url-w3)
(common-lisp-hyperspec-root
"file://c:/home/docs/Hyperspec/")
(common-lisp-hyperspec-symbol-table
(concat common-lisp-hyperspec-root
"Data/Map_Sym.txt"))
(hyperspec-prog
"c:/home/site/ilisp/extra/hyperspec"))
(load-library hyperspec-prog)
(common-lisp-hyperspec
(thing-at-point 'symbol)))))
Standard shell¶
I switch between UNIX® and Windows environments and, although Emacs makes this switch a lot easier, I find it inconvenient having to use different Shell environments on different operating systems.
Using ACL tools with Emacs¶
I would like to use Emacs with Franz’s ACL but find that I use the Franz tools so much that I can’t afford to not load their IDE.
Windows-style cut/copy/paste¶
I want to use Emacs on a Windows machine. Unfortunately, I have the Windows cut/copy/paste key bindings burned into my fingertips and would find it very difficult to switch back and forth between the Windows standard for these shortcut keys and the Emacs standard.
;; Windows-like mouse/arrow movement & selection (pc-selection-mode)
(delete-selection-mode t)
;; C-z=Undo, C-c=Copy, C-x=Cut, C-v=Paste (needs cua.el)
(require 'cua) (CUA-mode t)
Simplified Emacs setup¶
There was a lot of Emacs Lisp code presented in this paper. Do I really have to type in all this stuff to get started with Emacs and Lisp?
Alternatives to Emacs for CL programming¶
I’ve tried out Emacs and I just can’t get used to it. What other Lisp-friendly alternative are there?
- The Franz, LispWorks, Corman, and Digitool commercial Lisp offerings all have Lisp-aware editors.
- CMUCL has Hemlock, which is also being adapted for other Lisps.
- XEmacs is an alternative to GNU Emacs that works with many of the same Elisp libraries. Some people prefer it to GNU Emacs.
- Vim can be used to edit Lisp code. An article by Larry Clapp gives some pointers on how to use Vim with Lisp.
- Jabberwocky is a Lisp editor/debugger written in Java.
- Lastly, for true masochists, notepad on Windows or ed on UNIX® can also be used. ;-)
Disclaimer¶
The original material on this page was originally presented at the ILC 2003 conference. A paper with more in-depth coverage of some of the material on this page can be found on Bill Clementson’s ILC2003 page, which is now archived.