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::plugin_is_GPL_compatible!();
#[emacs::module(name = "greeting")]
fn init(_: &Env) -> Result<()> { Ok(()) }
#[defun]
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.
Macros§
- define_
errors - Defines new error signals.
- plugin_
is_ GPL_ compatible - Declares that this module is GPL-compatible. Emacs will not load it otherwise.
- use_
symbols - Defines static
&OnceGlobalRef
variables that point to corresponding Lisp symbols.
Structs§
- CallEnv
- Like
Env
, but is available only in exported functions. This has additional methods to handle arguments passed from Lisp code. - Env
- Main point of interaction with the Lisp runtime.
- Error
- The
Error
type, a wrapper around a dynamic error type. - Global
Ref - A “global reference” that can live outside the scope of an
Env
. This is useful for sharing an otherwise short-lived LispValue
across multiple invocations of Rust functions defined withdefun
. Examples include efficient access to interned symbols or Lisp functions, and Rust-based multi-threading. - Once
Global Ref - 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 macrouse_symbols!
. - Value
- A type that represents Lisp values.
Values of this type can be copied around, but are lifetime-bound to the
Env
they come from. - Vector
- A type that represents Lisp vectors. This is a wrapper around
Value
that provides vector-specific methods.
Enums§
- Error
Kind - Error types generic to all Rust dynamic modules.
Traits§
- From
Lisp - Converting Lisp
Value
into a Rust type. - Into
Lisp - Converting a Rust type into Lisp
Value
. - Result
Ext - Emacs-specific extension methods for the standard library’s
Result
. - Transfer
- Allowing a type to be exposed to Lisp, where its values appear as opaque objects, or “embedded
user pointers” (printed as
#<user-ptr ...>
).
Type Aliases§
Attribute Macros§
- defun
- 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.
- module
- 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.