1 History and Motivation

1.1 Origins in Emacs Lisp

SLIME was initially developed in the early 2000s by Eric Marsden, Luke Gorrie, and Helmut Eller as an Emacs Lisp package. The motivation stemmed from the desire to bring the interactive, incremental development style of Lisp machines to the GNU Emacs environment. Earlier attempts, such as ILISP, had limitations in performance and extensibility. SLIME aimed to provide a more modern and modular architecture by separating the editor interface from the Lisp backend.

1.2 Relationship with SWANK

SLIME is composed of two main parts: the Emacs-side client written in Emacs Lisp and a Lisp-side server called SWANK. SWANK (System Wide Area Network Kludge) runs inside the target Common Lisp implementation and handles compilation, evaluation, debugging, and introspection. The communication between the two is mediated by a simple, flexible protocol. This separation allows SLIME to support multiple Lisp dialects and backends.

2 Architecture

2.1 Emacs-side Client (slime.el)

The Emacs-side component, implemented in the file slime.el, provides the user interface and buffer management. It handles keybindings, mode activation, and graphical displays such as the REPL, debugger, and inspector. It communicates with SWANK by sending and receiving s-expressions over a network connection.

2.2 Lisp-side Server (swank)

SWANK runs inside the Lisp process and exposes the underlying implementation’s compiler, debugger, and inspector APIs. It listens for requests from SLIME and responds with Lisp data. SWANK is extensible: users can add custom backends for different Lisp systems.

2.2.1 Communication Protocol (Sexp over TCP)

The protocol between SLIME and SWANK is text-based, using s-expressions over TCP sockets. Each message is a list prefixed with a length header. The design is intentionally simple to allow debugging and to support alternative transports (e.g., Unix sockets, SSH tunnels). The protocol defines operations such as evaluation, compilation, and symbol lookup.

2.3 Network and Process Layers

SLIME supports both local and remote connections. Locally, it launches a Lisp subprocess and connects via TCP on localhost. For remote development, the user can manually start SWANK on a remote machine and connect Emacs via a network socket. The process layer handles startup, shutdown, and error recovery, ensuring a stable development loop.

3 Installation and Setup

3.1 Using Quicklisp

The recommended method is via Quicklisp, the package manager for Common Lisp. After installing Quicklisp, running (ql:quickload :swank) in the Lisp REPL downloads and loads SWANK. Emacs users can then configure SLIME using the package manager (e.g., MELPA) to install the slime Emacs package.

3.2 Manual Installation

Manual installation involves downloading the SLIME source from the official Git repository, loading it into Emacs, and ensuring SWANK is available in the Lisp search path. The user must set the variable inferior-lisp-program to the path of the Common Lisp implementation (e.g., SBCL, Clozure CL).

3.3 Configuration in Emacs Init File

A typical configuration in .emacs or init.el includes:

