The Kalem Book GitHub

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

Plain text and code

Kalem opens any text file. Org, Markdown, LaTeX, CSV and BibTeX files get the views of their formats (Writing in Org, Markdown, LaTeX files, which covers .bib files too, and CSV files); code, configuration files and every other text file are plain text: monospace, colored by their language, with line numbers, the cursor's line marked and indentation guides. Tab follows the file's indentation (tabs, or its number of spaces) and indents selected lines; Shift+Tab outdents.

In code, Enter keeps the line's indentation and goes a level deeper after an opening bracket (after : in Python and YAML); between a pair, {|}, the closing bracket moves to a line of its own, and a closing bracket typed alone on its line goes back a level. The bracket matching the one at the cursor is marked, and Go to Matching Bracket (Ctrl+Alt+B) goes to it. Toggle Comment (Ctrl+Alt+C) comments the selected lines out with the language's marker (//, #, --, ;, %, or <!-- … --> in HTML and Markdown), or back in; in an Org document it works in source blocks with their language, and elsewhere writes Org's # comments.

Duplicate Lines (Ctrl+Shift+D), Move Lines Up and Down (Alt+Up and Alt+Down; Org keeps them for headings, items and rows), Join Lines, Sort Lines and Trim Trailing Whitespace act on the lines of the selection. Expand Selection (Ctrl+Alt+Right) grows the selection to the word, the inside of the brackets around it, the brackets, the line and the paragraph (in Org documents, the object and the element around it); Shrink Selection (Ctrl+Alt+Left) goes back.

Format Document (Shift+Alt+F; SPC c f in the Vim profile) formats the whole file with the formatter of its type, as Emacs's format-all language server's formatting where one serves the file, else a language plugin's formatter command, else a plugin's formatter for the type, else the language's usual program when it is installed (rustfmt, mix format, ruff or black, prettier, gofmt, clang-format, shfmt, stylua, zig fmt and others), run from the project's root with the text on its standard input. The setting formatters chooses the formatter of a type and comes before all of these: [formatters] python = "black -q -" in settings.toml, the type a language (rust, python), a file extension (rs), a mode (markdown) or a file name (cmakelists.txt), the value the command line with {file} for the file's path, or off, which turns formatting of the type off: a language server's and a plugin's formatter neither, on save neither, and Format Document says so. For a type with no formatter known, such as a workbook or a picture, the command says so and names the setting that would add one; a program not installed is named in the status bar. kalem fmt FILE formats the same way from the command line. The setting editor.format_on_save (off by default) formats the document the same way each time it is saved; a formatter that fails leaves the text as it is, the file is saved all the same, and the status bar says why.

The kind of a file comes from, in order: your choice with Set Document Mode (remembered in the workspace settings), a mode line such as -*- mode: org -*- on the first line, the extension, and a #! line. Binary files are not opened.