Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way of indenting Erlang?

Till yesterday, I was a happy user of out-of-the-box emacs + erlang-mode. Then my colleague started contributing to the project (using some windows editor), and it seems he is not very happy with the mixed indent mode used by default by erlang-mode. Here is an example. This a part of a function, written using auto-indent on erlang-mode

handle_info(get_gss_latest_versions, State) ->
    GetReqIds = fun(Branch) ->
            GetInfoUri = State#state.gss_uri ++ Branch ++ "/api/getinfo",
            case ibrowse:send_req(GetInfoUri, [], get, [], [{stream_to, self()}]) of
                {ibrowse_req_id, ReqId} ->
                {ReqId, Branch};
                {error, Reason} ->

If you take a closer look, you'll see that line 2 (starting with GetReqIds) is indented with 4 spaces. Line 3 is indented with 3 tabs. Line 5 is indented with 3 tabs + 4 spaces. Line 6 is indented with 4 tabs. As a result, most (dumb) editors (unlike emacs) display lines 5 and 6 (the ones starting with {ibrowse and {ReqId) at the same indentation level. Which looks ugly. (even stackoverflow shows them that way).

I had a look at several prominent erlang softwares (like gproc) and most of them seem to use spaces-only indentation mode.

So my questions are:

  1. Am I doing it wrong (seems likely to me).
  2. If spaces-only is the predominant indentation way, why is erlang-mode not implementing it (or not configured to using it by default)?
  3. How can I configure erlang-mode to force spaces-only?
  4. What's the "right way" after all? Things like cross-editor compatibility seem to matter, and we can't make all editors as smart as emacs.
like image 692
loxs Avatar asked Nov 01 '11 10:11

loxs


2 Answers

This seems to be the right solution for me, right at the moment (put in ~/.emacs) :

(add-hook 'erlang-mode-hook '(lambda() (setq indent-tabs-mode nil)))

I shamelessly copied it from here: http://erlang.2086793.n4.nabble.com/erlang-mode-emacs-tabs-vs-spaces-td2096289.html

like image 73
loxs Avatar answered Sep 22 '22 00:09

loxs


To generally disable tabs in indention, not only, but also for erlang-mode, use:

(set-default 'indent-tabs-mode nil)
like image 20
Rörd Avatar answered Sep 25 '22 00:09

Rörd