Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Lib/idlelib/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ def make_pat():
# self.file = open("file") :
# 1st 'file' colorized normal, 2nd as builtin, 3rd as string
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
trailing_space = any("TRAILINGSPACE", [r"[ \t]+(?=\n)"])
comment = any("COMMENT", [r"#[^\n]*"])
stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?"
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
return kw + "|" + builtin + "|" + comment + "|" + string +\
"|" + any("SYNC", [r"\n"])
return kw + "|" + builtin + "|" + trailing_space + "|" + comment +\
"|" + string + "|" + any("SYNC", [r"\n"])

prog = re.compile(make_pat(), re.S)
idprog = re.compile(r"\s+(\w+)", re.S)
Expand Down Expand Up @@ -56,6 +57,7 @@ class ColorDelegator(Delegator):

def __init__(self):
Delegator.__init__(self)
self.delay_render_trailing_space = None
self.prog = prog
self.idprog = idprog
self.LoadTagDefs()
Expand Down Expand Up @@ -90,6 +92,7 @@ def LoadTagDefs(self):
"SYNC": {'background':None,'foreground':None},
"TODO": {'background':None,'foreground':None},
"ERROR": idleConf.GetHighlight(theme, "error"),
"TRAILINGSPACE": idleConf.GetHighlight(theme, "error"),
# The following is used by ReplaceDialog:
"hit": idleConf.GetHighlight(theme, "hit"),
}
Expand Down Expand Up @@ -157,6 +160,9 @@ def toggle_colorize_event(self, event):

def recolorize(self):
self.after_id = None
if self.delay_render_trailing_space is not None:
self.after_cancel(self.delay_render_trailing_space)
self.delay_render_trailing_space = None
if not self.delegate:
if DEBUG: print("no delegate")
return
Expand Down Expand Up @@ -220,9 +226,17 @@ def recolorize_main(self):
for key, value in m.groupdict().items():
if value:
a, b = m.span(key)
self.tag_add(key,
head + "+%dc" % a,
head + "+%dc" % b)
if key == "TRAILINGSPACE" and b - a == 1:
self.delay_render_trailing_space = self.after(
1000,
self.tag_add,
key,
head + "+%dc" % a,
head + "+%dc" % b)
else:
self.tag_add(key,
head + "+%dc" % a,
head + "+%dc" % b)
if value in ("def", "class"):
m1 = self.idprog.match(chars, b)
if m1:
Expand Down