ignatov / intellij-erlang

Erlang IDE
https://www.jetbrains.com/help/idea/2018.2/getting-started-with-erlang.html
Other
735 stars 120 forks source link

Comma-first style #292

Closed dmitriid closed 11 years ago

dmitriid commented 11 years ago

Quite a few projects (or at least me :) use comma-first style. See, for example, http://www.scribd.com/doc/101504510/Erlang-Programming-Style-Guide. Currently, IDEA and Erlang plugin don't support it.

See related http://youtrack.jetbrains.com/issue/IDEA-112365

The fix for comma-first in Erlang could be:

    - on enter
     - if line starts with comma
       - if previous line starts with comma
        - align with the previous line
       - if open bracket/parenthesis exists within scope
        - align with innermost bracket/parenthesis

Sorry I have no pull request for this :(

andrzejsliwa commented 11 years ago

erlang-mode for Emacs (part of Erlang distribution) have already support for it (will be published with next Erlang release)

https://github.com/erlang/otp/commit/8bfff9e0f80868ad7edc08dfda6c51a2b00966e6

@dmitriid +1 from my side to this feature request.

ignatov commented 11 years ago

@dmitriid @andrzejsliwa I've just pushed an experimental formatter with comma first setting, please see my gist.

ignatov commented 11 years ago

Also Erlang.comma.first.zip is available for installation.

dmitriid commented 11 years ago

@ignatov Awesome! Will try it as soon as I can!

andrzejsliwa commented 11 years ago

@ignatov I check your gist, and its looks like there is problem: only lists should be formatted this way, not a tuples... formating should be also repeatable only if there is already comma in previous line, this means if somebody already format something as one line, this should not change in reformat, this should respect existing format (please look on @dmitriid algorithm). I will check tomorrow how this is working exactly in emacs case and I will review @dmitriid aglorithm.

ignatov commented 11 years ago

@dmitriid @andrzejsliwa Please try the 325 build. How it works you can see in https://github.com/ignatov/intellij-erlang/commit/28624020e2052c9396325262b135ab5eb82e5f75#diff-3 and https://github.com/ignatov/intellij-erlang/commit/28624020e2052c9396325262b135ab5eb82e5f75#diff-2.

andrzejsliwa commented 11 years ago

@ignatov: I check 325... but is not working for me, are you sure that this is part of 325?

before:

test() ->
    Bar = [X || X <- [ 1
                     , 2
                     , a
                     , 3
                     , 4
                     , b
                     , 5
                     , 6], is_integer(X), X > 3].

after:

test() ->
    Bar = [X || X <- [1, 2, a, 3, 4, b, 5, 6], is_integer(X), X > 3].
ignatov commented 11 years ago

@andrzejsliwa Code style > Wrapping and braces > Comma first style is on? image

andrzejsliwa commented 11 years ago

@ignatov ok :) now formatting seems to working, but what about proper indenting in writing time?

actual:

test() ->
    Bar = [X || X <- [ 1 [Enter]
        , 1

expected:

test() ->
    Bar = [X || X <- [ 1 [Enter]
                     , 1
ignatov commented 11 years ago

@andrzejsliwa Alignment > Blocks also should be checked in.

andrzejsliwa commented 11 years ago

@ignatov I have everything checked in.

ignatov commented 11 years ago

@andrzejsliwa Got it, it's another issues about auto indentation.

andrzejsliwa commented 11 years ago

@ignatov working ok. thx