Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Zig binding for Emacs's dynamic modules

License

Notifications You must be signed in to change notification settings

sirpengi/zig-emacs

 
 

Repository files navigation

Zig-emacs

https://github.com/jiacai2050/zig-emacs/actions/workflows/ci.yml/badge.svg https://github.com/jiacai2050/zig-emacs/actions/workflows/lisp-ci.yml/badge.svg https://img.shields.io/badge/zig%20version-0.15.1-blue.svg

Zig binding for Emacs’s dynamic modules.

Docs

See https://jiacai2050.github.io/zig-emacs/

Example

const std = @import("std");
const emacs = @import("emacs");

// Every module needs to call `module_init` in order to register with Emacs.
comptime {
    emacs.module_init(@This());
}

fn add(e: emacs.Env, v1: emacs.Value, v2: emacs.Value) emacs.Value {
    const a = e.extractInteger(v1);
    const b = e.extractInteger(v2);
    return e.makeInteger(a + b);
}

// Emacs dynamic module entrypoint
pub fn init(env: emacs.Env) c_int {
    env.defineFunc(
        "zig-add",
        add,
        // This make `zig-add` interactive.
        .{ .interactive_spec = "nFirst number: \nnSecond number: " },
    );

    return 0;
}

Compile this example with zig build, then load it into Emacs.

(module-load (expand-file-name "zig-out/lib/libzig-example.dylib"))
(zig-greeting "Jiacai")

If everything is OK, you should see our greeting message in minibuffer.

screenshot.jpg

Usage

zig-emacs support package manager introduced in Zig 0.11.

zig fetch --save=emacs https://github.com/jiacai2050/zig-emacs/archive/${COMMIT}.tar.gz

Replace ${COMMIT} with a real one.

License

MIT

About

Zig binding for Emacs's dynamic modules

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Zig 90.3%
  • Emacs Lisp 7.9%
  • Makefile 1.8%