8000 GitHub - dangom/cooked: A comit-mode based terminal emulate specially designed for emacs · GitHub
[go: up one dir, main page]

Skip to content
dangomPublic
forked from vodik/cooked

About

A comit-mode based terminal emulate specially designed for emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

cooked

I wanted to write a quick introduction to this project because I’ve been a bit nervous to share this. It is almost 100% vibe coded, which isn’t really my taste. It’s been a consequence of wanting to test out a design while being very short on time to actually try and do it by hand. Having build and worked on terminal emulators before I didn’t feel I stood as much to lose using an llm and felt I’d be comfortable adopting the project afterwards as I’ve built terminal emulators in the past (and it felt good that even using strong models, I was able to better identify and diagnose performance bottlenecks despite the llm literally being able to script emacs).

I’ve been really happy with how this project turned out - so much so that I feel comfortable sharing it despite it’s vibe coded origins - and I plan to transition to maintaining it much more by hand - starting by removing the yap. It’s legitimately gotten to the point that emacs-with-cooked is becoming my daily driver as I like it that much.

There are three main design goals of this take on an emacs terminal emulator:

First, split a terminal emulation into two parts. A rust component which handles the pts, process communication, and offloads as much terminal state as possible. It tries to be as fast as possible (it’s not going to win any awards for being as fast as possible, but it’s magnitudes of order faster than the elisp part) and pace the emacs side so that it refreshes at a slower, more fixed framerate. This gets us close to eat’s architecture while having the performance characteristics of vterm.

Second, the terminal emulator is built around exposing the kernel line discipline and, when present, OSC 133 semantic prompt markers so we can thoughtfully determine what the terminal is doing. That allows the whole thing to be deeply integrated into comint-mode

Third, I’m an evil-mode user and I’ve never been happy with how either vterm/eat integrate. Between OSC 133 and the line discipline, we can also intelligently and automatically switch between normal/insert/emacs modes automatically as needed. Visual mode automatically pauses redrawing to help support yanking.

Then with some additional vanity features (for example, support for box-drawing characters as bitmaps) we end up with a visually beautiful, performant, and ergonomic terminal emulator inside emacs.

cooked

A terminal emulator for Emacs that knows who should own the keyboard, and hands it back when the program you’re running wants a line of text rather than keystrokes.

Type a command at a shell prompt and you’re editing a line: Emacs owns it, with your keybindings, your kill ring, your undo, your completion UI. Run htop and every key goes straight through, because that’s what htop needs. Run ssh and get a password prompt, and cooked asks for it in the minibuffer — where it can be answered from auth-source instead of typed.

Nobody toggles a mode to make that happen. cooked works it out.

Why

Every other terminal in Emacs treats the child as an opaque rectangle of characters and has to ask you which mode you’re in. cooked reads two signals the terminal already carries and answers the question itself:

  1. The kernel’s line discipline. cooked allocates the pty itself, so it can read the child’s own termios: canonical mode with echo on is a shell prompt or a read loop (Emacs should own the line); canonical with echo off is getpass(3) (a secret, answer in the minibuffer); neither is a full-screen program (vim, htop — keys pass straight through).
  2. OSC 133 semantic prompts. Any interactive shell can be made to mark where a prompt starts, where input ends and output begins, and how the command exited. An explicit mark always beats the inferred termios state.

Between the two, cooked knows which program is reading, in what mode, and where each command began and ended. That knowledge pays for itself in the everyday stuff:

  • The input line is a buffer — your keybindings, kill ring and completion, with no forwarding involved.
  • Passwords land in the minibuffer, answerable from auth-source or pass. No ordinary terminal can do this, because it never learns a password was being asked for.
  • ~next-error~ over one command’s output (more below). M-g M-n after a failed build walks that build’s errors, not the whole scrollback — make run as an ordinary command, without ever needing M-x compile.
  • Per-command records — rerun, copy the command, copy just its output, jump between commands, a fringe marker coloured by exit code.
  • Real completion from your shell, so git checkout <TAB> offers branches and kill <TAB> offers processes with their command lines.
  • Scrollback that rewraps when you resize the window, because cooked knows which rows were wrapped rather than newline-terminated.

cooked-mode derives from comint-mode rather than inventing its own keymap from scratch, so the C-c bindings you already have from M-x shell — C-c C-c, C-c C-d, C-c C-\, C-c M-o and the rest — mean the same thing here, aimed at the pty instead of an Emacs process. Where comint’s own idea of a command didn’t fit a terminal, cooked kept the key and gave it a terminal-shaped implementation instead of picking a new one; see docs/KEYBOARD.md for the full comparison against comint.

