[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kate
From:       Paul Giannaros <ceruleanblaze () gmail ! com>
Date:       2008-04-18 0:23:47
Message-ID: 1208478227.539578.5702.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 798344 by giannaros:

KateDocumentScript is now as featureful as its KJS predecessor.
KateScriptView needs the same level of love. Python indent script seems
to work fine now, but the C indenter doesn't -- it complains of a
SyntaxError. Anyone?



 M  +2 -0      CMakeLists.txt  
 M  +10 -13    script/data/python.js  
 M  +2 -2      script/kateindentscript.cpp  
 M  +16 -12    script/katescript.cpp  
 M  +18 -16    script/katescript.h  
 A             script/katescriptdocument.cpp   [License: LGPL (v2)]
 A             script/katescriptdocument.h   [License: LGPL (v2)]
 M  +1 -1      script/katescriptmanager.h  


--- trunk/KDE/kdelibs/kate/CMakeLists.txt #798343:798344
@@ -63,6 +63,8 @@
 script/katescript.cpp
 script/kateindentscript.cpp
 script/katescriptmanager.cpp
+# scripting wrappers
+script/katescriptdocument.cpp
 
 # mode (modemanager and co)
 mode/katemodemanager.cpp
--- trunk/KDE/kdelibs/kate/script/data/python.js #798343:798344
@@ -53,28 +53,25 @@
 
 function indent(line, indentWidth, character) {
 //     dbg(document.attribute.toString());
-    dbg("indent character: " + character);
+//     dbg("indent character: " + character);
 //     dbg("line text: " + document.line(line));
     var currentLine = document.line(line);
-    dbg("current line: " + currentLine);
+//     dbg("current line: " + currentLine);
     var lastLine = document.line(line - 1);
     var lastCharacter = lastLine.lastCharacter();
     // we can't really indent line 0
     if(line == 0)
         return -2;
-    // check what state the last character of the previous line is in -- if 
-    // it's a string/comment, we don't want to go any further
-    var lastLetterType = document.attribute(line - 1, document.lineLength(line - 1) \
                - 1);
-    // 19 = docstring or comment, 20 = string
-    if((lastLetterType == 19 || lastLetterType == 20) && lastCharacter != "\"" && \
                lastCharacter != "'") {
-        dbg("attributes that we don't want! Returning");
+    // make sure the last line is code
+    if(!document.isCode(line - 1, document.lineLength(line - 1) - 1) && \
lastCharacter != "\"" && lastCharacter != "'") { +//         dbg("attributes that we \
don't want! Returning");  return -1;
     }
     // otherwise, check the line contents
     // for :, we simply indent
-    dbg('line without white space: ' + currentLine.sansWhiteSpace().length);
+//     dbg('line without white space: ' + currentLine.sansWhiteSpace().length);
     if(lastLine.endsWith(':')) {
-        dbg('indenting line for :');
+//         dbg('indenting line for :');
         return document.firstVirtualColumn(line - 1) + indentWidth;
     }
     // generally, when a brace is on its own at the end of a regular line
@@ -85,7 +82,7 @@
     // }
     // etc..
     else if(lastCharacter == '{' || lastCharacter == '[') {
-        dbg('indenting for { or [');
+//         dbg('indenting for { or [');
         return document.firstVirtualColumn(line - 1) + indentWidth;
     }
     // XX this introduces irritating bugs. Commenting it out for now
@@ -99,10 +96,10 @@
     // finally, a raise, pass, and continue should unindent
     lastLine = lastLine.stripWhiteSpace();
     if(lastLine == 'continue' || lastLine == 'pass' || lastLine == 'raise' || \
                lastLine.startsWith('raise ')) {
-        dbg('unindenting line for keyword');
+//         dbg('unindenting line for keyword');
         return Math.max(0, document.firstVirtualColumn(line - 1) - indentWidth);
     }
-    dbg('continuing with regular indent');
+//     dbg('continuing with regular indent');
     return -1;
 }
 
--- trunk/KDE/kdelibs/kate/script/kateindentscript.cpp #798343:798344
@@ -38,9 +38,9 @@
 
   m_triggerCharactersSet = true;
   
-  m_triggerCharacters = global("triggerCharacters").toString ();
+  m_triggerCharacters = global("triggerCharacters").toString();
 
-  kDebug () << "trigger chars: '" << m_triggerCharacters << "'";
+  kDebug() << "trigger chars: '" << m_triggerCharacters << "'";
 
   return m_triggerCharacters;
 }
--- trunk/KDE/kdelibs/kate/script/katescript.cpp #798343:798344
@@ -17,6 +17,7 @@
 /// Boston, MA 02110-1301, USA.
 
 #include "katescript.h"
+#include "katescriptdocument.h"
 #include "kateview.h"
 #include "katedocument.h"
 
@@ -34,6 +35,7 @@
 
 namespace Kate {
   namespace Script {
+
     QScriptValue debug(QScriptContext *context, QScriptEngine *engine) {
       QStringList message;
       for(int i = 0; i < context->argumentCount(); ++i) {
@@ -41,18 +43,18 @@
       }
       // debug in blue to distance from other debug output if necessary
       std::cerr << "\033[34m" << qPrintable(message.join(" ")) << "\033[0m\n";
+      return engine->nullValue();
     }
+
   }
 }
-KateScriptDocument::KateScriptDocument ()
- : QObject ()
- , m_document (0)
+
+KateScriptView::KateScriptView() : QObject(), m_view (0)
 {
 }
 
-KateScriptView::KateScriptView ()
- : QObject ()
- , m_view (0)
+KateScriptCursor::KateScriptCursor(uint line, uint column, QObject *parent)
+  : QObject(parent), m_line(line), m_column(column)
 {
 }
 
@@ -64,10 +66,12 @@
 
 KateScript::~KateScript()
 {
-  // remove data...
-  delete m_engine;
-  delete m_document;
-  delete m_view;
+  if(m_loadSuccessful) {
+    // remove data...
+    delete m_engine;
+    delete m_document;
+    delete m_view;
+  }
 }
 
 void KateScript::displayBacktrace(const QScriptValue &error, const QString &header)
@@ -137,8 +141,8 @@
 
 void KateScript::initEngine() {
   // set the view/document objects as necessary
-  m_engine->globalObject().setProperty("document", m_engine->newQObject(m_document = \
                new KateScriptDocument ()));
-  m_engine->globalObject().setProperty("view", m_engine->newQObject(m_view = new \
KateScriptView ())); +  m_engine->globalObject().setProperty("document", \
m_engine->newQObject(m_document = new KateScriptDocument())); +  \
m_engine->globalObject().setProperty("view", m_engine->newQObject(m_view = new \
KateScriptView()));  
   m_engine->globalObject().setProperty("debug", \
m_engine->newFunction(Kate::Script::debug));  }
--- trunk/KDE/kdelibs/kate/script/katescript.h #798343:798344
@@ -32,6 +32,9 @@
 class KateDocument;
 class KateView;
 
+class KateScriptDocument;
+
+
 namespace Kate {
   enum ScriptType {
     /** The script is an indenter */
@@ -94,36 +97,35 @@
 
 //END
 
+
 /**
- * wrapper for a document
+ * wrapper for a view
  */
-class KateScriptDocument : public QObject, protected QScriptable
+class KateScriptView : public QObject, protected QScriptable
 {
   Q_OBJECT
-
   public:
-    KateScriptDocument ();
-
-    void setDocument (KateDocument *document) { m_document = document; }
-
+    KateScriptView ();
+    void setView (KateView *view) { m_view = view; }
   private:
-    KateDocument *m_document;
+    KateView *m_view;
 };
 
 /**
- * wrapper for a view
+ * Cursor wrapper -- used only when returning
  */
-class KateScriptView : public QObject, protected QScriptable
+class KateScriptCursor : public QObject
 {
   Q_OBJECT
-
+  Q_PROPERTY(uint line READ line)
+  Q_PROPERTY(uint column READ column)
   public:
-    KateScriptView ();
-
-    void setView (KateView *view) { m_view = view; }
-
+    KateScriptCursor(uint line, uint column, QObject *parent=0);
+    uint line() { return m_line; }
+    uint column() { return m_column; }
   private:
-    KateView *m_view;
+    uint m_line;
+    uint m_column;
 };
 
 //BEGIN KateScript
--- trunk/KDE/kdelibs/kate/script/katescriptmanager.h #798343:798344
@@ -111,7 +111,7 @@
 
     /**
      * hash of all existing indenter scripts
-     * hashs basename -> script
+     * hashes basename -> script
      */
     QHash<QString, KateIndentScript*> m_indentationScripts;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic