Recession and its impact on Soonicorns

Any startup ecosystem is built by the willingness of its entrepreneurs to take enormous amounts of risks on new-age technologies. Silicon Valley has been the startup capital of the world for almost 4…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Elixir development on Emacs

After configuring the basic stuff on Emacs we can talk about a possible Elixir configuration (in Emacs there is always a LOT of ways of making things).

Elixir is a dynamically typed language that runs atop Erlang. It compiles down to BEAM bytecode (Björn’s Erlang Abstract Machine) but has a very modern macro system that makes some people categorize it as a LISP dialect.

The language itself is very small because of its macro system and its Erlang heritage. So, many people use a pure text editor without anything too fancy for coding. Valim is one person I’ve seen using a very raw text editor for coding and he is THE creator of the language.

Thankfully, tooling on the language has since evolved a lot! We have auto-complete, formatter, xref (cross reference for navigation) and so on. It all starts with the language syntax highlighting, then formatting and code analysis.

Let’s start with the language major mode then!

Emacs works with the concept of major and minor modes. The first type is for the given language of a file (or buffer). The second one are the addons like spelling and so one.

Here is my emacs-elixir configuration with use-package:

It only adds the package and configures the font “ligatures”. With that, when I type a pipe like |> I get the unicode char ▷ and so on. There is not much here to customize.

One thing to note, though, is that I use an external package for formatting source code. It is reformatter which works really great with the built-in Elixir format. Here is the config:

It is a bit dense but works pretty well! There are comments on each important line to help clarify how it works.

All right! Now we have syntax highlighting and formatting. Let’s check now the language server!

To have all the features of a nice IDE we need to compile and analyze the code. That is done with the help of 2 projects: elixir-sense and elixir-ls. These projects are evolving real quickly. This is nice though it needs some local setup for using bleeding edge features like type spec suggestions.

My approach is this:

So first, let’s clone the repository and build it locally. I will use ~/Projects directory as the target dir.

git clone git@github.com:elixir-lsp/elixir-ls.git

cd elixir-ls && mix deps.get && mix test

With that we have a local version of the elixir-ls project that compiles and passes on its tests. We now need to build its release:

mkdir release/erl21

This will package and generate the release deps and files on the directory ~/Projects/elixir-ls/release/erl21 . It is important to note that I normally use a version of OTP different than that of the repository. It currently uses OTP 20 as the base compiler version but I am using 21. Feel free to test and try different versions but it is important to notice that the version you compile the server with is the minimum OTP version the server will support.

All right! Now we need to setup lsp-mode with our elixir configuration. Thankfully this is very easy and was already done on the post about configuraing emacs for development (linked at the top of this article). I will add here just the line that is important for lsp-mode :

And we are done! When you open an Elixir file in a project, it will start a language server process and you can see its progress in the buffer *lsp-log* .

Emacs is a powerful tool for editing. With a bit of configuration we have MANY features available to us. Although the learning curve is steep at first, it pays off with time.

Add a comment

Related posts:

A Heartwarming Tale Of My Fluff Balls

Starting right from keeping fishes in the aquarium, raising dwarf hamsters and finally keeping a dog. My journey has been an adventurous one. It was hard convincing my parents to keep pets. Any how…

How to painlessly remember your passwords

It is known that we as humans struggle with remembering and managing multiple complicated passwords, that are required to access different applications on a daily basis. To comply with the latest…

Manageably safe and secure

Managing flexibility in software is key to adapting to change. Since change was a given long before the software industry realized this, it should be a given it’s worth optimizing for. Configuration…