Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: White-Tiger on August 31, 2016, 01:04:26 pm

Title: DoxyBlocks' block comment trailing whitespace
Post by: White-Tiger 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->DelLineLeft(); // clears any indentation
     iPos = control->PositionFromLine(control->GetCurrentLine());
-    control->GotoPos(iPos);
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(" "));

    // Doing this first prevents me ending up with the function declaration indented i.e. I work in the blank line.
    if (iBlockComment == 4 || iBlockComment == 5)
        control->AddText(sIndent + sStartComment);
        iPos = control->PositionFromLine(control->GetCurrentLine());
        control->AddText(sIndent + sMidComment + sTagBrief + sSpace);
        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)...
Title: Re: DoxyBlocks' block comment trailing whitespace
Post by: ollydbg 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:
Title: Re: DoxyBlocks' block comment trailing whitespace
Post by: White-Tiger 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