An Emacs feature that defines support for Org-Mode Babel code blocks written in Racket.
Includes support for many of the usual Org SRC
block header arguments (with the notable exception of :session
), as well as some extras for controlling the way that code blocks are evaluated. The additional controls are perhaps more important for Racket than for most other languages, since Racket is not just one language. Rather, Racket is an open-ended, user-extensible collection of languages (including, e.g., Racket, Scribble, Slideshow, Redex, and Magnolisp), which may not always be evaluated in the Racket VM in the usual way of just invoking the racket
executable.
To use ob-racket
, first ensure that Org-Mode is installed in Emacs, as it probably is. For a richer editing experience you may also want to ensure that a major mode (such as racket-mode) has been configured for editing racket
code blocks in Org.
If your mode for editing Racket code is not called racket-mode
, you’ll want to specify the mode to use with something like:
(add-to-list 'org-src-lang-modes '("racket" . geiser))
Firstly, you may want to byte compile the “ob-racket.el” file, for example by invoking the byte-compile-file
function under Emacs.
Then make sure the ob-racket
feature is on Emacs’ load-path
so that it can be loaded on demand:
(add-to-list 'load-path "/my/path/to/emacs-ob-racket")
Furthermore, you should enable racket
code for evaluation (e.g., upon invoking org-babel-execute-src-block
, by default bound to C-c C-c
under Org) by making available the *:racket
definitions of the ob-racket
feature. One way to do that is to simply require
the feature, but Org can also be made to load ob-racket
by having the customizable org-babel-load-languages
variable include racket
. Programmatically, something like this should do the trick:
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(racket . t)
;;(scribble . t) ;; if Scribble support is available
))
Code evaluation may still require confirmation, depending on the value of the org-confirm-babel-evaluate
variable, which is customizable, and may also be set file locally.
Some ob-racket
functionality relies on a Racket module for converting Racket values to Emacs Lisp ones, and it can be worthwhile to byte-compile the implementations of that module:
raco make ob-racket-runtime*.rkt
The “ob-racket-runtime.rkt” module is the default implementation, but as there is no one “correct” way to map values between languages, nor is the particular implementation even compatible with all possible Racket-based languages, it is possible to use different implementations in different situations or with different #lang
‘uages. An example “ob-racket-runtime-typed.rkt” module is included for Typed Racket.
The cloning, byte-compilation, loading, and configuration can all be done declaratively with straight.el, use-package, and the included ob-racket-raco-make-runtime-library
function:
(use-package ob-racket
:after org
:config
(add-hook 'ob-racket-pre-runtime-library-load-hook
#'ob-racket-raco-make-runtime-library)
:straight (ob-racket
:type git :host github :repo "hasu/emacs-ob-racket"
:files ("*.el" "*.rkt")))
For evaluating code blocks written in Racket in the usual way the ob-racket
feature by default assumes that there is an executable named “racket” in the search PATH
of the Emacs process. If that is not the case then a different way of invoking Racket can be specified using ob-racket
’s “command templates.”
For example, if you have set the variable racket-program
for racket-mode
so that it specifies a path to a racket
program executable, then you can also configure the same value for ob-racket
by overriding the default racket
program template:
(setq ob-racket-custom-command-templates
`((racket . ,racket-program)))
There is no separate documentation for ob-racket
, so look at the source code, and the Emacs Lisp docstrings of the functions and variables appearing there. You will probably also find the relevant Org documentation useful:
(progn
(info-display-manual "org")
(Info-goto-node "Working With Source Code"))