Spaces vs. Tabs in Eclipse
Join the DZone community and get the full member experience.
Join For Freei admit: i’m a ‘space’ person. what i mean is that i prefer ‘spaces’ over ‘tabs’ in my source code. why? because i don’t want to relay on the tab width, and i prefer to use ‘two spaces for an intention level’.
i would assume that maybe half of the world is for spaces, and half of the world is for tabs. i don’t want to cause a religious wars here. i’m for freedom of choice, and this is what eclipse and codewarrior for mcu (which is eclipse based) offers. now as i have outed myself as a ‘spacer’, and given the fact that codewarrior comes as ‘tabser’ by default, this is something i have to change as a setting for my workspace. here is what i do….
show white-space characters
a useful thing is to show tabs and spaces in the source view. for this i use this toolbar button:
if it is not present, that button is added with the menu window > customize perspective:
that button makes the tabs and spaces visible in the source view:
tabs for spaces
being a ‘spacer’, i want to use tabs to insert spaces. for this there is a preference under the menu window > preferences > general > editors > text editors:
the next thing to do is to define my own code style . for this go the preferences and go into c/c++ > code style and press edit :
this offers a dialog where i can specify the tab policy and the intention size :
as noted in the bottom of above dialog: i have modified a built-in profile, and i’m not allowed to change it. so i specify my coding style profile and press ok:
now the editor is using spaces instead of tabs, with the given intention level (number of spaces for tabs).
this of course will only apply to new source changes. existing tabs are not affected. but there is an easy way to convert tabs into spaces (with the right plugin).
anyedit tools and plugin
for any advanced manipulation of spaces and tabs, i recommend the anyedit tools which offers really cool features. it offers a powerful automatic conversion of tabs and spaces:
summary
if you are a ‘spacer’ or a ‘tabser’: it does not matter, eclipse is a perfect choice for both worlds. and allows you to easily switch sources from one world to another. and don’t worry that you have to apply settings for every workspace: see copy my workspace settings which helps to apply them to multiple workspaces.
happy spacing
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Top 10 Pillars of Zero Trust Networks
-
Operator Overloading in Java
-
Mastering Time Series Analysis: Techniques, Models, and Strategies
-
How To Approach Java, Databases, and SQL [Video]
Comments