8
8
9
9
DEBUG = False
10
10
11
+
11
12
def any (name , alternates ):
12
13
"Return a named group pattern matching list of alternates."
13
14
return "(?P<%s>" % name + "|" .join (alternates ) + ")"
14
15
16
+
15
17
def make_pat ():
16
18
kw = r"\b" + any ("KEYWORD" , keyword .kwlist ) + r"\b"
17
19
builtinlist = [str (name ) for name in dir (builtins )
18
- if not name .startswith ('_' ) and \
19
- name not in keyword .kwlist ]
20
+ if not name .startswith ('_' ) and
21
+ name not in keyword .kwlist ]
20
22
builtin = r"([^.'\"\\#]\b|^)" + any ("BUILTIN" , builtinlist ) + r"\b"
21
23
comment = any ("COMMENT" , [r"#[^\n]*" ])
22
24
stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"
@@ -25,12 +27,14 @@ def make_pat():
25
27
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
26
28
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
27
29
string = any ("STRING" , [sq3string , dq3string , sqstring , dqstring ])
28
- return kw + "|" + builtin + "|" + comment + "|" + string + \
29
- "|" + any ("SYNC" , [r"\n" ])
30
+ return (kw + "|" + builtin + "|" + comment + "|" + string +
31
+ "|" + any ("SYNC" , [r"\n" ]))
32
+
30
33
31
34
prog = re .compile (make_pat (), re .S )
32
35
idprog = re .compile (r"\s+(\w+)" , re .S )
33
36
37
+
34
38
def color_config (text ):
35
39
"""Set color options of Text widget.
36
40
@@ -49,7 +53,7 @@ def color_config(text):
49
53
selectforeground = select_colors ['foreground' ],
50
54
selectbackground = select_colors ['background' ],
51
55
inactiveselectbackground = select_colors ['background' ], # new in 8.5
52
- )
56
+ )
53
57
54
58
55
59
class ColorDelegator (Delegator ):
@@ -120,14 +124,17 @@ def LoadTagDefs(self):
120
124
"BUILTIN" : idleConf .GetHighlight (theme , "builtin" ),
121
125
"STRING" : idleConf .GetHighlight (theme , "string" ),
122
126
"DEFINITION" : idleConf .GetHighlight (theme , "definition" ),
123
- "SYNC" : {'background' :None ,'foreground' :None },
124
- "TODO" : {'background' :None ,'foreground' :None },
127
+ "SYNC" : {'background' : None , 'foreground' : None },
128
+ "TODO" : {'background' : None , 'foreground' : None },
125
129
"ERROR" : idleConf .GetHighlight (theme , "error" ),
126
- # The following is used by ReplaceDialog:
130
+ # "hit" is used by ReplaceDialog to mark matches. It shouldn't be changed by Colorizer, but
131
+ # that currently isn't technically possible. This should be moved elsewhere in the future
132
+ # when fixing the "hit" tag's visibility, or when the replace dialog is replaced with a
133
+ # non-modal alternative.
127
134
"hit" : idleConf .GetHighlight (theme , "hit" ),
128
135
}
129
136
130
- if DEBUG : print ('tagdefs' ,self .tagdefs )
137
+ if DEBUG : print ('tagdefs' , self .tagdefs )
131
138
132
139
def insert (self , index , chars , tags = None ):
133
140
"Insert chars into widget at index and mark for colorizing."
@@ -184,8 +191,8 @@ def toggle_colorize_event(self, event=None):
184
191
if self .allow_colorizing and not self .colorizing :
185
192
self .after_id = self .after (1 , self .recolorize )
186
193
if DEBUG :
187
- print ("auto colorizing turned" ,\
188
- self . allow_colorizing and "on" or "off" )
194
+ print ("auto colorizing turned" ,
195
+ "on" if self . allow_colorizing else "off" )
189
196
return "break"
190
197
191
198
def recolorize (self ):
@@ -232,10 +239,7 @@ def recolorize_main(self):
232
239
head , tail = item
233
240
self .tag_remove ("SYNC" , head , tail )
234
241
item = self .tag_prevrange ("SYNC" , head )
235
- if item :
236
- head = item [1 ]
237
- else :
238
- head = "1.0"
242
+ head = item [1 ] if item else "1.0"
239
243
240
244
chars = ""
241
245
next = head
@@ -307,7 +311,7 @@ def _color_delegator(parent): # htest #
307
311
"elif False: print(0)\n "
308
312
"else: float(None)\n "
309
313
"if iF + If + IF: 'keyword matching must respect case'\n "
310
- "if'': x or'' # valid string- keyword no-space combinations\n "
314
+ "if'': x or'' # valid keyword-string no-space combinations\n "
311
315
"async def f(): await g()\n "
312
316
"# All valid prefixes for unicode and byte strings should be colored.\n "
313
317
"'x', '''x''', \" x\" , \" \" \" x\" \" \" \n "
0 commit comments