Bug 2970 - Entering tabs as spaces (1GL3BDU)
Summary: Entering tabs as spaces (1GL3BDU)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Kai-Uwe Maetzel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-10 22:47 EDT by Knut Radloff CLA
Modified: 2003-09-05 06:37 EDT (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Knut Radloff CLA 2001-10-10 22:47:02 EDT
A good idea from the eclipse.tools newsgroup:

"I've just started working in a project that requires all files to have 
spaces rather than any tabs. I personally agree that this is a good 
thing. With my previous editor (a plain Java-aware text editor) I didn't 
need to do anything fancy for this, as I could set it to do everything 
using spaces anyway, and pressing "tab" just put the cursor to the 
"right place" on the line rather than inserting a normal tab character.

I'm okay with tabbing to the right place on the line using Eclipse, but 
I'd love it if (either at save time or key entry time) it could convert 
the tabs into spaces. Is there any way to do this? I know that the code 
formatter is capable of using spaces rather than tabs for indentation, 
but it doesn't seem to apply that to "hand-entered" tabs.

Jon Skeet - <skeet@pobox.com>
"

We should support entering "tabs as spaces" and allow the user to
specify the number of spaces to use as well. 
NOTES:
Comment 1 DJ Houghton CLA 2001-10-29 19:29:04 EST
PRODUCT VERSION:
136

Comment 2 Robert Watkins CLA 2001-11-13 17:57:10 EST
As well as entering spaces instead of tabs, the auto-indenter should insert 
spaces instead of tabs.

Currently, the only easy way to not have tabs in your code is to run it through 
the formatter afterwards.
Comment 3 Kevin Haaland CLA 2001-11-20 22:01:17 EST
Does the underlying SWT widget support the requested behavior?
Comment 4 Lynne Kues CLA 2001-11-21 10:44:18 EST
We do not directly support this; however, one could do it via the 
ExtendedModifyEvent. 

My initial thought was that one could set the key binding for tab and insert 
spaces, but currently TAB is not defined as a key that can be customized.

So we could provide a new key binding for tab.  This would be more 
straightforward for the application to handle (vs. ExtendedModifyEvent).  Or we 
could introduce new StyledText API and handle it.
Comment 5 Knut Radloff CLA 2001-11-21 10:47:22 EST
The easiest solution would be to insert spaces whenever tab is pressed by 
implementing a VerifyListener.
I assume that the user also wants existing tabs replaced with spaces when the 
file is opened.
Comment 6 Lynne Kues CLA 2001-11-21 11:00:18 EST
Knut is right, you can use the VerifyEvent to do this quite painlessly.  Just 
replace the tab character with spaces in the VerifyEvent text field.
Comment 7 Mike Wilson CLA 2001-12-10 12:11:26 EST
No action. Use KR's suggested workaround.
Comment 8 Jon Skeet CLA 2001-12-10 12:23:08 EST
As a plain user (rather than anyone developing a plug-in) this sounds like it's 
not actually a resolution - if it can be done in straight Eclipse without me 
adding/changing any code, could you point to exactly where it needs to be done?

If it *does* involve adding code, would it be possible for me to write a plug-
in module that allows this within the JDT (or general editors?) easily, and 
which could be distributed quite simply? Obviously I'd rather just use an 
existing configuration option if it's there, but I'm willing to get my hands 
dirty a *bit* :)
Comment 9 Jacob Marner CLA 2001-12-10 12:31:38 EST
I agree completely with Jon Skeet. This doesn't sound simple to do. Frankly, I 
don't know how to do it. If it is so simple to workaround, why not fix it in 
the code so regular people can benefit from it once and for all?

The Preferences/Java/Editor should the contain a check box saying something like
"Use spaces instead of tabs". The tab width field already present in the 2.0 
stream would then tell how many spaces should be inserted instead of each tab.

There is regularly people in the newsgroup (approximately twice a week) 
complaining about this issue so I think it is worth fixing.
Comment 10 Knut Radloff CLA 2001-12-10 13:09:21 EST
This PR should go back to Kevin or to JDT (Kai). 
The original problem was that, when pressing tab, a tab character is inserted 
instead of spaces. SWT supports this but JDT has to do it, although I believe 
this is a general editor problem/feature and not Java specific.
Bug 6552 is related (http://bugs.eclipse.org/bugs/show_bug.cgi?id=6552). 
Basically the Java editor doesn't use the settings of the Java formatter. The 
Java formatter will convert tabs but the editor shouldn't put them in the code 
in the first place.
Can we add a general editor preference for this that the Java editor honors as 
well (for auto-indent)?
Comment 11 Andre Weinand CLA 2002-02-27 05:52:07 EST
The CC list seems to be long enough to have this issue resolved for 2.0
Comment 12 Leon J. Breedt CLA 2002-02-27 06:08:52 EST
Orthogonal to this behaviour for Tab, making <Delete>/<Backspace> behave as 
they do when a literal Tab is inserted would be optimal: 

delete <tabsize> spaces when current column is a multiple of <tabsize>.


The 3plusfour plugin for Eclipse already implements both <Tab> and 
<Delete>/<Backspace> behaviour:

http://www.3plus4software.de/eclipse/.
Comment 13 Jon Skeet CLA 2002-02-27 06:11:28 EST
Note that the 3plus4 patch is fantastic in all but one respect - it still
inserts tabs when you're in a JavaDoc comment. (Must mail the authors about 
that some time...)

Jon
Comment 14 Kai-Uwe Maetzel CLA 2002-09-12 12:26:54 EDT
Part of 2.0
Comment 15 Pedro Caetano CLA 2003-09-05 06:37:04 EDT
This feature should be implemented for ALL text editors, not just Java Editor.