Commits

Henning Schröder committed 419cc6e

fixes

Comments (0)

Files changed (2)

codeaide/fileio.py

               strip_blank_lines=True, 
               untabify=True, 
               tab_width=4,
-              encoding=DEFAULT_ENCODING):
+              encoding=DEFAULT_ENCODING,
+              backup_name="%s~", autosave_name="#%s#"):
         self.settings = dict(
             backups=backups, 
-            strip_blank_lines=True,
-            untabify=True,
-            tab_width=4,
+            strip_blank_lines=strip_blank_lines,
+            untabify=untabify,
+            tab_width=tab_width,
             encoding=encoding,
-            backup_name="%s~",
-            autosave_name="#%s#",
+            backup_name=backup_name,
+            autosave_name=autosave_name,
           )
         self.file_dialog = FileDialog("Python Source (*.py *.pyw)")
 
     def guess_encoding(self, filename, text):
         lines = text.splitlines()
         enc_match = re.compile("#\s*-\*-\s*coding:\s*(.*?)\s*-\*-").match
-        
+        encoding = self.settings["encoding"]
         if filename.startswith(".py"):
-            encoding = self.settings["encoding"]
             for i, l in enumerate(lines):
                 if i > 200:
                     break
                 found = en_match(l)
                 if found:
                     encoding = found.group(1)
+                    print "found encoding", repr(encoding), "for", filename
                     break
-            return encoding
+        return encoding
 
 
     def open_dialog(self):
         text = f.read()
         f.close()
         encoding = encoding or self.guess_encoding(filename, text)
+        if self.settings["untabify"]:
+            tab = " " * self.settings["tab_width"]
+            text = text.replace("\t", tab)
+            if self.settings["strip_blank_lines"]:
+                new = []
+                lines = text.splitlines()
+                for l in lines:
+                    if len(l.strip()) == 0:
+                        new.append("")
+                    else:
+                        new.append(l)
+                text = "\n".join(new)
         return text.decode(encoding)
 
 
             if settings["strip_blank_lines"] and len(l.strip()) == 0:
                 l = ""
             elif settings["untabify"]:
-                l = l.replace(l, tab)
+                l = l.replace("\t", tab)
             out.append(out)
         text = "\n".join(out).encode(encoding)
         
         Configurable.__init__(self)
         self.filename = filename
         if text is None and filename and os.path.exists(filename):
-            text = self.file_io.load(filename)
+            text = FileIO.instance.load(filename)
         self.plain_text_layout = QPlainTextDocumentLayout(self)
         self.setDocumentLayout(self.plain_text_layout)
         if text:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.