eric6/QScintilla/Editor.py

changeset 7635
0cdead130a81
parent 7628
f904d0eef264
child 7637
c878e8255972
equal deleted inserted replaced
7634:8c3d033e5044 7635:0cdead130a81
653 # check filetype 653 # check filetype
654 from . import Lexers 654 from . import Lexers
655 supportedLanguages = Lexers.getSupportedLanguages() 655 supportedLanguages = Lexers.getSupportedLanguages()
656 if self.filetype in supportedLanguages: 656 if self.filetype in supportedLanguages:
657 bindName = supportedLanguages[self.filetype][1] 657 bindName = supportedLanguages[self.filetype][1]
658 elif self.filetype in ["Python", "Python2", "Python3", 658 elif self.filetype in ["Python", "Python3", "MicroPython"]:
659 "MicroPython"]:
660 bindName = "dummy.py" 659 bindName = "dummy.py"
661 660
662 if not bindName and line0.startswith("#!"): 661 if not bindName and line0.startswith("#!"):
663 # #! marker detection 662 # #! marker detection
664 if "python3" in line0: 663 if "python3" in line0:
665 bindName = "dummy.py" 664 bindName = "dummy.py"
666 self.filetype = "Python3" 665 self.filetype = "Python3"
667 elif "python2" in line0:
668 bindName = "dummy.py"
669 self.filetype = "Python2"
670 elif "python" in line0: 666 elif "python" in line0:
671 bindName = "dummy.py" 667 bindName = "dummy.py"
672 self.filetype = "Python2" 668 self.filetype = "Python3"
673 elif "pypy3" in line0: 669 elif "pypy3" in line0:
674 bindName = "dummy.py" 670 bindName = "dummy.py"
675 self.filetype = "Python3" 671 self.filetype = "Python3"
676 elif "pypy2" in line0:
677 bindName = "dummy.py"
678 self.filetype = "Python2"
679 elif "pypy" in line0: 672 elif "pypy" in line0:
680 bindName = "dummy.py" 673 bindName = "dummy.py"
681 self.filetype = "Python2" 674 self.filetype = "Python3"
682 elif ("/bash" in line0 or "/sh" in line0): 675 elif ("/bash" in line0 or "/sh" in line0):
683 bindName = "dummy.sh" 676 bindName = "dummy.sh"
684 elif "ruby" in line0: 677 elif "ruby" in line0:
685 bindName = "dummy.rb" 678 bindName = "dummy.rb"
686 self.filetype = "Ruby" 679 self.filetype = "Ruby"
698 if match: 691 if match:
699 mode = match.group(1).lower() 692 mode = match.group(1).lower()
700 if mode in ["python3", "pypy3"]: 693 if mode in ["python3", "pypy3"]:
701 bindName = "dummy.py" 694 bindName = "dummy.py"
702 self.filetype = "Python3" 695 self.filetype = "Python3"
703 elif mode in ["python2", "pypy2", "python", "pypy"]:
704 bindName = "dummy.py"
705 self.filetype = "Python2"
706 elif mode == "ruby": 696 elif mode == "ruby":
707 bindName = "dummy.rb" 697 bindName = "dummy.rb"
708 self.filetype = "Ruby" 698 self.filetype = "Ruby"
709 elif mode == "perl": 699 elif mode == "perl":
710 bindName = "dummy.pl" 700 bindName = "dummy.pl"
1739 if language == "Python": 1729 if language == "Python":
1740 # correction for Python 1730 # correction for Python
1741 pyVer = Utilities.determinePythonVersion( 1731 pyVer = Utilities.determinePythonVersion(
1742 filename, self.text(0), self) 1732 filename, self.text(0), self)
1743 language = "Python{0}".format(pyVer) 1733 language = "Python{0}".format(pyVer)
1744 if language in ['Python2', 'Python3', 'MicroPython', 'Ruby', 1734 if language in ['Python3', 'MicroPython', 'Ruby',
1745 'JavaScript', 'YAML', 'JSON']: 1735 'JavaScript', 'YAML', 'JSON']:
1746 self.filetype = language 1736 self.filetype = language
1747 else: 1737 else:
1748 self.filetype = "" 1738 self.filetype = ""
1749 else: 1739 else:
1841 self.apiLanguage.startswith("Pygments|") 1831 self.apiLanguage.startswith("Pygments|")
1842 ): 1832 ):
1843 lang = self.lexer_.name() 1833 lang = self.lexer_.name()
1844 if normalized: 1834 if normalized:
1845 # adjust some Pygments lexer names 1835 # adjust some Pygments lexer names
1846 if lang == "Python": 1836 if lang == "Python 3":
1847 lang = "Python2"
1848 elif lang == "Python 3":
1849 lang = "Python3" 1837 lang = "Python3"
1850 else: 1838 else:
1851 lang = self.apiLanguage 1839 lang = self.apiLanguage
1852 if forPygments: 1840 if forPygments:
1853 # adjust some names to Pygments lexer names 1841 # adjust some names to Pygments lexer names
1854 if lang == "Python2": 1842 if lang == "Python3":
1855 lang = "Python"
1856 elif lang == "Python3":
1857 lang = "Python 3" 1843 lang = "Python 3"
1858 return lang 1844 return lang
1859 1845
1860 def getApiLanguage(self): 1846 def getApiLanguage(self):
1861 """ 1847 """
2030 """ 2016 """
2031 return self.encoding 2017 return self.encoding
2032 2018
2033 def __getPyVersion(self): 2019 def __getPyVersion(self):
2034 """ 2020 """
2035 Private method to return the Python main version (2 or 3) or 0 if it's 2021 Private method to return the Python main version or 0 if it's
2036 not a Python file at all. 2022 not a Python file at all.
2037 2023
2038 @return Python version (2 or 3) or 0 if it's not a Python file (int) 2024 @return Python version or 0 if it's not a Python file (int)
2039 """ 2025 """
2040 return Utilities.determinePythonVersion( 2026 return Utilities.determinePythonVersion(
2041 self.fileName, self.text(0), self) 2027 self.fileName, self.text(0), self)
2042 2028
2043 def isPyFile(self): 2029 def isPyFile(self):
2044 """ 2030 """
2045 Public method to return a flag indicating a Python (2 or 3) file. 2031 Public method to return a flag indicating a Python (2 or 3) file.
2046 2032
2047 @return flag indicating a Python (2 or 3) file (boolean) 2033 @return flag indicating a Python3 file (boolean)
2048 """ 2034 """
2049 return self.__getPyVersion() in [2, 3] 2035 return self.__getPyVersion() == 3
2050 2036
2051 def isPy2File(self): 2037 def isPy2File(self):
2052 """ 2038 """
2053 Public method to return a flag indicating a Python2 file. 2039 Public method to return a flag indicating a Python2 file.
2054 2040
2055 @return flag indicating a Python2 file (boolean) 2041 @return flag reporting always False
2056 """ 2042 @rtype bool
2057 return self.__getPyVersion() == 2 2043 """
2044 # kept to kep the API compatible for plugins
2045 return False
2058 2046
2059 def isPy3File(self): 2047 def isPy3File(self):
2060 """ 2048 """
2061 Public method to return a flag indicating a Python3 file. 2049 Public method to return a flag indicating a Python3 file.
2062 2050
5533 ) 5521 )
5534 coEnable = ( 5522 coEnable = (
5535 (coEnable or 5523 (coEnable or
5536 os.path.isfile("{0}.coverage".format(basename)) or 5524 os.path.isfile("{0}.coverage".format(basename)) or
5537 os.path.isfile("{0}.coverage".format(tbasename))) and 5525 os.path.isfile("{0}.coverage".format(tbasename))) and
5538 (self.project.isPy3Project() or 5526 self.project.isPy3Project()
5539 self.project.isPy2Project())
5540 ) 5527 )
5541 5528
5542 # now check ourselves 5529 # now check ourselves
5543 fn = self.getFileName() 5530 fn = self.getFileName()
5544 if fn is not None: 5531 if fn is not None:

eric ide

mercurial