Many edits seem to be about taking code snippets and properly formatting them, taking care of indentation, spacing etc. The tools of the trade are things like jsbeutifier, cleancss.com, etc.

Would be nice if the editor itself prompted to do this for me. e.g. when it notices a new js snippet it could open a preview pane where the code is properly formatted so the user can opt into the enhancement.

Could start this feature out small with just one particular language as a pilot and see how many people accept the suggested beautification. Alternatively this feature could start off as a moderator tool and if it proves itself it could be opened to the public.

  • 1
    I think this is a great idea. It's already possible to state the language in snippet comments (meta.stackexchange.com/questions/79785/…), so why not have a beautify option upon edit. – James Wiseman Oct 12 '12 at 11:00
  • 2
    @JamesWiseman I like the idea, but this is definitely going to provoke some serious holy wars for languages without universally accepted formatting standards. Limiting to non-controversial languages might be a good idea. – blahdiblah Oct 12 '12 at 20:18
  • @blahdiblah - Yes, you have a point, however, we're not talking about achieving consistency across a large code base, we're just talking about making questions look better on a Q&A site. And, also, the top languages on SO - C#, Java, PHP, JavaScript and C++ have universally understood (if not accepted) conventions for formatting. – James Wiseman Oct 12 '12 at 21:36
  • 4
    From reviewing edits, I think a tool that just removes useless whitespace and unifies indentation (ie line up text per block) would already do wonders, without crossing the line into 'holy wars'. – jv42 Oct 17 '12 at 11:48
  • 1
    @JamesWiseman: so you've solved the {-on-its-own-line-or-not problem? ;-) – Joachim Sauer Oct 19 '12 at 10:47
  • @jw42 :-) Most developers I've met are pragmatic about that, and just about all would overlook their opinions in favour of a perfectly consistent convetion across their code base. In addition, devs here won't have to maintain the code snippets. The people this will affect, are the question writers and editors. If they really want to enforce their own style then they can just apply it retrospectively. – James Wiseman Oct 22 '12 at 12:26
  • 1
    Adding a format code button using some predefined formatting standard on a few popular languages may be a start. The intention is not to make everyone's code look the same (though that would be nice), but rather to be able to fix absolutely terrible, completely unreadable formatting with a single click (even if it won't format it to your ideal format). Finding or extending a code formatter to format code on the clipboard may be something to do oneself in the mean time to make life easier. – Dukeling Mar 17 '13 at 18:45
  • 1
    I don't understand why this does not get more attention. So many times have I seen questions where the OP asks about a problem in the code and it is totally messed up. Even copy and paste from the editor gives bad results. We need an auto format feature because so much time is wasted by reformatting that could be avoided. – Nobody Oct 24 '13 at 18:00

You must log in to answer this question.

Browse other questions tagged .