Skip to content

Commit

Permalink
Merge pull request #1247 from ernop/patch-1
Browse files Browse the repository at this point in the history
fixes a bug causing extra newlines after comments in colorized code.
  • Loading branch information
takluyver committed Jan 30, 2012
2 parents 69c627c + 1017601 commit b2e0923
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions IPython/utils/PyColorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def format2(self, raw, out = None, scheme = ''):
out should be a file-type object. Optionally, out can be given as the
string 'str' and the parser will automatically return the output in a
string."""

string_output = 0
if out == 'str' or self.out == 'str' or \
isinstance(self.out,StringIO.StringIO):
Expand All @@ -159,14 +159,14 @@ def format2(self, raw, out = None, scheme = ''):
return raw,error
else:
return None,error

# local shorthands
colors = self.color_table[scheme].colors
self.colors = colors # put in object so __call__ sees it

# Remove trailing whitespace and normalize tabs
self.raw = raw.expandtabs().rstrip()

# store line offsets in self.lines
self.lines = [0, 0]
pos = 0
Expand Down Expand Up @@ -217,11 +217,6 @@ def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line):
newpos = self.lines[srow] + scol
self.pos = newpos + len(toktext)

# handle newlines
if toktype in [token.NEWLINE, tokenize.NL]:
owrite(linesep)
return

# send the original whitespace, if needed
if newpos > oldpos:
owrite(self.raw[oldpos:newpos])
Expand All @@ -248,7 +243,7 @@ def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line):

# send text
owrite('%s%s%s' % (color,toktext,colors.normal))

def main(argv=None):
"""Run as a command-line script: colorize a python file or stdin using ANSI
color escapes and print to stdout.
Expand Down

0 comments on commit b2e0923

Please sign in to comment.