(add-to-list 'load-path "~/path/to/slime")
(require 'slime)
(setq inferior-lisp-program "sbcl")
(slime-setup '(slime-fancy slime-company))

The slime-fancy contrib loads optional features like the REPL, debugger, and inspector. Additional contribs provide completion (slime-company), profiler, and macro expansion.

4 Core Features

4.1 REPL Integration (Inferior Lisp)

SLIME provides a full-featured REPL (Read-Eval-Print Loop) buffer called *inferior-lisp* or *slime-repl*. It supports input editing, history, tab completion, and inline evaluation. The REPL integrates with the debugger: errors spawn an interactive debugger buffer without leaving the editing environment.

4.2 Code Compilation and Evaluation

4.2.1 Compiling Files and Functions

The user can compile an entire file with C-c C-k (slime-compile-and-load-file) or compile a single function definition with C-c C-c (slime-compile-defun). SLIME sends the region to SWANK, which compiles it using the Lisp system’s compiler and reports warnings or errors in a dedicated *slime-compilation* buffer.

4.2.2 Interactive Evaluation in Buffer

SLIME supports evaluating arbitrary s-expressions directly in source buffers. Pressing C-x C-e (slime-eval-last-expression) evaluates the expression before the cursor and displays the result in the minibuffer. This enables rapid prototyping without leaving the editor.

4.3 Debugging and Error Handling

4.3.1 Debugger Interface

When an error occurs, SLIME presents an interactive debugger buffer showing the restarts offered by the Lisp condition system. The user can select a restart, inspect local variables, or enter the debugger’s recursive REPL. The debugger is fully keyboard-driven.

4.3.2 Backtrace and Inspect

A backtrace of the call stack is displayed with source references. The slime-inspect command (default C-c I) opens an inspector buffer that allows the user to navigate complex Lisp data structures (lists, arrays, objects) interactively.

4.4 Code Navigation

4.4.1 Symbol Completion and Documentation Lookup

SLIME provides symbol completion (M-TAB or slime-complete-symbol). Documentation lookups (C-c C-d d for slime-describe-symbol) fetch the docstring and hyperlink to source. The hyperspec lookup (C-c C-d h) can query the Common Lisp HyperSpec online.

4.4.2 Definition Jumping (M-.)

Pressing M-. (slime-edit-definition) navigates to the source definition of the symbol under the cursor. If the definition is in a different file, SLIME opens that file and jumps to the correct line. M-, returns to the previous location.

5 Advanced Capabilities

5.1 Macro Expansion

SLIME can expand macros step by step. The slime-macroexpand-1 command (bound to C-c M-m) shows the first expansion, while slime-macroexpand-all (bound to C-c M-e) fully expands the macro. Expansions are displayed in a separate buffer with syntax highlighting.

5.2 Profiling and Optimization

The slime-profile contrib allows profiling Lisp functions. It wraps function calls to collect timing and call-count statistics. Results are displayed in a table that can be sorted. This helps identify performance bottlenecks during development.

5.3 Cross-Reference and Who-Calls Analysis

SLIME provides cross-reference commands. slime-who-calls (C-c C-w h) lists all functions that call a given function. slime-calls-who (C-c C-w c) lists all functions called by a given function. These tools support refactoring and code comprehension.

5.4 Customizable Keybindings and Extensions

Users can customize nearly every keybinding via Emacs’s standard mechanisms. SLIME’s contrib system allows adding features like an interactive profiler, a REPL with augmented history, or integration with external tools (e.g., Git). Popular contribs include slime-autodoc (displaying argument lists) and slime-company (company-mode integration).

6 SLIME for Other Lisp Dialects

6.1 Scheme Support via Xscheme and Other Backends

While primarily designed for Common Lisp, SLIME can be adapted for Scheme. The slime-scheme-contrib provides basic support using the Xscheme backend. However, Scheme support is less mature; dedicated tools like Geiser are often preferred.

6.2 Clojure and CIDER Analogues

Clojure developers commonly use CIDER, which is inspired by SLIME. CIDER similarly provides a REPL, debugger, and code navigation for Clojure running on the JVM. SLIME itself does not directly support Clojure—CIDER is the de facto analog for that dialect.

7 Community and Ecosystem

7.1 Contributing and Bug Tracking

SLIME is maintained on GitHub under the slime organization. Bug reports and feature requests are tracked via the issue tracker. Contributions follow Emacs Lisp coding conventions, and the project welcomes patches. The SLIME developers also maintain SWANK as a separate library.

Sly is a fork of SLIME with a redesigned user interface and improved performance. It remains compatible with SWANK backends. Additionally, SLIME’s architecture has influenced other Emacs development tools, such as elisp-slime-nav for navigating Emacs Lisp code.

8 References and Further Reading

* Luke Gorrie, Helmut Eller et al., *SLIME User Manual* (included in the SLIME distribution). * Peter Seibel, *Practical Common Lisp* (Apress, 2005) – includes a chapter on using SLIME. * The SLIME GitHub repository: https://github.com/slime/slime * Common Lisp HyperSpec: http://www.lispworks.com/documentation/HyperSpec/Front/index.htm