Author Topic: Does the "Source Code Formatter" plugin have an active maintainer?  (Read 12174 times)

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
I've added a few features and would be happy to add it to the C::B trunk if the community would like it.

I'm unfamiliar with how to get the ball rolling with this.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #1 on: March 12, 2008, 04:49:12 pm »
you can submit a patch to the project page on berlios (use svn diff to create it). it's always good to advertise here, though. outlining your changes will attract community interest.

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #2 on: March 12, 2008, 04:59:40 pm »
I'm happy to discuss it.

Anyone reading this, please let me know what you think.

What exists in my build is reformatting via the context menu, specifically:

  • Code-formatting a file via right-clicking in the file editor
  • Code-formatting a file via right-clicking any source file in the Project Manager
  • Code-formatting an entire project (source files only, of course) file via right-clicking the project Project Manager

It's fully functional now, I'm just reviewing the code at this point to make sure the new features behave under all circumstances.

I have several other changes in mind, but I wanted to evolve this code publicly, in the forums here.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #3 on: March 12, 2008, 05:09:30 pm »
DrewBoo: Please have in mind that the Source Code Formatter plugin uses AStyle to do its magic. If the changes you're proposing modify the AStyle code, then you should send them to the AStyle project. If, on the other hand, the changes you're proposing modify the plugin, the do as dmoore suggested: submit a patch to BerliOS and then report here that you did so.

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #4 on: March 12, 2008, 05:16:40 pm »
DrewBoo: Please have in mind that the Source Code Formatter plugin uses AStyle to do its magic. If the changes you're proposing modify the AStyle code, then you should send them to the AStyle project. If, on the other hand, the changes you're proposing modify the plugin, the do as dmoore suggested: submit a patch to BerliOS and then report here that you did so.

Hi, Ceniza.

Yes I saw that, and I'm leaving astyle untouched.  (I found an obscure bug there, but that's for another forum.) :)

Offline deadneurons

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #5 on: March 12, 2008, 06:51:26 pm »
I'll take this opportunity to ask for feature request,(mods feel free to delete if it doesn't belong)
Request:
When formatting a source can the fold be kept?
I meant instead of expanding, keep the folded parts collapsed.

thanks.
« Last Edit: March 12, 2008, 06:53:30 pm by deadneurons »

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #6 on: March 12, 2008, 07:09:41 pm »
I'll take this opportunity to ask for feature request,(mods feel free to delete if it doesn't belong)
Request:
When formatting a source can the fold be kept?
I meant instead of expanding, keep the folded parts collapsed.

thanks.

Hm...it sounds feasible.  Not sure how difficult that would be.

First, the Code::Blocks SDK would have to expose the folding state of the opened file, so the formatted file could be told to fold the same way that the unformatted file was folded.  I don't know if it does.  Gurus?

There's already similar logic in that plugin that plucks out bookmarks and sticks them back into the formatted code.

Second, there would have to be an elegant solution if the folding tree changes when the code gets formatted.  I don't know if there are any AStyle settings that would change the folding tree, but even if there are none, that doesn't guarantee that the tree will never change in future versions of AStyle.

I imagine that it might be a fair compromise to preserve the folding state only if the folding tree has the same shape after formatting as it did before.

Do you follow what I'm saying, deadneurons?  What do you think?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #7 on: March 12, 2008, 07:18:19 pm »
Second, there would have to be an elegant solution if the folding tree changes when the code gets formatted.  I don't know if there are any AStyle settings that would change the folding tree, but even if there are none, that doesn't guarantee that the tree will never change in future versions of AStyle.

Sourcecode formatting is just for readability and is not allowed to change the blocks in the code. For example a function is a function egally how it is formatted.
That means folding should never be changed by formatting, the only thing that can change is the line wher the folding starts or end.

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #8 on: March 12, 2008, 07:31:51 pm »
Sourcecode formatting is just for readability and is not allowed to change the blocks in the code. For example a function is a function egally how it is formatted.
That means folding should never be changed by formatting, the only thing that can change is the line wher the folding starts or end.

What if, hypothetically, this code
Code
if ( x )
{
    DoSomething();
}

was changed to look like this code?
Code
if ( x ) { DoSomething(); }

