jcollard / elm-mode

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

how can I normalize elm indentation to standard spacing #125

Open buhman opened 6 years ago

buhman commented 6 years ago

https://ptpb.pw/oVV2.gif

I expect 4 spaces, but I get very strange combinations of 6, 2, and 1-space, depending on moon phase and cosmic rays.

purcell commented 6 years ago

What you're seeing is different levels of "bounce indenting" in order to achieve alignment with elements such as the empty list on the line above. If you want to disable that, it looks like you can (add-hook 'elm-mode-hook 'turn-off-elm-indent).

purcell commented 6 years ago

P.S. I personally feel that the best solution is to embrace elm-format... :-)

buhman commented 6 years ago

If you want to disable [bounce indenting] … you can (add-hook 'elm-mode-hook 'turn-off-elm-indent)

It seems like this has the opposite effect, elm-indent doesn't seem to be bounce-indenting, while turning it off does bounce-indent:

https://ptpb.pw/Cckz.gif https://ptpb.pw/Lecz.gif

purcell commented 6 years ago

I've made this more straightforward in the latest code, which should build into a MELPA package automatically in the next few hours: specifically, all you'll need to do will be (remove-hook 'elm-mode-hook 'elm-indent-mode).

purcell commented 6 years ago

The "bounce indentation" you're seeing without elm-indent-mode is your Emacs-wide default behaviour of trying to align indentation with previous indentations. In the latter screen capture, with elm-indent-mode, it looks like it's positioning the [ relative to where it thinks the [ ] should be, not where it is.

buhman commented 6 years ago

all you'll need to do will be (remove-hook 'elm-mode-hook 'elm-indent-mode)

I do like the cycling though, is it not possible to make it match elm-format behavior, or at least snap to a multiple of 4 spaces?

purcell commented 6 years ago

If you want multiples of 4 spaces, there'll be a default Emacs indentation function for that. Re. exactly matching elm-format, I doubt that will happen, since the indentation system is already quite complex. If the elm-format style is the right one for you, elm-format-on-save is the way to go IMO: indent with tab until syntactically valid, then save. That's my personal strategy. :-)

ranjanified commented 3 years ago

I've made this more straightforward in the latest code, which should build into a MELPA package automatically in the next few hours: specifically, all you'll need to do will be (remove-hook 'elm-mode-hook 'elm-indent-mode).

For me, I took this approach. At least with this, the new line isn't adding a "tab" of its own.