Comparison with other terminal emulators

Eat

Eat is the most portable of the four: pure Emacs Lisp, nothing to compile, and it works wherever Emacs does. It’s also a rectangle of characters like any other terminal, with no idea where one command ends and the next begins, and it runs on Emacs’ own thread, so heavy output competes with redisplay. If portability matters more than throughput, or you just don’t want to touch a compiler, eat is the right choice.

Vterm

Vterm is powered by libvterm, a C library, so it handles large bursts of output that would make eat or Emacs’ own Term crawl. Like eat, it treats the child as an opaque rectangle of characters — no idea where a command starts or ends, so vterm-copy-mode, prompt regexps and directory tracking are all guesses at structure the terminal was never told — and getting an editable line back means leaving the terminal for a separate, read-only mode. If you need raw throughput and don’t need cooked’s structure, vterm is mature and fast.

Ghostel

Ghostel embeds libghostty — the same engine behind the Ghostty app — and it’s fast on raw throughput, though cooked is now faster on every workload measured below. Like eat and vterm, its terminal is a rectangle of characters with no idea where a command starts or ends; what it calls “comint support” is a minor mode that drops libghostty’s colour handling into somebody else’s shell-mode buffer, not a comint-derived terminal. If a native rendering engine is what you’re after and you don’t need cooked’s structure, ghostel is newer and worth a look.

cooked

cooked is fast, like vterm, but also knows what eat and vterm structurally can’t, because it reads the pty instead of treating it as a wire: who’s typing, where a command started, and how it ended. The common case — type a command, read its output — needs no mode switch at all, and a manual peek (C-c C-v) covers the one case the signal can’t, a full-screen program with the whole keyboard. The cost is a Rust toolchain and a build step (automatic, but real). If you want that structure and don’t mind the toolchain, cooked is the pick.

Performance against ghostel

< 8000 a id="user-content-performance-against-ghostel" class="anchor" aria-label="Permalink: Performance against ghostel" href="#performance-against-ghostel">

The same workloads, each run in a fresh GUI Emacs (31.1, -Q, a 160×50 frame, Emacs’ default GC settings), both terminals native-compiled and at their default settings. Each workload is a program printing as fast as it can; the time is from starting it until its last line is in the buffer and drawn.

Workloadcookedghostel
Key echo latency, median of 1001.2 ms1.4 ms
300,000 lines of plain text0.33 s0.90 s
100,000 lines, ten 256-colour words per line0.35 s1.00 s
400 full-screen redraws, alternate screen0.63 s1.08 s
1,500 redraws of a 12-row inline region0.08 s0.16 s

The colour workload’s own program takes 0.27 s to print its 20 MB even into /dev/null, so most of cooked’s 0.35 s is the program, not the terminal: cooked’s own work for it is 0.25 s, of which 0.14 s is garbage collection, and 0.17 s with the larger GC threshold most configurations (Doom’s included) run with. Two things make floods cheap. Scrollback that cooked-scrollback-lines would trim the moment it arrived is dropped in the native core and never reaches Emacs, and the styling of a long batch of scrollback is applied by jit-lock when it is about to be displayed, so lines nobody ever looks at are never styled.

Measured on an Apple M5 Pro, macOS 26.6, ghostel 0.62.0 at commit 6dfe798.

Installing

You need Emacs 29.1+ built with dynamic module support, and a current stable Rust toolchain (1.100+; rustup update stable gets it). Linux and macOS.

The native core is built with cargo on first use and rebuilt whenever the Rust sources are newer than the artifact, so there’s no separate build step to remember. The first M-x cooked after installing will take a minute and say so. A first build in a fresh install leaves only the library behind: cargo’s own build tree is deleted once the library is in place. A checkout you build in yourself keeps it, as a cache for the next build.

;; straight.el
(use-package cooked
  :straight (cooked :type git :host github :repo "vodik/cooked"
                    :files ("lisp/*.el"))
  :commands (cooked cooked-other-window))

;; elpaca
(use-package cooked
  :ensure (cooked :host github :repo "vodik/cooked" :files ("lisp/*.el"))
  :commands (cooked cooked-other-window))

