Author Topic: Patch, Auto add a semicolon for '{}' auto-complete  (Read 23149 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Patch, Auto add a semicolon for '{}' auto-complete
« Reply #15 on: March 24, 2010, 05:13:36 pm »
namespace blah{};  ?
namespace blah{};
Sorry, I can not reproduce this problem.
Can you give me some demo?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Patch, Auto add a semicolon for '{}' auto-complete
« Reply #16 on: March 24, 2010, 05:57:53 pm »
I make a new patch, welcome test.
Code
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]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Patch, Auto add a semicolon for '{}' auto-complete
« Reply #17 on: March 25, 2010, 10:56:17 am »
Can you give me some demo?
Code
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."