tmr08c / ob-zig.el

Org babel bindings for the Zig language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ob-zig.el - Org Babel bindings for the Zig programming language

Introduction

ob-zig.el provides Org Babel support for the Zig programming language. Org Babel allows you to interactively edit and execute source code for many different languages in the same document.

This implementation mostly follows ob-C.el, which provides org-babel support for the C/C++/D languages.

Prerequisites

  • A recent zig compiler that is installed on the exec PATH. Download Zig.
  • org-mode/org-babel - these packages come installed with most recent emacs.

It is also nice to have zig-mode installed for working with zig source:

Installation

git clone https://github.com/jolby/ob-zig.el.git
(add-to-list 'load-path "/home/path-to-where-you-checked-out-ob-zig/")

At this point, you should be able to interactively execute zig source blocks in org mode documents.

Usage

See the file ob-zig-test.org for examples of zig code blocks. If you place your cursor within the code blocks you can compile and execute using the key chord: C-c C-c You can also view the expanded source code block with the key chord: C-c C-v C-v

Here is an example of a zig code block within an org-mode document:

#+source: simple
#+begin_src zig :imports '(std)
const stdout = std.io.getStdOut().writer();
try stdout.print("{s}", .{"hello"});
#+end_src

If you place the cursor somewhere within the above code block, and then press the key chord: C-c C-c, emacs will execute that zig source code and insert the result below:

Read the documentation of Org Babel for more examples of what you can do with source code blocks of many different languages.

Testing

ob-zig.el has a test suite that works with the ERT (Emacs Lisp Regression Testing) and org-test framework that comes with emacs. The directory containing org-test.el needs to be on the load path. In most cases this will be the “testing” directory under the root of the main org package on your system. On my doom-emacs setup, I needed to do this to get org-test on the load path:

(add-to-list 'load-path (expand-file-name "straight/repos/org/testing" doom-local-dir))

The file test-ob-zig-runner.el has some utility functions for setting up paths and running the ERT test suite. It should be sufficient to load that file and then call the interactive function: M-x test-ob-zig-run-tests.

About

Org babel bindings for the Zig language

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 100.0%