[][src]Attribute Macro emacs_macros::defun


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


By default, the function's Lisp name has the form <feature-prefix>[mod-prefix]<base-name>.

  • feature-prefix is the feature's name, followed by -. This can be customized by the name and separator options on #[module].
  • mod-prefix is constructed from the function's Rust module path (with _ replaced by -). This can be turned off crate-wide, or for individual function, using the option mod_in_name.
  • base-name is the function's Rust name (with _ replaced by -). This can be overridden with the option name, e.g. #[defun(name = "foo:bar")].


  • Each argument's type must be either:
    • A type that implements FromLisp. Examples: i64, String, Value.
    • &Env. This is used to interact with the Lisp runtime. It does not appear in the function's Lisp signature. This is unnecessary if there's already another argument with type Value.
  • The return type must be Result<T>, where T is a type that implements IntoLisp. Examples: i64, String, Value, impl IntoLisp.