Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Loaden on April 23, 2010, 01:43:20 am

Title: Comment the word first(Stream-comment)
Post by: Loaden on April 23, 2010, 01:43:20 am
If we have not selected, in SVN6204 version, CB will comment current line.
But we can do it use Box-comment too.

In many cases, we only need one word comment.
Example:
void OnKeyUp(wxKeyEvent& /*evt*/)
{
}

Code
Index: src/src/main.cpp

===================================================================

--- src/src/main.cpp (revision 6204)

+++ src/src/main.cpp (working copy)

@@ -3287,9 +3287,13 @@

         {
             int startPos = stc->GetSelectionStart();
             int endPos   = stc->GetSelectionEnd();
-            if ( startPos == endPos ) { // if nothing selected stream comment current line
-                startPos = stc->PositionFromLine  (stc->LineFromPosition(startPos));
-                endPos   = stc->GetLineEndPosition(stc->LineFromPosition(startPos));
+            if ( startPos == endPos ) { // if nothing selected stream comment current *word* first
+                startPos = stc->WordStartPosition(stc->GetCurrentPos(), true);
+                endPos   = stc->WordEndPosition  (stc->GetCurrentPos(), true);
+                if ( startPos == endPos ) { // if nothing selected stream comment current line
+                    startPos = stc->PositionFromLine  (stc->LineFromPosition(startPos));
+                    endPos   = stc->GetLineEndPosition(stc->LineFromPosition(startPos));
+                }
             }
             else {
                 /**


[attachment deleted by admin]
Title: Re: Comment the word first(Stream-comment)
Post by: oBFusCATed on April 23, 2010, 09:52:58 am
I've tested it and there are 3 problems:

1. "TestClass *|test", stream commenting here will do "TestClass */*test*/" and this is a warning in VC8+.
    I think it is better to do "TestClass * /*test*/
2. The selection after the commenting is broken. "TestClass *>/*test<*/ .
    '>' is placed where the selection starts, '<' is placed where the selection ends.
   The expected result is "TestClass *>/*test*/<"
3. "TestClass*|   test", in this case the white spaces have not been ignored and the word 'test' is not found.
    The result of stream commenting is that the whole line is commented.

This feature is great, I'll keep using it if I don't forget about it:)
Title: Re: Comment the word first(Stream-comment)
Post by: Loaden on April 23, 2010, 05:35:58 pm
I've tested it and there are 3 problems:

1. "TestClass *|test", stream commenting here will do "TestClass */*test*/" and this is a warning in VC8+.
    I think it is better to do "TestClass * /*test*/
2. The selection after the commenting is broken. "TestClass *>/*test<*/ .
    '>' is placed where the selection starts, '<' is placed where the selection ends.
   The expected result is "TestClass *>/*test*/<"
3. "TestClass*|   test", in this case the white spaces have not been ignored and the word 'test' is not found.
    The result of stream commenting is that the whole line is commented.

This feature is great, I'll keep using it if I don't forget about it:)

1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:
Quote
error: expected unqualified-id before ';' token|
2. Yes, in current patch, it's not handle this case.
3. Because in current position, the current word is a blank space, but not be "test".
Title: Re: Comment the word first(Stream-comment)
Post by: oBFusCATed on April 23, 2010, 06:09:04 pm
1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:
Quote
error: expected unqualified-id before ';' token|
2. Yes, in current patch, it's not handle this case.
3. Because in current position, the current word is a blank space, but not be "test".
1. The code I've shown is not full, so the build error is expected.