Author Topic: Tabs-to-Spaces  (Read 22005 times)

jweathers

  • Guest
Tabs-to-Spaces
« on: August 07, 2005, 07:28:27 am »
Hello,

Before I get into my question, I would just like to offer a BIG thanks to the people who are developing Code::Blocks! It is a really nice piece of software and I see it only getting better with time. I've been using it for the last few days, and I'm really enjoying it.

However, I'm the kind of programmer who never uses tab characters in his code. So under the Editor->General->TAB options settings I have "Use TAB character" unchecked, "TAB indents" checked, and TAB size = 3 as I like indenting 3 spaces in my code. However, I've noticed from opening the source files in VIM that Code::Blocks seems to be using TABS characters despite my settings preferences. I searched the forum, but the only comments seem to suggest that this feature works. Is there something that I am missing?

Thanks!

-John

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Tabs-to-Spaces
« Reply #1 on: August 07, 2005, 08:47:00 am »
Frankly I couldn't tell you... I never edit my source files except with Code::Blocks :-P

However, there is the possibility of the editor module (scintilla) to save the files NOT as requested... or maybe it's a misconfiguration problem. Anyone else has noticed it?

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #2 on: August 07, 2005, 01:08:12 pm »
Hi, reporting in =)

I'm also using UseTab=false, TabIndents=true, TabSize=4.

I not only can confirm this, but while reproducing it, I encountered 3 bugs :shock: in cbEditor.

1) The one noticed by jweathers is caused by Smart Indent, and you can reproduce it by typing "{" followed by ENTER.
Note that when I say "{" is the brace without quotes.

You also can see it that is a TAB instead of 4 spaces without leaving C::B (and I double checked it in SciTE and WinHEX):
Go to Editor->General->Whitespace options->View whitespaces (tabs and spaces) and set it to ALWAYS.

Well, I found that this bug was a Yiannis's TODO :) in sdk/cbeditor.cpp @ cbEditor::OnEditorCharAdded():

In if (smartIndent) block ...

Code
// Original code:
if (b == '{')
    indent << '\t'; // TODO: decide between spaces/tabs

Code
// Must be something like this:
if (b == '{')
{
    if(m_pControl->GetUseTabs())
        indent << '\t'; // 1 tab
    else
        indent << wxString(' ', m_pControl->GetTabWidth()); // n spaces
}

2) This other bug is very ugly (and it took me a while to reproduce it)
How to reproduce it: Press "{" and ENTER and ENTER (without writting anything more than ENTER).
You can continue pressing ENTER and the indentation goes forever.

I guess that the bug this time is also in cbEditor::OnEditorCharAdded()'s @ else if (ch == '\n').

3) The 3rd isn't really a bug, but a design flaw.
The "{", "}", "<", and a lot of other chars in cbEditor are hardcoded to C/C++, but a lot of things in C::B are hardcoded to C/C++, so it's not THAT important.
But if you are writting a plain TXT or something, you wouldn't need Smart Indent and other things enabled.

So I think that all the Indentation and Auto-Completion functionality <maybe> can be moved to the Code-Completion Plugin.


Overall, I noticed that if something appears to be a bug of Scintilla/cbEditor, check it first if that happens in the Scintilla Editor SciTE (http://www.scintilla.org/SciTE.html).
The 3 bugs above aren't found in SciTE, so you can suppose that the bug isn't in Scintilla, but in cbEditor.


A side note: I use a lot of times SciTE instead of C::B because of minor flaws that C::B haves but SciTE Does It Right (TM) :(.
(Specially the margin thing: http://sourceforge.net/tracker/index.php?func=detail&aid=1201664&group_id=126998&atid=707419)

Bug submitted to tracker: http://sourceforge.net/tracker/index.php?func=detail&aid=1253490&group_id=126998&atid=707416 :)
« Last Edit: August 07, 2005, 04:01:04 pm by takeshimiya »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Tabs-to-Spaces
« Reply #3 on: August 07, 2005, 02:09:14 pm »
And there is a fourth that causes a tab to be inserted at the last line, causing gcc to bail out "no newline at end of line", but I don't know how to reproduce it. Happens sporadically, no clue, why.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #4 on: August 07, 2005, 04:00:37 pm »
UPDATE: I compiled and tested my little fix for the Bug 1) and it appears to work ok.

However 2) 3) and now :shock: 4) remains to be fixed  :)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Tabs-to-Spaces
« Reply #5 on: August 07, 2005, 04:41:38 pm »
Well, I found that this bug was a Yiannis's TODO :) in sdk/cbeditor.cpp @ cbEditor::OnEditorCharAdded():

In if (smartIndent) block ...

Code
// Original code:
if (b == '{')
    indent << '\t'; // TODO: decide between spaces/tabs

Code
// Must be something like this:
if (b == '{')
{
    if(m_pControl->GetUseTabs())
        indent << '\t'; // 1 tab
    else
        indent << wxString(' ', m_pControl->GetTabWidth()); // n spaces
}

2) This other bug is very ugly (and it took me a while to reproduce it)
How to reproduce it: Press "{" and ENTER and ENTER (without writting anything more than ENTER).
You can continue pressing ENTER and the indentation goes forever.

I guess that the bug this time is also in cbEditor::OnEditorCharAdded()'s @ else if (ch == '\n').


Hey, why not submit a PATCH about it? Just say "in line #nnn of filename.cpp:
is: (code)
should be: (code)

That would make our job MUCH EASIER, thank you :P

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #6 on: August 07, 2005, 05:01:50 pm »
Sorry, that was because I'm using C::B CVS and probably you'll want a patch for VERSION_1, and I'm trying to add a little functionality.
And more important, I don't have the patch tool (I never used it) :oops:

