tmax

Extensible terminal text editor with T-Lisp scripting - combines vim-like modal

This is a fork of mekkamagnus/tmax, kept for reference and contributions. It is not an original project.

tmax - An Extensible Terminal Editor

tmax is an extensible terminal-based text editor written in TypeScript, running on the Bun runtime. It follows the Emacs architecture: a T-Lisp interpreter (like Emacs Lisp) handles all editor functionality, with vim-style key bindings as the user interface layer.

The daemon/client architecture mirrors Emacs (tmax --daemon / tmaxclient), supporting multiple TUI frames sharing the same buffers and interpreter. A built-in *Messages* buffer provides observability for both users and AI agents.

Note: tmax is currently in development (v0.2.0). Features and APIs may change. Feedback and contributions are welcome!

Architecture

Features

Core Functionality

Daemon/Client Architecture

T-Lisp Integration

T-Lisp Features

Installation

Prerequisites

Setup

# Clone the repository
git clone https://github.com/mekkamagnus/tmax.git
cd tmax

# Install dependencies
bun install   # dev dependencies only (runtime has zero external deps)

# Make the launcher executable
chmod +x bin/tmax

# Add to PATH
echo 'export PATH="$PATH:$(pwd)/bin"' >> ~/.bashrc
source ~/.bashrc

Usage

Daemon/Client (Recommended)

# Start tmax with a file (runs the embedded editor)
tmax filename.txt

# Start daemon only (no TUI)
tmax --daemon

# Evaluate T-Lisp on the daemon
tmax -e '(+ 1 2)'

# Stop the daemon
tmax --stop

Client Commands

tmaxclient file.txt           # Open file in daemon
tmaxclient --eval '(code)'    # Evaluate T-Lisp
tmaxclient --list-buffers     # List open buffers
tmaxclient --messages         # Show *Messages* buffer
tmaxclient --ping             # Check if daemon running
tmaxclient --status --json    # Structured daemon/client/frame status
tmaxclient --clients --json   # Connected client metadata
tmaxclient --frames --json    # Connected TUI frame metadata
tmaxclient --tui              # Launch TUI client

Direct Editing (No Daemon)

# Run editor directly (no daemon)
bun run start filename.txt

# Development mode with auto-reload
bun run dev

First Time Usage

  1. Enter insert mode: Press i to start typing
  2. Return to normal mode: Press Escape
  3. Save and quit: Press : then type wq and press Enter
  4. Just quit: Press q in normal mode
  5. Use M-x: Press SPC then ; to execute T-Lisp functions

Advanced Usage

Key Bindings (Default)

Normal Mode

Insert Mode

T-Lisp REPL

# Start the standalone T-Lisp REPL
bun run tlisp

# Evaluate one expression
bun run tlisp -- -e '(+ 1 2)'

# Run a script without launching the editor
bin/tlisp script.tlisp

# Build a standalone T-Lisp binary
bun run build:tlisp
./dist/tlisp -e '(+ 1 2)'

The standalone REPL keeps definitions across inputs, supports multiline forms, and provides Clojure-like result bindings: *1, *2, *3, and *e. It uses the same interpreter as the editor but loads a standalone runtime profile with stdout/stdin/filesystem primitives and standalone module loading. See docs/memos/standalone-tlisp-gap-analysis.md and docs/memos/standalone-tlisp-options-analysis.md for the architecture rationale.

Configuration

Create an init.tlisp file in ~/.config/tmax/ to customize tmax:

;; Custom key bindings
(key-bind "w" "(cursor-move (+ (cursor-line) 5) (cursor-column))" "normal")
(key-bind "b" "(cursor-move (- (cursor-line) 5) (cursor-column))" "normal")

;; Custom macros
(defmacro save-and-quit ()
  '(progn
     (file-write (buffer-current) (buffer-text))
     (editor-quit)))

;; Custom commands
(defun center-cursor ()
  (let ((line-count (buffer-line-count))
        (center-line (/ line-count 2)))
    (cursor-move center-line 0)))

(key-bind "zz" "(center-cursor)" "normal")

Init File Features

Reload Configuration:

Evaluate Buffer:

Custom Init File:

Query Init File:

T-Lisp Editor API

Buffer Management

Cursor Operations

Text Editing

Mode Management

File Operations

Key Bindings

