Giter VIP home page Giter VIP logo

erlang-formatter's Introduction

erlang-formatter's People

Contributors

bjosv avatar fenollp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

erlang-formatter's Issues

Wrong indentation in binary pattern match

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

Add command arguments to execute for a single file

Hi,

Thanks for this library, I was wondering if it is possible to add command line arguments to enable running formatting on a single file like below:

rebar3 fmt -f test.erl

It would be easier to integrate your plugin to other tools this way that might support format on save like VS Code. For example currently the erlang formatter plugin for VS Code supports 3 formatters erlfmt, rebar3_format, steamroller, I think emacs formatting would be a good addition to that list.

I have checked the emacs binary arguments and there is a --file flag along with --directory flag you are currently using. I. can submit a pull request with the proposed changes if you like.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.