hjkl-bonsai
Tree-sitter syntax highlighting for the hjkl editor stack — runtime grammar loading, no baked-in languages.
Renamed from
hjkl-tree-sitter(the old crate stays as a deprecated 0.5.0 artifact on crates.io). New releases ship underhjkl-bonsai.
bonsai ships a manifest of 421 languages (sourced from helix +
nvim-treesitter) and resolves grammars at runtime through a chain of:
- System — distro-shipped
.sounder/usr/share/hjkl/grammars/(or/usr/local/share/hjkl/grammars/). - User —
.sopreviously installed under<user_data>/hjkl/grammars/. - On-demand — clone the upstream repo, compile with
cc/c++, and install the result into the user dir for next time.
A <name>.rev sidecar tracks <git_rev>:abi<N>, so a manifest bump or a
tree-sitter ABI change recompiles in place automatically.
The release rlib is ~720 KB because no grammars are baked in. The first edit
of an unknown language pays a one-time clone+compile cost; everything after that
is a dlopen.
Usage
= "0.2"
use Arc;
use ;
use ;
// 1. Load the embedded manifest + standard XDG-defaulted loader.
let registry = embedded?;
let loader = user_default?;
// 2. Resolve a language by name (or path → registry.name_for_path).
let spec = registry.by_name.expect;
let grammar = new;
// 3. Highlight.
let mut highlighter = new?;
let spans = highlighter.highlight;
let theme = dark;
for span in &spans
# Ok::
Distro packagers
The runtime layout bonsai looks for is:
<prefix>/hjkl/grammars/<name>.so
<prefix>/hjkl/grammars/<name>.scm
To pre-build the full set against the current manifest:
System-shipped grammars are not rev-checked at runtime — the packager owns that lifecycle.
On-disk layout
/usr/share/hjkl/grammars/ # 1st lookup (system)
/usr/local/share/hjkl/grammars/ # 2nd lookup (system)
<user_data>/hjkl/grammars/ # 3rd lookup + install target
rust.so rust.scm rust.rev
python.so python.scm python.rev
<user_cache>/hjkl/grammars/ # source clones, transient
rust-e86119bdb496/
python-710796b8b877/
Platform user dirs are resolved via the dirs crate:
| OS | <user_data> |
<user_cache> |
|---|---|---|
| Linux | $XDG_DATA_HOME or ~/.local/share |
$XDG_CACHE_HOME or ~/.cache |
| macOS | ~/Library/Application Support |
~/Library/Caches |
| Windows | %APPDATA% |
%LOCALAPPDATA% |
License
MIT. See LICENSE.