Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: Halan on December 30, 2011, 06:21:57 pm

Title: C++0x autocomplete
Post by: Halan on December 30, 2011, 06:21:57 pm
Hey Guys,

does the Autocomplete-Plugin already support C++0x? On my machine it for example doesn't indent blocks like "for(auto x : list)" properly.

greetings,
Halan
Title: Re: C++0x autocomplete
Post by: Alpha on January 02, 2012, 07:05:35 am
This indents as expected on my computer.
Are you using a nightly?  How does what actually happens differ from what you expected to happen?
Title: Re: C++0x autocomplete
Post by: Halan on January 22, 2012, 01:19:58 am
Are you sure it's working properly on your machine?

With the latest stable it doesn't get indented at all, with the latest nightly it gets one tab less indented as expected...
Title: Re: C++0x autocomplete
Post by: Alpha on January 22, 2012, 10:25:21 pm
I am not sure if I completely understand what (or even if) the problem is; could you please:
a.  Post a snippet of code that you enter.  (Using code tags.)
b.  Post a snippet of code showing what (if anything) Code::Blocks does to change/auto-format it.  (Using code tags.)
and
c.  Post a snippet of code showing what it is you would have liked Code::Blocks to have changed/auto-formatted it to.  (And again, using code tags.)

I am willing to look into this when I have time (I have messed around with that part of the code recently :), so I think I know my way around it), but simply do not know what I am supposed to be trying to fix it to do.
Title: Re: C++0x autocomplete
Post by: Halan on March 17, 2012, 03:19:02 pm
Looks at this source code for example

Code
{
bool ok = true;

for(auto it: events)
ok = ok && this->subscribeEvent(elem, it);

return ok;
}

The for-loop isn't indented correctly..
Title: Re: C++0x autocomplete
Post by: Alpha on March 18, 2012, 12:16:08 am
Now I understand.  Try the following patch.
Code
Index: src/plugins/astyle/astyle/ASBeautifier.cpp
===================================================================
--- src/plugins/astyle/astyle/ASBeautifier.cpp (revision 7900)
+++ src/plugins/astyle/astyle/ASBeautifier.cpp (working copy)
@@ -2373,9 +2373,9 @@
  tabCount += classInitializerTabs;
  }
 
- else if (isJavaStyle() && lastLineHeader == &AS_FOR)
+ else if ((isJavaStyle() || isCStyle()) && lastLineHeader == &AS_FOR)
  {
- // found a java for-each statement
+ // found a java/C++0x for-each statement
  // so do nothing special
  }
 
Title: Re: C++0x autocomplete
Post by: ollydbg on March 18, 2012, 02:49:41 am
I suggest OP give us a step by step instructions, so we won't guess.
It should related to CodeCompletion OR cbEditor,  not astyle, right?
Title: Re: C++0x autocomplete
Post by: Alpha on March 18, 2012, 03:30:21 am
The AStyle plugin was the only thing I could get to reproduce this behavior.  (Although the lack of steps is why it took me some time to track it down.)
Title: Re: C++0x autocomplete
Post by: Halan on March 23, 2012, 08:25:34 pm
Yeah I am using the AStyle formatter. Didn't even know there were other sourcecode-formatters in Code::Blocks.

And sorry, I thought my last post made the behaviour clear..
Title: Re: C++0x autocomplete
Post by: Alpha on March 25, 2012, 08:57:28 pm
@Developers:  The patch in my previous post appears to solve the problem (although it would probably be best if the OP could confirm this as well).  Is this something that should be submitted to Code::Block's patch tracker, or to the actual AStyle project?  (If it is the AStyle project, could someone who already has a SourceForge account submit it there - I do not really want to create an account just for a single action.)
Title: Re: C++0x autocomplete
Post by: MortenMacFly on March 26, 2012, 07:07:33 am
Is this something that should be submitted to Code::Block's patch tracker, or to the actual AStyle project?
This is astyle, not Code::Blocks. However, you should first look at the astyle code whether this has probably been fixed already. You can integrate later versions of astyle easily into Code::Blocks, just make sure you keep these two methods in the public section:
      void setBlockIndent(bool state);
      void setBracketIndent(bool state);
Title: Re: C++0x autocomplete
Post by: Alpha on March 28, 2012, 12:34:08 am
However, you should first look at the astyle code whether this has probably been fixed already.
You were right; I checked the AStyle project, and it appears this problem has already been fixed.  Patch #3268 (https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3268&group_id=5358) updates Code::Blocks to this.
Title: Re: C++0x autocomplete
Post by: MortenMacFly on March 28, 2012, 06:48:29 am
Patch #3268 (https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3268&group_id=5358) updates Code::Blocks to this.
You don't need to provide patches - I am maintaining this already, but thanks anyways.
Title: Re: C++0x autocomplete
Post by: Alpha on March 28, 2012, 08:17:20 pm
OK.
Title: Re: C++0x autocomplete
Post by: Halan on May 12, 2012, 11:18:57 am
Just wondering, is this commited upstream now?

I am using the packages from Jens' repository and I still have this formatting issue :/
Title: Re: C++0x autocomplete
Post by: MortenMacFly on May 12, 2012, 03:17:09 pm
Just wondering, is this commited upstream now?
No, whats missing is the integration of the new features to the UI.

I may do an interim-commit, but this would mean that you cannot setup all features.
Title: Re: C++0x autocomplete
Post by: Halan on May 22, 2012, 01:30:58 pm
Just wondering, is this commited upstream now?
No, whats missing is the integration of the new features to the UI.

I may do an interim-commit, but this would mean that you cannot setup all features.

Isn't this just a small patch for supporting these new-style lopps?
Title: Re: C++0x autocomplete
Post by: MortenMacFly on May 22, 2012, 01:34:46 pm
Isn't this just a small patch for supporting these new-style lopps?
Yes.