vim-erlang / vim-erlang-runtime

Erlang indentation and syntax for Vim
https://vim-erlang.github.io
101 stars 29 forks source link

Inconsistent map-type brackets/parens indentation behavior #43

Closed yowcow closed 4 years ago

yowcow commented 4 years ago

Current indentation of maps:

    M1 = #{
     },
    M2 = #{
      k1 => v1
     },

doesn't seem quite right in 2 cases, when a map is:

Examples:

    L = [
         (
         ),
         [
         ],
         {
         },
         <<
         >>,
         #{
     },
         #{
      k => v
     }
        ],
a_func() ->
    #{
 }.

a_func() ->
    #{
  k => v
 }.

For consistency, maps look so much better when indented as something similar to:

    M1 = #{
          },
    M2 = #{
           k => v
          },

so that maps align better with other types of opening and closing brackets/parens in a list or a function:

    L = [
         (
         ),
         [
         ],
         {
         },
         <<
         >>,
         #{
          },
         #{
           k => v
          }
        ],
a_func() ->
    #{
     }.

a_func() ->
    #{
      k => v
     }.
hcs42 commented 4 years ago

Hi @yowcow,

Thank you for the issue and your PR, I looked at both of them.

The method I generally follow when deciding how something should be indented is that I look at how the Erlang mode of Emacs indents it and try to replicate that in vim-erlang-runtime. (Emacs's Erlang mode is shipped with Erlang/OTP itself, and most of the original developers of Erlang use Emacs, thus that is the de facto standard for indenting Erlang code.)

In this particular case, Emacs indents maps the way you propose. Since vim-erlang-runtime already indents records the "correct" way, I think this makes us very lucky now and we only need to add one letter to the indentation script to make maps behave that way.

Could you look at my commit 939f3f9? I copied your new tests too, but re-indented them.

yowcow commented 4 years ago

Hi @hcs42, it looks perfect now!

I didn't notice the prev_term_plus block but I should've looked for it as records were already working in that way.

Anyways, the code stays clean while working as expected, so I'm closing my PR.

Thanks!

hcs42 commented 4 years ago

Thanks for the feedback!

Issue closed by #45.