Editor, MiniEditor: harmonized the lexer determination code.

Sun, 10 Feb 2019 16:53:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 10 Feb 2019 16:53:42 +0100
changeset 6722
c58295e218b7
parent 6720
ba02b7a62dbc
child 6723
dd868b0bfdba

Editor, MiniEditor: harmonized the lexer determination code.
(grafted from 24a7a749e132cc8a3837edb69a57dbe8c9184795)

QScintilla/Editor.py file | annotate | diff | comparison | revisions
QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
--- a/QScintilla/Editor.py	Sun Feb 10 17:05:14 2019 +0100
+++ b/QScintilla/Editor.py	Sun Feb 10 16:53:42 2019 +0100
@@ -611,23 +611,17 @@
         elif line0.startswith("\\documentclass"):
             bindName = "dummy.tex"
         
-        # check filetype
         if not bindName and self.filetype:
-            if self.filetype in ["Python", "Python2"]:
-                bindName = "dummy.py"
-            elif self.filetype == "Python3":
+            # 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"
-            elif self.filetype == "Ruby":
-                bindName = "dummy.rb"
-            elif self.filetype == "D":
-                bindName = "dummy.d"
-            elif self.filetype == "Properties":
-                bindName = "dummy.ini"
-            elif self.filetype == "JavaScript":
-                bindName = "dummy.js"
-        
-        # #! marker detection
+        
         if not bindName and line0.startswith("#!"):
+            # #! marker detection
             if "python3" in line0:
                 bindName = "dummy.py"
                 self.filetype = "Python3"
--- a/QScintilla/MiniEditor.py	Sun Feb 10 17:05:14 2019 +0100
+++ b/QScintilla/MiniEditor.py	Sun Feb 10 16:53:42 2019 +0100
@@ -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.fileName
         
         return bindName
     

eric ide

mercurial