Patch #1839 2007-01-19 13:01

dmoore

comment/uncomment multiple languages, smart indent python
Download
1839-comment_uncomm.patch (12.6 KB)
Category
Application::Refinement
Status
Accepted
Close date
2007-04-12 12:32
Assigned to
 
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 3508)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -2290,16 +2336,33 @@
             wxString indent = GetLineIndentString(currLine - 1);
             if (smartIndent)
             {
-                // if the last entered char before newline was an opening curly brace,
-                // increase indentation level (the closing brace is handled in another block)
+                cbStyledTextCtrl* stc = GetControl();
+                 // if the last entered char before newline was an opening curly brace,
+                 // increase indentation level (the closing brace is handled in another block)
+
+                // SMART INDENTING - THIS IS LANGUAGE SPECIFIC, BUT CURRENTLY ONLY IMPLEMENTED FOR C/C++ AND PYTHON
                 wxChar b = m_pData->GetLastNonWhitespaceChar();
-                if (b == _T('{'))
+                switch(stc->GetLexer())
                 {
-                    if(control->GetUseTabs())
-                        indent << _T('\t'); // 1 tab
-                    else
-                        indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
-                }
+                    case wxSCI_LEX_CPP:
+                        if (b == _T('{'))
+                        {
+                            if(control->GetUseTabs())
+                                indent << _T('\t'); // 1 tab
+                            else
+                                indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+                        }
+                        break;
+                    case wxSCI_LEX_PYTHON:
+                        if (b == _T(':'))
+                        {
+                            if(control->GetUseTabs())
+                                indent << _T('\t'); // 1 tab
+                            else
+                                indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+                        }
+                        break;
+                 }
             }
             control->InsertText(pos, indent);
             control->GotoPos(pos + indent.Length());
Index: src/src/main.cpp
===================================================================
--- src/src/main.cpp    (revision 3508)
+++ src/src/main.cpp    (working copy)
@@ -2693,6 +2693,87 @@
         ed->GetControl()->SelectAll();
 }

+
+wxString GetCommentToken(cbStyledTextCtrl* stc)
+{
+    wxString comment;
+    switch(stc->GetLexer())
+    {
+        case wxSCI_LEX_CONTAINER: comment = _T(""); break;
+        case wxSCI_LEX_NULL: comment = _T(""); break;
+        case wxSCI_LEX_PYTHON: comment = _T("#"); break;
+        case wxSCI_LEX_CPP: comment = _T("//"); break;
+        case wxSCI_LEX_HTML: comment = _T(""); break; // uses pairs <!-- and -->
+        case wxSCI_LEX_XML: comment = _T(""); break;
+        case wxSCI_LEX_PERL: comment = _T("#"); break;
+        case wxSCI_LEX_SQL: comment = _T("--"); break;
+        case wxSCI_LEX_VB: comment = _T("'"); break;
+        case wxSCI_LEX_PROPERTIES: comment = _T("#"); break;
+        case wxSCI_LEX_ERRORLIST: comment = _T(""); break;
+        case wxSCI_LEX_MAKEFILE: comment = _T("#"); break;
+        case wxSCI_LEX_BATCH: comment = _T("REM "); break;
+        case wxSCI_LEX_XCODE: comment = _T(""); break;
+        case wxSCI_LEX_LATEX: comment = _T("%"); break;
+        case wxSCI_LEX_LUA: comment = _T("--"); break;
+        case wxSCI_LEX_DIFF: comment = _T(""); break;
+        case wxSCI_LEX_CONF: comment = _T(""); break;
+        case wxSCI_LEX_PASCAL: comment = _T("//"); break;  //delphi style comments, otherwise use { } or (* and *)
+        case wxSCI_LEX_AVE: comment = _T(""); break;
+        case wxSCI_LEX_ADA: comment = _T("--"); break;
+        case wxSCI_LEX_LISP: comment = _T(";"); break;
+        case wxSCI_LEX_RUBY: comment = _T("#"); break;
+        case wxSCI_LEX_EIFFEL: comment = _T("--"); break;
+        case wxSCI_LEX_EIFFELKW: comment = _T("--"); break;
+        case wxSCI_LEX_TCL: comment = _T(""); break;
+        case wxSCI_LEX_NNCRONTAB: comment = _T(""); break;
+        case wxSCI_LEX_BULLANT: comment = _T(""); break;
+        case wxSCI_LEX_VBSCRIPT: comment = _T("'"); break;
+        case wxSCI_LEX_BAAN: comment = _T(""); break;
+        case wxSCI_LEX_MATLAB: comment = _T("%"); break;
+        case wxSCI_LEX_SCRIPTOL: comment = _T("`"); break;
+        case wxSCI_LEX_ASM: comment = _T("#"); break;
+        case wxSCI_LEX_CPPNOCASE: comment = _T("//"); break;
+        case wxSCI_LEX_FORTRAN: comment = _T("!"); break;
+        case wxSCI_LEX_CSS: comment = _T(""); break; // uses /* and */
+        case wxSCI_LEX_POV: comment = _T("//@-"); break;
+        case wxSCI_LEX_LOUT: comment = _T("#"); break;
+        case wxSCI_LEX_ESCRIPT: comment = _T(""); break; //couldn't find
+        case wxSCI_LEX_PS: comment = _T("%"); break; // not sure
download for full patch...
dmoore 2007-01-19 17:19

* adds block comment/uncomment support for most languages that allow single line comments

* reselects entire region after comment/uncomment (could be refined further)

* smart indent for python and cpp. (no smart indent for any other language)

dmoore 2007-01-19 21:35

updated patch for latest svn and also modified "toggle" comment

dmoore 2007-01-19 21:41

oops

mandrav 2007-04-12 12:32

Patch applied, thank you.