eric6/QScintilla/MiniEditor.py

changeset 7635
0cdead130a81
parent 7628
f904d0eef264
child 7690
a59680062837
equal deleted inserted replaced
7634:8c3d033e5044 7635:0cdead130a81
3032 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded) 3032 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
3033 3033
3034 filename = os.path.basename(filename) 3034 filename = os.path.basename(filename)
3035 language = Preferences.getEditorLexerAssoc(filename) 3035 language = Preferences.getEditorLexerAssoc(filename)
3036 if language == "Python": 3036 if language == "Python":
3037 if self.__isPy2File(): 3037 language = "Python3"
3038 language = "Python2"
3039 else:
3040 language = "Python3"
3041 if language.startswith("Pygments|"): 3038 if language.startswith("Pygments|"):
3042 pyname = language.split("|", 1)[1] 3039 pyname = language.split("|", 1)[1]
3043 language = "" 3040 language = ""
3044 3041
3045 if not self.filetype: 3042 if not self.filetype:
3076 # now set the lexer properties 3073 # now set the lexer properties
3077 self.lexer_.initProperties() 3074 self.lexer_.initProperties()
3078 3075
3079 self.lexer_.setDefaultColor(self.lexer_.color(0)) 3076 self.lexer_.setDefaultColor(self.lexer_.color(0))
3080 self.lexer_.setDefaultPaper(self.lexer_.paper(0)) 3077 self.lexer_.setDefaultPaper(self.lexer_.paper(0))
3081 3078
3082 def __isPy2File(self):
3083 """
3084 Private method to return a flag indicating a Python 2 file.
3085
3086 @return flag indicating a Python 2 file (boolean)
3087 """
3088 if self.filetype in ["Python", "Python2"]:
3089 return True
3090
3091 if self.filetype == "":
3092 line0 = self.__textEdit.text(0)
3093 if (
3094 line0.startswith("#!") and
3095 ("python2" in line0 or
3096 ("python" in line0 and "python3" not in line0))
3097 ):
3098 return True
3099
3100 if self.__curFile is not None:
3101 exts = []
3102 for ext in Preferences.getDebugger("PythonExtensions").split():
3103 if ext.startswith("."):
3104 exts.append(ext)
3105 else:
3106 exts.append(".{0}".format(ext))
3107
3108 ext = os.path.splitext(self.__curFile)[1]
3109 if ext in exts:
3110 return True
3111
3112 return False
3113
3114 def __styleNeeded(self, position): 3079 def __styleNeeded(self, position):
3115 """ 3080 """
3116 Private slot to handle the need for more styling. 3081 Private slot to handle the need for more styling.
3117 3082
3118 @param position end position, that needs styling (integer) 3083 @param position end position, that needs styling (integer)
3144 # check filetype 3109 # check filetype
3145 from . import Lexers 3110 from . import Lexers
3146 supportedLanguages = Lexers.getSupportedLanguages() 3111 supportedLanguages = Lexers.getSupportedLanguages()
3147 if self.filetype in supportedLanguages: 3112 if self.filetype in supportedLanguages:
3148 bindName = supportedLanguages[self.filetype][1] 3113 bindName = supportedLanguages[self.filetype][1]
3149 elif self.filetype in ["Python", "Python2", "Python3", 3114 elif self.filetype in ["Python", "Python3", "MicroPython"]:
3150 "MicroPython"]:
3151 bindName = "dummy.py" 3115 bindName = "dummy.py"
3152 3116
3153 if not bindName and line0.startswith("#!"): 3117 if not bindName and line0.startswith("#!"):
3154 # #! marker detection 3118 # #! marker detection
3155 if "python3" in line0: 3119 if "python3" in line0:
3156 bindName = "dummy.py" 3120 bindName = "dummy.py"
3157 self.filetype = "Python3" 3121 self.filetype = "Python3"
3158 elif "python2" in line0:
3159 bindName = "dummy.py"
3160 self.filetype = "Python2"
3161 elif "python" in line0: 3122 elif "python" in line0:
3162 bindName = "dummy.py" 3123 bindName = "dummy.py"
3163 self.filetype = "Python2" 3124 self.filetype = "Python3"
3164 elif ("/bash" in line0 or "/sh" in line0): 3125 elif ("/bash" in line0 or "/sh" in line0):
3165 bindName = "dummy.sh" 3126 bindName = "dummy.sh"
3166 elif "ruby" in line0: 3127 elif "ruby" in line0:
3167 bindName = "dummy.rb" 3128 bindName = "dummy.rb"
3168 self.filetype = "Ruby" 3129 self.filetype = "Ruby"
3180 if match: 3141 if match:
3181 mode = match.group(1).lower() 3142 mode = match.group(1).lower()
3182 if mode in ["python3", "pypy3"]: 3143 if mode in ["python3", "pypy3"]:
3183 bindName = "dummy.py" 3144 bindName = "dummy.py"
3184 self.filetype = "Python3" 3145 self.filetype = "Python3"
3185 elif mode in ["python2", "pypy2", "python", "pypy"]:
3186 bindName = "dummy.py"
3187 self.filetype = "Python2"
3188 elif mode == "ruby": 3146 elif mode == "ruby":
3189 bindName = "dummy.rb" 3147 bindName = "dummy.rb"
3190 self.filetype = "Ruby" 3148 self.filetype = "Ruby"
3191 elif mode == "perl": 3149 elif mode == "perl":
3192 bindName = "dummy.pl" 3150 bindName = "dummy.pl"

eric ide

mercurial