lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
605 stars 105 forks source link

Configuration, customization, hooks #2

Open lassik opened 6 years ago

lassik commented 6 years ago

From the MELPA PR thread:

@lassik: I thought some more about the minor mode and before-save-hook and the customize variables and I'd like to hold off on those for now because It's far from obvious how to do them right.

The thing is that everyone working on a particular codebase should really be using the same external formatter with the same settings (whether they use Emacs, Vim or any other editor). Otherwise version control diffs will eventually turn into a mess and much of the point of auto-formatting in the first place is moot. This implies that formatter settings should really be stored in an editor-independent file that is checked into version control. (Ideally some existing settings file such as .editorconfig would be extended for this purpose instead of making Yet Another Dotfile with its own syntax and filename globbing rules :))

So basically, I think any effort that we spent putting code formatting settings in Emacs would only serve to detract from the much more important goal of specifying a unified cross-editor settings file. We should work together with people from the Vim, Atom and other communities to make it a reality sooner. Once a de facto cross-editor standard is agreed upon, we can then add a global minor mode for Emacs and people can leave it always enabled and not worry about configuring it specifically for Emacs. (EDIT: Maybe we should just wait for Unibeautify to finish this, they already have this: https://unibeautify.com/docs/config-file.html)

@purcell: I get your point about standardising configuration into .editorconfig etc., and supporting such a thing is a worthy goal that isn't in conflict with providing good Emacs-only configuration for the package: if format-all had a very Emacs-oriented configuration system, then it would be easy to translate settings to it from any editorconfig standard that might arise.

lassik commented 6 years ago

I thought about this some more.


The domain model from the user's point of view would seem to be:


The domain model we need in software would be:

But I would really like to avoid coding and maintaining such mappings in Emacs. It sounds like a very thankless job, without a clear payoff, and difficult to do well.


What's important to note here is that in no case should format-all have its own customize variables for things like indent style and brace placement. If it concerns itself with such variables at all, it should re-use the ones from Emacs and its major modes. The maximum amount of configuration we should have is picking which formatter to use for what language.

We could also let the user set command line switches for each formatter, but I think that's a really bad fit to the above model - it re-uses neither Emacs own variables, nor the proposed universal style settings, but introduces a third set of redundant settings to concern ourselves with (actually, N extra sets, since many formatters are again bound to have different names for the same things).

lassik commented 6 years ago

TL;DR: This is a social problem, not a technical one. Let's be social.

What I'd really like us to do:

oscu0 commented 6 years ago

As someone who almost always works on single files, I'd appreciate if this package never demanded local configuration and other such things. This package is very important to me - I've started and quit switching to Emacs for the first time because of a lack of a universal formatting frontend.