Fixed an issue in the editor setting the correct language.

Tue, 06 Sep 2011 18:18:40 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 06 Sep 2011 18:18:40 +0200
changeset 1295
b3db3070d104
parent 1294
d051b9d1426d
child 1297
6347cf782036

Fixed an issue in the editor setting the correct language.

QScintilla/Editor.py file | annotate | diff | comparison | revisions
--- a/QScintilla/Editor.py	Mon Sep 05 20:01:12 2011 +0200
+++ b/QScintilla/Editor.py	Tue Sep 06 18:18:40 2011 +0200
@@ -1123,7 +1123,8 @@
         from pygments.lexers import get_all_lexers
         lexerList = sorted([l[0] for l in get_all_lexers()])
         try:
-            lexerSel = lexerList.index(self.getLanguage(normalized=False))
+            lexerSel = lexerList.index(
+                self.getLanguage(normalized=False, forPygments=True))
         except ValueError:
             lexerSel = 0
         lexerName, ok = QInputDialog.getItem(
@@ -1355,19 +1356,19 @@
             language = self.project.getEditorLexerAssoc(os.path.basename(filename))
         if not language:
             ext = os.path.splitext(filename)[1]
-            if ext in [".py", ".pyw"]  and \
-               Preferences.getProject("DeterminePyFromProject")and \
-               self.project.isOpen() and \
-               self.fileName is not None and \
-               self.project.isProjectFile(self.fileName):
-                if self.project.getProjectLanguage() in ["Python", "Python2"]:
+            if ext in [".py", ".pyw"]:
+                if self.isPy2File():
                     language = "Python2"
+                elif self.isPy3File():
+                    language = "Python3"
                 else:
+                    # default is Python 3
                     language = "Python3"
             else:
                 filename = os.path.basename(filename)
                 language = Preferences.getEditorLexerAssoc(filename)
                 if language == "Python":
+                    # correction for Python
                     if self.isPy2File():
                         language = "Python2"
                     else:
@@ -1432,12 +1433,14 @@
         """
         return self.lexer_
         
-    def getLanguage(self, normalized=True):
+    def getLanguage(self, normalized=True, forPygments=False):
         """
         Public method to retrieve the language of the editor.
         
         @keyparam normalized flag indicating to normalize some Pygments
             lexer names (boolean)
+        @keyparam forPygments flag indicating to normalize some lexer
+            names for Pygments (boolean)
         @return language of the editor (string)
         """
         if self.apiLanguage == "Guessed" or self.apiLanguage.startswith("Pygments|"):
@@ -1448,9 +1451,15 @@
                     lang = "Python2"
                 elif lang == "Python 3":
                     lang = "Python3"
-            return lang
         else:
-            return self.apiLanguage
+            lang = self.apiLanguage
+            if forPygments:
+                # adjust some names to Pygments lexer names
+                if lang == "Python2":
+                    lang = "Python"
+                elif lang == "Python3":
+                    lang = "Python 3"
+        return lang
         
     def __bindCompleter(self, filename):
         """

eric ide

mercurial