jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
375 stars 67 forks source link

Indentation seems to be inconsistent with Elm example code #71

Closed yupferris closed 8 years ago

yupferris commented 8 years ago

First off, let me say I really like the cycles-based indentation approach used by elm-mode. I've used a similar one in haskell-mode before, and it works really nicely with this kind of language (in fact haskell-mode renders _'s underneath the various levels in the cycle as well, which would be nice to have in this mode as well, but I digress...) :)

However, it seems the indentation level is a bit inconsistent with all of the Elm example code I see elsewhere. It seems that most example code just uses two spaces for an indentation "level", yet the various levels in the cycles provided by this plugin seem more arbitrary.

For example, here's a simple main definition in one of my projects, indented by hand to match what I believe is the standard with Elm example code:

main =
  App.program
    { init = init
    , update = update
    , subscriptions = \_ -> Sub.none
    , view = view
    }

However, when I use the levels provided by this mode, it looks like this:

main =
  App.program
       { init = init
       , update = update
       , subscriptions = \_ -> Sub.none
       , view = view
       }

Notice the extra spaces in the record value lines. The only options for indentation the mode provides in the first record line (starting with {) are either no indentation, or the indentation shown above. Before inserting the { character, it gives me either no indentation or the position directly under the . from the line above, which is also wrong (3 spaces from the line above instead of 2). This is just one example, but the problem seems to manifest in many places and in many different ways.

Is there a specific reason this style was chosen? It appears to be inconsistent with both other Elm code I see around, and also what haskell-mode does (though I may be wrong).

Bogdanp commented 8 years ago

The issues and inconsistencies you see are mostly due lack of time on my part to spend on fixing and improving the indentation code. Contributions in this area are very much welcome :D.

That being said, I just pushed a couple of changes that should make the indentation more consistent with how elm-format formats code and I believe this issue is fixed (although the default indent offset is now 4 (set elm-indent-offset to 2 if you want 2-space indentation)). Let me know if you run into any other issues!

yupferris commented 8 years ago

You're a champion, thanks :D