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

List:       pykde
Subject:    [PyKDE] Small autoindent feature for eric-3.0.1
From:       Torsten Marek <shlomme () gmx ! net>
Date:       2003-01-02 21:43:42
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Back in the days when QScintilla was really new, I wrote a little widget 
to test out its features, and I also added a small autoindentation which 
goes somewhat beyond autoIndent(bool), because it unindents on return or 
pass resp. two blank lines. It's more a poc, but nice, though, so I 
added it to the eric3 Editor widget.
There are some configuration features I miss about eric3, like setting 
the font for the pyshell or for brace highlighting, but I did not want 
to mess up the configuration dialogs (and I was to lazy, too), so I 
wrote no patch for that. Keep on hacking, eric3 is really great.

mfg

Torsten

["autoindent-eric-3.0.1.patch" (text/plain)]

--- Editor.py.old	2003-01-02 22:23:33.000000000 +0100
+++ Editor.py	2003-01-02 22:29:03.000000000 +0100
@@ -230,6 +230,40 @@
         self.menu.insertItem(QIconSet(IconPrint),
             self.trUtf8('Print'), self.printFile)
         self.connect(self.menu, SIGNAL('aboutToShow()'), self.handleShowContextMenu)
+        self.connect(self, SIGNAL("SCN_CHARADDED(int)"), self.indentEngine)
+    
+    
+    def getline(self, line):
+        t = self.text(line).left(self.lineLength(line))
+        return t.stripWhiteSpace()
+
+        
+    def indentEngine(self, t):
+        # on newline
+        if t == 10:
+            (line, index) = self.getCursorPosition()
+            oldin = self.indentation(line-1)
+            l = self.getline(line)
+            l_1 = self.getline(line-1)
+            l_2 = self.getline(line-2)
+            # increase indentation level by one if line above ends on :
+            if str(l_1.right(1)) == ":":
+                oldin += self.indentationWidth()
+            # decrease on return or pass
+            elif str(l_1) in ("return", "pass"):
+                oldin -= self.indentationWidth()
+            # after to blank lines, return to indentation of last defun
+            elif l_1.length() == l_2.length() == l.length() == 0 and oldin > 0:
+                i = 3
+                while(line - i > 0):
+                    ltext = self.getline(line - i) 
+                    if str(ltext.section(" ", 0, 0)) == "def":
+                        oldin = self.indentation(line - i)
+                        break
+                    i+=1
+            self.setIndentation(line, oldin)
+            self.setCursorPosition(line, oldin)
+    
     
     def bindLexer(self, language):
         """

[Attachment #6 (application/pgp-signature)]
_______________________________________________
PyKDE mailing list    PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde

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

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