When formatting code we get some strange results from the erlang-formatter.
Indifferent of using the makefile-method or via rebar3 fmt
the following code example:
-module(parser).
parse(Token) ->
case Token of
<<"$", Rest/binary>> -> {done, Rest};
<<"1", Rest/binary>> -> {done, Rest};
<<"2", Rest/binary>> -> {done, Rest}
end.
results in a bit skewed output:
-module(parser).
parse(Token) ->
case Token of
<<"$", Rest/binary>> -> {done, Rest};
<<"1", Rest/binary>> -> {done, Rest};
<<"2", Rest/binary>> -> {done, Rest}
end.
By experimenting a bit it seems that "$"
is to be blamed for the skewed lines further down (see line with <<"2"
and end
).
When opening the same file in emacs manually the fomatting can be restored by either the menu Erlang->Indent->Indent buffer
or by M-x erlang-indent-current-buffer
. Using tab will also correct the lines in emacs.
So there seem to be a difference using erlang-formatter and doing it manually.
Another finding is that when trying to break down what fmt.el
was doing and reproducing it via an own test function in my emacs,
I found that the following function resulted in the same skewed output as from erlang-formatter.
(defun my-erlang-format ()
(interactive)
(erlang-mode)
(erlang-indent-current-buffer))
while removing (erlang-mode)
in the above function resulted in an ok output!
Any ideas what is happening?
Tested using GNU Emacs 28.1 and Emacs 26.3 emacs-nox 1:26.3+1, with and without newer erlang.el