In those cases, we just lost a fold.
« Last Edit: March 12, 2008, 07:34:59 pm by DrewBoo »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #9 on: March 12, 2008, 07:50:43 pm »
You are right ! :oops:

The problem wit source-code formatting and folding is, that the FoldingLevel is saved on a per line base in wxScintilla, but if the code gets formatted the line-count (in most times) change.
That means a backup of the Foldinglevels is quiet difficult.

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #10 on: March 12, 2008, 08:05:34 pm »
You are right ! :oops:

:)

The problem wit source-code formatting and folding is, that the FoldingLevel is saved on a per line base in wxScintilla, but if the code gets formatted the line-count (in most times) change.
That means a backup of the Foldinglevels is quiet difficult.

That sounds pretty similar to how bookmarks are handled.  The formatter plugin effectively feeds the code to AStyle one line at a time and if a bookmark exists in the source at the current line, a bookmark is placed in the formatted code (whatever line the formatted code may happen to be on).

But all the same, I don't think it would be wise for a plugin to explicity place folds anywhere.  It probably wouldn't last long anyway.  My thought is that a very simple tree could be generated on the fly describing the current folds.  No data in the tree other than what folds are folded as what's important is the shape of that data structure.  If the formatted code has a folding tree that is the same shape, then the plugin could make the folding state match.

Do you follow what i mean by the shape of the data structure?  If a simple source file had 3 top-level folds, and a fourth fold inside the first top-level fold, the plugin could run the formatter and if the resulting code has that same folding structure, it could assume that it is safe to restore the old folding state.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #11 on: March 12, 2008, 08:27:06 pm »
For patches please use the BerliOS webpage (so far...) If the patch is not too big you might also post it here.

As for the folding stuff: I clearly vote against it. It makes the code far too complex and has just to less in result. Even worse: Most people don't want to leave the folding as they inspect what has happened (within the focus of source code formatting). So this functionality should be optional and this is even worse. We cannot and will not will make everything extremely flexible and configurable. Some devs are already really unhappy with the complexity that got into C::B in recent times because of each and every "flexibility feature" was added no matter whether this is valuable or not. That simple doesn't makes sense. In addition there are a lot more important refactorings required.

Anyways - this feature *can* be implemented as plugin... so whoever wants to I won't stop you. But please: No changes in the core for such.
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 DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #12 on: March 12, 2008, 08:42:45 pm »
As for the folding stuff: I clearly vote against it. It makes the code far too complex and has just to less in result.

Nobody's crawling out of the woodwork to support this idea either.  I think it just got scrapped.

Some devs are already really unhappy with the complexity that got into C::B in recent times because of each and every "flexibility feature" was added no matter
whether this is valuable or not.

Hm, perhaps a "Dev Mission Statement" should be placed prominentlyon the Wiki.  Something to keep all the devs on the same page and keep the focus on the big picture.

Or perhaps there is one and I just didn't check.   :oops:

Anyways - this feature *can* be implemented as plugin... so whoever wants to I won't stop you. But please: No changes in the core for such.

So far, the plugin system has been really sharp.  I haven't gotten near the core and I like that I don't have to.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #13 on: March 12, 2008, 08:43:41 pm »
Folding is trickier than bookmarks. I'm not really sure if I'll be doing that, but, for the record, the trick would be (it seems) using m_cbe->GetControl()->GetLineVisible(line) from ASStreamIterator and possibly m_cbe->ToggleFoldBlockFromLine(line) to restore it.

Does anyone feel like playing around and submitting a patch? ;)

If you want something a bit "easier" to start with, try to save the state of breakpoints :D

Have fun.

P.S.: Saving the state of breakpoints looks a bit more useful, but... who would decide to start a debugging session and then change the formatting before continuing debugging?
P.S. 2: I also think Morrrrrrrrrrrrrten has a good point there. There are, definitely, more important things to do right now.
P.S. 3: Next time I should try to incorporate the content of P.S.s into the post's body, so I don't have to put them at the end of it.

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Does the "Source Code Formatter" plugin have an active maintainer?
« Reply #14 on: March 12, 2008, 09:07:03 pm »
that would be a cool feature! :D