Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Tabs instead of spaces in Java editor, how?(Tabs instead of spaces in Java editor, how?)
Tabs instead of spaces in Java editor, how? [message #548038] Tue, 20 July 2010 13:50 Go to next message
Neutrino  is currently offline Neutrino Friend
Messages: 3
Registered: July 2010
Junior Member
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 #548044 is a reply to message #548038] Tue, 20 July 2010 14:00 Go to previous messageGo to next message
Neutrino  is currently offline Neutrino Friend
Messages: 3
Registered: July 2010
Junior Member
It's even crazier now. Without changing configuation at all now when I press return the first tab worth of indent is spaces and additional levels of indentation are tabs.

Wth!

Edit: And clicking the Source->Correct Indentation menuitem (which I've just found) doesn't correct the indentation.

[Updated on: Tue, 20 July 2010 14:02]

Report message to a moderator

Re: Tabs instead of spaces in Java editor, how? [message #548052 is a reply to message #548044] Tue, 20 July 2010 14:12 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Neutrino wrote:
> It's even crazier now. Without changing configuation at all now when I
> press return the first tab worth of indent is spaces and additional
> levels of indentation are tabs.
Maybe those preferences are set on the project and override your
workspace settings? Also note that Eclipse tries to use the same
indentation policy as the previous line(s).

Dani
>
> Wth!
>
Re: Tabs instead of spaces in Java editor, how? [message #548104 is a reply to message #548038] Tue, 20 July 2010 16:32 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

<Religious Issue>
If your source is going to be viewed by others, you really ought to use spaces.

Different folks in different viewers WILL have different tab widths. Code with tabs invariably looks horrible to someone. Spare the rest of the world a little eye strain. Use spaces.

Or face excommunication from the Church of That Egotistical Nutjob Guy Over There!

</Religious Issue>

Adjusting the indentation may not "unify" the whitespace, but reformatting it should. ctrl+shift+F I believe.

And I believe in spaces. Tabs are for unlettered barbarians and heretics. Spaces are the one true path to universal code formatting. Embrace the Space.

Okay, I'll stop now.


--Mark Storer
Senior Software Engineer
Autonomy Cardiff

import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;

Google Code Search

[Updated on: Tue, 20 July 2010 16:36]

Report message to a moderator

Re: Tabs instead of spaces in Java editor, how? [message #548112 is a reply to message #548104] Tue, 20 July 2010 16:40 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 7/20/2010 10:32 AM, Mark Storer wrote:
>
> If your source is going to be viewed by others, you really ought to be
> using spaces.
>
> Different folks in different viewers WILL have different values for
> their "tab width". Code with tabs invariably looks horrible to someone.
> Spare the rest of the world a little eye strain. Use spaces.
>
> Or face excommunication from the Church of That Egotistical Nutjob Guy
> Over There!
> [/Religious Issue]
>
> Adjusting the indentation may not "unify" the whitespace, but
> reformatting it should. ctrl+shift+F I believe.
> And I believe in spaces. Tabs are for unlettered barbarians and
> heretics. Spaces are the one true path to universal code formatting.
> Embrace the Space.
>
> Okay, I'll stop now.

Mark,

I see you probably grew up next door to the Tab family and their boys
beat you up at the flagpole after school every day!

:-)

Russ
Re: Tabs instead of spaces in Java editor, how? [message #548115 is a reply to message #548112] Tue, 20 July 2010 17:16 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

Thanks for bringing up the painful memories. Fortunately they had "beat up kids smaller than you" classes immediately after school on Wednesdays. The down side was that they had some new tricks to try out every Thursday.

--Mark Storer
Senior Software Engineer
Autonomy Cardiff

import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;

Google Code Search
Re: Tabs instead of spaces in Java editor, how? [message #548624 is a reply to message #548038] Thu, 22 July 2010 13:56 Go to previous messageGo to next message
Neutrino  is currently offline Neutrino Friend
Messages: 3
Registered: July 2010
Junior Member

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 Smile

That is all.

Re: Tabs instead of spaces in Java editor, how? [message #548692 is a reply to message #548624] Thu, 22 July 2010 16:39 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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.


--Mark Storer
Senior Software Engineer
Autonomy Cardiff

import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;

Google Code Search

[Updated on: Thu, 22 July 2010 16:48]

Report message to a moderator

Re: Tabs instead of spaces in Java editor, how? [message #548774 is a reply to message #548624] Thu, 22 July 2010 23:06 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

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
Previous Topic:Embedding a button in a jFace table
Next Topic:"error in opening zip file"
Goto Forum:
  


Current Time: Sat Apr 20 00:16:16 GMT 2024

Powered by FUDForum. Page generated in 0.09099 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top