Crate emacs[][src]

Expand description

This provides a high-level binding to emacs-module, Emacs’s support for dynamic modules.

Code for a minimal module looks like this:

use emacs::{defun, Env, Result, Value};


#[emacs::module(name = "greeting")]
fn init(_: &Env) -> Result<()> { Ok(()) }

fn say_hello(env: &Env, name: String) -> Result<Value<'_>> {
    env.message(&format!("Hello, {}!", name))
(require 'greeting)
(greeting-say-hello "Emacs")

See User Guide and examples.


Defines new error signals.

Declares that this module is GPL-compatible. Emacs will not load it otherwise.

Defines static &OnceGlobalRef variables that point to corresponding Lisp symbols.


Main point of interaction with the Lisp runtime.

The Error type, a wrapper around a dynamic error type.

A “global reference” that can live outside the scope of an Env. This is useful for sharing an otherwise short-lived Lisp Value across multiple invocations of Rust functions defined with defun. Examples include efficient access to interned symbols or Lisp functions, and Rust-based multi-threading.

A GlobalRef that can be initialized once. This is useful for long-lived values that should be initialized when the dynamic module is loaded. A typical use case is specifying frequently-used symbols, which can be done with the help of the macro use_symbols!.

A type that represents Lisp values. Values of this type can be copied around, but are lifetime-bound to the Env they come from.

A type that represents Lisp vectors. This is a wrapper around Value that provides vector-specific methods.


Error types generic to all Rust dynamic modules.


Converting Lisp Value into a Rust type.

Converting a Rust type into Lisp Value.

Emacs-specific extension methods for the standard library’s Result.

Allowing a type to be exposed to Lisp, where its values appear as opaque objects, or “embedded user pointers” (printed as #<user-ptr ...>).

Type Definitions

A specialized Result type for Emacs’s dynamic modules.

Attribute Macros

Exports a function to the Lisp runtime. The function is bound when the module is loaded, even if it is defined inside another function which is never called.

Registers a function as the initializer, to be called when Emacs loads the module. Each dynamic module must have one and only one such function.