aspose file tools*
The moose likes Beginning Java and the fly likes Help with indentation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with indentation" Watch "Help with indentation" New topic
Author

Help with indentation

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Hi,

I am using \t for indentation. How to acheive the opposite(un indent)?

Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

For your information \t is a tab. It isn't some special indentation symbol.

You can try to use \b (backspace), but unless you then overwrite that character it will still remain.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
Get yourself a decent text editor. I usually use Gnome Linux, where gedit works nicely. On Windows try Notepad2 or Notepad++, which are both available free of charge, and much better for programming than what you get with Windows. They will support automatic indentation. Set the options to "replace tabs with spaces" and "tab = 4 spaces." There are explanations in the JavaRanch style guide.

On gedit I use the tab key to start a line more indented than the line above. I can use ctrl-T and ctrl-shift-T to increase or decrease indentation, and there are bound to be similar options in other editors. IDEs can indent everything automatically.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374

OP is looking for Output Formatting (Indenting) or Indenting the code itself.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
Originally posted by Vishal Pandya:

OP is looking for Output Formatting (Indenting) or Indenting the code itself.


Sorry, I have misunderstood the question. ( ) I don't think there is an out-dent character.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

But there isn't an indent character either. Tab is used for it most times but some editors convert these to tabs.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
OP has used \t ,IMO that means , he is looking for output formatting. But he says indentation, Indentation generally means coding indentation. I never use indentation for output rather I will say output formatting.

Anyways he got answers in both context.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3015
    
  10
[Vishal]: But he says indentation, Indentation generally means coding indentation. I never use indentation for output rather I will say output formatting.

I don't agree with this at all. While code may be the most common place where programmers care about indentation, it's not the only one. Indentation is just one part of formatting, which can be applied to any text, output or input, code or not code.

[Rob]: For your information \t is a tab. It isn't some special indentation symbol.

[Rob]: But there isn't an indent character either. Tab is used for it most times but some editors convert these to tabs.

I assume the last word was intended to be spaces. I'm not sure why it matters whether we call a tab an indent character or not. The original poster said he is using \t for indentation, and that seems simple enough - in most contexts, a leading tab does achieve indentation, whether it's subsequently converted to spaces or not. And I think we all agree that there is no similar way to reverse this, other than removing the character(s) that created the indentation in the first place.

As for the side topic of Java style:

[Campbell]: Set the options to "replace tabs with spaces" and "tab = 4 spaces." There are explanations in the JavaRanch style guide.

Well, the guide doesn't actually say anything about what your tab setting should be. It says use four spaces for the indent level, which is not the same as the tab level. It recommends you don't use tabs at all for code formatting, which I agree with.

However there is a large body of code written by Sun which does use tabs mixed with spaces. This practice is, of course, utterly evil. However it's outside our control. And I find it's useful to be able to browse Sun's source files within my IDE. In order to achieve this, it's best to have your tab set to the same number of spaces that Sun uses, which is 8. This won't affect code we write at all, because our code won't use tabs. But it's nice to be able to read Sun's code too.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
8 spaces always seemed excessive - i prefer 2 and i understand that that's probably too lean for a lot of people - if I worked on a team I'd vote for 4...

but why 8? (seems like a waste of pixels)
[ December 21, 2008: Message edited by: Bert Bates ]

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

8 does seem way too excessive. Like Bert, I prefer 2.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Bear Bibeault:
8 does seem way too excessive. Like Bert, I prefer 2.

+1 for 2.

I'll do 4 in the interest of being pragmatic. But 8...? That's just excessive.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3015
    
  10
There seems to be a lot of confusion here.

NO ONE is suggesting that you should indent by eight spaces.

I said that you should set your tabs to eight spaces. Meaning one tab is equivalent to eight spaces. Because that's what Sun does. However their indent amount is only four spaces.

When they indent one level, they use 4 spaces. When they indent another level, they use one tab, which is equivalent to 8 spaces. For another level, one tab and 4 spaces, which is equivalent to 12 spaces. Another level, 2 tabs for 16 spaces. And so on.

The tab size and the indent size are not the same thing.

Of course no one outside Sun should mix spaces and tabs, because that's eeevil. (Sun shouldn't either, but I'm assuming it's too late to save them.) I'm not advocating that. I'm just describing what is done in most of the standard library code from Sun.

If you don't work for Sun, then don't use tabs at all in code, and you can set your tab size to anything you want - it won't affect your code at all. But if you set the tab size to 8, it will make Sun's code more readable, if and when you browse it.

And personally, yes, I prefer an indent size of only two spaces nowadays. But that has nothing to do with setting the tab size to 8.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Right. Let's quit this discussion and get back to the main problem: how to unindent code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with indentation