Community
Participate
Working Groups
I have an indentation problem in some of my c++ files. The problem is that sometimes the indentation of 'if' and 'else' clauses of the same level moves the 'else' clause inside or outside and not show it in the same level of the 'if'(This problem is acute when the 'if' clause contains some if levels inside it). I want to emphasize: when I open in Eclipse a file that is indented well in other editors (like xEmacse or VI),the indentation breaks! In the attached file you can see an example of this problem.
Created attachment 16261 [details] A file that shows the indentaion problem
Coming from a basic text editor, I would guess that your indentations are a mixture of tabs and spaces depending on their depth. In CDT, tabs are displayed with a default size of 4 (where in a text editor they would likely be 8). This would account for the misalignment of your blocks. Try going to Window->Preferences->C/C++->Editor->Displayed Tab Width and change it to 8 to see if this fixes things. If that does fix it, then this isn't really a bug.
> Try going to Window->Preferences->C/C++->Editor->Displayed Tab Width and change > it to 8 to see if this fixes things. And you will probably need CDT-2.1 (now RC4), there was a bug in the previous version when doihg the Displayed tab.
Thanks. I did as you said and it fixed the problem. I think you should add it to the documentation. I have another 2 problems with the indentation (I wasn't sure if I should open them in different separate bugs, so I wrote them here) 1. I noticed that only on Linux machines, for C++ files, the option 'Format' appears in the Edit option in the menu bar (I attached a file that shows it),but this option doesn't do anything ! Is it supposed to work? 2. Ctrl +I doesn’t indent a line (or selected lines) but only shift them right. Is it supposed to work like that and not like it works for Java's files? How can I indent a line or the all file? Thanks a lot, Guy
Created attachment 16286 [details] A picture that shows that the 'Format' option appears on the Edit menu in Linux
> How can I indent a line or the all file? CDT-2.1 do have a framework for ISV to plug there "Formatters", but by default there is "NONE", see the preference page C/C++ --> Code Formatter. We did however, send to the mailing list an example plugin based on the "GNU Indent", that we'll enable formatting for CDT-2.1. Having a default formatting is something we are looking for CDT-3.0. For the "GNU Indent" plugin look at the cdt-ui-dev mailing list archive. You will find the plugin and instructions, let us know(via the mailing list) if if works for you. > Thanks. I did as you said and it fixed the problem. Allright changing the state. Please verify.
What about the first paragraph in my latter: "I noticed that only on Linux machines, for C++ files, the option 'Format' appears in the Edit option in the menu bar (I attached a file that shows it),but this option doesn't do anything ! Is it supposed to work?"