erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.3k stars 2.94k forks source link

ERL-210: {} inside multiline strings are indented #3521

Open OTP-Maintainer opened 8 years ago

OTP-Maintainer commented 8 years ago

Original reporter: fenollp Affected version: OTP-19.0.2 Component: tools Migrated from: https://bugs.erlang.org/browse/ERL-210


When curly braces ({, }) are embedded inside multiline strings, Emacs erlang-mode will indent the multiline string's contents as if it were Erlang code. No modifications should be done to the insides of the multiline string.

Example code before (erlang-indent-current-buffer):

{code:erlang}
-module(teletype_new_account).

-export([a/0
        ]).

-define(TEMPLATE_TEXT, <<"
{% if A %}
A
{% endif %}

{% if B %}
B
{% endif %}
                                          C
">>).

a() ->
    ?TEMPLATE_TEXT.
{code}

Same code after (erlang-indent-current-buffer):

{code:erlang}
-module(teletype_new_account).

-export([a/0
        ]).

-define(TEMPLATE_TEXT, <<"
{% if A %}
  A
  {% endif %}

    {% if B %}
      B
      {% endif %}
        C
        ">>).

a() ->
              ?TEMPLATE_TEXT.
{code}

Note the braced clauses indented inside the multiline string.
Note how a/0's clause is also wrongly indented.

Workaround: split the multiline string into multiple one-line strings, the compiler will concatenate them.

Minified test cases: https://github.com/fenollp/erlang-formatter/pull/4/files
Formatting code used: https://github.com/fenollp/erlang-formatter/blob/master/fmt.el
u3s commented 1 year ago