News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Patch, Auto add a semicolon for '{}' auto-complete

Started by Loaden, March 24, 2010, 08:47:56 AM

Previous topic - Next topic

Loaden

Quote from: thomas on March 24, 2010, 04:30:15 PM
namespace blah{};  ?
namespace blah{};
Sorry, I can not reproduce this problem.
Can you give me some demo?

Loaden

I make a new patch, welcome test.
Index: src/sdk/cbeditor.cpp

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

--- src/sdk/cbeditor.cpp (revision 6195)

+++ src/sdk/cbeditor.cpp (working copy)

@@ -414,6 +414,23 @@

             control->GotoPos(pos);
             if (ch == _T('{'))
             {
+                int curLine = control->GetCurrentLine();
+                int keyLine = curLine;
+                wxString text;
+                do
+                {
+                    int keyPos = control->GetLineIndentPosition(keyLine);
+                    int start = control->WordStartPosition(keyPos, true);
+                    int end = control->WordEndPosition(keyPos, true);
+                    text = control->GetTextRange(start, end);
+                }
+                while ((text.IsEmpty() || text == _T("public") || text == _T("protected") || text == _T("private"))
+                       && text != _T("namespace")
+                       && (--keyLine));
+
+                if (text == _T("class") || text == _T("struct") || text == _T("enum") || text == _T("union"))
+                    control->InsertText(control->GetLineEndPosition(curLine), _T(";"));
+
                 const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
                 if (reg.Matches(control->GetCurLine()))
                 {


[attachment deleted by admin]

thomas

Quote from: Loaden on March 24, 2010, 05:13:36 PMCan you give me some demo?
Quote from: oBFusCATed on March 24, 2010, 04:55:42 PM
namespace my
{
}; <--- here the semicolon is not needed!
That's what I wanted to point out:)
Although most compilers in non-strict mode will silently convert that trailing semicolon to ((void)0); and ignore it, nevertheless it doesn't belong there.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."