Skip to content

Instantly share code, notes, and snippets.

@jaseemabid
Created March 3, 2016 20:03
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaseemabid/75f5607304a8186ba228 to your computer and use it in GitHub Desktop.
Save jaseemabid/75f5607304a8186ba228 to your computer and use it in GitHub Desktop.
Setup Emacs dev env for Erlang

Setup with Emacs Development environment with EDTS, Flycheck and use-package

This tutorial assumes a reasonably new version of Emacs (24.4+)

EDTS

Erlang Development Tool Suite aims to provide common IDE like functionality.

Use-package

use-package is a simple way to keep various configurations under a top level sexp in a nice and clean manner.

Installation

Packages for Emacs can be installed from various package repositories like MELPA.

Add this to `~/.emacs.d/init.el` to set remote repositories and update cache the first time Emacs is started.

(setq package-archives
      '(("org" . "http://orgmode.org/elpa/")
        ("gnu" . "http://elpa.gnu.org/packages/")
        ("melpa" . "http://melpa.org/packages/")))

(package-initialize)

;; Fetch packages the first time
(unless (file-exists-p package-user-dir)
  (package-refresh-contents))

Now install required packages

M-x package-install-package <RET> use-package
M-x package-install-package <RET> edts
M-x package-install-package <RET> flycheck

If EDTS installation fails, cd to installation path (`~/.emacs.d/elpa/edts-<version>`) and run `make` to complete the installation manually.

Require the packages

(eval-and-compile
  (require 'use-package))

Configuration

Configure erlang-mode.

(use-package erlang
  :init
  (add-to-list 'auto-mode-alist '("\\.P\\'" . erlang-mode))
  (add-to-list 'auto-mode-alist '("\\.E\\'" . erlang-mode))
  (add-to-list 'auto-mode-alist '("\\.S\\'" . erlang-mode))
  :config
  (add-hook 'erlang-mode-hook
            (lambda ()
              (setq mode-name "erl"
                    erlang-compile-extra-opts '((i . "../include"))
                    erlang-root-dir "/usr/local/lib/erlang"))))

Configure EDTS.

(use-package edts
  :init
  (setq edts-inhibit-package-check t
        edts-man-root "~/.emacs.d/edts/doc/18.2.1"))

Evaluate all sexp or restart.

Follow instructions here here to setup docs. Match the version the configuration above.

Configure flycheck

Flycheck provides very powerful syntax checking for GNU Emacs. `C-c ! l` in any erlang buffer lists all possible errors and warnings in a dedicated buffer.

(use-package flycheck
  :diminish flycheck-mode
  :config
  (add-hook 'after-init-hook 'global-flycheck-mode)
  (setq flycheck-display-errors-function nil
        flycheck-erlang-include-path '("../include")
        flycheck-erlang-library-path '()
        flycheck-check-syntax-automatically '(save)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment