DEV Community

Cover image for Elixir and DooM Emacs
Mario Mazo
Mario Mazo

Posted on • Edited on

Elixir and DooM Emacs

Genesis

Recently I gave up on configuring vim and spacevim over and over, and I decided to try emacs... a piece of tech I have avoided for over 20 years. My goal was to have something that worked out of the box, with all the nice stuff that vim provides. After some searching I found doom emacs so I installed emacs for the first time in my live in my 20+ years of *nix, ops and programming career.

So first things first; doom emacs is freaking amazing, now I feel bad for all the time I wasted tuning vim and vscode, with doom 99% of the things worked out of the box, some minor relearning was needed, but was some love at first sight kind of thing, only thing left was having full integration with my favourite programming language elixir to have a nice IDE like experience

Nice soap opera dude! Where is the elixir-ls part?

So I began reading how to integrate elixir and I found a lot of tutorials but seems like doom moves fast and almost of all them were outdated, did not work and were quite long. So here is they simplest way i have found to integrate elixir-ls with doom emacs and turned out it was super simple.

Elixir-ls in doom emacs

install elixir-ls

git clone https://github.com/elixir-lsp/elixir-ls.git ~/.elixir-ls
cd ~/.elixir-ls
mix deps.get
MIX_ENV=prod mix compile
MIX_ENV=prod mix elixir_ls.release -o release
Enter fullscreen mode Exit fullscreen mode

add elixir-ls to your path

Add elixir-ls to your PATH
in your shell rc, in my case .bashrc or .zshrc

export PATH=$PATH:$HOME/.elixir-ls/release
Enter fullscreen mode Exit fullscreen mode

add your env variables to doom

I use a mac so the emacs.app starts isolated and the PATH is not the same as the one in your shell. Also i almost never start emacs from the command line so the path to the elixir-ls has to be in your doom env variables

~/.emacs.d/bin/doom env
Enter fullscreen mode Exit fullscreen mode

you can validate that the elixir-ls path is in ~/.emacs.d/.local/env

activite lsp and elixir with lsp support

In the config.el uncomment lsp, tree-sitter and replace elixir as follows

tree-sitter
lsp
(elixir +lsp +tree-sitter)
Enter fullscreen mode Exit fullscreen mode

sync doom

~/.emacs.d/bin/doom sync
Enter fullscreen mode Exit fullscreen mode

restart emacs... profit
you should see a little 🚀 (rocket) in your status bar that means is connected to the lsp server, and you get auto-complete and all other good stuff.

troubleshooting

you can use SPC b B and search for a buffer *lsp-log* to see error messages

Closing notes

This gives the basic set up to start working, you can customize the lsp with lsp-ui but I dont know how and Im not that interested in fine tuning every single piece of it. This is enough to get me up and running.

Also make sure you keep your elixir-ls up to date. And if you have multiple erlang/OTP versions is very likely you will need a compiled elixir-lsp to each specific version.

If you know useful cool tricks for doom+elixir please do share them! Im kind of new in this :D

Top comments (2)

Collapse
 
rasoulrostami profile image
Rasoul Rostami

Doom is great, I have just started to use it. But I need some good tutorial. Especially for python developer. Can you help me

Collapse
 
mariomazo profile image
Mario Mazo

Hey Rasoul
I have just started with python, so I still dont know how to make it work properly.
I had a basic setup working activating python in doom emacs with

(python +lsp +tree-sitter)
Enter fullscreen mode Exit fullscreen mode

and installing the the lsp with

pip install 'python-lsp-server[all]'
Enter fullscreen mode Exit fullscreen mode

So far my basic needs with python are covered with that