Editor support
As discussed in the quickstart there are Extempore plugins for several popular editors. This page shows how to set things up and lists any editor-specific instructions (e.g. the specific names of the commands & keybindings).
VSCode
Section titled “VSCode”Visual Studio Code, which is usually referred to as just VSCode, is a cross-platform text editor from Microsoft. For a general introduction to VSCode, check out the excellent docs.
VSCode has an Extempore extension, so it knows how to work with Extempore code. The VSCode setup instructions are actually listed in the quickstart guide already, so you should head over there and get started.
Helix talks to Extempore through its
language server, which is part of the extempore binary.
In ~/.config/helix/languages.toml:
[language-server.extempore]command = "extempore"args = ["lsp"]
[[language]]name = "extempore"scope = "source.extempore"file-types = ["xtm"]comment-token = ";"language-servers = ["extempore"]auto-format = trueauto-format formats each file as it’s saved. For syntax
highlighting, add the
tree-sitter grammar
as well. Then Space a offers “Evaluate top-level form” and
“Evaluate buffer”. For one key each, add this to config.toml:
[keys.normal.","]e = ':lsp-workspace-command extempore.eval {"uri":"file://%{file_path_absolute}","range":{"start":{"line":%sh{echo $((%{cursor_line}-1))},"character":0},"end":{"line":%sh{echo $((%{cursor_line}-1))},"character":0}}}'b = ':lsp-workspace-command extempore.evalBuffer {"uri":"file://%{file_path_absolute}"}'i = ':lsp-workspace-command extempore.interrupt', e evaluates the top-level form the cursor’s line is in
(the server counts lines from 0 and Helix from 1, which is what the %sh{} is
for), , b the whole buffer and , i
interrupts an evaluation. The buffer is evaluated as it stands, saved or not.
Values and the first line of output appear in the status line, and an error is
marked on its form until the form is edited or evaluates cleanly. Completion
and hover (Space k) work as for any language. The bindings
take over Helix’s , (keep primary selection); pick another prefix if
you use it. On Windows the path in %{file_path_absolute} isn’t valid inside
the JSON, so use the Space a menu there.
Any editor with a language client
Section titled “Any editor with a language client”extempore lsp is a language server:
point your editor’s language client at that command for .xtm files. It is a
client of a running extempore’s nREPL server, which it finds
as extempore send does (.nrepl-port, or 7888); the initializationOptions
host, port and process say otherwise.
Without a running extempore it reports unbalanced parentheses (when a file is opened or saved), gives an outline of the definitions in a file and folding ranges, and formats a document or a range of its lines. With one, it completes names (Scheme’s and xtlang’s), shows a function’s arguments, type and docstring on hover, and adds three commands, which are also offered as code actions:
| command | argument | what it does |
|---|---|---|
extempore.eval |
{uri, range} |
evaluates the selection, or with none the top-level form at the cursor |
extempore.evalBuffer |
{uri} |
evaluates the whole buffer |
extempore.interrupt |
stops the evaluation which is running |
The range is an LSP range: lines and characters from 0. Values and the first
line of output come back as window/showMessage, the whole output as
window/logMessage, and an error as a diagnostic on the first line of its form.
A client which sends "evalResults": "response" in its initializationOptions
gets each evaluation’s result as the answer to its workspace/executeCommand
request, sent when the evaluation finishes, in place of the two messages:
values (one per form), out (what it printed), interrupted, and when it
failed error (message, and kind and line where extempore gives them).
range is where the code came from: the selection or form evaluated, or for
extempore.evalBuffer the form which failed. Errors are still marked as
diagnostics. This suits an editor which shows results beside the code, as the
VSCode extension does.
An editor which can only run a shell command can use
extempore send: pipe the selection to
it, or give it --file and --line.
Formatting
Section titled “Formatting”extempore fmt formats .xtm files: extempore fmt FILE or extempore fmt DIR
rewrites them in place, --check lists the ones which aren’t formatted (and
exits 1 if there are any), and with no files it formats stdin to stdout. It
changes whitespace only, and indents as Racket and Clojure code is indented. A
call’s arguments align with the first one when it’s on the head’s line, and
with the head when it isn’t; a body form’s body (begin, cond, lambda,
let, when, a bind-func, and anything named define…, def-… or
with-…) indents two columns; data (a quoted list, a vector, a list not headed
by a symbol) aligns with its first element. Whitespace at the ends of lines and of
the file goes. Line breaks stay where they are, and so do the lines of a string
or a block comment. The Extempore source tree is formatted this way, and CI
checks that it stays so.
The language server formats too, so an editor with a language client can format
on save (Helix with auto-format = true); in Emacs it’s
M-x extempore-format-buffer, or set extempore-format-on-save. The
editors’ own indentation (Emacs’s extempore-mode, and Helix’s through
tree-sitter-extempore) follows the same rules as you type.
extempore-emacs-mode
(Emacs 29.1 or later) is on MELPA: M-x
package-install RET extempore-mode RET. It starts
Eglot with the language server, so it finds a running
extempore as extempore send does, and shows each result at the end of its
form. Completion, eldoc and errors marked as diagnostics come from the server.
| command | keybinding |
|---|---|
extempore-send-dwim (the region, or the top-level form) |
C-M-x |
extempore-send-buffer |
C-c C-k |
extempore-interrupt |
C-c C-b |
switch-to-extempore (or start Extempore if it isn’t running) |
C-c C-z |
extempore-repl (extempore repl in a buffer) |
C-c C-e |
extempore-format-buffer (with extempore fmt) |
For an extempore older than the nREPL server, set extempore-transport to
legacy and connect to its eval server with C-c C-j. The mode’s
README has the rest.
Sublime Text
Section titled “Sublime Text”Extempore’s Sublime Text plugin is available from GitHub.
The plugin’s commands and key bindings are documented in its own repo.
Known issues
Section titled “Known issues”The syntax highlighting currently doesn’t cover a few edge cases—so if you end
up tinkering with Extempore.JSON-tmLanguage to fix anything then feel free to
submit a pull request.
Extempore’s vim plugin is written by Tim Burgess.
| command | keybinding |
|---|---|
| open connection to Extempore | LEADERo |
| close connection to Extempore | LEADERx |
| send enclosing block to Extempore | LEADERw |
| send selection to Extempore | LEADERs |
| send entire file to Extempore | LEADERa |
The vim mode doesn’t yet support multiple connections or user-specified host/port, but pull requests are welcome.