If I paste C++ code with many functions/classes (braces), I have to indent all of them, including their content. I've replaced tabs with spaces in my editor, but still no improvements. What's the best solution?
Java is my standard language, but, for formatting code to put here, this is typically what I do, depending on where I am...
For example, someone posts a question to Stack Overflow, and the indenting/formatting is horrible....
First, I edit the post, then select the code that needs indenting/fixing.
Type CtrlX to cut it, then:
- AltTab to get to Eclipse
- AltShiftN Up,Up,Up,Up to start a new untitled text document
- CtrlV into new document
- CtrlA, CtrlI, Tab (select everything, make indenting consistent, increase all indent by 4 spaces).
- CtrlF4 to close the untitled text document (don't save)
- AltTab (copy it all, back to Stack Exchange)
- CtrlV to paste fixed code back again.
- Do the same as for Eclipse, to paste to a new document
- CtrlA, Tab (can't do easily fix indenting, but can indent everything)
- Edit->Blank Operations->Tab to Spaces
- CtrlW to close file
- AltTab back to Stack Overflow
- CtrlV to paste fixed code back again
This works for most C-like languages (Java, C++, C#, whatever).
Some programs to do this have been submitted for review, so you might be able to use one of them: