edij - Emacs Does Interactive J

edij is an Emacs mode for interactive J programming, inspired by ediprolog by Markus Triska. It lets you evaluate J expressions directly in any buffer, with results appearing as comments below your code.

Download: edij.el

How It Works

The core idea is simple: write J code in any buffer, press a key, and see results inline. The mode manages a background J process (jconsole) and handles all the communication for you.

I have it bound to C-n (see my keyboard layout) via edij-dwim (Do What I Mean), which intelligently decides what to do based on cursor position:

Results are prefixed with NB. (J’s comment syntax), so they’re ignored if you re-evaluate the buffer.

Example Session

Here’s what interactive development looks like:

a =: i. 3 4
a
NB. a
NB. 0 1  2  3
NB. 4 5  6  7
NB. 8 9 10 11

|: 10 * a
NB. |: 10 * a
NB.  0 40  80
NB. 10 50  90
NB. 20 60 100
NB. 30 70 110

First I define a as a 3x4 array (nothing prints for assignments). Then I evaluate a and get the array displayed as a comment block. Finally I transpose and scale it, seeing the transformed result immediately.

The output preserves J’s array formatting, which matters for understanding the shape of your data:

(];drawcube) gencube''
NB. (];drawcube) gencube''
NB. +-------+------------------+
NB. |1 1 0 1|                  |
NB. |1 1 0 1|     ############ |
NB. |0 0 1 0|    ##            |
NB. |       |   # #            |
NB. |       |  #  #            |
NB. |       | ############     |
NB. |       | #   #      #     |
NB. |       | #   #      #     |
NB. |       | #   #      #     |
NB. |       | #   #      #   # |
NB. |       | #          #  #  |
NB. |       | #          # #   |
NB. |       | #          ##    |
NB. |       | #          #     |
NB. |       |                  |
NB. +-------+------------------+

This example uses code from my incomplete-open-cubes.ijs - a function that generates and draws ASCII cubes.

Installation

Copy edij.el to your load-path and add to your init file:

(require 'edij)
(global-set-key [f11] 'edij-dwim)

The mode will automatically find jconsole, ijconsole, or j in your PATH. You can customize this with edij-program.

Commands

Command Description
edij-dwim Do What I Mean - the main entry point
edij-load Load entire buffer (or region) into J
edij-remove-interactions Strip all NB. output lines from buffer
edij-localize Make J process buffer-local (for multiple independent sessions)
edij-kill-j Kill the background J process

Prefix Arguments for edij-dwim

Prefix Action
None Evaluate expression at point, or load buffer if not on an expression
C-u Load buffer, then evaluate expression
C-u C-u Start fresh J process, load buffer, evaluate expression
0 Kill J process
Any other Remove all interaction output

Expression Detection

edij understands J’s various definition forms:

Simple expressions:

+/ i. 10

Explicit definitions (with : syntax):

sum =: 3 : 0
+/ y
)

Direct definitions (with {{ }} syntax):

double =: {{ y + y }}

Multi-line expressions (with \ continuation):

long_expression =: very_long_thing \
                   that_continues

The mode correctly identifies definition boundaries so pressing the key inside a multi-line verb sends the whole thing.

Implementation Notes

The mode maintains several buffers behind the scenes:

J’s prompt is just whitespace (), so edij detects completion by watching for a line matching ^[ \t]+$ after output.

Output formatting preserves indentation - if your expression was indented, the output comments will be too. This keeps things readable when working with indented code blocks.

The edij-localize function is useful when you want separate J sessions for different buffers. By default, all buffers share one J process.

Why edij?

Interactive development is central to J. The traditional approach is to work in the J IDE or a terminal REPL. edij brings that interaction directly into Emacs, so you can:

It’s particularly nice for exploratory programming where you’re building up expressions incrementally and want to see intermediate results.