jcollard / elm-mode

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

How to enable format-on-save for all Elm buffers? #170

Closed tad-lispy closed 4 years ago

tad-lispy commented 4 years ago

Hi! Thanks for your work on Elm Mode.

My question really stems from my Emacs ignorance. I'm a relatively new user and I've struggled with it for few hours. I'm using Doom.

Eventually I got it working by putting this line in my ~/.doom.d/config.el:

(setq-default elm-format-on-save t)

I'm not sure if this is the best solution. Either way perhaps the README could be improved by providing a code snippet to make lives of newcomers like me easier.

purcell commented 4 years ago

I think the README covered this pretty well tbh, but I've added an example snippet for the add-hook method it suggested. Generally the elm-format-on-save is somewhat discouraged now.

purcell commented 4 years ago

I'm sympathetic to the confusion, of course, and I'd probably suggest reading some more general content about how to configure Emacs: the Emacs info manual covers this quite well, and there are various guides and books (Mastering Emacs is a good-value option IMO). Doom Emacs is a really nice starter kit, but you'll always end up needing to know how to add your own special tweaks.

tad-lispy commented 4 years ago

Thanks 🙏

Why is elm-format-on-save somewhat discouraged now?

purcell commented 4 years ago

Why is elm-format-on-save somewhat discouraged now?

We switched to wrapping up that behaviour as elm-format-on-save-mode (generated by my reformatter.el) and the elm-format-on-save variable just triggers elm-mode to turn it on when it starts: that means it's just a redundant ad-hoc version of adding it to the major mode hook, which is a more standard Emacs configuration mechanism.

Also, the nice thing about using a minor mode is that it can be toggled on and off interactively within individual buffers if desired.