;; package-vc (Emacs 29+)
(use-package cooked
  :vc (:url "https://github.com/vodik/cooked" :lisp-dir "lisp" :rev :newest)
  :commands (cooked cooked-other-window))

;; from a checkout
(use-package cooked
  :load-path "/path/to/cooked/lisp"
  :commands (cooked cooked-other-window))

Every one of these keeps the whole repository on disk, which matters: the Lisp finds Cargo.toml, terminfo/ and shell-integration/ by walking up from its own resolved location, so a :files clause that ships only the Lisp is fine, but a hand-rolled install that copies the .el files somewhere on their own is not. Point cooked-native-module at a prebuilt artifact if you package cooked that way.

To try it without installing anything:

cargo build --release
emacs -Q -L lisp -l cooked-mode -f cooked

Usage

To start cooked, run M-x cooked (or cooked-other-window). Unlike other Emacs terminals, there are no input modes to switch between by hand — cooked has two states and moves you between them itself:

  • At a shell prompt, Emacs owns the input line, and the usual editing keys work:
    • RET: submit the line.
    • S-<return> or M-RET: insert a newline instead of submitting, for a multi-line command.
    • TAB: completion-at-point — your shell’s own completion, if cooked-shell-completion is loaded.
    • M-p / M-n: previous/next input, like Comint.
    • C-a: first non-blank column, then column 0 on a second press.
    • M->: the end of the line being typed, then the end of the buffer on a second press.
    • C-l: Emacs’ own recentring cycle; its “top” keeps a multi-line prompt whole.
    • C-d: delete a character, or send EOF on an empty line.
    • C-r: forwarded to the shell’s own history search.
  • Once a full-screen program or a raw read loop takes over, every key is sent straight through, ESC included, so M-x reaches a shell-side Emacs just as it would in a real terminal. C-c is the one prefix cooked never forwards, and it’s Comint’s own — if you’ve used M-x shell, most of this is already muscle memory:
    • C-c C-c / C-c C-\ / C-c C-d: interrupt / quit / EOF.
    • C-c C-y: paste the kill ring as typed input.
    • C-c C-z: suspend (C-z, as a real terminal sends it).
    • C-c C-v: peek — freeze the display to read back over a program without stalling it.
    • C-c C-p / C-c C-n: jump to the previous/next command.
    • C-c M-o: clear the scrollback.
    • C-c TAB: fold a command’s output to one line.
    • C-c C-q: send the next key exactly as typed, even C-c itself.
    • C-c M-x: run whatever you have M-x bound to — the way out, whatever the child is doing.
    • C-c C-k: end the session and close its buffer — the program is hung up on, as closing a terminal window does, and for a hosted session the session itself ends.
  • A program that exits cleanly takes its buffer with it (exit at a shell, /exit in an agent’s chat), and a window made to show it goes too; one that fails leaves its last words on screen. See cooked-kill-buffer-on-exit.
  • A password prompt (getpass, no echo) is its own case: cooked asks in the minibuffer instead, so cooked-password-function can answer it from auth-source or pass.

