#emacs #module #bindings #symbol #basic #mut #emacs-val

emacs_module_bindings

Rust library for creating emacs modules

4 releases

Uses old Rust 2015

0.7.0 Dec 9, 2017
0.6.2 Dec 3, 2017
0.6.1 Nov 7, 2017
0.6.0 Aug 19, 2017

#22 in #emacs

BSD-3-Clause

23KB
474 lines

Emacs Module Bindings

This crate provides access to the new Emacs module functionality recently introduced in Emacs 25. It's a basic FFI with a relatively straightforward API. Have have a look at the source for details.

Usage aka How to write an oxidized Emacs module in a few easy steps

  1. Clone this project to some $EMB_PATH
  2. Create a new Cargo lib project, say my_fancy_module
  3. Open up Cargo.toml in an editor, and:
    • Add crate-type = ["cdylib"] to the [lib] section (NOTE: Only Rust nightly correctly handles this at the moment)
    • Add the following dependencies:
    libc = "0.2.14"
    emacs_module_bindings = { path = "$EMB_PATH" }
    
  4. Add the following to your src/lib.rs:
    extern crate libc;
    extern crate emacs_module_bindings as emacs;
    
    use emacs::emacs_module::{EmacsEnv, EmacsRT, EmacsVal};
    
    /// This states that the module is GPL-compliant.
    /// Emacs won't load the module if this symbol is undefined.
    #[no_mangle]
    #[allow(non_upper_case_globals)]
    pub static plugin_is_GPL_compatible: libc::c_int = 0;
    
    #[no_mangle]
    pub extern "C" fn emacs_module_init(ert: *mut EmacsRT) -> libc::c_int {
        let env = emacs::get_environment(ert);
    
        // Add any other things you need the module to do here
    
        emacs::provide(env, "my-fancy-module");
        0
    }
    
  5. Execute cargo build
  6. If you're on OS X, copy target/debug/libmy_fancy_module.dylib to target/debug/libmy_fancy_module.so
  7. Load it in emacs with (require 'my-fancy-module "/path/to/libmy_fancy_module.so"). Note that this requires Emacs to be configured and compiled with the --with-modules flag.

Dependencies

~3–4.5MB
~100K SLoC