Eclipse indentation issues - eclipse

(Note: this is a self answered question and I just wanted to share my experience)
Working with Eclipse Juno 4.2.2 I set the general editor to indent code with 4 spaces. However, I wanted to indent html files with only 2 spaces and changed the HTML editor to use spaces and a length of 2 but nothing seemed to take effect because it was always indenting using 4 spaces. So, what was the problem?

To solve this, I just restored default settings in the default editor (using 1 tab) and everything just worked as expected: The Java editor and PyDev are set to indent with 4 spaces and html editor is set to indent with 2 spaces. This seems to be a bug in Eclipse.
Cheers.

Related

Eclipse "Correct Indentation" ignoring spaces vs. tabs setting

I'm running Eclipse Juno Service Release 2 (20130225-0426) in Windows and I'm finding that auto-indent (Ctrl-I) ignores both the General/Editors/Text Editors/Insert spaces for tabs and Java/Code Style/Formatter/Indentation/Tab policy="Spaces only" settings. With both of those set, Ctrl-I indents the code with a combination of tabs and spaces, even though Ctrl-Shift-F uses spaces only. The problem is I don't want Eclipse to reformat my code -- just correct the indentation with spaces.
Is this a known bug or am I missing a setting somewhere? Thanks!
It appears the "Correct Indentation" (Ctrl+I) will attempt to copy whatever indentation was used on the line of code immediately preceding your selected block. (Even if that line is using a combination of tabs and spaces!) If I select the whole file then it actually uses my preferences.
Seems pretty deliberate to be a bug though in my opinion there should at least be an option for it. I looked through the Eclipse bug tracker for a while and didn't see anything.

Indentation issue using sublime text 2

I have the following problem.
I use ubuntu 12.04 and sublime-text-2 or gedit.
Sometimes i copy/paste something in a haml/ruby file, i indent it at 2 spaces, but when i push it up to github, the indentation is all wrong and not only the part I've copy/pasted. In my editor looks good.
If I open the file with LibreOffice/LeafPad the identation is like on github, but i wanna have it working on ST2.
Any suggestions?
To have correct indent across the service you should not use hard tabs
http://opensourcehacker.com/2012/05/13/never-use-hard-tabs/
You can achieve this functionality in Sublime Text 2 with a tab policy setting:
http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Configure_sane_tab_and_whitespace_policy_and_other_settings
Also not that you might need to choose new policy for existing files from View > Indentation menu.
You can also mass-convert existing files away from tabs.
With Sublime Text 2:
http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Converting_existing_files_to_use_spaces_instead_of_tabs
... or batch convert the whole project:
http://miohtama.github.com/vvv/tools/expandtabs.html

Aptana Studio 3 / Eclipse : strange different widths for tabs/spaces in PHP editor?

Somehow in a PHP editor in Aptana Studio 3 I get very strange behaviour of spaces before indented lines.
The spaces seem to change in width (!) after you type them. Even with a monospace font the text columns are not aligned.
For example :
Both lines in this example have 8 spaces before the text, but they are aligned differently !
What could cause this? I tried every setting in Aptana to fix this, but I can't solve the problem.
Found the solution:
I was using the Aptana Studio 2.x theme. Changed it to Eclipse theme and the editor works like it should...
Here's the solution I found:
Go to Preferences > Aptana Studio > Themes.
In the element list, find "punctuation", then deselect "B"(bold). That should fix the problem.

How to show/reveal hidden or invisible characters in NetBeans?

How can you show/reveal hidden characters in NetBeans? In other editors, if this feature is turned on, a space might be shown as a small centered dot, and a tab as a right arrow. (This feature is useful to see if a file uses tabs or spaces for indentation, among other things.)
This feature was missing for a long time—a feature request was created on November 1999 and it was finally implemented on August 2010 (NetBeans 6.10). You can enable/disable it at "View → Show Non-printable Characters".
Bug history
As of NetBeans 7.0.1, the definition for "non-printable" seems to include tabs and carriage returns but not regular white space char:
NetBeans 7.1.0 finally displays spaces. However, now it has a new bug where consecutive tabs (or tabs & spaces combinations) collapse into one tab:
NetBeans 7.4.0 fixes this:
There're yet a couple of issues:
The end of file is represented with the same symbol as line feeds, thus making it non-obvious to determine whether the file ends with EOL.
Hidden chars are displayed in the same colour as regular text.
These issues have not been addressed so far but they can be sort of mitigated with the Editor Whitespace third-party plugin, which:
Hides the EOL and EOF markers (which aren't useful anyway).
Displays other whitespace characters using always the same colour.
in netbeans 7 you can enable display of spaces, tabs & line feeds like this:
spaces
download font from: http://netbeans.org/bugzilla/attachment.cgi?id=97902
install the ttf font
tools > options > font & colors > Syntax > All Languages > Whitespaces
choose the installed whitespace font
more info about the netbeans 6 bug: http://netbeans.org/bugzilla/show_bug.cgi?id=4619
tabs & line feeds
in netbeans 7 you can enable to see non-printable characters:
view > show non-printable characters
in netbeans 6 only the spaces part works
Using Netbeans 8.0.1
View-> Show Non-Printable characters
Ubuntu 11.10 => Netbeans 7.0.1
The "View → Show Non-printable Characters" mode really not shows whitespaces while font was not installed by me.
Thanks!
View -> Show Non-Printable characters
Using Netbeans 7.3.1,
View -> Show Non-Printable characters
I can see white-spaces, tabs, and carriage returns.
This feature has finally been added and is available in NetBeans 6.10. Since this has not been released yet, you can try out 6.10 MileStone 1: http://bits.netbeans.org/netbeans/6.10/m1/. I look forward to the final release!

How do I reindent all my codes in Eclipse?

In most of the IDEs, I had a Reindent All command. How do I do that in Eclipse 1.2?
Edit: The commands work with Java codes but is there a way I can get it to work with Clojure?
Ctrl+Shift+F
will format all your code according to active formatting rules, this includes any indentation rules you defined (tabs/spaces, amount of those, etc...)
You can change those rules at:
Window > Preferences
Java > Code Style > Formatter
Is CRTL+SHIFT+F working in eclipse 1.2 ?
In 3.5 is working fine.
You can also select all the code you want to indent, and then hit CTRL + I
Eclipse is up to version 3.5 now. You might want to upgrade.
To format your code however you like, including indentation and a dozen other minute details that you might care about, you can set Formatter options (under Preferences / Java / Code Style / Formatter). You can also tell Eclipse to run the Formatter on every save, along with other rules.
TAB and SHIFT+TAB should also work for selected lines of code/text - provided your tab character is configured to be equal to your indent space count.