Appendix D. Using Erlang with Emacs

For many Erlang developers, the editor of choice is Emacs. As a longtime Emacs user I have found there to be many reasons for this.

One feature of the Emacs Erlang mode is that you can compile a file by typing “C-c C-k”, which will open Erlang in a shell and compile the buffer you are in. You can also copy and paste code from a buffer to an Erlang shell.

Being able to copy and paste code from a buffer to the Erlang REPL makes it very easy to explore solutions to a problem. The programmer can create a simple module and load it into Erlang with “C-c C-k”, then create a bunch of test cases that are copied via standard Emacs editing to the shell to ensure that the code is working correctly. This does not replace formal testing, but supplements it when doing development.

In addition, the Erlang mode has a set of templates that can be used to create common structures. So if you need to work with the OTP gen_server pattern, you can generate the skeleton of that structure by opening up a new buffer and selecting the correct structure. The template for gen_server is shown in Example D-3 at the end of this chapter.


Erlang comes with a very nice Erlang mode. You can find more details on it at


If you want to have a powerful interface between Emacs and Erlang, check out Distel mode. Distel (short for Distributed Emacs Lisp) extends Emacs Lisp to be able to speak to an Erlang node in a way ...

Get Building Web Applications with Erlang now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.