- Emacs Lisp 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .github/workflows | ||
| test | ||
| LICENSE | ||
| ob-janet.el | ||
| README.org | ||
Introduction
ob-janet provides Org
Babel support for the Janet
language to enable Janet code blocks in literate Org files.
Installation
Manual Installation
Download ob-janet.el, place it in the
load path, and add a require to your init
file. It may be necessary to set or customize ob-janet-path and ob-janet-executable if either can't be found by
default.
(require 'ob-janet)
(add-to-list 'org-babel-load-languages '(janet . t))via use-package
(use-package ob-janet
:after org
:init
(setq ob-janet-executable "janet"
ob-janet-path "/usr/local/lib/janet")
:config
(add-to-list 'org-babel-load-languages '(janet . t)))via straight.el
(use-package ob-janet
:straight (:host github :repo "zzkt/ob-janet")
:after org
:config
(add-to-list 'org-babel-load-languages '(janet . t)))Usage
Execute a code block with C-c C-c using
the header :results output to capture
stdout, or :results value to capture the
return value of the block.
(var void 'boundless)
(print "I live in a boundless void.")
(string "The void is " void)
(var void 'boundless)
(print "I live in a boundless void.")
(string "The void is " void)
Variables can be passed from named Org blocks (including tables) or assigned in the header
| Name | Age |
|---|---|
| Eleanor | 36 |
| Jason | 29 |
| Kamilah | 31 |
(each row data
(print (string "Name: " (row 0) ", Age: " (row 1))))
(print (+ x y))
Header arguments
| Header | Description | Default |
|---|---|---|
:cmd <path> |
Janet executable or path | janet |
:results <format> |
Result format: raw, none, output or
value |
output |
:session <name> |
Session name for persistent eval | none |
:file <path> |
Output file path | none |
:prologue <code> |
Code to prepend before the body | none |
:epilogue <code> |
Code to append after the body | none |
:debug |
Show expanded body | none |
Sessions
Use :session for persistent state
(sessions) across code blocks that share the same session name
(var *count* 0)
(defn increment [] (++ *count*) *count*)
(increment)
(increment)
(increment)
Prologue and Epilogue
Use :prologue or :epilogue to include code before or after the
main body of the src block.
(def phi^2 (+ phi 1))
File Output
Use :file and a path to write output
(or value) to a file
(loop [i :range [1 11]]
(print i))
see: file:numbers.txt
Debug
Preview expanded code, without evaluation, by adding :debug to the header. The output is the
unevaluated code that would be sent to a Janet process.
(+ x 10)
(+ x 10)
Customization
Customize ob-janet settings with the
ob-janet customization group, M-x customize-group ob-janet
| Variable | Description | Default |
|---|---|---|
ob-janet-executable |
Path to Janet executable | "janet" |
ob-janet-hline-to |
Replacement for table hlines in Janet | "nil" |
ob-janet-nil-to |
Replacement for Janet nil in results | 'hline |
ob-janet-value-wrapper |
Template for wrapping value results | see: ob-janet.el |
ob-janet-output-wrapper |
Template for wrapping output results | see: ob-janet.el |
Troubleshooting
Janet not found
Ensure janet is on your PATH, or customize ob-janet-executable to include the full path to
the janet executable.
(setq ob-janet-executable "/usr/local/bin/janet")Modules (or symbols) not found
Modules and libraries are located using the JANET_PATH environment variable. If JANET_PATH is not set, or has been redefined,
the variable ob-janet-path can be used to
set the correct path.
(setq ob-janet-path "/usr/local/lib/janet/")