Author Topic: DoxyBlocks' block comment trailing whitespace  (Read 6288 times)

Offline White-Tiger

  • Multiple posting newcomer
  • *
  • Posts: 83
DoxyBlocks' block comment trailing whitespace
« on: August 31, 2016, 01:04:26 pm »
If someone uses DoxyBlocks to create a block comment, it'll usually have some trailing white-space after the comment.
A patch like this fixes this:
Code: diff
 src/plugins/contrib/DoxyBlocks/AutoDoc.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/plugins/contrib/DoxyBlocks/AutoDoc.cpp b/src/plugins/contrib/DoxyBlocks/AutoDoc.cpp
index c2e08ee..28fb499 100644
--- a/src/plugins/contrib/DoxyBlocks/AutoDoc.cpp
+++ b/src/plugins/contrib/DoxyBlocks/AutoDoc.cpp
@@ -422,8 +422,8 @@ void DoxyBlocks::AddCommentLine(cbStyledTextCtrl *control, int& iPos, wxString s
 {
     // Use NewLine() to get the correct line ending chars.
     control->NewLine();
+    control->DelLineLeft(); // clears any indentation
     iPos = control->PositionFromLine(control->GetCurrentLine());
-    control->GotoPos(iPos);
     control->AddText(sText);
 }
 
Which triggered one question... if "NewLine()" causes automated indentation and that's the reason why GotoPos() was used in first place (without my change and no GotoPos(), you'll end up with increasing indentation)
Why is it actually used everywhere around? or more specifically, why is "iPos" stored in a shared variable as it's not really used anywhere and seems quite unnecessary...

So why not get rid of iPos entirely? Does anyone see a real use for it?

Btw, the following code used some alternate bizarre approach to get rid of indentation:
Code: cpp
void DoxyBlocks::StartComment(cbStyledTextCtrl *control, int &iPos, int iBlockComment, wxString sStartComment, wxString sMidComment, wxString sTagBrief, wxString sIndent)
{
    wxString sSpace(wxT(" "));

    control->GotoPos(iPos);
    // Doing this first prevents me ending up with the function declaration indented i.e. I work in the blank line.
    control->NewLine();
    control->LineUp();
    if (iBlockComment == 4 || iBlockComment == 5)
    {
        control->AddText(sIndent + sStartComment);
        control->NewLine();
        iPos = control->PositionFromLine(control->GetCurrentLine());
        control->AddText(sIndent + sMidComment + sTagBrief + sSpace);
    }
    else
        control->AddText(sIndent + sStartComment + sTagBrief + sSpace);
}
It basically goes to the beginning of the line (#5), triggers a new line (#7) there (without indentation because spaces would follow and are instead moved to the next line) and then moves up to get a line without indentation (#8)...
Windoze 8.1 x86_64 16GiB RAM, wxWidgets-2.8x (latest,trunk), MinGW-builds (latest, posix-threads)
Code::Blocks (x86 , latest , selection length patch , build option fixes/additions , toggle comments)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: DoxyBlocks' block comment trailing whitespace
« Reply #1 on: August 31, 2016, 11:13:17 pm »
I can confirm this bug, thanks, see my screen shot below, it has five spaces after the added c style comment(note the text in the image is wrong, it should be "five" spaces):

But I'm not quite familiar with the internal code logic.  :)

EDIT: if I first put the cursor on the line of function declaration, such as the line "void f2();", then I get the three trailing spaces. see image shot below:
« Last Edit: August 31, 2016, 11:42:48 pm by ollydbg »
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 White-Tiger

  • Multiple posting newcomer
  • *
  • Posts: 83
Re: DoxyBlocks' block comment trailing whitespace
« Reply #2 on: September 01, 2016, 11:07:40 am »
which my patch should fix...

Each line after the first 2 lines adds trailing spaces. This is why the one with 7 lines had 5 spaces (7-2) and the one with 5 lines just 3 (5-2)
It's even worse if you intend the function/definition you're adding the block comment for.. as that indentation will be also used.

I do know how to solve it, as we just need to fix all NewLine() calls. Ok.. it's some kind of workaround to first issue a NewLine() and then remove spaces with DelLineLeft().. I would prefer a NewLineWithoutIndentation().
But still, I wonder if DoxyBlocks ever needs that iPos variable which really doesn't do much besides storing the current line's position.. (which we could request through control->PositionFromLine(control->GetCurrentLine()))

P.S. one could of course rewrite DoxyBlocks to not use any indentation itself... so it's always handled by the IDE... but IIRC people can disable automatic indentation in which case DoxyBlocks must handle it manually
Windoze 8.1 x86_64 16GiB RAM, wxWidgets-2.8x (latest,trunk), MinGW-builds (latest, posix-threads)
Code::Blocks (x86 , latest , selection length patch , build option fixes/additions , toggle comments)