views:

292

answers:

5

Is there any way to persuade Eclipse to use tabs instead of spaces for indenting its built-in Java content assist proposals (such as when creating an empty method which overrides a method in the parent class)?

The only setting I could find that looked relevant is in Windows/Preferences/General/Editors/Text Editors/Insert spaces for tabs, and this setting is unchecked.

(EDIT: Several posters have pointed out Java / Code Style / Formatter / Indentation / Tab policy, which is set to "Tabs only")

At the moment I have to remember to select them and re-format with <Ctrl>+<Shift>+<F>.

A: 

Have a look in the preferences at Java / Code Style / Formatter
Create your own profile and set "Indentation" / "Tab policy" to "Tabs only"

Stroboskop
Thanks, but this is already set
Simon Nickerson
A: 

Preferences > Java > Code Style > Formatter > Edit > Indentation > Use tabs only for leading indentation checkbox

Chris Dolan
I don't see this exact setting, but the "Tab policy" setting in the same dialogue box is set to "Tabs only".
Simon Nickerson
I found that on Windows Eclipse 3.5.1
Chris Dolan
+1  A: 

The way I have it setup is to enable the "Format source code" in the Editor->Save Actions preferences.

That way it reformats the source code on save.

rep_movsd
Clever, but I don't want to do this as it would introduce too much noise into the source control diffs.
Simon Nickerson
OK here's another brainwave ( though it may be a bit tedious )Goto java->Editor->Templates, edit each of the templates you use and fix them by pasting to an editor that can reformat tabs to spaces, and then paste back the fixed versions.
rep_movsd
The template I'm most interested appears to be defined elsewhere (in Java / Code Style / Code Templates / Code / Method body), but these just give the body of the methods, and there is no indentation at all!
Simon Nickerson
@Simon: not surprising: as indicated by bug 231832 (mentioned in my answer), ASTRewrite has no access to Formatting preferences.
VonC
+3  A: 

It seems to be currently a bug (not fixed in the 3.5 train):

bug 44755 (for comments, but also valid for other refactoring JDT operations)

Also linked to bug 231832, involving a bug in the AST rewrite...

I believe this is a problem with ASTRewrite, not with the client of ASTRewrite. We have to make sure that code formatter settings are available for the rewrite part.
Moving to JDT/Core for investigation.

Detected in late 3.4, still not fixed in 3.5

VonC
A: 

I also had this problem. The issue turned out to be some configuration that was buried somewhere in my workspace. I created a new workspace and reimported my project and my tabs were not converted to spaces any more.