mirror of
https://github.com/python/cpython.git
synced 2025-11-06 08:31:58 +00:00
py-cvs-rel2_1 (Rev 1.11 and 1.12) merge
Colorize "as" after "import" / use DEBUG instead of __debug__
This commit is contained in:
parent
d6c4c9e846
commit
6df4bf2864
1 changed files with 28 additions and 15 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
#$ win <Control-slash>
|
#$ win <Control-slash>
|
||||||
#$ unix <Control-slash>
|
#$ unix <Control-slash>
|
||||||
|
|
||||||
__debug__ = 0
|
DEBUG = 0
|
||||||
|
|
||||||
|
|
||||||
def any(name, list):
|
def any(name, list):
|
||||||
|
|
@ -28,6 +28,7 @@ def make_pat():
|
||||||
|
|
||||||
prog = re.compile(make_pat(), re.S)
|
prog = re.compile(make_pat(), re.S)
|
||||||
idprog = re.compile(r"\s+(\w+)", re.S)
|
idprog = re.compile(r"\s+(\w+)", re.S)
|
||||||
|
asprog = re.compile(r".*?\b(as)\b", re.S)
|
||||||
|
|
||||||
class ColorDelegator(Delegator):
|
class ColorDelegator(Delegator):
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ def __init__(self):
|
||||||
Delegator.__init__(self)
|
Delegator.__init__(self)
|
||||||
self.prog = prog
|
self.prog = prog
|
||||||
self.idprog = idprog
|
self.idprog = idprog
|
||||||
|
self.asprog = asprog
|
||||||
|
|
||||||
def setdelegate(self, delegate):
|
def setdelegate(self, delegate):
|
||||||
if self.delegate is not None:
|
if self.delegate is not None:
|
||||||
|
|
@ -82,13 +84,13 @@ def delete(self, index1, index2=None):
|
||||||
def notify_range(self, index1, index2=None):
|
def notify_range(self, index1, index2=None):
|
||||||
self.tag_add("TODO", index1, index2)
|
self.tag_add("TODO", index1, index2)
|
||||||
if self.after_id:
|
if self.after_id:
|
||||||
if __debug__: print "colorizing already scheduled"
|
if DEBUG: print "colorizing already scheduled"
|
||||||
return
|
return
|
||||||
if self.colorizing:
|
if self.colorizing:
|
||||||
self.stop_colorizing = 1
|
self.stop_colorizing = 1
|
||||||
if __debug__: print "stop colorizing"
|
if DEBUG: print "stop colorizing"
|
||||||
if self.allow_colorizing:
|
if self.allow_colorizing:
|
||||||
if __debug__: print "schedule colorizing"
|
if DEBUG: print "schedule colorizing"
|
||||||
self.after_id = self.after(1, self.recolorize)
|
self.after_id = self.after(1, self.recolorize)
|
||||||
|
|
||||||
close_when_done = None # Window to be closed when done colorizing
|
close_when_done = None # Window to be closed when done colorizing
|
||||||
|
|
@ -97,7 +99,7 @@ def close(self, close_when_done=None):
|
||||||
if self.after_id:
|
if self.after_id:
|
||||||
after_id = self.after_id
|
after_id = self.after_id
|
||||||
self.after_id = None
|
self.after_id = None
|
||||||
if __debug__: print "cancel scheduled recolorizer"
|
if DEBUG: print "cancel scheduled recolorizer"
|
||||||
self.after_cancel(after_id)
|
self.after_cancel(after_id)
|
||||||
self.allow_colorizing = 0
|
self.allow_colorizing = 0
|
||||||
self.stop_colorizing = 1
|
self.stop_colorizing = 1
|
||||||
|
|
@ -111,41 +113,41 @@ def toggle_colorize_event(self, event):
|
||||||
if self.after_id:
|
if self.after_id:
|
||||||
after_id = self.after_id
|
after_id = self.after_id
|
||||||
self.after_id = None
|
self.after_id = None
|
||||||
if __debug__: print "cancel scheduled recolorizer"
|
if DEBUG: print "cancel scheduled recolorizer"
|
||||||
self.after_cancel(after_id)
|
self.after_cancel(after_id)
|
||||||
if self.allow_colorizing and self.colorizing:
|
if self.allow_colorizing and self.colorizing:
|
||||||
if __debug__: print "stop colorizing"
|
if DEBUG: print "stop colorizing"
|
||||||
self.stop_colorizing = 1
|
self.stop_colorizing = 1
|
||||||
self.allow_colorizing = not self.allow_colorizing
|
self.allow_colorizing = not self.allow_colorizing
|
||||||
if self.allow_colorizing and not self.colorizing:
|
if self.allow_colorizing and not self.colorizing:
|
||||||
self.after_id = self.after(1, self.recolorize)
|
self.after_id = self.after(1, self.recolorize)
|
||||||
if __debug__:
|
if DEBUG:
|
||||||
print "auto colorizing turned", self.allow_colorizing and "on" or "off"
|
print "auto colorizing turned", self.allow_colorizing and "on" or "off"
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def recolorize(self):
|
def recolorize(self):
|
||||||
self.after_id = None
|
self.after_id = None
|
||||||
if not self.delegate:
|
if not self.delegate:
|
||||||
if __debug__: print "no delegate"
|
if DEBUG: print "no delegate"
|
||||||
return
|
return
|
||||||
if not self.allow_colorizing:
|
if not self.allow_colorizing:
|
||||||
if __debug__: print "auto colorizing is off"
|
if DEBUG: print "auto colorizing is off"
|
||||||
return
|
return
|
||||||
if self.colorizing:
|
if self.colorizing:
|
||||||
if __debug__: print "already colorizing"
|
if DEBUG: print "already colorizing"
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.stop_colorizing = 0
|
self.stop_colorizing = 0
|
||||||
self.colorizing = 1
|
self.colorizing = 1
|
||||||
if __debug__: print "colorizing..."
|
if DEBUG: print "colorizing..."
|
||||||
t0 = time.clock()
|
t0 = time.clock()
|
||||||
self.recolorize_main()
|
self.recolorize_main()
|
||||||
t1 = time.clock()
|
t1 = time.clock()
|
||||||
if __debug__: print "%.3f seconds" % (t1-t0)
|
if DEBUG: print "%.3f seconds" % (t1-t0)
|
||||||
finally:
|
finally:
|
||||||
self.colorizing = 0
|
self.colorizing = 0
|
||||||
if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
|
if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
|
||||||
if __debug__: print "reschedule colorizing"
|
if DEBUG: print "reschedule colorizing"
|
||||||
self.after_id = self.after(1, self.recolorize)
|
self.after_id = self.after(1, self.recolorize)
|
||||||
if self.close_when_done:
|
if self.close_when_done:
|
||||||
top = self.close_when_done
|
top = self.close_when_done
|
||||||
|
|
@ -198,6 +200,17 @@ def recolorize_main(self):
|
||||||
self.tag_add("DEFINITION",
|
self.tag_add("DEFINITION",
|
||||||
head + "+%dc" % a,
|
head + "+%dc" % a,
|
||||||
head + "+%dc" % b)
|
head + "+%dc" % b)
|
||||||
|
elif value == "import":
|
||||||
|
# color all the "as" words on same line;
|
||||||
|
# cheap approximation to the truth
|
||||||
|
while 1:
|
||||||
|
m1 = self.asprog.match(chars, b)
|
||||||
|
if not m1:
|
||||||
|
break
|
||||||
|
a, b = m1.span(1)
|
||||||
|
self.tag_add("KEYWORD",
|
||||||
|
head + "+%dc" % a,
|
||||||
|
head + "+%dc" % b)
|
||||||
m = self.prog.search(chars, m.end())
|
m = self.prog.search(chars, m.end())
|
||||||
if "SYNC" in self.tag_names(next + "-1c"):
|
if "SYNC" in self.tag_names(next + "-1c"):
|
||||||
head = next
|
head = next
|
||||||
|
|
@ -214,7 +227,7 @@ def recolorize_main(self):
|
||||||
self.tag_add("TODO", next)
|
self.tag_add("TODO", next)
|
||||||
self.update()
|
self.update()
|
||||||
if self.stop_colorizing:
|
if self.stop_colorizing:
|
||||||
if __debug__: print "colorizing stopped"
|
if DEBUG: print "colorizing stopped"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue