Editing HEEX with Emacs web-mode - how to recognize <.tag> as a tag?

A (doom) emacs user here.

web-mode ignores <.liveviewtags> which is especially annoying for closing the tags.
Has anyone here figured out how to configure web-mode to recognize live view tags as tags?
Tried to tweak the web-mode-(start-)tag-regexp variable, as well as messing with web-mode-engine-* variable but these did not help.

2 Likes

Hi,

not a solution, but have you considered Heex Tresitter Mode?

1 Like

Thank you for the pointer! I looked there, but I understand it requires emacs 29 and I am not sure Doom Emacs config is v29 ready yet…

Confirming that in with emacs29 heex-ts-mode does what I expect :slight_smile:
However, emacs29 is still under development and can break some packages

Perhaps you should file a bug report at the web-mode repo? That way once they fix it, you won’t have to upgrade to Emacs 29.

Actually I did this as first thing after failing to configure web-mode myself, but there is still no reply Elixir LiveView <.tag> syntax · Issue #1269 · fxbois/web-mode · GitHub

If you want to resolve this within web-mode itself (which is what I would do since this is something web-mode needs to sort out) the only thing we can do is to either fix this ourselves or wait for the maintainer.

I haven’t contributed to web-mode myself, but there is a chance that this is as simple as editing the regex for constitutes as a valid tag. Elisp is not my forte (it’s not many people’s forte), but if you do work on the PR, and you need some help, you can always ping me.

True,

but hopefully Emacs 29 pretests will come out soon :slight_smile:

Marcin via Elixir Programming Language Forum noreply@elixirforum.com writes:

Related post on the Doom discord: Customize tag name regexp in web-mode - User Support - Doom Emacs Discourse

(no resolution there on having web-mode support HEEx, either)

Yep, in the end I switched to using Helix which supports tree sitter. I still have EMacs open for Magit and org-mode though… Best bet is to wait till emacs gets native tree sitter support (and doom too)

I ended up getting a bit further with this by upgrading to Emacs v29 (which natively supports tree-sitter), and using the elixir-ts-mode package.

Doom’s docs do specifically call out that Emacs 29 is unsupported - but I haven’t found any issues after ~1 week of use.

Here’re the rough steps I took:

  1. Upgraded to Emacs 29 (I’m using emacs-plus on macOS), so for me this looked like:

    # I'm using emacs-plus on macOS
    brew uninstall emacs-plus && brew install emacs-plus@29
    
  2. Installed tree-sitter:

    brew install tree-sitter
    
  3. Added the elixir-ts-mode package to Doom config:

    ; packages.el
    (package! elixir-ts-mode)
    
  4. Configured .heex files to use elixir-ts-mode instead of web-mode:

    ; config.el
    ; Elixir: Use elixir-ts-mode instead of web-mode for HEEx
    (use-package! elixir-ts-mode
      :mode "\\.heex\\'")
    
  5. Followed instructions on heex-ts-mode README to install grammar, YMMV, but for me it was as easy as M-x heex-ts-install-grammar.

  6. $ doom sync and restarted Emacs.

  7. Verified it all works by opening a HEEx file and running M-x treesit-explore-mode. You should see it print a HEEx AST, like this:

You could also use elixir-ts-mode in .ex files to get syntax highlighting in ~H sigils, and then disable Doom’s default elixir config altogether… but I’m leaving that experiment for another day!

3 Likes

I found that setting the following variables makes it work. The variables are defined in web-mode and some people got very close by setting first and second but not the third one:

(setq web-mode-start-tag-regexp "<\\([[:alpha:].][[:alnum:].:_-]*\\|>\\)")
(setq web-mode-tag-regexp "</?\\([[:alpha:].][[:alnum:].:_-]*\\)")
(setq web-mode-dom-regexp "<\\(/?>\\|/?[[:alpha:].][[:alnum:].:_-]*\\|!--\\|!\\[CDATA\\[\\|!doctype\\|!DOCTYPE\\|\?xml\\)")

Maybe someone else can check it in her installation.

Mmmmm, I am afraid it is not working when combined with EEx (<%= ... %>) in a slot :frowning: