slumos / ob-session-async

Asynchronous org-mode session evaluation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ob-session-async

This package extends org-babel to allow asynchronous session evaluation.

It currently implements async session evaluation for R, Ruby, and Python*, and also provides functionality for implementing async session evaluation in other language modes that use comint.

Status

This package is still in an experimental stage, and not available in MELPA.

However, the code is fairly robust now, and I am using it regularly for my day-to-day data analysis in R.

Currently, we have implemented async session evaluation for R and Ruby. We have partial support for Python (we support :results output, but NOT :results value).

The org-mode mailing list has expressed some interest in including this code in org-mode (thread), and a long-term goal of the project is to contribute this functionality back upstream to org-mode.

Installation & usage

First ensure the lisp/ directory is in your load-path, and R is in org-babel-load-languages. Then, (require 'ob-session-async-R). You will then be able to asynchronously evaluate R code blocks like the below:

#+begin_src R :async :session
  Sys.sleep(5)
  "this won't hang your emacs"
#+end_src

Related packages

  • emacs-jupyter enables using jupyter kernels with org-babel source blocks, and supports async session evaluation. It’s an excellent package and I like using it, especially with Python. However, there are some situations where I’d rather not use jupyter, which lead me to writing this package. For example, when using R, I prefer the ESS (Emacs Speaks Statistics) environment over the jupyter IRkernel.
  • ob-async enables async evaluation for regular (non-session) org-babel source blocks. It does not support the :session header argument for evaluating multiple source blocks in an existing session.

How it works

Whenever new output is added to the session’s comint buffer, the function ob-session-async-filter scans the output for an indicator token. Upon encountering the token, the filter uses a regular expression to extract a UUID or temp-file associated with the result, then searches for the appropriate location to add the result in.

This code is loosely based on org-babel-comint-with-output in ob-comint.el, which is the upstream code in org-mode to evaluate code in a comint session and return the output.

A lot of the code in this package is just copied from org-mode, then slightly adjusted to accommodate async evaluation. I plan to eventually refactor the code and contribute it back upstream to org-mode, to reduce code duplication and improve code reuse.

Links

About

Asynchronous org-mode session evaluation

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 98.7%Language:Makefile 1.3%