MacPython Logo from __future__ import *

2007-03-14

Erlang Mode for Emacs

Filed under: erlang — bob @ 4:51 pm

Erlang ships with a quite nice Erlang mode for Emacs. Editing Erlang code is actually the only thing I ever use Emacs for.

Setting it up is only slightly painful. For a default R11B-3 installation your .emacs will look like this:

(setq load-path (cons  "/usr/local/lib/erlang/lib/tools-2.5.3/emacs"
      load-path))
      (setq erlang-root-dir "/usr/local/lib/erlang")
      (setq exec-path (cons "/usr/local/lib/erlang/bin" exec-path))
      (require 'erlang-start)
(defvar inferior-erlang-prompt-timeout t)

The first set of expressions sets up Emacs to find erlang.el and the path to your Erlang installation.

The second expression tells the emacs mode not to wait for an Erlang prompt. This is my only annoyance with the mode. Without this defvar, when you send a command from Emacs to Erlang it'll hang for 60 seconds (or until you hit Ctrl-G) if there was any IO since the last prompt (e.g. an error_logger report or an io:format call). The caveat with this setting is that the first command you issue (the one that causes the inferior shell to get started) will get sent before Erlang is started and get lost. Issuing the first command twice is a small price to pay in this case, because the lock-up is annoying as all hell when you're in the middle of the compile/play cycle.

Using the Erlang mode is pretty straightforward. Tab does the right thing for indentation and is a good way to check to see if your code makes sense syntactically. If it doesn't indent to the right place, you probably screwed up. The electric stuff like comma and semicolon are great and save you a good deal of typing. The only command I really use is C-c C-k which compiles and reloads the current module into the running Erlang inferior shell. It will start one if one isn't already running (C-c C-z just starts the shell).

The other gripe I have is that when you get compiler errors sometimes clicking the line numbers takes you to the wrong line in the source file, but that's a relatively minor annoyance for me. Restarting seems to fix that (until it breaks again) and normally I'm not fighting too many compiler errors :)

6 Comments »

  1. You’re using emacs? Hell has frozen over.

    Comment by Joe Grossberg — 2007-03-14 @ 6:15 pm

  2. You could also try out ‘distel’ a very powerful extension to the Erlang env.in Emacs, see:

    http://code.google.com/p/distel

    Comment by etnt — 2007-03-15 @ 12:21 am

  3. BTW, you should look up add-to-list as a replacement for that manual setqing and consing; aside from being shorter and idiomatic, it comes with the added benefit of idempotence.

    Comment by Per Vognsen — 2007-03-15 @ 1:44 am

  4. Honestly I really do not want to learn elisp. I don’t even like Emacs, I only like the Erlang mode. What I have is stuff I found somewhere else.

    Except for the (defvar inferior-erlang-prompt-timeout t), which I figured out by reading the source to erlang.el. And I only went through that effort after months of the timeout pissing me off.

    Comment by bob — 2007-03-15 @ 1:47 am

  5. Make sure you turn on syntax highlighting with ESC ~ 1. It makes a world of difference!

    Comment by Joey — 2007-03-15 @ 5:19 am

  6. The Erlang mode for Emacs is kick ass (I admit with a full heart that on Linux, Emacs is the *only* editor I use. You can sue me now.) A lot of the things it does for you are really intuitive such as automatically starting new case/function definitions when you define a function twice or have several cases in a case statement. It’s easily one of the best 3rd party Emacs modes I’ve ever used (when there’s a Haskell mode to match it, I’ll be in heaven.)

    I bet everybody in the blogosphere thinks I’m a total freak now.

    Comment by Austin Seipp — 2007-03-15 @ 9:37 am

RSS feed for comments on this post.

Leave a comment

Powered by WP Hashcash

Powered by WordPress