how can I do lsp-format-buffer
run after save buffer?
This is what I have in my Emacs init file:
(add-hook 'elixir-mode-hook
(lambda ()
(add-hook 'before-save-hook #'lsp-format-buffer nil t)))
anyone figured out how to get inline heex (via ~H) syntax highlighted?
Not specific to doom, but you can use poly-mode to combine web-mode and elixir-mode to accomplish this:
(use-package
polymode
:ensure t
:mode ("\\.ex\\'" . poly-elixir-web-mode)
:init (setq web-mode-engines-alist '(("elixir" . "\\.ex\\'")))
:config
(define-hostmode poly-elixir-hostmode :mode 'elixir-mode)
(define-innermode poly-surface-expr-elixir-innermode
:mode 'web-mode
:head-matcher (rx line-start (* space) "~H" (= 3 (char "\"'")) line-end)
:tail-matcher (rx line-start (* space) (= 3 (char "\"'")) line-end)
:head-mode 'host
:tail-mode 'host
:allow-nested nil
:keep-in-mode 'host
:fallback-mode 'host)
(define-polymode poly-elixir-web-mode
:hostmode 'poly-elixir-hostmode
:innermodes '(poly-surface-expr-elixir-innermode)))
my full init.el
is here if anyone is interested:
https://dotfilehub.com/knoebber/emacs
Doom Emacs now supports tree-sitter. Have restructured my config (Org mode ftw!) and will soon update the topic start post.
Did you manage to make tree-sitter work to correctly syntax highlight HTML code inside ~H ~F and ~L sigils?
Not yet, but that is the main reason the opening post has to be updated as Doom Emacs does not work that well with Phoenix projects.
Due to Emacs not doing great with a professional project I have to work on at a daily basis; I have to postpone my usage of Doom Emacs. As a result I wonāt be able to keep the opening post as updated as it should be.
Please drop me a message when you are able to maintain the opening post.
I still use CentaurEmacs (even though I already use LunarVim for most of of my development) and it is doing surprisingly well, has good errors and warnings detection, for Elixir and Rust both it does linting with dialyzer
and clippy
respectively, shows docs on autocomplete and sometimes when you put cursor under a thing.
It works much better than I expected. Even with that I get the occasional lockups for 2-3 secs.
Havenāt checked how well it integrates with Phoenix though. I suspect not well but if youāre curious and have time you could give it a go. Itās based on Doom Emacs.
A bit of a necro, but Iāve been using Doom for a while. And I use Emacs for almost everything - The Way of Emacs .
Been using alchemist since 2016 and just upgraded to use eglot and elixir-ls. Itās much better than alchemist and eglot will ship by default with Emacs 29.
Configuration below:
packages.el
(package! elixir-mode)
(package! eglot)
(package! exunit)
(package! inf-elixir)
config.el
;; eglot configuration
(use-package elixir-mode)
(use-package eglot)
(use-package exunit)
(add-to-list
'eglot-server-programs
'(elixir-mode . ("sh" "/home/YOUR_HOME_DIR/.elixir-ls/release/language_server.sh")))
(add-hook
'elixir-mode-hook
(lambda ()
(subword-mode)
(eglot-ensure)
(company-mode)
(flymake-mode)
(add-hook 'before-save-hook 'eglot-format nil t)
))
(setq inf-elixir-project-command "iex -S mix phx.server")
Iāve also been using the Elixir mode with Treesitter support for while now, as Emacs 29 will come with support for it.
I really like it.
Iām using that too, but I canāt make elixir code inside html/heex be correct displayed (with syntax highlighting). Did you figured a way to fix that?
There is no support for that, but there I raised an issue about it. It seems having Elixir with embbeded Heex and Heex with embbeded Elixir at the same time is a bit tricky with their current project structure.
If you are getting some warning like ālsp is scanning 5000 files in current projectā¦consider adding to ignore listā, try adding this to
config.el
A bunch of these directories are now ignored by default.
In my case, adding the following to my config.el
was enough to get rid of the warning:
; Elixir: Ignore files which don't need to be watched
; https://emacs-lsp.github.io/lsp-mode/page/file-watchers/
(after! lsp-mode
(dolist (match
'("[/\\\\]_build\\'"
"[/\\\\]deps\\'"))
(add-to-list 'lsp-file-watch-ignored-directories match)))
I followed this post recently to upgrade my Emacs to 29 finally. Thought Iād post it here. Basically you need to put this in packages.el
:
(package! elixir-ts-mode)
And then follow the tutorial about the configuration. Works like a charm. Syntax highlighting in heex files too.
can you send a snippet on how you did it on your config.el
?
iāve tried that and everytime i opened a new project it errored with no language registered for elixir-ts-mode
or something like that.
I just added that line. But thereās also a step from elixir-ts-mode readme, you should run M-x elixir-ts-install-grammar
to, well, install the grammar. Maybe thatās what you are missing?