[erlang-questions] Erlang emacs workflow question

Klas Johansson klas.johansson@REDACTED
Mon May 16 21:48:37 CEST 2011


On Thu, May 12, 2011 at 8:39 PM, Mike Oxford <moxford@REDACTED> wrote:
> Write some code
> C-c C-k to make sure it compiles
> Spin a release (using rebar) in another window
> Run the code in another window
> Is there a better/more streamlined way to do this, all from within emacs (I
> have erl running in another window.)
> Optimally it would be C-c C-k to compile it, maybe load the .beam, and test
> directly from within emacs.
> I feel like I'm missing something here...
> Thanks!
> -mox
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>

Hi Mike,

There are some options already available within the
Erlang/OTP distribution.  Don't know if you've seen
these? They need (better) documentation to be
easier to find and use, however.

First, there's erlang-eunit which makes it quicker to
work with eunit tests.  Just edit your code or test and
type "C-c C-e k" to compile both source code and test
modules.  Type "C-c C-e t" to toggle between the code
and test.  More bindings and options exist.

Then there's erlang-flymake which will compile an
erlang module and highlight any warnings and errors on
the fly.  This may require some customization if your
project needs include files or beam files from other
apps than the one currently being compiled.

More details below.  Hope that's a start.


Cheers,
Klas


EUnit support
=============

If you work a lot with eunit tests, these addons might
come in handy.

Add this to .emacs:

    (require 'erlang-eunit)

Running test suites
-------------------

C-c C-e k Compile the source and test files and run all
          EUnit tests in the module.

C-c C-e t Switch to the src file if the EUnit test file
          is the current buffer and vice versa

C-c C-e l Compile the source and test files and repeat
          the most recent EUnit test run.

C-c C-e j Compile the source and test files and run the
          current EUnit test.


Code coverage analysis
----------------------

C-c C-e c Compile the source and test files and run the
          EUnit test suite and measure code coverage.

C-c C-e v Cover compile current module.

C-c C-e a Analyze the data collected by cover tool for
          the module in the current buffer.


Customization
-------------

These variables alter the default behaviour of the eunit addons:

erlang-eunit-src-candidate-dirs (default "../src" followed by ".")

    Names of directories which to search for source
    files matching an EUnit test file.  The first
    directory in the list will be used, if there is no
    match.

erlang-eunit-test-candidate-dirs (default "../test" followed by ".")

    Names of directories which to search for EUnit test
    files matching a source file.  The first directory
    in the list will be used, if there is no match.

erlang-eunit-autosave (default nil)

    Set to non-nil to automtically save unsaved buffers
    before running tests.  This is useful, reducing the
    save-compile-load-test cycle to one keychord.


On-the-fly syntax check
=======================

This will compile source code on the fly (integrates
with flymake) and give you instant feedback.

Start using flymake with erlang by putting the
following somewhere in your .emacs file:

    (require 'erlang-flymake)

Flymake is rather eager and does its syntax checks
frequently by default and if you are bothered by this,
you might want to put the following in your .emacs as
well:

    (erlang-flymake-only-on-save)

There are a couple of variables which control the
compilation options:

erlang-flymake-command (default "erlc")

  The command that will be used to perform the syntax
  check.

erlang-flymake-get-code-path-dirs-function

    This is the name of a function which shall return a
    list of ebin directories to add to the code path.
    Will by default return the compiled apps's ebin
    directory.

erlang-flymake-get-include-dirs-function

    This is the name of a function which shall return a
    list of include directories to add to the include
    path.  Will by default return the compiled apps's
    include directory.

erlang-flymake-extra-opts

    A list of options that will be passed to the
    compiler.  These are in there by default:

        warn_obsolete_guard
        warn_unused_import
        warn_shadow_vars
        warn_export_vars
        strong_validation
        report



More information about the erlang-questions mailing list