Tabs instead of spaces in Java editor, how? [message #548038] |
Tue, 20 July 2010 09:50  |
Eclipse User |
|
|
|
How do I configure it so that the Ecplise Java editor uses tabs for indentation?
General->Editors->Text Editors->Insert Spaces for Tabs is unchecked.
Java->Code Style->Formatter-><active profile>->Tab Policy is set to Tabs Only.
Java->Code Style->Formatter-><active profile>->Use Spaces To Indent Wrapped Lines is unchecked.
Java->Code Style->Formatter-><active profile>->Tab Size is set to 4.
And yet in a .java file pressing <return> at any level of indentation results in the editor padding the new line with spaces.
Eclipse 3.5.2
Win7 Pro
|
|
|
|
|
|
|
|
|
Re: Tabs instead of spaces in Java editor, how? [message #548692 is a reply to message #548624] |
Thu, 22 July 2010 12:39   |
Eclipse User |
|
|
|
Unclean! Unclean!
Quote: | What's more scrolling through heavily indented code padded with spaces is wrist slittingingly tiresome.
|
You don't use CTRL+arrow, do ya? Give it a shot. Heathen.
Quote: | If you use tabs for indentation all users can configure their IDE to represent that as 2 spaces or 4 spaces or whatever according to their individual preference. If you use spaces for indentation then everybody is screwed and forced to look at whatever your idea of nice indentation looks like which likely varies from person to person and is at least partly dependent on how much horizontal screen real estate you have.
|
Okay, technically you're right... UNTIL:
private final static int SOME_CONST = 0;
private MyLongTypeName = new MyLongTypeName();
public int foo = 42;
Code formatted like this is flat out easier to read.
That first "= alignment" is probably one tab, for everyone.
The second one is 16 spaces. It could be between 8 and 4 tabs depending on who first spaced it out.
The third? More... don't feel like counting any more.
So if a 2-spaces=1-tab person originally formatted the code, and a 4-spacer opens the file, it'll look Horribly Wrong. Ditto going the other way.
Basically, as soon as a tab appears after a fixed-length character or characters (spaces, variable names, whatever), Mr Tab is a Bad Idea.
Which happens in javadocs all the time:
/**
* Witty and insightful commentary.
* @param foo Short description.
* @param bar Really long description. I mean like... LONG. "So
* long it wraps down to the next line" long. We're talking
* LONG! Did I mention it's long?
*/
The auto-formatter will do this for (or "to") you.
So what I'm trying to say is this: You're wrong. Furthermore, you almost certainly have some odious personal habits that should not be discussed in a professional forum such as this. In conclusion, you blow goats.
CTRL+SHIFT+F is great. IIRC, there's a Magic Comment you can insert to convince eclipse to leave the commenting of a particular section of code alone... AHA!
stick "@formatter:off" and "@formatter:on" inside your comments to control it. Spiffy. Found that one in "Java development user guide > Reference > Java Editor > Formatter". I'd be stunned if it wasn't java-specific.
[Updated on: Thu, 22 July 2010 12:48] by Moderator
|
|
|
Re: Tabs instead of spaces in Java editor, how? [message #548774 is a reply to message #548624] |
Thu, 22 July 2010 19:06  |
Eclipse User |
|
|
|
On 2010.07.22 7:56, Neutrino wrote:
>
> CTRL-SHIFT-F to reformat the document. That's a life-saver many thanks.
>
> P.S. If you use tabs for indentation all users can configure their IDE
> to represent that as 2 spaces or 4 spaces or whatever according to their
> individual preference. If you use spaces for indentation then everybody
> is screwed and forced to look at whatever your idea of nice indentation
> looks like which likely varies from person to person and is at least
> partly dependent on how much horizontal screen real estate you have.
> What's more scrolling through heavily indented code padded with spaces
> is wrist slittingingly tiresome.
> Tbh anyone who uses spaces for indentation should be hanged, or at least
> sterilized so they can't pass on the degenerate genes :)
>
> That is all.
While I generally like tabs as a great idea, I must nevertheless point
out that this advice ONLY works for leading tabs. Subsequent tabs (and I
use such to align variables AFTER their types, so between types and
variables) will never look good except with the space-width of the
original author.
When sharing code, always and only the space, sadly, never the tab.
Russ
|
|
|
Powered by
FUDForum. Page generated in 0.09146 seconds