Skip to content

Instantly share code, notes, and snippets.

@RobinJadoul
Created January 20, 2023 13:08
Show Gist options
  • Save RobinJadoul/aab9ea148dbd2a81cc1e896120638cf1 to your computer and use it in GitHub Desktop.
Save RobinJadoul/aab9ea148dbd2a81cc1e896120638cf1 to your computer and use it in GitHub Desktop.
HEPL - a simple repl integration for the helix editor

HEPL

This is a simple repl integration for the helix editor. It relies on on tmux to show the repl in a separate pane and on jupyter (jupyter-console and whatever jupyter kernels you might like) to run the actual repl.

Features

  • Works with any jupyter kernel
  • Code is dedented to the highest common level, so you can send python code from the middle of a function to the repl too
  • No issues with multiline pieces of code or blank lines inside of a function body, it works as you'd expect it to

Installation and usage

  1. Put hepl.sh somewhere on your PATH
  2. Update your helix config.toml with keybinds to spawn repls and send code to the current repl
  3. Open a tmux session
  4. Open helix
  5. Spawn a repl and enjoy

Limitations

  • Only one repl can be active per instance of helix, as it's currently tied to the PID of the helix process
  • Currently, if you want the repl interaction not to look messy, you'll need to use jupyter/jupyter_console#274
[keys.normal." "]
z = ":pipe-to hepl.sh send"
Z.p = ":run-shell-command hepl.sh spawn python"
Z.Z = ":run-shell-command hepl.sh spawn your_favorite_kernel"
#!/usr/bin/env bash
function tmux_or_die() {
if [ -z "$TMUX" ]; then
echo >/dev/stderr Please run me in tmux...;
exit 1;
fi
}
function spawn_pane() {
tmux_or_die
tmux split-window -d jupyter console --kernel="$1" -f="/tmp/hepl-$PPID.json" --ZMQTerminalInteractiveShell.include_other_output=True --ZMQTerminalInteractiveShell.other_output_prefix=''
}
function send() {
python3 -c 'import sys, textwrap; sys.stdout.write(textwrap.dedent(sys.stdin.read()))' | jupyter run --existing="/tmp/hepl-$PPID.json"
}
case "$1" in
spawn) spawn_pane "$2" >/dev/null ;;
send) send >/dev/null 2>&1 ;;
*) exit 1 ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment