-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add format-all recipe #5390
Add format-all recipe #5390
Conversation
Thanks, and sorry about the slow response. I'm pretty sure there's at least one package like this in MELPA already, but I can't find it right now, and I think it's a good idea which I would use myself! So, feedback re. the code:
Hope that helps! |
No problem, we are all volunteers here :) I appreciate the detailed feedback.
I also tried hard to find one but couldn't. I tried again to go through all MELPA search results for the words multiple, several, many, languages, format, indent and did similar Google searches and couldn't find anything either.
I personally really like this feature and would like to keep it. It is obviously destined to be imperfect but I often wish programs would go the extra mile to give me useful hints like this ("most people in your situation will want to try X"). Given that universal installation commands don't exist, I think suggesting a system-dependent command is more helpful than suggesting nothing at all. If you go through the current list of install commands there is a lot of variation among them which each user would otherwise have to figure out manually via web search. It's also really easy to implement this, just a few extra lines of code. I should definitely change it to say
The thing is that many (probably most) of the external formatters already do their own whitespace cleanup as part of their normal operation. It usually can't even be turned off. I think they are doing the right thing, since accidental whitespace changes are a common annoyance in version control diffs. I can't imagine anyone wanting to auto-format their code to a precise standard, yet not remove trailing whitespace.
I think Emacs' own To clarify, I think most if not all external formatters fix tabs vs spaces (to their idea of what it should be) but some of them don't fix trailing whitespace. We can easily lop off trailing whitespace in with an Emacs function without caring about tabs vs spaces. Hence the custom function.
Sweet :) I'll keep that in mind. In the current code most properties are system-dependent (or can be) so in practice they are accessed via
Will do. We should obviously provide a save hook but I didn't know how to make one and kept putting it off.
I know, I expect that part of the code to keep evolving. I think we should collect many more formatters (2-3x the current amount) before worrying about making it pretty. There is indeed boilerplate with all the similar functions but I haven't refactored it yet because it isn't clear how to best do it. It's easy to come up with a prettier data structure but the trick is to cover all the special cases that are bound to come up. (For example, the What should we do about release - should we hold off on putting this into MELPA in case you find the other similar package you recall coming across? What do you think about the points we discussed and do you think the package should be polished more before adding it in? I think there is necessarily some experimentation involved in a package dealing with so many unknowns (look at how many formatters atom-beautify supports and imagine all the corner cases they had to cover) so I didn't worry about making everything perfect. My main criterion was to beat at it until it supports many languages and is a pleasure for me to use (which it wasn't at first but now is) and figure out the rest later. I think the main point for users is to have the following stable interface:
and the internals can then evolve as needed from release to release. |
I thought some more about the minor mode and 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 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) |
Great, thanks for your patience. I get your point about standardising configuration into In any case, I'll go ahead and merge this now. |
Thanks :) I quoted the relevant parts of the above discussion in the project's GitHub issues. |
Brief summary of what the package does
Lets you auto-format source code in any one of several languages using the same command for all languages, instead of learning a different elisp package and formatting command for each language.
Currently supported:
New formatters can be added fairly easily if they are external programs that can read code from stdin and format it to stdout.
Direct link to the package repository
https://github.com/lassik/emacs-format-all-the-code
Your association with the package
Just wrote it :p
Checklist
Please confirm with
x
:M-x checkdoc
is happy with my docstrings