Skip to content

About

A scientific workbench in a single native binary — literate org-mode notebooks with org-babel, REPL sessions, inline figures, and LSP, configured in hot-reloadable Nim.

Resources

Stars

9 stars

Watchers

0 watching

Forks

Repository files navigation

wkbenchless

A native scientific workbench in a single binary — a deeply Nim-configurable literate editor with org-babel execution, LSP completion, interactive REPL sessions, a real embedded terminal, and native org src-block highlighting. A workbench-less alternative to heavier IDEs: no language-server manager, no background service, no Electron.

docs/screenshot.png

Written in Nim on uirelays (custom rendering, no GTK/Qt), so it targets Linux/macOS/Windows. Your configuration is plain Nim compiled into the binary — commands are Nim procs, keybindings, languages, and themes are data, and C-c r recompiles and restarts in place, without dropping your running sessions or terminals.

Features

  • Org-babel: C-c C-c runs a #+begin_src block in a persistent :session and writes #+RESULTS:. C-Enter sends the current line to the current session.
  • Sessions are live terminals: R, Python, and bash run on a PTY we own. The bottom pane is a live terminal — type at it interactively and run blocks against the same process (shared state). C-c s cycles sessions/terminals, C-c k opens a bash session.
  • Embedded terminal: M-t opens a bash terminal in the bottom pane. A built-in VT/ANSI screen emulator renders cursor-addressed TUIs — top, htop, vim — correctly, with colors, mouse text-selection (drag to copy), and wheel scrollback. Terminals are first-class tabs alongside sessions.
  • Src-edit (C-c e / C-c b): zoom into a block as a real code file with LSP + highlighting, then splice it back. C-c t tangles a whole session.
  • LSP completion: always-on as you type in code buffers (C-Space also triggers it); nim / python / R (config-registerable).
  • Native org highlighting: #+begin_src r … #+end_src bodies are syntax-highlighted in their language, in place. Blocks start folded — Tab toggles; C-c u unfolds all. *bold* / /italic/ render in their faces, #+caption a touch larger, and [[target][label]] links show just the label. Click (or C-c C-o) follows a link — [[file:…]] to a text/source file opens it in the editor, URLs and other files hand off to the system.
  • Inline figures: whole-line image links render right in the buffer, Emacs org-mode style — [[file:fig.png]] or ![](fig.png). Shown at the image’s own dimensions by default; size a figure with a preceding #+ATTR_ORG: :width N (aspect ratio preserved) or set a default with gInlineImageWidth. Toggle with M-x toggle-inline-images. PNG/JPG/GIF/… decode natively with pixie (pure Nim, a nimble dependency — no ImageMagick needed); BMP decodes directly.
  • LaTeX previews: M-x latex-preview renders whole-line display math — $$…$$, \[…\], \(…\), $…$ — to images shown in place (org-latex-preview style), via latex + dvipng. #+LATEX_HEADER: lines feed the preamble; the source returns while the cursor is on the line. gLatexDpi sets the size.
  • Remote sessions over SSH: a :session name@host header — or a document-level #+PROPERTY: header-args LANG :session … :ssh host — runs blocks on a remote interpreter over a multiplexed SSH connection and captures the results locally, password hosts included.
  • CriticMarkup (tracked changes): org buffers colour {++insertions++} (green), {--deletions--} (red), {~~old~>new~~}, {>>comments<<} (grey), and {==highlights==} (yellow). Resolve with M-x criticmarkup-accept-all / -reject-all (C-c j / C-c l). Pairs with the org-tracked-docx round-trip.
  • Command palette: M-x (or C-p); C-x C-r opens a recent file.

Src-edit (C-c e) zooms a block into an isolated code file with LSP, alongside the objects/environment and help panes — then splices it back into the org document:

docs/screenshot-srcedit.png

Build & run

Needs the Nim toolchain. On Linux, wkbenchless renders on the GPU by default: FigDraw (OpenGL) drawing into a siwin window – native Wayland on a Wayland session, X11 otherwise. That needs Nim >= 2.4 and nimble install figdraw siwin (a current nimble; it fetches Nim 2.4 itself if a dependency asks for it). Built with an older Nim, or with -d:wkbX11, it uses the CPU X11 driver instead (libX11 + libXft). C-c r in a GPU build rebuilds with nimble’s Nim >= 2.4 when the nim on PATH is older. macOS uses the native Cocoa backend, Windows the winapi one.

nimble run          # build + run
# or
nim c -o:wkbenchless src/wkbenchless.nim
./wkbenchless file.org

Prebuilt binaries for Linux/macOS are attached to each GitHub release.

Configuration

Edit ~~/.config/wkbenchless/wkbconfig.nim~ (M-x edit-config / C-c f) — ordinary Nim with full access to the editor model. The complete default keymap, the languages, and the themes all live there, so everything is in one place. The first C-c f creates it from the default src/wkbconfig.nim; whenever it exists, builds compile it in place of the default (config.nims), so a nimble install~ed binary is configurable too. Apply changes with ~C-c r (recompile & restart — your open sessions and terminals survive the reload). WKB_USER_CONFIG=<file> points elsewhere; nimble release ignores it (WKB_NO_USER_CONFIG=1) so a shared binary carries the default config.

proc configure*(app: var App) =
  bindkey("C-c d", "insert-date")
  registerRepl("python", pySpec)                 # teach it a language
  registerTheme("mine", [rgb(0x1e1e2e), …16…])   # add a base16 theme
  addExecPath("~/.local/bin")                    # extend PATH for sessions
  addHook("startup", proc(a: var App) = a.msg = "ready")

Sessions and terminals inherit a PATH seeded from your login shell ($SHELL -lc), so they find R / python / latex even when launched from a GUI; add more with addExecPath.

C-c r needs a Nim + C compiler. To work without a system toolchain, bundle one next to the binary: nimble bundle -- /path/to/zig (see scripts/bundle-toolchain.sh); Nim uses zig cc as a hermetic C backend.

Control (ctl)

The editor exposes a loopback control socket (127.0.0.1, token-authenticated) that drives a running instance — handy for scripts and for agents in the embedded terminal. It’s built into the binary, so wkbenchless ctl <verb> is all you need; the shipped release is a single binary. (wkbctl is an optional convenience — symlink it to wkbenchless; the examples below work with either name.) Works on Linux/macOS/Windows.

wkbctl buffer                          # print the current buffer
wkbctl blocks                          # list #+begin_src blocks
echo 'summary(fit)' | wkbctl eval r default    # run code in a live session
echo TEXT | wkbctl set-buffer          # replace the buffer
echo TEXT | wkbctl insert 12           # insert before line 12
echo TEXT | wkbctl replace 3 5         # replace lines 3..5
wkbctl goto 40                         # move the cursor
wkbctl run-block 16                    # run the src block at line 16 (writes #+RESULTS)
wkbctl diff old.txt new.txt "changes"  # show a side-by-side diff
wkbctl command <name>                  # run any M-x command (echoes its status line)
wkbctl bib maes 2022                   # search BibTeX -> "key — Author (year). Title"
wkbctl cite-context <key>              # dossier for a citation: your notes + prose + paper
wkbctl zotero-search <query>           # search the whole Zotero library (see below)

License

MIT.

About

A scientific workbench in a single native binary — literate org-mode notebooks with org-babel, REPL sessions, inline figures, and LSP, configured in hot-reloadable Nim.

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages