Author Topic: Problem with tab in lines  (Read 14365 times)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Problem with tab in lines
« on: November 24, 2010, 02:38:37 pm »
Hi all,

I found I problem with the CodeCompletion plugin. It was not finding some symbols in my code. At first, it seemed random, but I could trace down the problem to lines that had a strange combination of spaces and tabs, after doing some debugging.

Here is an example code (. means space and > is the final position of a tab, my settings are tab=4 spaces)
Code
void main(void)
{
   >int aabbaa;

   >aabbaa
}
(The code above has one tab before each declaration)

If you right click and say go to declaration, it works...

Now, replace the tab before aabbaa (equivalent to 4 spaces) with space+space+tab. The final code is:
Code
void main(void)
{
   >int aabbaa;

.. >aabbaa
}
With this code, if you right click on aabbaa and say go to declaration, is says "Not found".

This is because the tab is expanded in the nativeparser.cpp at line 2169
Code
actual_search.Replace(_T("\t"), tabwidth);
actual_search.Remove(col);

, so each tab is replaced with 4 spaces, but the next line truncates the line based on the column position from screen, so 2 characters are left out. The reason is that the tab on editor is equivalent to 2 spaces only, keeping an indentation of 4.

I found a way to solve this by using the GetTextRange() function from wxscintilla...
Code
actual_search = searchData->control->GetTextRange(searchData->control->PositionFromLine(line), pos);

A patch is attached against svn trunk r6857...
I'm using the patch in my systems and it seems to be working fine now.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5513
Re: Problem with tab in lines
« Reply #1 on: November 24, 2010, 03:06:28 pm »
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: Problem with tab in lines
« Reply #2 on: November 24, 2010, 03:31:18 pm »
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....
I did so and it seems to work.
I attach the same patch after removing some stuff, that was only needed by the old version.

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Problem with tab in lines
« Reply #3 on: November 24, 2010, 03:36:11 pm »
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....
I did so and it seems to work.
I attach the same patch after removing some stuff, that was only needed by the old version.

Thanks jens.. I've forget about it...  :oops:

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Problem with tab in lines
« Reply #4 on: November 29, 2010, 01:07:47 pm »
Hi again!

Should I submit a bug report with the patch to the BerliOs server? Or is the patch I've already submitted here being considering?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: Problem with tab in lines
« Reply #5 on: November 30, 2010, 01:45:50 pm »
@killerbot and other devs:
Did you test the patch ?
If yes:
did you experience any problems ?
Are there any objections (especially from the cc gurus) against applying it to trunk ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Problem with tab in lines
« Reply #6 on: November 30, 2010, 02:04:12 pm »
Did you test the patch ?
No, as I for myself am very short in time atm

Are there any objections (especially from the cc gurus) against applying it to trunk ?
From a quick look I don't see anything wrong. Seems logical.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem with tab in lines
« Reply #7 on: January 28, 2011, 01:11:28 pm »
this patch is applied in trunk or not???
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Problem with tab in lines
« Reply #8 on: February 10, 2011, 03:19:00 am »
this patch is applied in trunk or not???
Yes, I am sure.