Eclipse "Correct Indentation" ignoring spaces vs. tabs setting - eclipse

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.

Related

Eclipse indents new line with tabs instead of spaces

I've followed all the suggestions here.
When I press return, I get a new line that is indented with tabs instead of spaces.
If I backspace to clear the tabs, and then press TAB a series of times, it correctly indents with spaces.
I'm pretty sure I have all my settings set up correctly. I created a new Code Style > Formatter policy for every language in the project, and specified to always use spaces. It seems as though these settings are partially active (ex: when I press tab), but inactive when I use return. I tried restarting Eclipse. I'll try restarting the computer now...
I'm using Mac OS X 10.9.2 and a Liferay Developer Studio (1.6.3.v201312111844) version of Eclipse (not sure which Eclipse build its based on though).
Can anyone think of another setting/solution to ensure that newlines are created with spaces instead of tabs? I recently saw http://editorconfig.org/, and I'm wondering if there's some interference.
Thanks for any suggestions
If the file has existing lines that are using tabs, then Enter will respect that and try to create new lines in a similar way (see this comment by topchef for a solution). Also, it could be something in Liferay Studio's proprietary settings is overriding Eclipse standard preferences (as suggested by user John).
Keep in mind that each type of editor in Eclipse can have its own preferences and perhaps that's what you're running into here. You can try to find them all by opening Preferences and searching for "indent" in the search field. That will show all the preferences pages where indentation can be configured.
Also note that the Formatter settings don't have any affect on as-you-type formatting; that's for when you select a file or group of files or part of a file and choose Source > Format from the menu.

How to set ZendStudio NOT to delete trailing spaces?

I've just installed the latest Linux version of ZendStudio 9.0.4 Trial to test it out. And now when I save a file it removes all the trailing spaces inside that file which "damages" the SVN.
I know about the option Preferences->PHP->Editor->Save Action->Remove trailing whitespace and it's not checked neither inside the preferences nor inside project specific preferences. When it's checked it makes no difference.
My question is there some kind of quick fix maybe I should write something somewhere inside the settings file or this is just a bug and I'll have to wait until it's fixed ?
edit: it happends with all the built-in editors
After a lot of hours spent searching in the preferences I've finally found that checkbox udner
Window->Preferences->General->Editors->AnyEdit Tools
Inside the "Auto-Convert" tab there is a "Remove tailing spaces" checkbox

How do I type a literal tab character in Eclipse?

I feel very silly asking this question, but here goes. :)
I've configured Eclipse to insert spaces instead of tabs, but I'm working on a Makefile, which requires literal tab characters (see Can you make valid Makefiles without tab characters? for a good explanation).
So how do I type one, short of opening the Text Editors preferences, unticking the "Insert spaces for tabs" option, clicking Apply, and then undoing all of that when I'm done editing the makefile?
Only way I can find to do it in Eclipse (version=Juno) was to type say XXX where I wanted the tab character and then do a find/replace. Switch on regexp matching in the find and put XXX as find with \t as the replace. Painful but works.
If you're using the Eclipse's built-in Makefile editor (included in the C++ package I believe), tabs should be literal.
Sorry, I don't appear to have enough points to comment on the accepted answer, but I wanted to add that although the Makefile editor allows tabs to be entered, it doesn't use tabs when indenting multiple lines with the tab key, or if you enter a tab in block selection mode. This made me think I couldn't enter tabs for a while (I should probably raise a defect report).

Tab vs Space indenting (Dreamweaver vs NetBeans) problem

I use Dreamweaver at work and NetBeans IDE at home, but in both cases project is stored at github. My problem is that NetBeans seems to be constructing code indenting out of spaces and when opened in dreamweaver or exported to github, indenting here and there breaks (moves unexpectedly further then it was intended or vice versa), although when opened again in NetBeans, goes back to normal. It has been pain for some time already. Is there any resolution to this?
I should say that we at work (and me including) prefer tab indenting.
It depends on the IDE's definition of a TAB. There are usually options within the IDE to indent using a TAB but turn the TAB into a given number of SPACES. I usually indent using TAB but have the IDE turn that into 3 SPACES. This means that it doesn't matter what I (or anyone else) use to read my code later the indets are always the same.
In NetBeans you need to look in the Code Editor options but I have no idea where to find the settings in Dreamweaver.
Its been known that one should use double space rather than tab, because that fact that different IDEs define how the tab button works DIFFERENTLY.
For example, emberjs team require contributor to use double-space rather than tab for formatting the code.
It make sense that to use something recognized in common without an IDE, so that the code structure will not be a problem in a highly collaborated coding team environment.
HOWEVER, if customization of how a tab works in an IDE is enabled, tab will be a great time saver in this case-- Press twice the button cost 200% of the time to press one obviously :)
Hope that helps!

Setting up your editor: indentation and encoding

I'm developing a small project with some friends and we're facing some indentation issues. Each of us is using a different editor (we all have different favorites :) and we also are on different operating systems.
What is the best solution to be able to all develop together and set our programming editors so indentation and encoding is the same? What settings do you recommend and why?
You should have your version control system handle the line ending problems. In SVN, the "svn:eol-style" property can be set to "native" to handle auto-converting the line endings. I assume your code is ASCII or UTF8 so you don't have problems with character encoding.
As far as formatting goes, you'll have to choose roughly some style, such as where to put the braces, but there's no reason you have to have the same indent style, provided you use the same number of indents. That's a confusing statement, so allow me to explain: nearly every IDE ever has the ability to set tab widths to any value you want. If one team member likes to indent 2 character widths, another 4, that's fine. One tab character stored in the file can display either way based on IDE settings. Just configure your IDE to indent with tabs and then set the tab widths per your desires.
(at the risk of starting a flame war, this is why I am solidly in the camp of tabs in the tabs vs spaces war. strangely, the spaces folks seem to consider this very feature the reason to use spaces... I will never understand them).
If you are all insistent to have your own indentation settings, then you will need to use exclusively the tab character to indent the code. (Provided your various editors support this).
This approach is counter to the general consensus of using spaces and only spaces for indenting purposes.
Whatever you do, I recommend converting tabs to a common number of spaces. I know Eclipse can do this on the fly, but I'm not sure if edits like gvim can. In any case, with all spaces it is not up to the individual editors/IDEs to interpret how many spaces make up a tab. Also, if anyone's using a Windows editor/IDE, set it to use Unix-style newlines, so that you don't get the annoying ^M at the end of every line when you edit in a different OS.