paredit-ts: A TypeScript S-Expression Structural Editor Library

paredit-ts is a TypeScript rewrite of paredit.js, the structural S-expression editor library. If you’re editing Lisp, Clojure, or any language with balanced bracket structure and want to move through and manipulate expressions structurally rather than character-by-character, this is the library that handles the parsing and editing logic.

Why a rewrite

The original paredit.js is JavaScript with no types, and had several mutation bugs and unreachable code branches that caused subtle failures in structural editing operations. The TypeScript rewrite addresses those directly, adds full type safety throughout, and drops all runtime dependencies.

What it exports

Three modules:

  • parse — converts source text into an AST representing the sexp structure
  • navigator — functions for moving through expressions: forward, backward, up out of a list, down into one
  • editor — structural editing operations: kill, splice, wrap, transpose, raise

Custom bracket pairs are supported via setParentheses(), which makes it useful beyond just Lisp syntax.

Usage

npm install paredit-ts

Dual builds for ESM and CommonJS with source maps. The package is primarily used as the sexp engine in vscode-emacs-unified, which exposes the structural editing operations as VS Code commands.

Tests

Vitest-based test suite covering parse, navigation, and editor operations. The rewrite was driven partly by the desire to have a test suite that could catch the mutation bugs that were present in the original.

The code is on GitHub: kshartman/paredit-ts. MIT license.

← Emacs Unified: Consolidated Emacs Keybindings for VS Code