10
votes

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.
2
I would say, spaces only is preferred mode for all languages, especially in case different editors / ides are used in the project. 3 to 7 extra bytes saved by tabs are not worth it.Konstantin Pribluda
@HolgerJust - That's exactly how I feel right at the moment :)loxs
I used to think that tabs only was best (as it saves bytes :-p now seriously, because it's more difficult to get unaligned indents by just one difficult to spot character). But in the end, I felt that the most beautiful way was mixing: tabs for syntactic indentation plus spaces for inner alignment.fortran
Using tabs in Emacs is fine as long as you only use Emacs to edit your files. How Emacs handles tabs is defined and consistent. It when you then try to edit the file in another editor which handles tabs differently you run into problems and it looks "funny". Setting Emacs to only use spaces alleviates this.rvirding

2 Answers

6
votes

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

2
votes

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

(set-default 'indent-tabs-mode nil)