Elixir and DooM Emacs
Tags: elixir, emacs, doomemacs
Published: 2021-01-15 20:14:29

---
title: Elixir and DooM Emacs
published: true
description: configure doom emacs for elixir development using elixir-ls
tags: elixir, emacs, doomemacs
cover_image: https://raw.githubusercontent.com/hlissner/doom-emacs/screenshots/main.png
---
# 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](https://github.com/hlissner/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](https://github.com/hlissner/doom-emacs) 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](https://github.com/elixir-lsp/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
```
## 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
```

## 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
```
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

```lisp
tree-sitter
lsp
(elixir +lsp +tree-sitter)
```
## sync doom
```
~/.emacs.d/bin/doom sync
```

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