The Kalem Book GitHub

This Book describes Kalem's main branch, which may be ahead of the latest release.

What Kalem is

Kalem is a fast, open source editor for plain-text documents. It opens a file as what it is, Org, Markdown, LaTeX, CSV, BibTeX or code, shows it the way it reads, and writes back only what you changed. One editor runs in a window and in a terminal, and every operation on a document is also a command on the command line.

1. Text first

The file on disk is the truth. Kalem keeps no database, no container format and no sidecar files: the document is the text file you see in git diff and in any other editor. Bold reads as bold, a table is a grid, a formula is typeset, and under them the file is the same plain text it was. There is nothing to export before a colleague can read your work, and nothing to lose if you stop using Kalem.

2. Every format as itself

Kalem never converts a file to open it and never saves it as another format. Conversion is a command you run on purpose, Export, Convert to Org or kalem export, which writes a new file and leaves the old one alone. Three rules hold for every format (Part II explains them):

  1. Ranges, never text. A mode reads the file into ranges; an edit replaces only the characters it changes. The file is never written back from a tree, so untouched parts stay byte for byte: spacing, comments, line endings, a byte order mark.
  2. No extension. Kalem writes nothing into a file that its standard does not define. A Markdown file gets no font menu, a CSV file no formatting.
  3. Unknown constructs stay visible. What Kalem does not understand is shown as the source it is, never hidden or guessed.

3. The formats

Five formats are built in, each checked against a reference implementation or test suite, its oracle (Standard modes and their oracles).

Format Opens as Where in this book
Org A document; tables with formulas, TODO states, export Writing in Org, Org
Markdown A document; task lists, tables, front matter, wiki links Markdown
LaTeX A document; formulas, references, citations, PDF builds LaTeX files, LaTeX
CSV, TSV A grid with sorting, filters and statistics CSV files, CSV
BibTeX A grid of entries BibTeX
Everything else Plain text, colored by its language Plain text and code

Every other format is to be a plugin: more text formats, viewers for files that are not text (PDF, Word, Excel, images), language servers. A plugin is compiled Rust, run as a WebAssembly component with its own memory, a memory limit, a time budget and only the permissions it declares, so a plugin cannot freeze the editor and one that fails is disabled instead of taking Kalem down. Kalem ships no JavaScript, Lua or Lisp interpreter; configuration is data, in TOML and JSON. No plugin is built into the binary: the viewers of PDF files, pictures and Excel workbooks too are installed from the plugins' index, the first time such a file is opened or with kalem plugin install. The extension model says what can be changed today and Plugins has the design.

4. Fast

Kalem is one static binary with nothing to interpret. On an Apple M1 Max it starts to its first frame in 148 ms, opens a 1 MB document in 184 ms, draws a keystroke in 8.7 ms, and uses 47 MB of memory with an empty document. Performance has every target, the method and the scripts that repeat the measurement.

5. Two editors and a command line

The graphical and the terminal editor share one core: the same commands, keys, settings, menus and views. The terminal editor draws formulas, images and tables too, so a document reads the same over SSH as on the desktop; what it cannot show is listed in Terminal parity. Every document operation is also a command-line tool, for scripts and CI: The command line.

6. A power editor's tools

Word-like keys by default and Vim keys as an option, with Doom Emacs's leader keys, panes, workspaces and sessions (Keys). A file manager (The file manager), projects and find in files (Documents and projects), a command palette and bookmarks (Finding and commands), an outline, focus mode and narrowing (Views). Everything is a command with a configurable key, and configuration is data that Kalem checks when it reads it (Settings). Kalem borrows these tools from Emacs, and that is where the debt ends: it is made for anyone with text files.

7. What Kalem is not

Not a Microsoft Office clone: Word files will open through a plugin later, and go through pandoc today. Not a page layout tool, a full spreadsheet or a visual slide designer. Not a full IDE: language servers come as plugins, and the core knows no programming language. Not an Emacs: no Elisp, no agenda settings by the hundred; Kalem and Emacs says what is taken from it and what is left out. Not a collaboration service: files and git are enough. The design document lists the non-goals in full.