Doom Emacs - Elixir Wiki

As a curiosity perhaps, I decided to run a small experiment recently. Since majority of elixir-mode is now provided by tree-sitter, I disabled Elixir layer completely in Doom, just copied relevant parts from it to my config.el. All I needed was this:

(after! projectile
  (add-to-list 'projectile-project-root-files "mix.exs"))

(after! lsp-mode
  (add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]_build\\'"))

(after! highlight-numbers
  (puthash 'elixir-mode
           "\\_<-?[[:digit:]]+\\(?:_[[:digit:]]\\{3\\}\\)*\\_>"
           highlight-numbers-modelist))

(use-package! flycheck-credo
  :when (modulep! :checkers syntax -flymake)
  :config (flycheck-credo-setup))


(use-package! exunit
  :init
  (map! :localleader
        :map elixir-mode-map
        :prefix ("t" . "test")
        "a" #'exunit-verify-all
        "r" #'exunit-rerun
        "v" #'exunit-verify
        "T" #'exunit-toggle-file-and-test
        "t" #'exunit-toggle-file-and-test-other-window
        "s" #'exunit-verify-single))

This was on top on my existing config setting up eglot with Lexical, configuring tree-sitter etc.

So far after few days I see no problems with it. It even feels a bit snappier, but that’s probably my bias. However I think it can only work in Emacs 29 and 30 (I’m using 30).

2 Likes

I was doing a lot of rebuilding of things with emacs this morning because I was experiencing Emacs crashes during this week at work and it was messing up my whole vibe.
It all started when I switched from elixir-mode to elixir-ts-mode ( GitHub - wkirschbaum/elixir-ts-mode: Elixir mode using Treesitter for fontification, navigation and indentation ).
It turns out that older tree-sitter versions has a memory leak in elixir-ts-mode ( bug#72863: 30.0.50; tree-sitter elixir-ts-mode hangs and memory leak on ) and my default linux install of tree-sitter was older than 0.25.
Anyway, just writing my thoughts for future reference because I will forget all this by Monday.
Remove old tree-sitter libs, probably from, e.g. /usr/lib/local.
Install tree-sitter using github repo. Use the 0.25 branch. Usual make and make install.
Check ldconfig -p | grep tree-sitt to make sure you are using the 0.25 vsn.
Install emacs using github repo. Use the emacs-30 branch. Used ./configure --with-native-compilation then make and make install.

I think that’s all of it. I am using lsp-mode with Expert LS and everything is finally smooth. Hopefully my scrawled notes will help other lost travellers.

1 Like

I’ve been wondering.

Did someone managed to make doom use the latest elixir-ts-mode and heex-ts-mode that enables a bunch of sigils syntax highlighting?

I tried doing that using this code snippet:

(set-tree-sitter! 'elixir-mode 'elixir-ts-mode
  '((elixir :url "https://github.com/elixir-lang/tree-sitter-elixir"
            :commit "d24cecee673c4c770f797bac6f87ae4b6d7ddec5")
    (heex :url "https://github.com/phoenixframework/tree-sitter-heex"
          :commit "b5a7cb5f74dc695a9ff5f04919f872ebc7a895e9")
    (sql :url "https://github.com/DerekStride/tree-sitter-sql"
         :commit "fe77f6868d6cdea593052a6af390116495093dc1")))

But it doesn’t seem to work, I think it did fetch the correct versions, but the sigils still don’t work.

Edit: I also created a post about this in the Doom Emacs discord: Discord

I was experiencing an annoying thing where, for example, I was typing "for” but inside, say, a moduledoc and it was being expanded into a for do \n end snippet. This is smartparens not doing the right thing in elixir-ts-mode on Emacs 30.2.50. I am using latest libs of everything.

Anyway, I don’t have the spoons to trawl through github issues and I need to sleep so just writing down what I added to config.el to stop this annoying behaviour.

;; turn off annoying “for” autofill in new emacs elixir mode
(after! smartparens
(sp-local-pair 'elixir-ts-mode “for” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “if” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “case” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “cond” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “unless” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “with” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “try” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “fn” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “do” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “def” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “defp” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “defmodule” “end” :actions nil)
(sp-local-pair 'elixir-ts-mode “defimpl” “end” :actions nil))
1 Like