HEEx on Doom Emacs
A quick setup guide for .heex
files on Emacs. At the time of writing, Doom Emacs only
supports up to 28, and 29+ are not supported yet. This guide could become irrelevent
once Emacs 29 becomes stable.
Since I'm using Doom Emacs
, this will provide steps to get .heex
working on it as well.
We'll need to install the tree-sitter-cli
before proceeding.
Rust version
There's a NPM package as well so this can be used if Rust is not installed in your system.
NPM version
Verify with the following command.
Build
Let's start with retrieving the tree-sitter code for heex
.
The repo for tree-sitter-heex
is provided by the Phoenix team and is available at phoenixframework/tree-sitter-heex.
At the time of writting, tree-sitter-heex
comes with src/parser.c
, but since it was generated with v0.20 of the CLI, we'll need to use the v0.19 version to regenerate it.
You should see some diffs after the command which you can ignore.
> git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: src/parser.c
modified: src/tree_sitter/parser.h
no changes added to commit (use "git add" and/or "git commit -a")
cc -shared -fPIC -fno-exceptions -g -I src src/parser.c -o ./heex.so -O2
You should see a heex.so
file now.
Emacs
Now that heex.so
is available, it's time to get it loaded into Emacs.
Tree-sitter Emacs looks for custom built libraries in tree-sitter-load-path
, which is a list of strings.
You can run Alt
x
=> describe-variable
in Emacs to check for the current values. In my case, $HOME/.tree-sitter-/bin
was already included in the variable
so I'll be placing the built heex.so
there.
mkdir -p ~/.tree-sitter/bin
mv ./heex.so ~/.tree-sitter/bin/
Next step will be to instruct Emacs to load heex.so
when it opened a file with .heex
extension.
Add the following to ~/.doom.d/config.el
Restart/reload Emacs and this should now show up.
Notes
Syntax highlighting itself is not really working for me at the moment, so will
probably update this post after I figure that out. Might have to deal with web-mode
directly.