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" |
1414 Private method to select a specific pygments lexer. |
1404 Private method to select a specific pygments lexer. |
1415 |
1405 |
1416 @return name of the selected pygments lexer (string) |
1406 @return name of the selected pygments lexer (string) |
1417 """ |
1407 """ |
1418 from pygments.lexers import get_all_lexers |
1408 from pygments.lexers import get_all_lexers |
1419 lexerList = sorted(l[0] for l in get_all_lexers()) |
1409 lexerList = sorted(lex[0] for lex in get_all_lexers()) |
1420 try: |
1410 try: |
1421 lexerSel = lexerList.index( |
1411 lexerSel = lexerList.index( |
1422 self.getLanguage(normalized=False, forPygments=True)) |
1412 self.getLanguage(normalized=False, forPygments=True)) |
1423 except ValueError: |
1413 except ValueError: |
1424 lexerSel = 0 |
1414 lexerSel = 0 |
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 keep 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 |
6496 Private method to clear warnings of a specific kind. |
6483 Private method to clear warnings of a specific kind. |
6497 |
6484 |
6498 @param warningKind kind of warning to clear (Editor.WarningCode, |
6485 @param warningKind kind of warning to clear (Editor.WarningCode, |
6499 Editor.WarningStyle) |
6486 Editor.WarningStyle) |
6500 """ |
6487 """ |
6501 assert warningKind in [Editor.WarningCode, Editor.WarningStyle] |
|
6502 |
|
6503 for handle in list(self.warnings.keys()): |
6488 for handle in list(self.warnings.keys()): |
6504 warnings = [] |
6489 warnings = [] |
6505 for msg, warningType in self.warnings[handle]: |
6490 for msg, warningType in self.warnings[handle]: |
6506 if warningType == warningKind: |
6491 if warningType == warningKind: |
6507 continue |
6492 continue |
8082 matcher = difflib.SequenceMatcher(None, oldL, newL) |
8067 matcher = difflib.SequenceMatcher(None, oldL, newL) |
8083 |
8068 |
8084 formatStr = "@@{0} {1} {2} {3}" |
8069 formatStr = "@@{0} {1} {2} {3}" |
8085 commands = [] |
8070 commands = [] |
8086 for token, i1, i2, j1, j2 in matcher.get_opcodes(): |
8071 for token, i1, i2, j1, j2 in matcher.get_opcodes(): |
8087 if token == "insert": |
8072 if token == "insert": # secok |
8088 commands.append(formatStr.format("i", j1, j2 - j1, -1)) |
8073 commands.append(formatStr.format("i", j1, j2 - j1, -1)) |
8089 commands.extend(newL[j1:j2]) |
8074 commands.extend(newL[j1:j2]) |
8090 elif token == "delete": |
8075 elif token == "delete": # secok |
8091 commands.append(formatStr.format("d", j1, i2 - i1, -1)) |
8076 commands.append(formatStr.format("d", j1, i2 - i1, -1)) |
8092 elif token == "replace": |
8077 elif token == "replace": # secok |
8093 commands.append(formatStr.format("r", j1, i2 - i1, j2 - j1)) |
8078 commands.append(formatStr.format("r", j1, i2 - i1, j2 - j1)) |
8094 commands.extend(newL[j1:j2]) |
8079 commands.extend(newL[j1:j2]) |
8095 |
8080 |
8096 return "\n".join(commands) + "\n" |
8081 return "\n".join(commands) + "\n" |
8097 |
8082 |