With (require 'cooked-evil), evil’s own states decide how much of the keyboard the child gets instead: emacs hands over everything but C-c, insert forwards typing but keeps ESC and M-x for Emacs, normal=/=motion=/=operator are read-only while the child keeps running, and visual freezes the display. cooked switches to emacs state on its own the moment a full-screen program takes the keyboard. [[=/=]] move between prompts; vic=/=vac select a command’s output.

See docs/KEYBOARD.md for the rest.

Configuration

Most of what cooked can do is off until you ask for it, because a setting that gates code already loaded and running is a switch in name only — these are separate files you require:

(use-package cooked
  :straight (cooked :type git :host github :repo "vodik/cooked"
                    :files ("lisp/*.el"))
  :commands (cooked cooked-other-window
             cooked-project cooked-project-other-window
             cooked-here cooked-here-other-window)
  :config
  (require 'cooked-evil)
  (require 'cooked-osc-eval)
  (require 'cooked-shell-completion)
  (require 'cooked-file-link)
  (require 'cooked-next-error)
  (require 'cooked-command-decorations)
  (require 'cooked-project)
  (require 'cooked-process)
  (cooked-process-mode 1))

cooked-evil

Syncs evil’s states to who owns the keyboard — see Usage above — and adds the vic=/=vac text objects and [[=/=]] prompt motions.

What the child may do to Emacs

Out of the box, nothing. The command channel is closed until you require it, the child cannot write to the clipboard until cooked-clipboard-write is set (and can never read it), an OSC 8 hyperlink opens only the schemes in cooked-link-schemes, and a pasted string is stripped of control characters before the program sees it. Each of those is a way for text you merely displayed — a log, a file, the far end of an ssh — to act on your behalf, and each is yours to turn on.

cooked-osc-eval

Lets the child ask Emacs to do things: visit a file, open Dired, clear the scrollback. Read this one before enabling it — a terminal prints whatever it’s given, so a hostile cat or a compromised host over ssh can reach this channel too. What it grants is a closed set of verbs cooked implements itself and checks the arguments to, not an open name lookup; arbitrary named commands need a second, explicit entry in cooked-eval-commands. See docs/FEATURES.md.

cooked-shell-completion

Answers TAB from zsh’s or bash’s own completion system, over a side channel, instead of from Emacs’ own completion table — so git checkout <TAB> offers branches and kill <TAB> offers processes with their command lines.

cooked-file-link

Turns file names that appear in a command’s output into clickable links, the way compilation-mode does for error output. How a followed file opens is cooked-file-link-display, or, in a buffer that sets it, cooked-file-open-function – which is how a package that owns some cooked buffers can open their files its own way – in a pop-up, say – while every other terminal keeps the default.

cooked-next-error

Wires up compile integration inside a cooked buffer — see below.

cooked-process

Wires up compile integration for M-x compile, grep and the rest, outside any cooked buffer at all — see below.

cooked-command-decorations

A fringe marker per command, coloured by exit status — running, succeeded, failed — so you can see how a scrollback full of commands went without reading any of it.

cooked-annotate

A small API for packages that know something about a stretch of output that the terminal does not — “this is where the agent ran that command”. cooked-annotate puts a clickable mark in the fringe beside those rows (RET on them works too) and keeps it on them through repaints and scrolling; cooked-annotation-next / cooked-annotation-previous step between marks. cooked never decides what to annotate: that is up to the package marking the rows, such as an inspector of an agent’s tool calls.

(cooked-annotate beg end :help "ran: make test" :data call
                 :action (lambda (annotation) (message "%S" (cooked-annotation-data annotation))))

Two more seams of the same kind: cooked-prompt-positions-functions names extra places for C-c C-p / C-c C-n to stop at (an agent’s prompts, which the shell integration knows nothing about), and cooked-paste-string pastes text at the program’s input the way cooked-paste pastes a kill — bracketed, its controls removed, not submitted.

cooked-popup

A look at a buffer or a file in a small frame over the current one, which takes the keyboard while it is up and gives it back on q. No window is split or resized for it, so a terminal underneath keeps its size and its program is never told to redraw.

cooked-popup-file shows a file read-only, at a line, in the major mode it would be visited in — highlighted as it would be there, an image as an image — in a buffer that does not visit it: no mode hook runs and no local variables are read, so a look starts no language server and runs nothing the file says. v opens the real thing in a window. To have file names in a terminal’s output open this way:

(require 'cooked-popup)
(setq-default cooked-file-open-function #'cooked-popup-open-file)

cooked-popup-buffer is the same frame for a buffer of a package’s own, with cooked-popup-mode for its keys and cooked-popup-visit-function for what v opens. A pop-up opened from inside one replaces it, and l goes back. See cooked-popup-width, cooked-popup-top, cooked-popup-bottom and cooked-popup-max-file-size.

cooked-run

Some programs run commands whose output never reaches the terminal: they read it through a pipe and show a summary, or nothing until the command is done. If such a program runs its commands through cooked-host run in a hosted session, each becomes a run 8000 : the command runs exactly as it would have (same parent, input, environment, directory and exit status) and what it prints is also kept, as it comes, in a file under the session’s name.

cooked-host run --label "make test" -- sh -c 'make test'

cooked-run-latest follows the newest run of the current buffer’s session in a buffer that grows as the command prints, with its colours; cooked-run-select chooses one. There k interrupts the command and g looks again at once. From Lisp, cooked-runs lists a session’s runs and cooked-run-buffer gives the buffer following one.

Outside a hosted session, or where the run cannot be kept (a sandbox that denies the directory), cooked-host run simply becomes the command: it is never the reason one fails. Runs live under ~/.local/state/cooked/runs (or $COOKED_RUN_DIR), readable by you only; a session keeps its newest 200. What a command prints is shown as text and never obeyed: colours become faces, and every other control sequence is dropped.

cooked-project

Scopes a session to the current project root: cooked-project reuses one terminal per project the way project-shell does, rather than one per invocation.

cooked-host

Sessions that outlive Emacs – see below.

Shell integration

cooked injects its snippet into the zsh and bash shells it starts, so a local session needs no setup. ssh, sudo -i, docker exec and anything else that starts a shell elsewhere lands outside that injection — the fix is one line in the rc on the far end:

[[ $TERM_PROGRAM == cooked ]] && source /path/to/cooked/shell-integration/cooked.zsh

That line works over ssh too, which is the reason it exists at all — sourcing it twice is a no-op, so having it in your rc and getting injected locally is the normal arrangement, not a conflict. Where a shell stays unmarked, cooked says bare in the mode line.

Set cooked-shell-integration to none to turn injection off, or name a shell to force a scheme the basename guess would miss. docs/SHELL.md has the OSC 133 marks in full for anyone writing their own prompt integration, and the wire format for the optional command channel.

Terminal coverage

Text and rendition. SGR including truecolor, styled and coloured underlines, insert mode, autowrap control, background colour erase, DEC line-drawing, wide characters, combining marks, scroll regions, the alternate screen.

Input. modifyOtherKeys and the kitty keyboard protocol, bracketed paste, focus reporting, mouse press/release/wheel with SGR encoding, alternate scroll.

OSC. Title (with the title stack), working directory, hyperlinks, foreground/ background/cursor colour (queried and set), clipboard, desktop notifications, semantic prompts, iTerm2 images, and the optional command/completion channels. cooked-osc-handlers is a documented extension point, so teaching cooked a new sequence is an entry in an alist, not a change to the native core.

Links. OSC 8 hyperlinks are first-class — the core attaches a link id to the covered cells and carries it through wraps, rewraps and scrollback eviction. Text that merely looks like a URL is linkified by goto-address. With cooked-file-link loaded, file names in output become links too.

Box drawing. Box-drawing and block characters are rasterized to XBM at the current cell size rather than left to the font, so borders in htop, ranger or fzf tile exactly instead of showing font-dependent seams.

Images. The kitty graphics protocol, sixel, and iTerm2 inline images all become real Emacs images, one slice per cell, so text can overwrite them and they survive scrolling and rewrap.

Reflow. Narrowing the window rewraps rather than truncates, on the live screen and in scrollback both — narrow and widen back and you get the original layout, because cooked records which rows were continuations rather than discarding that.

Terminfo. Shipped and compiled on first use, no root needed; TERM defaults to cooked-256color and describes what cooked actually implements rather than borrowing xterm’s. M-x cooked-install-terminfo-remote gets it onto a host you ssh into. See docs/TERMINFO.md.

Not implemented. Pointer motion with no button held (mode 1003’s other half), and vttest-level conformance beyond the common paths — vim, htop, tmux and less all work, the long tail is untested. Full list in docs/ROADMAP.md.

Reading a program’s output while it runs

A program that reads every key raw but prints onto the main screen — an agent’s chat, a REPL — leaves what it prints in the buffer as ordinary text, and cooked lets you read it with Emacs’ own commands while the program keeps running. Nothing about this is specific to any program: it is decided from the terminal’s state, and applies whenever a program owns the keyboard on the main screen and has not asked for the mouse.

Where point is decides who a key is for:

  • On the program’s input — the row its cursor is on — it behaves like a shell prompt: C-p / C-n move by line (so C-p steps up into the output), M-p / M-n are the program’s input history (sent as Up and Down), C-y pastes the kill ring, C-s / C-r are isearch over the output, and M-v / M-< take you out too. Every other key is the program’s, as in any terminal (see cooked-navigation-keys). A click or the mouse wheel also takes you out.
  • Anywhere else, it is an ordinary read-only Emacs buffer: motion, isearch, the region, M-w, all of it, while the output keeps arriving underneath without moving the view. Scrolling up away from the input counts as leaving it.
  • Coming back: type, and the key goes to the program’s input, as comint and eshell send you back to the prompt; RET just goes back; so does moving onto the input row, or scrolling down until it is in view.

The moment the program takes the alternate screen or asks for the mouse, all of this switches off and every key is the program’s again. cooked-navigable-programs can narrow it to named programs, or turn it off.

The input stays in view. Scroll away from the bottom and the program’s live rows — its input, and the status and spinner rows around it — are split off into a dock under the window, pinned there, while the window above scrolls freely through the rest. Nothing moves when it happens, and the program is not resized for it: the two windows are one terminal. While docked:

  • Output never moves the window you are reading, wheel and pixel scrolling included.
  • Typing goes to the dock, so a reply can be written with the history still in view. M-v, C-p and the other ways out lead from the dock back up into the history.
  • RET sent from the dock, scrolling back down to it, or moving point onto it puts the two back together, following the program again.

Which rows are live is decided from the terminal alone: the cursor’s row, everything below it, and cooked-dock-context-rows above it. cooked-dock turns it off.

Editing the program’s line in Emacs. Set cooked-program-line-editor to emacs and the line you type into a program becomes an Emacs line, edited the way a shell prompt is in cooked: motion, C-SPC and the region, expand-region, kill and yank, M-p / M-n history, S-RET for a newline. RET hands the whole line to the program as one paste, then sends Enter.

  • How Emacs knows it is a line. Nothing on screen says so, and the same program asks questions with menus whose keys are answers, not text. So the first character you type into an empty line goes to the program as usual. If the program echoes it at its cursor, Emacs takes the line: the program is sent a Backspace for it and the character stays on screen as the start of the Emacs line. A menu does not echo, so 1, y and the arrows keep doing what they do there.
  • What stays the program’s. /, @ and ! typed into an empty line leave the line to the program, so an agent’s command menu, file picker and shell mode work as usual (cooked-program-line-delegate-characters). Escape and Shift-Tab reach the program while Emacs keeps the line (cooked-program-line-pass-keys); C-c C-q sends any other key. An empty line belongs to the program, so every key at it is the program’s. So does a line the program filled in itself – recalled from its history, pasted, completed – until it is sent or cleared. A shell is never taken this way: whether Emacs edits a shell’s prompt is cooked-shell-line-editor’s to say, and cooked-program-line-shells names the shells, ssh and the other remote logins included.
  • When the program asks instead. An agent can put a question where its prompt was while you have a line half typed. The line steps aside: it is taken off the screen and kept, the question is shown as the program drew it, and the keys – arrows, C-p / C-n, digits, RET – are the program’s until it is answered. The line comes back with the prompt. Emacs knows where the prompt is from where it last took a line (cooked-program-line-away-delay, cooked-navigation-yield-keys). Before any line has been typed in the buffer – a program that opens with a question, such as whether to trust the folder – it goes by the program’s cursor: with no prompt before it on its row, the program is taken to be asking, and C-p / C-n are its own.
  • The line’s edges. Whatever the program draws after its cursor for an empty line – its own cursor, a suggestion – is hidden while Emacs owns the line, so there is one cursor and only your text. Line commands stop at the line’s edges, whichever package’s they are (the program’s prompt and what follows the line are fields of their own, as in comint), and the program’s rows below the line cannot be killed or deleted.
  • Safe Enter. Enter is sent only once the program has visibly taken the paste. If it has put a question up meanwhile, nothing answers it: the line goes to the kill ring. So does a line the program walks away from by taking the alternate screen or exiting. Keys typed right after RET are held until the Enter has been taken, so they start the next line rather than being sent ahead of the Enter as the end of this one.

The program is left entirely to itself: cooked sets nothing in its environment, so its settings, memory and updates behave exactly as in any terminal. Many agent CLIs offer both an inline renderer and a fullscreen one, chosen in their own settings:

  • An inline renderer prints the conversation onto the main screen, so the whole conversation becomes buffer text you can scroll, search and copy as above.
  • A fullscreen renderer keeps the conversation inside the program, on the alternate screen with the mouse captured: Emacs shows one screenful, and the program scrolls it itself — as it does in any terminal.

A program can also name things about itself in the mode line — which model an agent is running, say — with iTerm2’s SetUserVar escape, shown for as long as it stays in the foreground. Claude Code’s status line command can send it; see Program variables in the mode line and cooked-mode-line-user-vars.

tmux, and other programs that are not a shell

M-x cooked starts a shell. For anything else there is cooked-exec, which runs a program directly in a buffer of your choosing — no shell underneath it, and no shell integration injected, because there is no shell for it to go into:

(cooked-exec (generate-new-buffer "*agent*") "tmux"
             '("new-session" "-A" "-s" "work"))

The buffer is yours to display, and get-buffer-process answers for it for exactly as long as the program lives.

tmux needs nothing in tmux.conf to get the most out of cooked: the terminfo entry tells it about synchronized output, extended keys, bracketed paste, focus events and hyperlinks, so a redraw arrives as one frame and S-RET or C-; reach the program in a pane with their modifiers. A few things are worth knowing when a full-screen program is most of what you run:

  • Keys that stay with Emacs. On the alternate screen every key goes to the program, which is right about the program and not about you. cooked-keymap-exceptions is the list of keys that never do — C-x, M-x and M-: by default; add your leader and whatever you switch windows with.
  • =C-c C-c= is a byte there, not a signal. A program that turned signal keys off did it to read them itself, and tmux passes them on to the pane.
  • The minibuffer does not resize it. A completion UI opening takes lines from the window above and gives them back; cooked waits until it closes rather than making a full-screen program redraw twice. See cooked-defer-resize-in-minibuffer.
  • A shorter window does not shorten a program drawing inline. An agent’s chat or a REPL redraws a live region at the bottom of its output, and once that region is taller than the screen its top rows scroll away where nothing can erase them — every redraw then leaves another copy in the scrollback. A split below the window would do exactly that, so while a program draws on the main screen a shrink in height is held back until it takes the alternate screen or exits; growing, and any change of width, go through at once. See cooked-defer-resize-on-main-screen.
  • Glyphs from fallback fonts are fitted to the cell. A character your default font lacks is drawn from another font at that font’s metrics, which makes its row a few pixels taller than the rest — and the rows under it move every time a spinner changes frame. cooked scales and pads such glyphs so that every row is one height and every column lines up. See cooked-fit-fallback-glyphs.

Sessions that outlive Emacs

An ordinary session is a child of Emacs and ends with it. With (require 'cooked-host) a session can instead be hosted: a child of a small program of its own, cooked-host, that keeps it running whether or not anything is looking. Build the program with make host; it is the same crate as the native core.

  • M-x cooked-host-shell: a shell that will still be there after Emacs is not.
  • M-x cooked-host-attach: look at a session, chosen by name.
  • M-x cooked-host-detach, or just killing the buffer: stop looking. Nothing asks first, because nothing is ended.
  • M-x cooked-host-kill: end a session.
  • M-x cooked-host-restore: attach a buffer to every session there is, and start again the shells that a reboot cut off, in the directories they were in.

From Lisp, cooked-host-exec is cooked-exec for a session that is kept:

(cooked-host-exec (generate-new-buffer "*agent*") "agent-1" (getenv "HARNESS"))

A buffer attached to a host is not a picture of somebody else’s terminal, the way a tmux client is. It is the terminal: the host hands over the pty itself, so typing, resizing and telling a prompt from a full-screen program work exactly as they do for a child of Emacs’ own, and the buffer is first rebuilt from what the child wrote before it existed – scrollback, prompts, command records, links and all – by replaying those bytes through the same emulator that would have read them the first time. While that replay runs, nothing the old output asks for is done: no bell, no notification, no clipboard write, no answer typed back at a child that stopped waiting for one.

The replay is bounded (eight megabytes by default; --ring on the command line), so a very long session comes back from part-way through, with the modes the child negotiated restored and a full-screen program asked to redraw.

Layouts. A hosted buffer is one of the buffers a saved session of Emacs brings back: desktop-save-mode knows how, and so does persp-mode (Doom’s workspaces, Spacemacs’s layouts). It comes back under the name it had, attached to the session it was looking at, which is all either needs to put it back in every window and workspace it was in. cooked keeps no layout of its own. A package with buffers of its own on hosted sessions lists what makes them its own in cooked-host-saved-locals, and says what starting one again after a reboot means in cooked-host-revive-functions.

From a script. The program is its own command line, for whatever is not Emacs:

cooked-host new build-1 --dir ~/src/thing -- make watch   # start, and return
cooked-host list --brief                                  # NAME STATE, one to a line
cooked-host capture build-1                               # the screen, as text
echo 'please stop' | cooked-host send --paste build-1     # typed; bracketed if asked for
cooked-host kill build-1
cooked-host run -- make test                              # in a session: output kept

With desktop-save-mode, hosted buffers are saved by name and come back attached. Ordinary sessions are still left out, for the reason they always were: restoring one would start a shell nobody asked for, and restoring one of these starts nothing.

cooked-host is usable without Emacs, which is the point for scripts and for agents started from a shell:

cooked-host new build -- make -j8      # start it, detached
cooked-host list                       # one JSON object per session
echo 'make test' | cooked-host send build
cooked-host kill build

Sessions live under ~/.local/state/cooked/hosts (or $COOKED_HOST_DIR), in a directory only you can enter: the socket there is the keyboard of a shell. The program is told its session’s name in $COOKED_HOST_SESSION, and cooked-host-attach-hook runs in a buffer attached to one, with the same name in cooked-host-name — which is how a package finds the buffer for something a program filed under its session’s name. It is also told where cooked-host itself is, in $COOKED_HOST.

Compile integration

cooked improves two separate things that both happen to be called “running a build.”

Inside a cooked buffer, run make, a linter, cargo build — anything — as an ordinary command at the prompt, no M-x compile required. The moment it finishes, M-g M-n / M-g M-p (next-error) walk its errors and warnings exactly the way they’d walk a *compilation* buffer, using the same compilation-error-regexp-alist patterns. It isn’t compilation-mode wearing a term 76CF inal’s clothes, either — that assumes a buffer that only grows at the end, and this one’s live screen gets rewritten in place on every drain, which would leave its caches pointing at text that has since changed. Instead each next-error reparses just the finished command’s own output from scratch, scoped to it by its OSC 133 record rather than by guessing where the build starts in a wall of scrollback. Opt in with (require 'cooked-next-error).

In =M-x compile= itself — and grep, rgrep, project-find-regexp, anything built on compilation-start — cooked-process-mode gives the child a real pty instead of Emacs’ default one. That default pty has no size (stty size reports 0 0) and no name Emacs sets, which most programs read as “no terminal here”: cargo draws no progress bar, a child that checks isatty before colouring its output stays plain. cooked’s emulator gives the process a real, sized pty, so it draws what it would draw for a human, and then hands `compilation-filter` the resolved text rather than raw bytes — carriage returns have already overwritten instead of being left for Emacs to delete, escape sequences that addressed the screen are spent, and a diagnostic the child wrapped at the pty’s width arrives rejoined onto one line so compilation-error-regexp-alist can still match it. A progress bar that keeps rewriting itself is shown as an overlay below the real output rather than becoming buffer text, so it can’t confuse next-error or get left behind as scrollback. Enable it globally with M-x cooked-process-mode (after (require 'cooked-process)); it changes nothing about how you invoke compile or grep, only what the child sees and what lands in the buffer afterward.

Neither vterm nor eat has an equivalent to either half: both would need to know where a command’s output begins and ends to scope a next-error search, and neither hooks compilation-start to fix what stock Emacs hands a build.

On passwords

The secret never reaches the buffer: it goes out as two writes rather than one concatenation, and the native core zeroes its copy afterwards. That’s the honest limit, though — read-passwd still builds the string in Emacs’ own heap, where the garbage collector can leave copies behind that clear-string never sees. cooked can’t promise a password leaves no trace in Emacs’ address space, and doesn’t claim to.

Documentation

  • Keyboard — what stays with Emacs, how modified keys are spelled, per-program overrides, the evil state discipline
  • Features — completion, the OSC 51 command channel, images, box drawing, links, the UI conventions
  • Shell — the OSC 133 marks, the shipped helpers, and writing your own on top of them
  • Terminfo — why we ship an entry, and every capability in it
  • Images — kitty graphics, sixel, iTerm2 inline images
  • Design — the grid/buffer seam, the source layout, and the reasoning behind both
  • Roadmap — what is missing, and where this could go

Contributing

make test          # cargo test, the ERT suite, clippy, byte-compilation
make lisp-test     # just the Emacs half
make bench         # the acceptance gate for the render and write paths

The suite drives real children — cat for the cooked path, stty -echo for secrets, a real zsh for the OSC 133 path — and each subject file also loads on its own, which is what you want while working on one. It runs -Q, so packages it tests against (evil, for instance) have to actually be installed to be picked up, and it points the shells it starts at a scratch ZDOTDIR rather than yours, so the tests don’t run your prompt.

Linux and macOS are both supported; a new platform is usually one short file under src/platform/. See docs/DESIGN.md for how the pieces fit together.

Licence

GPL-3.0-or-later. src/emu/parser/ is vte 0.15, vendored from alacritty/vte under Apache-2.0 OR MIT; both licences sit beside it, and src/emu/parser/mod.rs records what was changed and why.

About

A comit-mode based terminal emulate specially designed for emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0