This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects concrete information about configuring Emacs to be an Elixir editing environment.
- General Elixir Emacs resources/links/blog posts: Emacs - General Discussion, Blog Posts, Wiki
- Emacs lsp thread: Emacs lsp-mode (language server) + elixir-ls anyone?
- Alchemist - Very full featured but development has stalled, not currently recommended
elixir-mode - Provides the basic font-locking, indentation and navigation support
- Should be used as the baseline of support
- Elixir Language Server backend
- Language Server Emacs Frontend (choose 1)
- exunit.el - Simple test runner for ex_unit tests
Installing elixir language server
Note: Elixir 1.6.6 (compiled on otp 20) and Erlang 20.2.4 are recommended. If you use asdf, then this will be taken care of for you with a
- Clone the elixir-lsp elixir-ls fork locally
git clone https://github.com/elixir-lsp/elixir-ls.git
cd elixir-ls(that you just cloned)
This will create a
.bat for windows) file that you will need for the Emacs integration, so note down this path (referred to later as
(package-install 'eglot) (add-to-list 'eglot-server-programs `(elixir-mode "path-to-elixir-ls/release/language_server.sh"))
package-install line must come before the
Note: if you’re using spacemacs you’ll probably want to disable alchemist.el with
dotspacemacs-excluded-packages '(alchemist). Also if you’re using spacemacs you probably want to add this config to your user config.
And then type
M-x eglot in any elixir file.
(You may also want to view this alternative configuration example which used to be recommended here)
- Ensure that you are using the
developbranch of spacemacs (your
~/.emacs.dshould be on the
a. This is necessary as of 2019/03/03 but once 0.300 comes out it should be fine to use the stable release
- Set the elixir-backend variable inside your layer definitions i.e.
(elixir :variables elixir-backend 'lsp)
NOTE: As of https://github.com/syl20bnr/spacemacs/pull/12668 alchemist is no longer included by default so excluding alchemist is no longer necessary
Add alchemist to your excluded package list
dotspacemacs-excluded-packages '(alchemist) so that it is not loaded (since we’re using
With vanilla emacs:
For both spacemacs and vanilla emacs:
(use-package lsp-mode :commands lsp :ensure t :diminish lsp-mode :hook (elixir-mode . lsp) :init (add-to-list 'exec-path "path-to-elixir-ls/release"))
Verify that it is working by opening up a file in an elixir project (you should receive a prompt like
mix.exs is not part of any project. Select action:. To which you probably want to respond
Import project root. Then if there are no errors you can run
M-x lsp-describe-session which will show you all of your lsp server sessions. On this screen you can press
RET on the "diamond’ icon next to
Capabilities to see the detected capabilities of the server.
Note: there is also https://github.com/Trevoke/lsp-elixir.el that will manage the elixir-ls installation for you, but by installing it manually (as above) you can more easily contribute to elixir-ls.
Note: if you already have lsp-mode installed make sure it is up-to date (version 5.0 had many breaking changes)
As mentioned in the elixir-ls README, with VS Code you can configure the language server through entries in
settings.json. To configure through emacs (using lsp-mode), you can use code like the below.
(defvar lsp-elixir--config-options (make-hash-table)) (add-hook 'lsp-after-initialize-hook (lambda () (lsp--set-configuration `(:elixirLS, lsp-elixir--config-options))))
You can use a
.dir-locals.el file to set config options specific to the project. For example to disable dialyzer in one project, you’d run the above code in your init and the following in your
(puthash "dialyzerEnabled" :json-false lsp-elixir--config-options)
DAP(Debug Adapter Protocol)
For integrated debugging, optionally enable DAP (Debug Adapter Protocol) (requires installing
dap-mode from MELPA):
(require 'dap-elixir) (dap-ui-mode) (dap-mode)
Note: this is recommended because the LSP protocol does not currently include running tests (so this is a good supplement to
Install by cloning locally:
- clone https://github.com/ananthakumaran/exunit.el.git locally
Add this to your emacs configuration:
(add-to-list 'load-path "~/path_to_exunit.el") (require 'exunit)
Or Install via melpa:
Optional key binding examples with Spacemacs:
(with-eval-after-load 'elixir-mode (spacemacs/declare-prefix-for-mode 'elixir-mode "mt" "tests" "testing related functionality") (spacemacs/set-leader-keys-for-major-mode 'elixir-mode "tb" 'exunit-verify-all "ta" 'exunit-verify "tk" 'exunit-rerun "tt" 'exunit-verify-single))