Development

Project Structure

tmax/
├── src/
│   ├── core/           # TypeScript core (terminal, filesystem, buffer)
│   ├── tlisp/          # T-Lisp interpreter implementation
│   ├── editor/         # Editor with T-Lisp API, handlers, operations
│   ├── server/         # Daemon (JSON-RPC 2.0 over Unix socket)
│   ├── client/         # TUI client (ANSI rendering)
│   ├── frontend/       # Shared frontend interface + render helpers (Steep/ANSI)
│   └── main.ts         # Application entry point
├── test/
│   ├── unit/           # Unit tests
│   ├── integration/    # Integration tests
│   └── mocks/          # Mock implementations
├── scripts/
│   └── repl.ts         # T-Lisp REPL compatibility launcher
└── bin/
    ├── tmax            # Unified CLI (daemon/client)
    ├── tlisp           # Standalone T-Lisp CLI
    └── tmaxclient      # Daemon client CLI

Available Scripts

# Development
tmax                     # Start the editor (embedded)
bun run dev              # Start with auto-reload
bun run tlisp            # Run standalone T-Lisp REPL
bun run repl             # Compatibility alias for standalone T-Lisp REPL
bun run daemon           # Start daemon only
bun run build:tlisp      # Build standalone T-Lisp binary

# Testing
bun run typecheck:src    # Typecheck production source
bun run typecheck:test   # Typecheck tests and imported contracts
bun run typecheck        # Typecheck the full project
bun test                 # Run Bun unit/integration tests
bun run test:unit        # Run Bun unit tests only
bun run test:tmax-use    # Run tmax-use e2e playbooks + tests

T-Lisp Examples

Basic Operations

;; Arithmetic
(+ 1 2 3)                    ; => 6
(* (+ 2 3) (- 10 5))        ; => 25

;; String operations
(length "hello")             ; => 5
(substring "hello" 1 3)      ; => "el"
(string-append "hello" " " "world")  ; => "hello world"

;; List operations
(car '(1 2 3))              ; => 1
(cdr '(1 2 3))              ; => (2 3)
(append '(1 2) '(3 4))      ; => (1 2 3 4)

Functions and Macros

;; Function definition
(defun factorial (n)
  (if (= n 0)
    1
    (* n (factorial (- n 1)))))

(factorial 5)               ; => 120

;; Macro definition
(defmacro when (condition body)
  `(if ,condition ,body nil))

(when t "executed")         ; => "executed"

Editor Customization

;; Custom movement command
(defun goto-beginning ()
  (cursor-move 0 0))

;; Smart line insertion
(defun insert-line-above ()
  (let ((current-line (cursor-line)))
    (cursor-move current-line 0)
    (buffer-insert "\\n")
    (cursor-move current-line 0)))

;; Word count function
(defun word-count ()
  (let ((text (buffer-text)))
    (length (split-string text " "))))

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: bun test
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Roadmap

For detailed development plans and phase breakdowns, see the comprehensive roadmap.

Current Focus

Modes and Lisp Ownership

tmax loads built-in T-Lisp mode libraries before user init files and daemon eval requests. Major modes are buffer-local and selected by auto-mode rules for extensions such as .py, .ts, .tlisp, and .go. Minor modes are composable per-buffer features with status-line lighters; built-ins include line-numbers (Ln) and auto-fill (Fill).

(line-numbers-mode t)
(global-auto-fill-mode t)
(add-hook "mode-python-activate-hook"
  (lambda () (minor-mode-set "auto-fill" t)))

Clients can assert mode state with tmaxclient --status --json, which exposes currentMajorMode, activeMinorModes, and activeMinorModeLighters.

Recent Milestones

Quick Links

Design Philosophy

tmax follows the principle of "powerful core, extensible surface". The TypeScript core provides efficient, low-level operations while T-Lisp provides unlimited customization possibilities. This architecture allows users to:

The editor is designed to be both approachable for beginners and powerful for advanced users who want to craft their perfect editing environment.

For more information on the architecture patterns used in tmax, see the rules/ directory.

Frontend Architecture

tmax has two native frontends, both built on the same Frontend interface with zero UI framework dependencies:

Both frontends communicate with the editor core through the same interface. The daemon/client architecture enables remote frontends via JSON-RPC over Unix sockets.