Elsmith
Elsmith parses Emacs Lisp into a lossless syntax tree, resolves Lisp-2 bindings and indexes the workspace. It serves LSP over stdio and reuses unchanged forms after buffer edits.
| Feature | What Elsmith supplies |
|---|---|
| Navigation | Definitions, declarations and references across open buffers, indexed files and the Emacs catalog. Open buffers take priority over disk. Document symbols, highlights, folding ranges and selection ranges work within a file. |
| Completion and help | Context-aware completion, hover with argument lists and docstrings, and signature help for &optional, &rest and &key. Completion resolve can add a missing require when the client declares support for additionalTextEdits. |
| Semantic display | Full, delta and range semantic tokens based on Emacs 31.1 elisp-scope, parameter-name inlay hints and workspace symbol search. |
| Diagnostics and fixes | Static findings during edits, push or pull delivery, and exact quick fixes. Trusted workspaces also get Emacs byte-compile, Checkdoc, optional package-lint and explicit macro expansion. |
| Rename and call hierarchy | Capture-checked lexical renames, renames of uniquely defined workspace functions, and incoming and outgoing calls for statically identifiable callees. |
| Formatting | Document, range and on-type indentation from the Emacs 31.1 table and static (declare (indent N)) declarations. Edits affect leading whitespace and preserve comments and strings. Forms with function indenters or unclosed strings are skipped. |
The executable runs without an Emacs or Lean installation. Emacs adds the catalog and the optional trusted workspace features.
Emacs catalog
The server finds Emacs in this order: --emacs, emacs_path in $XDG_CONFIG_HOME/elsmith/config.toml, then the absolute directories of PATH. --emacs and emacs_path must be absolute. The search skips relative PATH entries and any PATH entry whose directory or resolved binary lies inside a workspace root. Project files never choose the Emacs binary.
On the first start for an Emacs binary, a background job runs emacs -Q --batch in an empty temporary directory. It clears the environment and sets only HOME, to that directory. The job records the function, macro, special form, variable and feature tables of that Emacs before it loads anything. Only then does it load help-fns to name the C files of primitives and C variables. It evaluates no project code. Elsmith stores the result in $XDG_CACHE_HOME/elsmith/catalog/KEY.json. KEY is a hash of the catalog schema and the real path, modification time and size of the binary. The file also records the Emacs version and the load-path order. Elsmith rebuilds the catalog when any of those load-path directories changes. Standard library sources from .el.gz files are written once, read-only, to $XDG_CACHE_HOME/elsmith/stdlib/KEY/RELATIVE-PATH.el.
On x86_64 Linux with Emacs 31.1 and a release build, the median of 7 runs from process start to the initialize response is 1.4 ms, with or without a cached catalog. The first hover that needs the catalog arrives after 1,384 ms when the catalog must be built and after 24.8 ms when it is cached. make bench-startup repeats the measurement and writes test-out/startup.json.
Project environment
Elsmith reads the project configuration as data and never evaluates it. The load path comes from these sources, in priority order:
load_pathsin the userconfig.toml.load_pathsinelsmith.tomlat the workspace root.ignored_pathsexcludes directories from the index. Other keys, includingemacs_path, are ignored and logged.- Installed packages in
.keg/VERSION/elpa/,.eask/VERSION/elpa/and.cask/VERSION/elpa/when the matchingKeg,EaskorCaskfile exists, plus literalload-pathandload-pathsentries inEask. - Literal strings for
elisp-flymake-byte-compile-load-pathorload-pathin.dir-locals.el, thenlisp/,test/and the root. EMACSLOADPATH, only for a trusted workspace.
The index walks each root with .gitignore rules. It also reads the files directly inside each load path directory that lies outside the root or under .keg, .eask or .cask. It watches every indexed directory without recursion and also accepts workspace/didChangeWatchedFiles.
Install and run
With Nix flakes enabled, run Elsmith directly from GitHub or install it on your PATH.
The flake supports x86_64 Linux and aarch64 macOS. From a checkout, use nix run . -- server run-server.
Once the crate is published, install it from crates.io with Cargo.
To install the current source with Cargo, use cargo install --git https://github.com/conao3/rust-elsmith --locked. Cargo builds from the generated Rust checked into the repository.
Point your editor at elsmith server run-server. The server reserves stdout for LSP frames. If you installed Elsmith somewhere outside the editor's PATH, use the absolute executable path in the corresponding example.
CLI
elsmith server run-server [--emacs PATH] [--log-file PATH]
elsmith check check-file --file PATH [--emacs PATH]
elsmith catalog build-catalog [--emacs PATH] [--force]
elsmith catalog show-catalog [--emacs PATH]
elsmith trust list-roots
elsmith trust add-root --path DIR
elsmith trust remove-root --path DIR
Use --output json|text|table for CLI reports. JSON is the default. --debug logs to stderr when no server log file is selected. --version prints the version, and a trailing help shows command help.
check-file reports File, LexicalBinding, Lines, Bytes and Diagnostics. LexicalBinding follows the cookie scanner of Emacs 31.1 load. The cookie must sit in a comment on the first line, or on the second line after a shebang. nil gives false, any other value gives true, and a missing cookie gives null. A Local Variables: entry for this setting produces a warning. Diagnostics contains the static findings with zero-based UTF-16 positions. Symbol checks also use the cached Emacs catalog when available.
build-catalog and show-catalog report the Emacs path, version, cache file, standard library cache directory and the number of functions, primitives, special forms, macros, autoloads, variables, features and libraries. build-catalog also reports whether it reused the cache and how long it took. show-catalog exits with 254 when no catalog is cached.
CLI exit codes are 0 for success, 252 for usage errors, 254 for rejected input, and 255 for other failures. The stdio process returns 0 on exit after shutdown and 1 on an early exit or EOF.
Workspace trust
The user manages trust with elsmith trust add-root and elsmith trust remove-root. The list lives in $XDG_CONFIG_HOME/elsmith/trusted-roots.toml or $HOME/.config/elsmith/trusted-roots.toml. Set ELSMITH_CONFIG_DIR to an absolute directory to use a different list.
Each workspace root must match a canonical directory in the list. Resolved file and dependency targets must also lie inside a trusted canonical root, including targets reached through symbolic links. The server tracks an epoch that advances when it observes a revocation. Changes to trust come exclusively from the user allowlist. Initialization options, configuration notifications, project files and execute commands have no trust authority.
Trust delegates permission to execute project code during byte compilation, linting and macro expansion. Grant it only to projects and dependencies you are willing to execute. Each job has its own temporary directory, a cleared environment and a ten-second time limit. Job code runs with the server user's OS permissions. Revocation stops running jobs and clears their diagnostics and macro expansions. The catalog job uses only the user-chosen Emacs binary and standard libraries, so it runs in untrusted workspaces as well.
Diagnostics and code actions
Syntax errors, arity mismatches, unused lexical locals, unknown symbols and footer-only lexical-binding are checked as you edit. When a trusted document is saved, one disposable Emacs process runs the byte compiler, Checkdoc and package-lint if the package is available. The server waits for imported open buffers to match their saved files. Rapid saves are grouped and the newest eligible snapshot enters the queue. Pull-capable clients receive document and workspace diagnostic reports. Other clients receive push notifications, including an empty list when findings clear.
Code actions can prefix an unused lexical local with _ or insert a require for a uniquely resolved feature. Adding or moving a lexical-binding cookie is an explicit refactor because it can change how the file executes.
To expand a project macro, call workspace/executeCommand with command elsmith.expandMacro and one argument containing uri and the LSP position of the macro name in a call. In a trusted workspace with saved dependencies, the result contains once and all with the expansions from macroexpand-1 and macroexpand-all. Elsmith caches the result until the diagnostic snapshot changes.
Editor setup
VS Code
Create a local client extension with the two files below in a directory outside the workspace you want to edit. The selector attaches to local .el files. VS Code language server guide
package.json
extension.js
const vscode = require;
const = require;
let client;
exports ;
exports client?.;
From the extension directory, run npm install, then launch the Extension Development Host with code --new-window --extensionDevelopmentPath="$PWD" /path/to/project. Use VS Code's Manage Workspace Trust command to allow the extension in that folder, then open an .el file. Trust in VS Code allows client activation. Emacs jobs still require an entry in the Elsmith allowlist. VS Code Workspace Trust guide
Neovim
Neovim uses the lisp filetype for both Emacs Lisp and Common Lisp. Match *.el when starting Elsmith.
vim..
Vim
With vim-lsp installed, add this to .vimrc. The compound filetype keeps Vim's Lisp highlighting and activates Elsmith only for .el. Use :LspHover, :LspDefinition and :LspRename from the buffer.
let g:markdown_fenced_languages = get(g:, 'markdown_fenced_languages', []) + ['elisp=lisp']
augroup elsmith_lsp
autocmd!
autocmd BufRead,BufNewFile *.el setlocal filetype=lisp.elsmith
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'elsmith',
\ 'cmd': {server_info -> ['elsmith', 'server', 'run-server']},
\ 'allowlist': ['lisp.elsmith'],
\ 'languageId': {server_info -> 'emacs-lisp'},
\ })
augroup END
Emacs
Choose one LSP client. For vowls.el, use M-x vowls-ensure in an Emacs Lisp buffer or enable the hook below.
(with-eval-after-load 'vowls
(add-to-list 'vowls-server-programs
'((emacs-lisp-mode :language-id "emacs-lisp")
. ("elsmith" "server" "run-server"))))
(add-hook 'emacs-lisp-mode-hook #'vowls-ensure)
For Eglot, use M-x eglot or enable eglot-ensure from the mode hook.
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'((emacs-lisp-mode :language-id "emacs-lisp")
. ("elsmith" "server" "run-server"))))
For lsp-mode, register an Emacs Lisp client and run M-x lsp.
(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration '(emacs-lisp-mode . "emacs-lisp"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("elsmith" "server" "run-server"))
:activation-fn (lsp-activate-on "emacs-lisp")
:server-id 'elsmith
:priority 1)))
Helix
Add this to ~/.config/helix/languages.toml. It extends the built-in elisp language. Open an .el file and use hx --health elisp to check the configuration. Helix language configuration
[]
= "elsmith"
= ["server", "run-server"]
[[]]
= "elisp"
= "emacs-lisp"
= ["elsmith"]
= ["elsmith.toml", ".git"]
Lean verification
Lean proves the rules for position and edit boundaries, document replacement, lifecycle transitions and response claims, capability negotiation, the lexical-binding cookie, Lisp-2 resolution and capture checks, the active signature parameter and diagnostic snapshot acceptance. leanfran generates the Rust implementations. The syntax tree, JSON and stdio transport, the atomic response claim and filesystem integration run in Rust and have integration tests.
make audit runs leanassay's #assay against the generated functions that Rust calls and against selected helpers. Equivalent mutants match the original on the inputs tested. Lean's type checker rejects the untyped mutants.
| Function | Mutants | Killed | Holes | Equivalent | Untyped |
|---|---|---|---|---|---|
resolve |
2 | 2 | 0 | 0 | 0 |
offset |
4 | 4 | 0 | 0 | 0 |
replaceRange |
3 | 3 | 0 | 0 | 0 |
transition |
75 | 63 | 0 | 0 | 12 |
requestAllowed |
3 | 3 | 0 | 0 | 0 |
completeOrCancel |
6 | 6 | 0 | 0 | 0 |
negotiateSession |
1 | 1 | 0 | 0 | 0 |
parseLexicalCookie |
1 | 1 | 0 | 0 | 0 |
scanLoop |
13 | 10 | 0 | 0 | 3 |
feed |
90 | 61 | 0 | 1 | 28 |
readName |
9 | 9 | 0 | 0 | 0 |
readValue |
14 | 13 | 0 | 0 | 1 |
verdict |
9 | 9 | 0 | 0 | 0 |
resolveSymbol |
16 | 13 | 0 | 0 | 3 |
canLocalRename |
5 | 5 | 0 | 0 | 0 |
declaredSpecial |
11 | 8 | 0 | 0 | 3 |
renameSite |
3 | 3 | 0 | 0 | 0 |
keepsResolution |
7 | 7 | 0 | 0 | 0 |
activeParameter |
3 | 3 | 0 | 0 | 0 |
activeFrom |
23 | 12 | 0 | 0 | 11 |
keyIndex |
16 | 13 | 0 | 0 | 3 |
governingKey |
9 | 4 | 0 | 0 | 5 |
acceptDiagnostics |
14 | 13 | 0 | 0 | 1 |
Every function has zero untested and zero timed-out mutants. Untyped mutants are reported by leanassay as stillborn.
See the proof details and audit inputs.
Development
make check runs formatting, Clippy, Lean proof checking, Rust tests and stdio tests for rename, call hierarchy and formatting. The formatting test compares a supported fixture with Emacs indent-region and checks idempotence. Stage the generated lean/ and .leanfran/cache/ files before this check. The Rust tests parse every .el and .el.gz file of the devShell Emacs. make corpus prints the corpus statistics. make audit checks for gaps in the theorems with leanassay. make check-protocol records a strict-client session and two proxy sessions in test-out/. One proxy session declares only push diagnostic support. The other exercises pull diagnostics, UTF-8 positions, Markdown and resolve support. Every report must have zero errors and zero warnings. make scope-oracle regenerates tests/fixtures/scope/expected.json with Emacs elisp-scope, and make lexical-oracle regenerates the lexical-binding fixtures.
make check-editors runs Emacs 31.1 with vowls and Eglot and Neovim 0.12.6 against Elsmith through lsp-touchstone. The vowls session also opens a pinned copy of vowls.el, jumps to a definition in vowls-server.el and saves a lexical rename. It verifies diagnostics, completion and resolve, hover, the displayed definition and cursor in a decompressed standard-library file, rename, formatting and a zero server exit status. Logs and protocol reports are written to test-out/editors/. The vowls record requires zero errors and warnings on both ends. The Eglot 31.1 record includes client warnings for the $streamingDiagnostics extension and the empty object sent with exit.
make bench-slo measures a release build over stdio with the vowls source revision from the flake lock. It records one cold catalog build and 25 samples per latency metric. It measures requests both at idle and while a trusted save's Emacs job is in progress. The report in test-out/slo.json includes raw samples, startup median, nearest-rank p95 and whether each value meets its target.
To test the Nix package using those same sessions, run the following after nix build.
Performance
The Nix release build was measured over stdio on x86_64 Linux with an Intel Core i5-8400 and GNU Emacs 31.1. The pinned vowls source contains 23 Emacs Lisp files. The edit and save probes run in a temporary copy of the 29,088-byte vowls-server.el. Each statistic uses 25 samples, with one sample for the cold catalog build. During-compile requests start and finish while the Emacs job is in progress.
| Measurement | Statistic | Time | Target | Result |
|---|---|---|---|---|
| Cached initialize | Median | 1.788 ms | < 30 ms | Met |
| Cold catalog build | Single run | 1,373 ms | < 2,000 ms | Met |
| Edit to static diagnostics | p95 | 11.88 ms | < 5 ms | Missed |
| Completion (idle) | p95 | 0.65 ms | < 10 ms | Met |
| Hover (idle) | p95 | 0.303 ms | < 10 ms | Met |
| Definition (idle) | p95 | 0.356 ms | < 10 ms | Met |
| Semantic tokens (idle) | p95 | 4.38 ms | < 10 ms | Met |
| Completion (during compile) | p95 | 2.751 ms | < 25 ms | Met |
| Hover (during compile) | p95 | 1.264 ms | < 25 ms | Met |
| Definition (during compile) | p95 | 1.473 ms | < 25 ms | Met |
| Semantic tokens (during compile) | p95 | 21.726 ms | < 25 ms | Met |
| Trusted save to byte-compile diagnostics | p95 | 407.305 ms | < 400 ms | Missed |
To repeat the benchmark with the built package, use nix develop --command python3 tests/slo_bench.py --binary result/bin/elsmith. The raw samples and targets are written to test-out/slo.json.
Release
For a new crate, the owner first publishes the current version with cargo publish --locked from a clean checkout using a short-lived crates.io API token. Once the crate exists, register GitHub repository conao3/rust-elsmith and workflow release.yml in the crate's Trusted Publishing settings. Leave the environment field blank. crates.io Trusted Publishing
Dispatch the release workflow on master and choose the version increment. It checks the Cargo package, pushes the version commit and tag atomically, publishes the crate through OIDC and creates the GitHub Release with generated notes.