QScintilla/MiniEditor.py

branch
maintenance
changeset 6826
c6dda2cbe081
parent 6721
48c3ca1ac264
child 6842
c83dcb7c6147
--- a/QScintilla/MiniEditor.py	Sat Feb 16 10:27:50 2019 +0100
+++ b/QScintilla/MiniEditor.py	Sat Mar 02 11:15:24 2019 +0100
@@ -3077,7 +3077,7 @@
             (string)
         @return dummy file name to be used for binding a lexer (string)
         """
-        bindName = self.__curFile
+        bindName = ""
         line0 = line0.lower()
         
         # check first line if it does not start with #!
@@ -3090,18 +3090,17 @@
         elif line0.startswith("\\documentclass"):
             bindName = "dummy.tex"
         
-        # check filetype
-        if self.filetype in ["Python", "Python2", "Python3"]:
-            bindName = "dummy.py"
-        elif self.filetype == "Ruby":
-            bindName = "dummy.rb"
-        elif self.filetype == "D":
-            bindName = "dummy.d"
-        elif self.filetype == "Properties":
-            bindName = "dummy.ini"
+        if not bindName and self.filetype:
+            # check filetype
+            from . import Lexers
+            supportedLanguages = Lexers.getSupportedLanguages()
+            if self.filetype in supportedLanguages:
+                bindName = supportedLanguages[self.filetype][1]
+            elif self.filetype in ["Python", "Python2", "Python3"]:
+                bindName = "dummy.py"
         
-        # #! marker detection
-        if line0.startswith("#!"):
+        if not bindName and line0.startswith("#!"):
+            # #! marker detection
             if "python3" in line0:
                 bindName = "dummy.py"
                 self.filetype = "Python3"
@@ -3124,26 +3123,30 @@
                 bindName = "dummy.d"
                 self.filetype = "D"
         
-        # mode line detection: -*- mode: python -*-
-        match = re.search(r"mode[:=]\s*([-\w_.]+)", line0)
-        if match:
-            mode = match.group(1).lower()
-            if mode in ["python3", "pypy3"]:
-                bindName = "dummy.py"
-                self.filetype = "Python3"
-            elif mode in ["python2", "pypy2", "python", "pypy"]:
-                bindName = "dummy.py"
-                self.filetype = "Python2"
-            elif mode == "ruby":
-                bindName = "dummy.rb"
-                self.filetype = "Ruby"
-            elif mode == "perl":
-                bindName = "dummy.pl"
-            elif mode == "lua":
-                bindName = "dummy.lua"
-            elif mode in ["dmd", "d"]:
-                bindName = "dummy.d"
-                self.filetype = "D"
+        if not bindName:
+            # mode line detection: -*- mode: python -*-
+            match = re.search(r"mode[:=]\s*([-\w_.]+)", line0)
+            if match:
+                mode = match.group(1).lower()
+                if mode in ["python3", "pypy3"]:
+                    bindName = "dummy.py"
+                    self.filetype = "Python3"
+                elif mode in ["python2", "pypy2", "python", "pypy"]:
+                    bindName = "dummy.py"
+                    self.filetype = "Python2"
+                elif mode == "ruby":
+                    bindName = "dummy.rb"
+                    self.filetype = "Ruby"
+                elif mode == "perl":
+                    bindName = "dummy.pl"
+                elif mode == "lua":
+                    bindName = "dummy.lua"
+                elif mode in ["dmd", "d"]:
+                    bindName = "dummy.d"
+                    self.filetype = "D"
+        
+        if not bindName:
+            bindName = self.__curFile
         
         return bindName
     

eric ide

mercurial