I'll send a patch later.

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #7 on: August 07, 2005, 11:11:26 pm »
Patch submitted here

Code
1227c1227,1232
<                     indent << _T('\t'); // TODO: decide between spaces/tabs
---
>                 {
>                     if(m_pControl->GetUseTabs())
>                         indent << _T('\t'); // 1 tab
>                     else
>                         indent << wxString(_T(' '), m_pControl->GetTabWidth()); // n spaces
>                 }

About the diff app, the best is to use diff -u (unified format) right?
I mean the more secure, the less likely to mess if the files changes too much

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Tabs-to-Spaces
« Reply #8 on: August 08, 2005, 01:04:30 am »
Actually, when I say patch I mean "the modified files". I've never used the patch tool :P

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #9 on: August 08, 2005, 01:14:26 am »
:D, well, from what I understand:

For creating a diff/patch file in Windows:
download the diff utils at http://gnuwin32.sourceforge.net/packages/diffutils.htm
Code
diff -u oldfile.cpp newfile.cpp > oldnew.diff

For applying a diff/patch file in Windows:
download the patch util at http://gnuwin32.sourceforge.net/packages/patch.htm
Code
patch < oldnew.diff


I'm not going to upload the separated files, SourceForge Grandfather :) reccommends diff for text patches and xdelta for binary patches. Although I found bsdiff that appears to compress better than xdelta.
We'll need binary patchs for devpacks upgrading and C::B minor upgradings (ie. non-cumulative).
« Last Edit: August 08, 2005, 02:08:35 am by takeshimiya »

jweathers

  • Guest
Re: Tabs-to-Spaces
« Reply #10 on: August 08, 2005, 02:03:14 am »
So I just got with the program and downloaded the source myself, fixed bugs #1 and #2, re-compiled, and found that everything works much better. 'Tis nice!

takeshimiya, didn't you mean to say that your patch fixed Bug #1 from http://sourceforge.net/tracker/index.php?func=detail&aid=1253490&group_id=126998&atid=707416 ?

My patch fixes both Bug #1 and Bug #2. However, I noticed that my source code does not have the _T() constructs for Unicode. Did I get my source from the wrong branch?

At any rate, here is my patch that fixes both Bug #1 and Bug #2:
http://sourceforge.net/tracker/index.php?func=detail&aid=1253767&group_id=126998&atid=707418

Thanks for finding the source of the bugs, takeshimiya!

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #11 on: August 08, 2005, 03:13:21 am »
Well, yep, :D you used the HEAD branch but everyone in the next days should be using the VERSION_1_0 branch, to debug all the Unicode conversion that is being made in that branch. It should be no more than 2 weeks. Later will be merged in HEAD.

So, I submitted the Unicode version of the patch for the VERSION_1_0 branch already Unicode converted here

jweathers, you can now remove the patch you submitted to avoid duplications (I already removed my old patch too)

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Tabs-to-Spaces
« Reply #12 on: August 08, 2005, 02:07:02 pm »
For creating a diff/patch file in Windows...

Or:
  • right-click onto the file
  • "TortoiseCVS"
  • "Make patch..."
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline phlox81

  • Multiple posting newcomer
  • *
  • Posts: 53
    • phlox81.de
Re: Tabs-to-Spaces
« Reply #13 on: August 08, 2005, 07:38:50 pm »
So, if there is a tabs to spaces function, there should also be a spaces to tabs function.  :lol:
For those who use tabs  :)

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #14 on: August 08, 2005, 09:51:18 pm »
phlox81: this thread is related to a bug where C::B must output spaces instead of tabs, it's not related to a function to convert from tabs to spaces.
What are you saying is being disscussed here: http://forums.codeblocks.org/index.php/topic,596.30.html
« Last Edit: August 08, 2005, 10:01:45 pm by takeshimiya »

takeshimiya

  • Guest
Re: Tabs-to-Spaces
« Reply #15 on: August 10, 2005, 01:52:56 am »
About the TortoiseCVS Make Patch function, I read somewhere that it's NOT recommended to use because it doesn't accepts diff -u (unified format) parameter, even if you specify to do so.
BTW, I don't tried to see if it's true or has changed.
« Last Edit: August 10, 2005, 02:38:14 am by takeshimiya »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
OT: Re: Tabs-to-Spaces
« Reply #16 on: August 10, 2005, 07:45:08 am »
About the TortoiseCVS Make Patch function, I read somewhere that it's NOT recommended to use because it doesn't accepts diff -u (unified format) parameter, even if you specify to do so.
BTW, I don't tried to see if it's true or has changed.

i use
Code
cvs diff -u
evey day, but also encountered some problems with Tortoise CVS

my solution for this is simple:
i installed WinCVS, which installes a separate copy of
"Concurrent Versions System (CVSNT) 2.0.51d (client/server)"
be sure to have it in your path settings and you can use from the commandline
Code
cvs diff -u

that works great parallel to TortoiseCVS, which comes with another copy of CVSNT
« Last Edit: August 10, 2005, 07:47:29 am by tiwag »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Tabs-to-Spaces
« Reply #17 on: August 29, 2005, 01:10:57 pm »
Coming back to #4 three weeks later... :)

After removing stale spaces from 6 header files for the 3rd time today, I wanted to know at least what made it go wrong.
This is one out of a several constellations (all related to preprocessor directives) which provoke the no-newline-at-end-of-file error:
Code
#ifdef __cplusplus
extern "C"
  {
    PLUGIN_EXPORT cbPlugin* GetPlugin();
  };
#endif


Another strange effect is duplication of the last line in the file if you additionally wrap the above into a standard multiple-inclusion protection. Funnily, that phenomenon does not occur if the curly braces are wrapped into individual #ifdefs.
That, however, I think is a known bug which has already been fixed in either HEAD or 1.0 (and merged?).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."